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