WPILibC++ 2023.4.3
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 mask
121 * @param values values
122 */
123 virtual void SetSolenoids(int mask, int values) = 0;
124
125 /**
126 * Gets a bitmask of solenoid values.
127 *
128 * @return 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 virtual bool ReserveCompressor() = 0;
187
188 virtual void UnreserveCompressor() = 0;
189
190 /**
191 * If supported by the device, returns the raw voltage of the specified analog
192 * input channel.
193 *
194 * This function is only supported by the REV PH. On CTRE PCM, this will
195 * return 0.
196 *
197 * @param channel The analog input channel to read voltage from.
198 * @return The voltage of the specified analog input channel.
199 */
200 virtual units::volt_t GetAnalogVoltage(int channel) const = 0;
201
202 /**
203 * If supported by the device, returns the pressure read by an analog
204 * pressure sensor on the specified analog 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 pressure from.
210 * @return The pressure read by an analog pressure sensor on the
211 * specified analog input channel.
212 */
213 virtual units::pounds_per_square_inch_t GetPressure(int channel) const = 0;
214
215 virtual Solenoid MakeSolenoid(int channel) = 0;
216 virtual DoubleSolenoid MakeDoubleSolenoid(int forwardChannel,
217 int reverseChannel) = 0;
219
220 /**
221 * For internal use to get a module for a specific type.
222 *
223 * @param module module number
224 * @param moduleType module type
225 * @return module
226 */
227 static std::shared_ptr<PneumaticsBase> GetForType(
228 int module, PneumaticsModuleType moduleType);
229
230 /**
231 * For internal use to get the default for a specific type.
232 *
233 * @param moduleType module type
234 * @return module default
235 */
237};
238} // namespace frc
Class for operating a compressor connected to a pneumatics module.
Definition: Compressor.h:36
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
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
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
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
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
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: AprilTagFieldLayout.h:22
CompressorConfigType
Definition: CompressorConfigType.h:8
PneumaticsModuleType
Definition: PneumaticsModuleType.h:8