WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
PneumaticsBase.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <memory>
8
9#include <units/current.h>
10#include <units/pressure.h>
11#include <units/time.h>
12#include <units/voltage.h>
13
16
17namespace frc {
18class Solenoid;
19class DoubleSolenoid;
20class Compressor;
21
22/**
23 * Base class for pneumatics devices.
24 */
26 public:
27 virtual ~PneumaticsBase() = default;
28
29 /**
30 * Returns whether the compressor is active or not.
31 *
32 * @return True if the compressor is on - otherwise false.
33 */
34 virtual bool GetCompressor() const = 0;
35
36 /**
37 * Returns the state of the pressure switch.
38 *
39 * @return True if pressure switch indicates that the system is full,
40 * otherwise false.
41 */
42 virtual bool GetPressureSwitch() const = 0;
43
44 /**
45 * Returns the current drawn by the compressor.
46 *
47 * @return The current drawn by the compressor.
48 */
49 virtual units::ampere_t GetCompressorCurrent() const = 0;
50
51 /** Disables the compressor. */
52 virtual void DisableCompressor() = 0;
53
54 /**
55 * Enables the compressor in digital mode using the digital pressure switch.
56 * The compressor will turn on when the pressure switch indicates that the
57 * system is not full, and will turn off when the pressure switch indicates
58 * that the system is full.
59 */
60 virtual void EnableCompressorDigital() = 0;
61
62 /**
63 * If supported by the device, enables the compressor in analog mode. This
64 * mode uses an analog pressure sensor connected to analog channel 0 to cycle
65 * the compressor. The compressor will turn on when the pressure drops below
66 * {@code minPressure} and will turn off when the pressure reaches {@code
67 * maxPressure}. This mode is only supported by the REV PH with the REV Analog
68 * Pressure Sensor connected to analog channel 0.
69 *
70 * On CTRE PCM, this will enable digital control.
71 *
72 * @param minPressure The minimum pressure. The compressor will turn on
73 * when the pressure drops below this value.
74 * @param maxPressure The maximum pressure. The compressor will turn
75 * off when the pressure reaches this value.
76 */
78 units::pounds_per_square_inch_t minPressure,
79 units::pounds_per_square_inch_t maxPressure) = 0;
80
81 /**
82 * If supported by the device, enables the compressor in hybrid mode. This
83 * mode uses both a digital pressure switch and an analog pressure sensor
84 * connected to analog channel 0 to cycle the compressor. This mode is only
85 * supported by the REV PH with the REV Analog Pressure Sensor connected to
86 * analog channel 0.
87 *
88 * The compressor will turn on when \a both:
89 *
90 * - The digital pressure switch indicates the system is not full AND
91 * - The analog pressure sensor indicates that the pressure in the system
92 * is below the specified minimum pressure.
93 *
94 * The compressor will turn off when \a either:
95 *
96 * - The digital pressure switch is disconnected or indicates that the system
97 * is full OR
98 * - The pressure detected by the analog sensor is greater than the specified
99 * maximum pressure.
100 *
101 * On CTRE PCM, this will enable digital control.
102 *
103 * @param minPressure The minimum pressure. The compressor will turn on
104 * when the pressure drops below this value and the pressure switch indicates
105 * that the system is not full.
106 * @param maxPressure The maximum pressure. The compressor will turn
107 * off when the pressure reaches this value or the pressure switch is
108 * disconnected or indicates that the system is full.
109 */
111 units::pounds_per_square_inch_t minPressure,
112 units::pounds_per_square_inch_t maxPressure) = 0;
113
114 /**
115 * Returns the active compressor configuration.
116 *
117 * @return The active compressor configuration.
118 */
120
121 /**
122 * Sets solenoids on a pneumatics module.
123 *
124 * @param mask Bitmask indicating which solenoids to set. The LSB represents
125 * solenoid 0.
126 * @param values Bitmask indicating the desired states of the solenoids. The
127 * LSB represents solenoid 0.
128 */
129 virtual void SetSolenoids(int mask, int values) = 0;
130
131 /**
132 * Gets a bitmask of solenoid values.
133 *
134 * @return Bitmask containing the state of the solenoids. The LSB represents
135 * solenoid 0.
136 */
137 virtual int GetSolenoids() const = 0;
138
139 /**
140 * Get module number for this module.
141 *
142 * @return module number
143 */
144 virtual int GetModuleNumber() const = 0;
145
146 /**
147 * Get a bitmask of disabled solenoids.
148 *
149 * @return Bitmask indicating disabled solenoids. The LSB represents solenoid
150 * 0.
151 */
152 virtual int GetSolenoidDisabledList() const = 0;
153
154 /**
155 * Fire a single solenoid shot.
156 *
157 * @param index solenoid index
158 */
159 virtual void FireOneShot(int index) = 0;
160
161 /**
162 * Set the duration for a single solenoid shot.
163 *
164 * @param index solenoid index
165 * @param duration shot duration
166 */
167 virtual void SetOneShotDuration(int index, units::second_t duration) = 0;
168
169 /**
170 * Check if a solenoid channel is valid.
171 *
172 * @param channel Channel to check
173 * @return True if channel exists
174 */
175 virtual bool CheckSolenoidChannel(int channel) const = 0;
176
177 /**
178 * Check to see if the solenoids marked in the bitmask can be reserved, and if
179 * so, reserve them.
180 *
181 * @param mask The bitmask of solenoids to reserve. The LSB represents
182 * solenoid 0.
183 * @return 0 if successful; mask of solenoids that couldn't be allocated
184 * otherwise
185 */
186 virtual int CheckAndReserveSolenoids(int mask) = 0;
187
188 /**
189 * Unreserve the solenoids marked in the bitmask.
190 *
191 * @param mask The bitmask of solenoids to unreserve. The LSB represents
192 * solenoid 0.
193 */
194 virtual void UnreserveSolenoids(int mask) = 0;
195
196 /**
197 * Reserve the compressor.
198 *
199 * @return true if successful; false if compressor already reserved
200 */
201 virtual bool ReserveCompressor() = 0;
202
203 /**
204 * Unreserve the compressor.
205 */
206 virtual void UnreserveCompressor() = 0;
207
208 /**
209 * If supported by the device, returns the raw voltage of the specified analog
210 * input channel.
211 *
212 * This function is only supported by the REV PH. On CTRE PCM, this will
213 * return 0.
214 *
215 * @param channel The analog input channel to read voltage from.
216 * @return The voltage of the specified analog input channel.
217 */
218 virtual units::volt_t GetAnalogVoltage(int channel) const = 0;
219
220 /**
221 * If supported by the device, returns the pressure read by an analog
222 * pressure sensor on the specified analog input channel.
223 *
224 * This function is only supported by the REV PH. On CTRE PCM, this will
225 * return 0.
226 *
227 * @param channel The analog input channel to read pressure from.
228 * @return The pressure read by an analog pressure sensor on the
229 * specified analog input channel.
230 */
231 virtual units::pounds_per_square_inch_t GetPressure(int channel) const = 0;
232
233 /**
234 * Create a solenoid object for the specified channel.
235 *
236 * @param channel solenoid channel
237 * @return Solenoid object
238 */
239 virtual Solenoid MakeSolenoid(int channel) = 0;
240
241 /**
242 * Create a double solenoid object for the specified channels.
243 *
244 * @param forwardChannel solenoid channel for forward
245 * @param reverseChannel solenoid channel for reverse
246 * @return DoubleSolenoid object
247 */
248 virtual DoubleSolenoid MakeDoubleSolenoid(int forwardChannel,
249 int reverseChannel) = 0;
250
251 /**
252 * Create a compressor object.
253 *
254 * @return Compressor object
255 */
257
258 /**
259 * For internal use to get a module for a specific type.
260 *
261 * @param module module number
262 * @param moduleType module type
263 * @return module
264 */
265 static std::shared_ptr<PneumaticsBase> GetForType(
266 int module, PneumaticsModuleType moduleType);
267
268 /**
269 * For internal use to get the default for a specific type.
270 *
271 * @param moduleType module type
272 * @return module default
273 */
275};
276} // namespace frc
Class for operating a compressor connected to a pneumatics module.
Definition Compressor.h:35
DoubleSolenoid class for running 2 channels of high voltage Digital Output on a pneumatics module.
Definition DoubleSolenoid.h:26
Base class for pneumatics devices.
Definition PneumaticsBase.h:25
virtual DoubleSolenoid MakeDoubleSolenoid(int forwardChannel, int reverseChannel)=0
Create a double solenoid object for the specified channels.
virtual void SetSolenoids(int mask, int values)=0
Sets solenoids on a pneumatics module.
virtual int GetModuleNumber() const =0
Get module number for this module.
virtual Solenoid MakeSolenoid(int channel)=0
Create a solenoid object for the specified channel.
static std::shared_ptr< PneumaticsBase > GetForType(int module, PneumaticsModuleType moduleType)
For internal use to get a module for a specific type.
virtual units::ampere_t GetCompressorCurrent() const =0
Returns the current drawn by the compressor.
virtual void EnableCompressorAnalog(units::pounds_per_square_inch_t minPressure, units::pounds_per_square_inch_t maxPressure)=0
If supported by the device, enables the compressor in analog mode.
virtual void DisableCompressor()=0
Disables the compressor.
virtual void SetOneShotDuration(int index, units::second_t duration)=0
Set the duration for a single solenoid shot.
virtual Compressor MakeCompressor()=0
Create a compressor object.
virtual void FireOneShot(int index)=0
Fire a single solenoid shot.
virtual void EnableCompressorDigital()=0
Enables the compressor in digital mode using the digital pressure switch.
static int GetDefaultForType(PneumaticsModuleType moduleType)
For internal use to get the default for a specific type.
virtual void UnreserveCompressor()=0
Unreserve the compressor.
virtual units::volt_t GetAnalogVoltage(int channel) const =0
If supported by the device, returns the raw voltage of the specified analog input channel.
virtual bool CheckSolenoidChannel(int channel) const =0
Check if a solenoid channel is valid.
virtual ~PneumaticsBase()=default
virtual units::pounds_per_square_inch_t GetPressure(int channel) const =0
If supported by the device, returns the pressure read by an analog pressure sensor on the specified a...
virtual void UnreserveSolenoids(int mask)=0
Unreserve the solenoids marked in the bitmask.
virtual void EnableCompressorHybrid(units::pounds_per_square_inch_t minPressure, units::pounds_per_square_inch_t maxPressure)=0
If supported by the device, enables the compressor in hybrid mode.
virtual int GetSolenoids() const =0
Gets a bitmask of solenoid values.
virtual CompressorConfigType GetCompressorConfigType() const =0
Returns the active compressor configuration.
virtual bool ReserveCompressor()=0
Reserve the compressor.
virtual int GetSolenoidDisabledList() const =0
Get a bitmask of disabled solenoids.
virtual bool GetCompressor() const =0
Returns whether the compressor is active or not.
virtual int CheckAndReserveSolenoids(int mask)=0
Check to see if the solenoids marked in the bitmask can be reserved, and if so, reserve them.
virtual bool GetPressureSwitch() const =0
Returns the state of the pressure switch.
Solenoid class for running high voltage Digital Output on a pneumatics module.
Definition Solenoid.h:26
Definition CAN.h:11
CompressorConfigType
Compressor config type.
Definition CompressorConfigType.h:11
PneumaticsModuleType
Pneumatics module type.
Definition PneumaticsModuleType.h:11