WPILibC++ 2023.4.3-108-ge5452e3
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 <wpi/DenseMap.h>
11#include <wpi/mutex.h>
12
13#include "PneumaticsBase.h"
14
15namespace frc {
16/** Module class for controlling a REV Robotics Pneumatic Hub. */
18 public:
19 /** Constructs a PneumaticHub with the default ID (1). */
21
22 /**
23 * Constructs a PneumaticHub.
24 *
25 * @param module module number to construct
26 */
27 explicit PneumaticHub(int module);
28
29 ~PneumaticHub() override = default;
30
31 bool GetCompressor() const override;
32
33 /**
34 * Disables the compressor. The compressor will not turn on until
35 * EnableCompressorDigital(), EnableCompressorAnalog(), or
36 * EnableCompressorHybrid() are called.
37 */
38 void DisableCompressor() override;
39
40 void EnableCompressorDigital() override;
41
42 /**
43 * Enables the compressor in analog mode. This mode uses an analog pressure
44 * sensor connected to analog channel 0 to cycle the compressor. The
45 * compressor will turn on when the pressure drops below {@code minPressure}
46 * and will turn off when the pressure reaches {@code maxPressure}.
47 *
48 * @param minPressure The minimum pressure. The compressor will turn on when
49 * the pressure drops below this value. Range 0 - 120 PSI.
50 * @param maxPressure The maximum pressure. The compressor will turn off when
51 * the pressure reaches this value. Range 0 - 120 PSI. Must be larger then
52 * minPressure.
53 */
55 units::pounds_per_square_inch_t minPressure,
56 units::pounds_per_square_inch_t maxPressure) override;
57
58 /**
59 * Enables the compressor in hybrid mode. This mode uses both a digital
60 * pressure switch and an analog pressure sensor connected to analog channel 0
61 * to cycle the compressor.
62 *
63 * The compressor will turn on when \a both:
64 *
65 * - The digital pressure switch indicates the system is not full AND
66 * - The analog pressure sensor indicates that the pressure in the system is
67 * below the specified minimum pressure.
68 *
69 * The compressor will turn off when \a either:
70 *
71 * - The digital pressure switch is disconnected or indicates that the system
72 * is full OR
73 * - The pressure detected by the analog sensor is greater than the specified
74 * maximum pressure.
75 *
76 * @param minPressure The minimum pressure. The compressor will turn on when
77 * the pressure drops below this value and the pressure switch indicates that
78 * the system is not full. Range 0 - 120 PSI.
79 * @param maxPressure The maximum pressure. The compressor will turn off when
80 * the pressure reaches this value or the pressure switch is disconnected or
81 * indicates that the system is full. Range 0 - 120 PSI. Must be larger then
82 * minPressure.
83 */
85 units::pounds_per_square_inch_t minPressure,
86 units::pounds_per_square_inch_t maxPressure) override;
87
89
90 bool GetPressureSwitch() const override;
91
92 units::ampere_t GetCompressorCurrent() const override;
93
94 void SetSolenoids(int mask, int values) override;
95
96 int GetSolenoids() const override;
97
98 int GetModuleNumber() const override;
99
100 int GetSolenoidDisabledList() const override;
101
102 void FireOneShot(int index) override;
103
104 void SetOneShotDuration(int index, units::second_t duration) override;
105
106 bool CheckSolenoidChannel(int channel) const override;
107
108 int CheckAndReserveSolenoids(int mask) override;
109
110 void UnreserveSolenoids(int mask) override;
111
112 bool ReserveCompressor() override;
113
114 void UnreserveCompressor() override;
115
116 Solenoid MakeSolenoid(int channel) override;
118 int reverseChannel) override;
120
121 struct Version {
128 };
129
130 /**
131 * Returns the hardware and firmware versions of this device.
132 *
133 * @return The hardware and firmware versions.
134 */
136
137 struct Faults {
160 };
161
162 /**
163 * Returns the faults currently active on this device.
164 *
165 * @return The faults.
166 */
168
177 };
178
179 /**
180 * Returns the sticky faults currently active on this device.
181 *
182 * @return The sticky faults.
183 */
185
186 /** Clears the sticky faults. */
188
189 /**
190 * Returns the current input voltage for this device.
191 *
192 * @return The input voltage.
193 */
194 units::volt_t GetInputVoltage() const;
195
196 /**
197 * Returns the current voltage of the regulated 5v supply.
198 *
199 * @return The current voltage of the 5v supply.
200 */
201 units::volt_t Get5VRegulatedVoltage() const;
202
203 /**
204 * Returns the total current drawn by all solenoids.
205 *
206 * @return Total current drawn by all solenoids.
207 */
208 units::ampere_t GetSolenoidsTotalCurrent() const;
209
210 /**
211 * Returns the current voltage of the solenoid power supply.
212 *
213 * @return The current voltage of the solenoid power supply.
214 */
215 units::volt_t GetSolenoidsVoltage() const;
216
217 /**
218 * Returns the raw voltage of the specified analog input channel.
219 *
220 * @param channel The analog input channel to read voltage from.
221 * @return The voltage of the specified analog input channel.
222 */
223 units::volt_t GetAnalogVoltage(int channel) const override;
224
225 /**
226 * Returns the pressure read by an analog pressure sensor on the specified
227 * analog input channel.
228 *
229 * @param channel The analog input channel to read pressure from.
230 * @return The pressure read by an analog pressure sensor on the specified
231 * analog input channel.
232 */
233 units::pounds_per_square_inch_t GetPressure(int channel) const override;
234
235 private:
236 class DataStore;
237 friend class DataStore;
238 friend class PneumaticsBase;
239 PneumaticHub(HAL_REVPHHandle handle, int module);
240
241 static std::shared_ptr<PneumaticsBase> GetForModule(int module);
242
243 std::shared_ptr<DataStore> m_dataStore;
244 HAL_REVPHHandle m_handle;
245 int m_module;
246
247 static wpi::mutex m_handleLock;
248 static std::unique_ptr<wpi::DenseMap<int, std::weak_ptr<DataStore>>>
249 m_handleMap;
250 static std::weak_ptr<DataStore>& GetDataStore(int module);
251};
252} // 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:17
friend class DataStore
Definition: PneumaticHub.h:237
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 masked solenoids.
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 masked solenoids can be reserved, and if not reserve them.
int GetSolenoids() const override
Gets a bitmask of solenoid values.
Definition: PneumaticsBase.h:21
Solenoid class for running high voltage Digital Output on a pneumatics module.
Definition: Solenoid.h:26
HAL_Handle HAL_REVPHHandle
Definition: Types.h:71
::uint32_t uint32_t
Definition: Meta.h:56
Definition: AprilTagPoseEstimator.h:15
CompressorConfigType
Definition: CompressorConfigType.h:8
::std::mutex mutex
Definition: mutex.h:17
Definition: PneumaticHub.h:137
uint32_t CanWarning
Definition: PneumaticHub.h:158
uint32_t Channel1Fault
Definition: PneumaticHub.h:139
uint32_t HardwareFault
Definition: PneumaticHub.h:159
uint32_t Channel9Fault
Definition: PneumaticHub.h:147
uint32_t Channel2Fault
Definition: PneumaticHub.h:140
uint32_t Channel13Fault
Definition: PneumaticHub.h:151
uint32_t CompressorOpen
Definition: PneumaticHub.h:155
uint32_t Channel10Fault
Definition: PneumaticHub.h:148
uint32_t Channel0Fault
Definition: PneumaticHub.h:138
uint32_t Brownout
Definition: PneumaticHub.h:157
uint32_t CompressorOverCurrent
Definition: PneumaticHub.h:154
uint32_t Channel14Fault
Definition: PneumaticHub.h:152
uint32_t Channel8Fault
Definition: PneumaticHub.h:146
uint32_t Channel12Fault
Definition: PneumaticHub.h:150
uint32_t SolenoidOverCurrent
Definition: PneumaticHub.h:156
uint32_t Channel3Fault
Definition: PneumaticHub.h:141
uint32_t Channel7Fault
Definition: PneumaticHub.h:145
uint32_t Channel15Fault
Definition: PneumaticHub.h:153
uint32_t Channel6Fault
Definition: PneumaticHub.h:144
uint32_t Channel11Fault
Definition: PneumaticHub.h:149
uint32_t Channel4Fault
Definition: PneumaticHub.h:142
uint32_t Channel5Fault
Definition: PneumaticHub.h:143
Definition: PneumaticHub.h:169
uint32_t CanBusOff
Definition: PneumaticHub.h:175
uint32_t CompressorOpen
Definition: PneumaticHub.h:171
uint32_t SolenoidOverCurrent
Definition: PneumaticHub.h:172
uint32_t Brownout
Definition: PneumaticHub.h:173
uint32_t CanWarning
Definition: PneumaticHub.h:174
uint32_t HasReset
Definition: PneumaticHub.h:176
uint32_t CompressorOverCurrent
Definition: PneumaticHub.h:170
Definition: PneumaticHub.h:121
uint32_t HardwareMinor
Definition: PneumaticHub.h:125
uint32_t FirmwareFix
Definition: PneumaticHub.h:124
uint32_t FirmwareMinor
Definition: PneumaticHub.h:123
uint32_t HardwareMajor
Definition: PneumaticHub.h:126
uint32_t UniqueId
Definition: PneumaticHub.h:127
uint32_t FirmwareMajor
Definition: PneumaticHub.h:122