WPILibC++ 2024.3.2
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 to set
125 * @param values solenoid values
126 */
127 virtual void SetSolenoids(int mask, int values) = 0;
128
129 /**
130 * Gets a bitmask of solenoid values.
131 *
132 * @return solenoid values
133 */
134 virtual int GetSolenoids() const = 0;
135
136 /**
137 * Get module number for this module.
138 *
139 * @return module number
140 */
141 virtual int GetModuleNumber() const = 0;
142
143 /**
144 * Get a bitmask of disabled solenoids.
145 *
146 * @return bitmask of disabled solenoids
147 */
148 virtual int GetSolenoidDisabledList() const = 0;
149
150 /**
151 * Fire a single solenoid shot.
152 *
153 * @param index solenoid index
154 */
155 virtual void FireOneShot(int index) = 0;
156
157 /**
158 * Set the duration for a single solenoid shot.
159 *
160 * @param index solenoid index
161 * @param duration shot duration
162 */
163 virtual void SetOneShotDuration(int index, units::second_t duration) = 0;
164
165 /**
166 * Check if a solenoid channel is valid.
167 *
168 * @param channel Channel to check
169 * @return True if channel exists
170 */
171 virtual bool CheckSolenoidChannel(int channel) const = 0;
172
173 /**
174 * Check to see if the masked solenoids can be reserved, and if not reserve
175 * them.
176 *
177 * @param mask The bitmask of solenoids to reserve
178 * @return 0 if successful; mask of solenoids that couldn't be allocated
179 * otherwise
180 */
181 virtual int CheckAndReserveSolenoids(int mask) = 0;
182
183 /**
184 * Unreserve the masked solenoids.
185 *
186 * @param mask The bitmask of solenoids to unreserve
187 */
188 virtual void UnreserveSolenoids(int mask) = 0;
189
190 /**
191 * Reserve the compressor.
192 *
193 * @return true if successful; false if compressor already reserved
194 */
195 virtual bool ReserveCompressor() = 0;
196
197 /**
198 * Unreserve the compressor.
199 */
200 virtual void UnreserveCompressor() = 0;
201
202 /**
203 * If supported by the device, returns the raw voltage of the specified analog
204 * input channel.
205 *
206 * This function is only supported by the REV PH. On CTRE PCM, this will
207 * return 0.
208 *
209 * @param channel The analog input channel to read voltage from.
210 * @return The voltage of the specified analog input channel.
211 */
212 virtual units::volt_t GetAnalogVoltage(int channel) const = 0;
213
214 /**
215 * If supported by the device, returns the pressure read by an analog
216 * pressure sensor on the specified analog input channel.
217 *
218 * This function is only supported by the REV PH. On CTRE PCM, this will
219 * return 0.
220 *
221 * @param channel The analog input channel to read pressure from.
222 * @return The pressure read by an analog pressure sensor on the
223 * specified analog input channel.
224 */
225 virtual units::pounds_per_square_inch_t GetPressure(int channel) const = 0;
226
227 /**
228 * Create a solenoid object for the specified channel.
229 *
230 * @param channel solenoid channel
231 * @return Solenoid object
232 */
233 virtual Solenoid MakeSolenoid(int channel) = 0;
234
235 /**
236 * Create a double solenoid object for the specified channels.
237 *
238 * @param forwardChannel solenoid channel for forward
239 * @param reverseChannel solenoid channel for reverse
240 * @return DoubleSolenoid object
241 */
242 virtual DoubleSolenoid MakeDoubleSolenoid(int forwardChannel,
243 int reverseChannel) = 0;
244
245 /**
246 * Create a compressor object.
247 *
248 * @return Compressor object
249 */
251
252 /**
253 * For internal use to get a module for a specific type.
254 *
255 * @param module module number
256 * @param moduleType module type
257 * @return module
258 */
259 static std::shared_ptr<PneumaticsBase> GetForType(
260 int module, PneumaticsModuleType moduleType);
261
262 /**
263 * For internal use to get the default for a specific type.
264 *
265 * @param moduleType module type
266 * @return module default
267 */
269};
270} // 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 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
Compressor config type.
Definition: CompressorConfigType.h:11
PneumaticsModuleType
Pneumatics module type.
Definition: PneumaticsModuleType.h:11