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