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