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