WPILibC++ 2023.4.3
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
131
132 /** Clears all sticky faults on this device. */
134
135 void SetSolenoids(int mask, int values) override;
136
137 int GetSolenoids() const override;
138
139 int GetModuleNumber() const override;
140
141 int GetSolenoidDisabledList() const override;
142
143 void FireOneShot(int index) override;
144
145 void SetOneShotDuration(int index, units::second_t duration) override;
146
147 bool CheckSolenoidChannel(int channel) const override;
148
149 int CheckAndReserveSolenoids(int mask) override;
150
151 void UnreserveSolenoids(int mask) override;
152
153 bool ReserveCompressor() override;
154
155 void UnreserveCompressor() override;
156
157 /**
158 * Unsupported by the CTRE PCM.
159 *
160 * @param channel Unsupported.
161 * @return 0
162 */
163 units::volt_t GetAnalogVoltage(int channel) const override;
164
165 /**
166 * Unsupported by the CTRE PCM.
167 *
168 * @param channel Unsupported.
169 * @return 0
170 */
171 units::pounds_per_square_inch_t GetPressure(int channel) const override;
172
173 Solenoid MakeSolenoid(int channel) override;
175 int reverseChannel) override;
177
178 private:
179 class DataStore;
180 friend class DataStore;
181 friend class PneumaticsBase;
182 PneumaticsControlModule(HAL_CTREPCMHandle handle, int module);
183
184 static std::shared_ptr<PneumaticsBase> GetForModule(int module);
185
186 std::shared_ptr<DataStore> m_dataStore;
187 HAL_CTREPCMHandle m_handle;
188 int m_module;
189
190 static wpi::mutex m_handleLock;
191 static std::unique_ptr<wpi::DenseMap<int, std::weak_ptr<DataStore>>>
192 m_handleMap;
193 static std::weak_ptr<DataStore>& GetDataStore(int module);
194};
195} // namespace frc
This file defines the DenseMap class.
Class for operating a compressor connected to a pneumatics module.
Definition: Compressor.h:36
DoubleSolenoid class for running 2 channels of high voltage Digital Output on a pneumatics module.
Definition: DoubleSolenoid.h:26
Definition: PneumaticsBase.h:21
Module class for controlling a Cross The Road Electronics Pneumatics Control Module.
Definition: PneumaticsControlModule.h:18
friend class DataStore
Definition: PneumaticsControlModule.h:180
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
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
DoubleSolenoid MakeDoubleSolenoid(int forwardChannel, int reverseChannel) override
PneumaticsControlModule(int module)
Constructs a PneumaticsControlModule.
units::ampere_t GetCompressorCurrent() const override
Returns the current drawn by the compressor.
bool ReserveCompressor() override
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
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
void UnreserveCompressor() override
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: AprilTagFieldLayout.h:22
CompressorConfigType
Definition: CompressorConfigType.h:8
::std::mutex mutex
Definition: mutex.h:17