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