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