WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
PneumaticHub.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 <hal/Types.h>
10#include <units/pressure.h>
11#include <wpi/DenseMap.h>
12#include <wpi/mutex.h>
13
14#include "PneumaticsBase.h"
15
16namespace frc {
17/** Module class for controlling a REV Robotics Pneumatic Hub. */
19 public:
20 /** Constructs a PneumaticHub with the default ID (1). */
22
23 /**
24 * Constructs a PneumaticHub.
25 *
26 * @param module module number to construct
27 */
28 explicit PneumaticHub(int module);
29
30 ~PneumaticHub() override = default;
31
32 bool GetCompressor() const override;
33
34 /**
35 * Disables the compressor. The compressor will not turn on until
36 * EnableCompressorDigital(), EnableCompressorAnalog(), or
37 * EnableCompressorHybrid() are called.
38 */
39 void DisableCompressor() override;
40
41 void EnableCompressorDigital() override;
42
43 /**
44 * Enables the compressor in analog mode. This mode uses an analog pressure
45 * sensor connected to analog channel 0 to cycle the compressor. The
46 * compressor will turn on when the pressure drops below {@code minPressure}
47 * and will turn off when the pressure reaches {@code maxPressure}.
48 *
49 * @param minPressure The minimum pressure. The compressor will turn on when
50 * the pressure drops below this value. Range 0 - 120 PSI.
51 * @param maxPressure The maximum pressure. The compressor will turn off when
52 * the pressure reaches this value. Range 0 - 120 PSI. Must be larger then
53 * minPressure.
54 */
56 units::pounds_per_square_inch_t minPressure,
57 units::pounds_per_square_inch_t maxPressure) override;
58
59 /**
60 * Enables the compressor in hybrid mode. This mode uses both a digital
61 * pressure switch and an analog pressure sensor connected to analog channel 0
62 * to cycle the compressor.
63 *
64 * The compressor will turn on when \a both:
65 *
66 * - The digital pressure switch indicates the system is not full AND
67 * - The analog pressure sensor indicates that the pressure in the system is
68 * below the specified minimum pressure.
69 *
70 * The compressor will turn off when \a either:
71 *
72 * - The digital pressure switch is disconnected or indicates that the system
73 * is full OR
74 * - The pressure detected by the analog sensor is greater than the specified
75 * maximum pressure.
76 *
77 * @param minPressure The minimum pressure. The compressor will turn on when
78 * the pressure drops below this value and the pressure switch indicates that
79 * the system is not full. Range 0 - 120 PSI.
80 * @param maxPressure The maximum pressure. The compressor will turn off when
81 * the pressure reaches this value or the pressure switch is disconnected or
82 * indicates that the system is full. Range 0 - 120 PSI. Must be larger then
83 * minPressure.
84 */
86 units::pounds_per_square_inch_t minPressure,
87 units::pounds_per_square_inch_t maxPressure) override;
88
90
91 bool GetPressureSwitch() const override;
92
93 units::ampere_t GetCompressorCurrent() const override;
94
95 void SetSolenoids(int mask, int values) override;
96
97 int GetSolenoids() const override;
98
99 int GetModuleNumber() const override;
100
101 int GetSolenoidDisabledList() const override;
102
103 void FireOneShot(int index) override;
104
105 void SetOneShotDuration(int index, units::second_t duration) override;
106
107 bool CheckSolenoidChannel(int channel) const override;
108
109 int CheckAndReserveSolenoids(int mask) override;
110
111 void UnreserveSolenoids(int mask) override;
112
113 bool ReserveCompressor() override;
114
115 void UnreserveCompressor() override;
116
117 Solenoid MakeSolenoid(int channel) override;
119 int reverseChannel) override;
121
122 /** Version and device data received from a REV PH. */
123 struct Version {
124 /** The firmware major version. */
126 /** The firmware minor version. */
128 /** The firmware fix version. */
129 uint32_t FirmwareFix;
130 /** The hardware minor version. */
132 /** The hardware major version. */
134 /** The device's unique ID. */
135 uint32_t UniqueId;
136 };
137
138 /**
139 * Returns the hardware and firmware versions of this device.
140 *
141 * @return The hardware and firmware versions.
142 */
144
145 /**
146 * Faults for a REV PH. These faults are only active while the condition is
147 * active.
148 */
149 struct Faults {
150 /** Fault on channel 0. */
151 uint32_t Channel0Fault : 1;
152 /** Fault on channel 1. */
153 uint32_t Channel1Fault : 1;
154 /** Fault on channel 2. */
155 uint32_t Channel2Fault : 1;
156 /** Fault on channel 3. */
157 uint32_t Channel3Fault : 1;
158 /** Fault on channel 4. */
159 uint32_t Channel4Fault : 1;
160 /** Fault on channel 5. */
161 uint32_t Channel5Fault : 1;
162 /** Fault on channel 6. */
163 uint32_t Channel6Fault : 1;
164 /** Fault on channel 7. */
165 uint32_t Channel7Fault : 1;
166 /** Fault on channel 8. */
167 uint32_t Channel8Fault : 1;
168 /** Fault on channel 9. */
169 uint32_t Channel9Fault : 1;
170 /** Fault on channel 10. */
171 uint32_t Channel10Fault : 1;
172 /** Fault on channel 11. */
173 uint32_t Channel11Fault : 1;
174 /** Fault on channel 12. */
175 uint32_t Channel12Fault : 1;
176 /** Fault on channel 13. */
177 uint32_t Channel13Fault : 1;
178 /** Fault on channel 14. */
179 uint32_t Channel14Fault : 1;
180 /** Fault on channel 15. */
181 uint32_t Channel15Fault : 1;
182 /** An overcurrent event occurred on the compressor output. */
184 /** The compressor output has an open circuit. */
185 uint32_t CompressorOpen : 1;
186 /** An overcurrent event occurred on a solenoid output. */
188 /** The input voltage is below the minimum voltage. */
189 uint32_t Brownout : 1;
190 /** A warning was raised by the device's CAN controller. */
191 uint32_t CanWarning : 1;
192 /** The hardware on the device has malfunctioned. */
193 uint32_t HardwareFault : 1;
194
195 /**
196 * Gets whether there is a fault at the specified channel.
197 * @param channel Channel to check for faults.
198 * @return True if a a fault exists at the channel, otherwise false.
199 * @throws A ChannelIndexOutOfRange error if the provided channel is outside
200 * of the range supported by the hardware.
201 */
202 bool GetChannelFault(int channel) const;
203 };
204
205 /**
206 * Returns the faults currently active on this device.
207 *
208 * @return The faults.
209 */
211
212 /**
213 * Sticky faults for a REV PH. These faults will remain active until they
214 * are reset by the user.
215 */
217 /** An overcurrent event occurred on the compressor output. */
219 /** The compressor output has an open circuit. */
220 uint32_t CompressorOpen : 1;
221 /** An overcurrent event occurred on a solenoid output. */
223 /** The input voltage is below the minimum voltage. */
224 uint32_t Brownout : 1;
225 /** A warning was raised by the device's CAN controller. */
226 uint32_t CanWarning : 1;
227 /** The device's CAN controller experienced a "Bus Off" event. */
228 uint32_t CanBusOff : 1;
229 /** The hardware on the device has malfunctioned. */
230 uint32_t HardwareFault : 1;
231 /** The firmware on the device has malfunctioned. */
232 uint32_t FirmwareFault : 1;
233 /** The device has rebooted. */
234 uint32_t HasReset : 1;
235 };
236
237 /**
238 * Returns the sticky faults currently active on this device.
239 *
240 * @return The sticky faults.
241 */
243
244 /** Clears the sticky faults. */
246
247 /**
248 * Returns the current input voltage for this device.
249 *
250 * @return The input voltage.
251 */
252 units::volt_t GetInputVoltage() const;
253
254 /**
255 * Returns the current voltage of the regulated 5v supply.
256 *
257 * @return The current voltage of the 5v supply.
258 */
259 units::volt_t Get5VRegulatedVoltage() const;
260
261 /**
262 * Returns the total current drawn by all solenoids.
263 *
264 * @return Total current drawn by all solenoids.
265 */
266 units::ampere_t GetSolenoidsTotalCurrent() const;
267
268 /**
269 * Returns the current voltage of the solenoid power supply.
270 *
271 * @return The current voltage of the solenoid power supply.
272 */
273 units::volt_t GetSolenoidsVoltage() const;
274
275 /**
276 * Returns the raw voltage of the specified analog input channel.
277 *
278 * @param channel The analog input channel to read voltage from.
279 * @return The voltage of the specified analog input channel.
280 */
281 units::volt_t GetAnalogVoltage(int channel) const override;
282
283 /**
284 * Returns the pressure read by an analog pressure sensor on the specified
285 * analog input channel.
286 *
287 * @param channel The analog input channel to read pressure from.
288 * @return The pressure read by an analog pressure sensor on the specified
289 * analog input channel.
290 */
291 units::pounds_per_square_inch_t GetPressure(int channel) const override;
292
293 private:
294 class DataStore;
295 friend class DataStore;
296 friend class PneumaticsBase;
297 PneumaticHub(HAL_REVPHHandle handle, int module);
298
299 static std::shared_ptr<PneumaticsBase> GetForModule(int module);
300
301 std::shared_ptr<DataStore> m_dataStore;
302 HAL_REVPHHandle m_handle;
303 int m_module;
304
305 static wpi::mutex m_handleLock;
306 static std::unique_ptr<wpi::DenseMap<int, std::weak_ptr<DataStore>>>
307 m_handleMap;
308 static std::weak_ptr<DataStore>& GetDataStore(int module);
309};
310} // namespace frc
This file defines the DenseMap class.
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
Module class for controlling a REV Robotics Pneumatic Hub.
Definition PneumaticHub.h:18
friend class DataStore
Definition PneumaticHub.h:295
units::pounds_per_square_inch_t GetPressure(int channel) const override
Returns the pressure read by an analog pressure sensor on the specified analog input channel.
void DisableCompressor() override
Disables the compressor.
void UnreserveCompressor() override
Unreserve the compressor.
int GetSolenoidDisabledList() const override
Get a bitmask of disabled solenoids.
units::volt_t GetAnalogVoltage(int channel) const override
Returns the raw voltage of the specified analog input channel.
void EnableCompressorHybrid(units::pounds_per_square_inch_t minPressure, units::pounds_per_square_inch_t maxPressure) override
Enables the compressor in hybrid mode.
units::ampere_t GetSolenoidsTotalCurrent() const
Returns the total current drawn by all solenoids.
units::volt_t Get5VRegulatedVoltage() const
Returns the current voltage of the regulated 5v supply.
void SetOneShotDuration(int index, units::second_t duration) override
Set the duration for a single solenoid shot.
bool ReserveCompressor() override
Reserve the compressor.
bool GetPressureSwitch() const override
Returns the state of the pressure switch.
int GetModuleNumber() const override
Get module number for this module.
units::volt_t GetSolenoidsVoltage() const
Returns the current voltage of the solenoid power supply.
void EnableCompressorAnalog(units::pounds_per_square_inch_t minPressure, units::pounds_per_square_inch_t maxPressure) override
Enables the compressor in analog mode.
bool CheckSolenoidChannel(int channel) const override
Check if a solenoid channel is valid.
Solenoid MakeSolenoid(int channel) override
Create a solenoid object for the specified channel.
bool GetCompressor() const override
Returns whether the compressor is active or not.
void ClearStickyFaults()
Clears the sticky faults.
CompressorConfigType GetCompressorConfigType() const override
Returns the active compressor configuration.
~PneumaticHub() override=default
Version GetVersion() const
Returns the hardware and firmware versions of this device.
units::ampere_t GetCompressorCurrent() const override
Returns the current drawn by the compressor.
Compressor MakeCompressor() override
Create a compressor object.
Faults GetFaults() const
Returns the faults currently active on this device.
void SetSolenoids(int mask, int values) override
Sets solenoids on a pneumatics module.
DoubleSolenoid MakeDoubleSolenoid(int forwardChannel, int reverseChannel) override
Create a double solenoid object for the specified channels.
StickyFaults GetStickyFaults() const
Returns the sticky faults currently active on this device.
PneumaticHub(int module)
Constructs a PneumaticHub.
void FireOneShot(int index) override
Fire a single solenoid shot.
void UnreserveSolenoids(int mask) override
Unreserve the solenoids marked in the bitmask.
void EnableCompressorDigital() override
Enables the compressor in digital mode using the digital pressure switch.
PneumaticHub()
Constructs a PneumaticHub with the default ID (1).
units::volt_t GetInputVoltage() const
Returns the current input voltage for this device.
int CheckAndReserveSolenoids(int mask) override
Check to see if the solenoids marked in the bitmask can be reserved, and if so, reserve them.
int GetSolenoids() const override
Gets a bitmask of solenoid values.
Base class for pneumatics devices.
Definition PneumaticsBase.h:25
Solenoid class for running high voltage Digital Output on a pneumatics module.
Definition Solenoid.h:26
HAL_Handle HAL_REVPHHandle
Definition Types.h:71
Definition CAN.h:11
CompressorConfigType
Compressor config type.
Definition CompressorConfigType.h:11
::std::mutex mutex
Definition mutex.h:17
Faults for a REV PH.
Definition PneumaticHub.h:149
uint32_t CanWarning
A warning was raised by the device's CAN controller.
Definition PneumaticHub.h:191
uint32_t Channel1Fault
Fault on channel 1.
Definition PneumaticHub.h:153
uint32_t HardwareFault
The hardware on the device has malfunctioned.
Definition PneumaticHub.h:193
uint32_t Channel9Fault
Fault on channel 9.
Definition PneumaticHub.h:169
uint32_t Channel2Fault
Fault on channel 2.
Definition PneumaticHub.h:155
uint32_t Channel13Fault
Fault on channel 13.
Definition PneumaticHub.h:177
uint32_t CompressorOpen
The compressor output has an open circuit.
Definition PneumaticHub.h:185
uint32_t Channel10Fault
Fault on channel 10.
Definition PneumaticHub.h:171
uint32_t Channel0Fault
Fault on channel 0.
Definition PneumaticHub.h:151
uint32_t Brownout
The input voltage is below the minimum voltage.
Definition PneumaticHub.h:189
uint32_t CompressorOverCurrent
An overcurrent event occurred on the compressor output.
Definition PneumaticHub.h:183
uint32_t Channel14Fault
Fault on channel 14.
Definition PneumaticHub.h:179
uint32_t Channel8Fault
Fault on channel 8.
Definition PneumaticHub.h:167
uint32_t Channel12Fault
Fault on channel 12.
Definition PneumaticHub.h:175
uint32_t SolenoidOverCurrent
An overcurrent event occurred on a solenoid output.
Definition PneumaticHub.h:187
uint32_t Channel3Fault
Fault on channel 3.
Definition PneumaticHub.h:157
bool GetChannelFault(int channel) const
Gets whether there is a fault at the specified channel.
uint32_t Channel7Fault
Fault on channel 7.
Definition PneumaticHub.h:165
uint32_t Channel15Fault
Fault on channel 15.
Definition PneumaticHub.h:181
uint32_t Channel6Fault
Fault on channel 6.
Definition PneumaticHub.h:163
uint32_t Channel11Fault
Fault on channel 11.
Definition PneumaticHub.h:173
uint32_t Channel4Fault
Fault on channel 4.
Definition PneumaticHub.h:159
uint32_t Channel5Fault
Fault on channel 5.
Definition PneumaticHub.h:161
Sticky faults for a REV PH.
Definition PneumaticHub.h:216
uint32_t CanBusOff
The device's CAN controller experienced a "Bus Off" event.
Definition PneumaticHub.h:228
uint32_t CompressorOpen
The compressor output has an open circuit.
Definition PneumaticHub.h:220
uint32_t SolenoidOverCurrent
An overcurrent event occurred on a solenoid output.
Definition PneumaticHub.h:222
uint32_t Brownout
The input voltage is below the minimum voltage.
Definition PneumaticHub.h:224
uint32_t CanWarning
A warning was raised by the device's CAN controller.
Definition PneumaticHub.h:226
uint32_t HasReset
The device has rebooted.
Definition PneumaticHub.h:234
uint32_t FirmwareFault
The firmware on the device has malfunctioned.
Definition PneumaticHub.h:232
uint32_t HardwareFault
The hardware on the device has malfunctioned.
Definition PneumaticHub.h:230
uint32_t CompressorOverCurrent
An overcurrent event occurred on the compressor output.
Definition PneumaticHub.h:218
Version and device data received from a REV PH.
Definition PneumaticHub.h:123
uint32_t HardwareMinor
The hardware minor version.
Definition PneumaticHub.h:131
uint32_t FirmwareFix
The firmware fix version.
Definition PneumaticHub.h:129
uint32_t FirmwareMinor
The firmware minor version.
Definition PneumaticHub.h:127
uint32_t HardwareMajor
The hardware major version.
Definition PneumaticHub.h:133
uint32_t UniqueId
The device's unique ID.
Definition PneumaticHub.h:135
uint32_t FirmwareMajor
The firmware major version.
Definition PneumaticHub.h:125