WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
PneumaticsControlModule.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/util/DenseMap.hpp"
12#include "wpi/util/mutex.hpp"
13
14namespace wpi {
15/** Module class for controlling a Cross The Road Electronics Pneumatics Control
16 * Module. */
18 public:
19 /**
20 * Constructs a PneumaticsControlModule with the default ID (0).
21 *
22 * @param busId The bus ID.
23 */
24 explicit PneumaticsControlModule(int busId);
25
26 /**
27 * Constructs a PneumaticsControlModule.
28 *
29 * @param busId The bus ID.
30 * @param module module number to construct
31 */
32 PneumaticsControlModule(int busId, int module);
33
34 ~PneumaticsControlModule() override = default;
35
36 bool GetCompressor() const override;
37
38 /**
39 * Disables the compressor. The compressor will not turn on until
40 * EnableCompressorDigital() is called.
41 */
42 void DisableCompressor() override;
43
44 void EnableCompressorDigital() override;
45
46 /**
47 * Enables the compressor in digital mode. Analog mode is unsupported by the
48 * CTRE PCM.
49 *
50 * @param minPressure Unsupported.
51 * @param maxPressure Unsupported.
52 * @see EnableCompressorDigital()
53 */
55 wpi::units::pounds_per_square_inch_t minPressure,
56 wpi::units::pounds_per_square_inch_t maxPressure) override;
57
58 /**
59 * Enables the compressor in digital mode. Hybrid mode is unsupported by the
60 * CTRE PCM.
61 *
62 * @param minPressure Unsupported.
63 * @param maxPressure Unsupported.
64 * @see EnableCompressorDigital()
65 */
67 wpi::units::pounds_per_square_inch_t minPressure,
68 wpi::units::pounds_per_square_inch_t maxPressure) override;
69
71
72 bool GetPressureSwitch() const override;
73
74 wpi::units::ampere_t GetCompressorCurrent() const override;
75
76 /**
77 * Return whether the compressor current is currently too high.
78 *
79 * @return True if the compressor current is too high, otherwise false.
80 * @see GetCompressorCurrentTooHighStickyFault()
81 */
83
84 /**
85 * Returns whether the compressor current has been too high since sticky
86 * faults were last cleared. This fault is persistent and can be cleared by
87 * ClearAllStickyFaults()
88 *
89 * @return True if the compressor current has been too high since sticky
90 * faults were last cleared.
91 * @see GetCompressorCurrentTooHighFault()
92 */
94
95 /**
96 * Returns whether the compressor is currently shorted.
97 *
98 * @return True if the compressor is currently shorted, otherwise false.
99 * @see GetCompressorShortedStickyFault()
100 */
102
103 /**
104 * Returns whether the compressor has been shorted since sticky faults were
105 * last cleared. This fault is persistent and can be cleared by
106 * ClearAllStickyFaults()
107 *
108 * @return True if the compressor has been shorted since sticky faults were
109 * last cleared, otherwise false.
110 * @see GetCompressorShortedFault()
111 */
113
114 /**
115 * Returns whether the compressor is currently disconnected.
116 *
117 * @return True if compressor is currently disconnected, otherwise false.
118 * @see GetCompressorNotConnectedStickyFault()
119 */
121
122 /**
123 * Returns whether the compressor has been disconnected since sticky faults
124 * were last cleared. This fault is persistent and can be cleared by
125 * ClearAllStickyFaults()
126 *
127 * @return True if the compressor has been disconnected since sticky faults
128 * were last cleared, otherwise false.
129 * @see GetCompressorNotConnectedFault()
130 */
132
133 /**
134 * Returns whether the solenoid is currently reporting a voltage fault.
135 *
136 * @return True if solenoid is reporting a fault, otherwise false.
137 * @see GetSolenoidVoltageStickyFault()
138 */
140
141 /**
142 * Returns whether the solenoid has reported a voltage fault since sticky
143 * faults were last cleared. This fault is persistent and can be cleared by
144 * ClearAllStickyFaults()
145 *
146 * @return True if solenoid is reporting a fault, otherwise false.
147 * @see GetSolenoidVoltageFault()
148 */
150
151 /** Clears all sticky faults on this device. */
153
154 void SetSolenoids(int mask, int values) override;
155
156 int GetSolenoids() const override;
157
158 int GetModuleNumber() const override;
159
160 int GetSolenoidDisabledList() const override;
161
162 void FireOneShot(int index) override;
163
164 void SetOneShotDuration(int index, wpi::units::second_t duration) override;
165
166 bool CheckSolenoidChannel(int channel) const override;
167
168 int CheckAndReserveSolenoids(int mask) override;
169
170 void UnreserveSolenoids(int mask) override;
171
172 bool ReserveCompressor() override;
173
174 void UnreserveCompressor() override;
175
176 /**
177 * Unsupported by the CTRE PCM.
178 *
179 * @param channel Unsupported.
180 * @return 0
181 */
182 wpi::units::volt_t GetAnalogVoltage(int channel) const override;
183
184 /**
185 * Unsupported by the CTRE PCM.
186 *
187 * @param channel Unsupported.
188 * @return 0
189 */
190 wpi::units::pounds_per_square_inch_t GetPressure(int channel) const override;
191
192 Solenoid MakeSolenoid(int channel) override;
194 int reverseChannel) override;
196
197 void ReportUsage(std::string_view device, std::string_view data) override;
198
199 private:
200 class DataStore;
201 friend class DataStore;
202 friend class PneumaticsBase;
203 PneumaticsControlModule(int busId, HAL_CTREPCMHandle handle, int module);
204
205 static std::shared_ptr<PneumaticsBase> GetForModule(int busId, int module);
206
207 std::shared_ptr<DataStore> m_dataStore;
208 HAL_CTREPCMHandle m_handle;
209 int m_module;
210
211 static wpi::util::mutex m_handleLock;
212 static std::unique_ptr<wpi::util::DenseMap<int, std::weak_ptr<DataStore>>[]>
213 m_handleMaps;
214 static std::weak_ptr<DataStore>& GetDataStore(int busId, int module);
215};
216} // 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 PneumaticsControlModule.hpp:201
void SetSolenoids(int mask, int values) override
Sets solenoids on a pneumatics module.
int GetSolenoidDisabledList() const override
Get a bitmask of disabled solenoids.
void SetOneShotDuration(int index, wpi::units::second_t duration) override
Set the duration for a single solenoid shot.
void EnableCompressorDigital() override
Enables the compressor in digital mode using the digital pressure switch.
bool GetCompressorCurrentTooHighStickyFault() const
Returns whether the compressor current has been too high since sticky faults were last cleared.
~PneumaticsControlModule() override=default
void FireOneShot(int index) override
Fire a single solenoid shot.
void EnableCompressorHybrid(wpi::units::pounds_per_square_inch_t minPressure, wpi::units::pounds_per_square_inch_t maxPressure) override
Enables the compressor in digital mode.
bool GetSolenoidVoltageStickyFault() const
Returns whether the solenoid has reported a voltage fault since sticky faults were last cleared.
bool GetCompressorNotConnectedFault() const
Returns whether the compressor is currently disconnected.
void ReportUsage(std::string_view device, std::string_view data) override
Report usage.
bool GetPressureSwitch() const override
Returns the state of the pressure switch.
int GetModuleNumber() const override
Get module number for this module.
bool GetCompressorShortedFault() const
Returns whether the compressor is currently shorted.
friend class PneumaticsBase
Definition PneumaticsControlModule.hpp:202
bool GetSolenoidVoltageFault() const
Returns whether the solenoid is currently reporting a voltage fault.
void ClearAllStickyFaults()
Clears all sticky faults on this device.
CompressorConfigType GetCompressorConfigType() const override
Returns the active compressor configuration.
wpi::units::ampere_t GetCompressorCurrent() const override
Returns the current drawn by the compressor.
void UnreserveCompressor() override
Unreserve the compressor.
void EnableCompressorAnalog(wpi::units::pounds_per_square_inch_t minPressure, wpi::units::pounds_per_square_inch_t maxPressure) override
Enables the compressor in digital mode.
bool GetCompressorNotConnectedStickyFault() const
Returns whether the compressor has been disconnected since sticky faults were last cleared.
int GetSolenoids() const override
Gets a bitmask of solenoid values.
wpi::units::volt_t GetAnalogVoltage(int channel) const override
Unsupported by the CTRE PCM.
Solenoid MakeSolenoid(int channel) override
Create a solenoid object for the specified channel.
wpi::units::pounds_per_square_inch_t GetPressure(int channel) const override
Unsupported by the CTRE PCM.
Compressor MakeCompressor() override
Create a compressor object.
PneumaticsControlModule(int busId)
Constructs a PneumaticsControlModule with the default ID (0).
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 CheckAndReserveSolenoids(int mask) override
Check to see if the solenoids marked in the bitmask can be reserved, and if so, reserve them.
bool GetCompressorShortedStickyFault() const
Returns whether the compressor has been shorted since sticky faults were last cleared.
PneumaticsControlModule(int busId, int module)
Constructs a PneumaticsControlModule.
DoubleSolenoid MakeDoubleSolenoid(int forwardChannel, int reverseChannel) override
Create a double solenoid object for the specified channels.
void UnreserveSolenoids(int mask) override
Unreserve the solenoids marked in the bitmask.
bool ReserveCompressor() override
Reserve the compressor.
void DisableCompressor() override
Disables the compressor.
bool GetCompressorCurrentTooHighFault() const
Return whether the compressor current is currently too high.
Solenoid class for running high voltage Digital Output on a pneumatics module.
Definition Solenoid.hpp:26
HAL_Handle HAL_CTREPCMHandle
Definition Types.h:67
::std::mutex mutex
Definition mutex.hpp:17
Definition CvSource.hpp:15
CompressorConfigType
Compressor config type.
Definition CompressorConfigType.hpp:11