WPILibC++ 2024.3.2
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 /** Constructs a PneumaticsControlModule with the default ID (0). */
22
23 /**
24 * Constructs a PneumaticsControlModule.
25 *
26 * @param module module number to construct
27 */
28 explicit PneumaticsControlModule(int module);
29
30 ~PneumaticsControlModule() override = default;
31
32 bool GetCompressor() const override;
33
34 /**
35 * Disables the compressor. The compressor will not turn on until
36 * EnableCompressorDigital() is called.
37 */
38 void DisableCompressor() override;
39
40 void EnableCompressorDigital() override;
41
42 /**
43 * Enables the compressor in digital mode. Analog mode is unsupported by the
44 * CTRE PCM.
45 *
46 * @param minPressure Unsupported.
47 * @param maxPressure Unsupported.
48 * @see EnableCompressorDigital()
49 */
51 units::pounds_per_square_inch_t minPressure,
52 units::pounds_per_square_inch_t maxPressure) override;
53
54 /**
55 * Enables the compressor in digital mode. Hybrid mode is unsupported by the
56 * CTRE PCM.
57 *
58 * @param minPressure Unsupported.
59 * @param maxPressure Unsupported.
60 * @see EnableCompressorDigital()
61 */
63 units::pounds_per_square_inch_t minPressure,
64 units::pounds_per_square_inch_t maxPressure) override;
65
67
68 bool GetPressureSwitch() const override;
69
70 units::ampere_t GetCompressorCurrent() const override;
71
72 /**
73 * Return whether the compressor current is currently too high.
74 *
75 * @return True if the compressor current is too high, otherwise false.
76 * @see GetCompressorCurrentTooHighStickyFault()
77 */
79
80 /**
81 * Returns whether the compressor current has been too high since sticky
82 * faults were last cleared. This fault is persistent and can be cleared by
83 * ClearAllStickyFaults()
84 *
85 * @return True if the compressor current has been too high since sticky
86 * faults were last cleared.
87 * @see GetCompressorCurrentTooHighFault()
88 */
90
91 /**
92 * Returns whether the compressor is currently shorted.
93 *
94 * @return True if the compressor is currently shorted, otherwise false.
95 * @see GetCompressorShortedStickyFault()
96 */
98
99 /**
100 * Returns whether the compressor has been shorted since sticky faults were
101 * last cleared. This fault is persistent and can be cleared by
102 * ClearAllStickyFaults()
103 *
104 * @return True if the compressor has been shorted since sticky faults were
105 * last cleared, otherwise false.
106 * @see GetCompressorShortedFault()
107 */
109
110 /**
111 * Returns whether the compressor is currently disconnected.
112 *
113 * @return True if compressor is currently disconnected, otherwise false.
114 * @see GetCompressorNotConnectedStickyFault()
115 */
117
118 /**
119 * Returns whether the compressor has been disconnected since sticky faults
120 * were last cleared. This fault is persistent and can be cleared by
121 * ClearAllStickyFaults()
122 *
123 * @return True if the compressor has been disconnected since sticky faults
124 * were last cleared, otherwise false.
125 * @see GetCompressorNotConnectedFault()
126 */
128
129 /**
130 * Returns whether the solenoid is currently reporting a voltage fault.
131 *
132 * @return True if solenoid is reporting a fault, otherwise false.
133 * @see GetSolenoidVoltageStickyFault()
134 */
136
137 /**
138 * Returns whether the solenoid has reported a voltage fault since sticky
139 * faults were last cleared. This fault is persistent and can be cleared by
140 * ClearAllStickyFaults()
141 *
142 * @return True if solenoid is reporting a fault, otherwise false.
143 * @see GetSolenoidVoltageFault()
144 */
146
147 /** Clears all sticky faults on this device. */
149
150 void SetSolenoids(int mask, int values) override;
151
152 int GetSolenoids() const override;
153
154 int GetModuleNumber() const override;
155
156 int GetSolenoidDisabledList() const override;
157
158 void FireOneShot(int index) override;
159
160 void SetOneShotDuration(int index, units::second_t duration) override;
161
162 bool CheckSolenoidChannel(int channel) const override;
163
164 int CheckAndReserveSolenoids(int mask) override;
165
166 void UnreserveSolenoids(int mask) override;
167
168 bool ReserveCompressor() override;
169
170 void UnreserveCompressor() override;
171
172 /**
173 * Unsupported by the CTRE PCM.
174 *
175 * @param channel Unsupported.
176 * @return 0
177 */
178 units::volt_t GetAnalogVoltage(int channel) const override;
179
180 /**
181 * Unsupported by the CTRE PCM.
182 *
183 * @param channel Unsupported.
184 * @return 0
185 */
186 units::pounds_per_square_inch_t GetPressure(int channel) const override;
187
188 Solenoid MakeSolenoid(int channel) override;
190 int reverseChannel) override;
192
193 private:
194 class DataStore;
195 friend class DataStore;
196 friend class PneumaticsBase;
197 PneumaticsControlModule(HAL_CTREPCMHandle handle, int module);
198
199 static std::shared_ptr<PneumaticsBase> GetForModule(int module);
200
201 std::shared_ptr<DataStore> m_dataStore;
202 HAL_CTREPCMHandle m_handle;
203 int m_module;
204
205 static wpi::mutex m_handleLock;
206 static std::unique_ptr<wpi::DenseMap<int, std::weak_ptr<DataStore>>>
207 m_handleMap;
208 static std::weak_ptr<DataStore>& GetDataStore(int module);
209};
210} // 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:25
Module class for controlling a Cross The Road Electronics Pneumatics Control Module.
Definition: PneumaticsControlModule.h:18
friend class DataStore
Definition: PneumaticsControlModule.h:195
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.
bool GetCompressorNotConnectedFault() const
Returns whether the compressor is currently disconnected.
void UnreserveSolenoids(int mask) override
Unreserve the masked solenoids.
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.
PneumaticsControlModule()
Constructs a PneumaticsControlModule with the default ID (0).
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.
PneumaticsControlModule(int module)
Constructs a PneumaticsControlModule.
units::ampere_t GetCompressorCurrent() const override
Returns the current drawn by the compressor.
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.
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 masked solenoids can be reserved, and if not 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:67
Definition: AprilTagPoseEstimator.h:15
CompressorConfigType
Compressor config type.
Definition: CompressorConfigType.h:11
::std::mutex mutex
Definition: mutex.h:17