1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <memory>
#include <hal/Types.h>
#include <wpi/DenseMap.h>
#include <wpi/mutex.h>
#include "PneumaticsBase.h"
namespace frc {
/** Module class for controlling a Cross The Road Electronics Pneumatics Control
* Module. */
class PneumaticsControlModule : public PneumaticsBase {
public:
/** Constructs a PneumaticsControlModule with the default ID (0). */
PneumaticsControlModule();
/**
* Constructs a PneumaticsControlModule.
*
* @param module module number to construct
*/
explicit PneumaticsControlModule(int module);
~PneumaticsControlModule() override = default;
bool GetCompressor() const override;
/**
* Disables the compressor. The compressor will not turn on until
* EnableCompressorDigital() is called.
*/
void DisableCompressor() override;
void EnableCompressorDigital() override;
/**
* Enables the compressor in digital mode. Analog mode is unsupported by the
* CTRE PCM.
*
* @param minPressure Unsupported.
* @param maxPressure Unsupported.
* @see EnableCompressorDigital()
*/
void EnableCompressorAnalog(
units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure) override;
/**
* Enables the compressor in digital mode. Hybrid mode is unsupported by the
* CTRE PCM.
*
* @param minPressure Unsupported.
* @param maxPressure Unsupported.
* @see EnableCompressorDigital()
*/
void EnableCompressorHybrid(
units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure) override;
CompressorConfigType GetCompressorConfigType() const override;
bool GetPressureSwitch() const override;
units::ampere_t GetCompressorCurrent() const override;
/**
* Return whether the compressor current is currently too high.
*
* @return True if the compressor current is too high, otherwise false.
* @see GetCompressorCurrentTooHighStickyFault()
*/
bool GetCompressorCurrentTooHighFault() const;
/**
* Returns whether the compressor current has been too high since sticky
* faults were last cleared. This fault is persistent and can be cleared by
* ClearAllStickyFaults()
*
* @return True if the compressor current has been too high since sticky
* faults were last cleared.
* @see GetCompressorCurrentTooHighFault()
*/
bool GetCompressorCurrentTooHighStickyFault() const;
/**
* Returns whether the compressor is currently shorted.
*
* @return True if the compressor is currently shorted, otherwise false.
* @see GetCompressorShortedStickyFault()
*/
bool GetCompressorShortedFault() const;
/**
* Returns whether the compressor has been shorted since sticky faults were
* last cleared. This fault is persistent and can be cleared by
* ClearAllStickyFaults()
*
* @return True if the compressor has been shorted since sticky faults were
* last cleared, otherwise false.
* @see GetCompressorShortedFault()
*/
bool GetCompressorShortedStickyFault() const;
/**
* Returns whether the compressor is currently disconnected.
*
* @return True if compressor is currently disconnected, otherwise false.
* @see GetCompressorNotConnectedStickyFault()
*/
bool GetCompressorNotConnectedFault() const;
/**
* Returns whether the compressor has been disconnected since sticky faults
* were last cleared. This fault is persistent and can be cleared by
* ClearAllStickyFaults()
*
* @return True if the compressor has been disconnected since sticky faults
* were last cleared, otherwise false.
* @see GetCompressorNotConnectedFault()
*/
bool GetCompressorNotConnectedStickyFault() const;
/**
* Returns whether the solenoid is currently reporting a voltage fault.
*
* @return True if solenoid is reporting a fault, otherwise false.
* @see GetSolenoidVoltageStickyFault()
*/
bool GetSolenoidVoltageFault() const;
/**
* Returns whether the solenoid has reported a voltage fault since sticky
* faults were last cleared. This fault is persistent and can be cleared by
* ClearAllStickyFaults()
*
* @return True if solenoid is reporting a fault, otherwise false.
* @see GetSolenoidVoltageFault()
*/
bool GetSolenoidVoltageStickyFault() const;
/** Clears all sticky faults on this device. */
void ClearAllStickyFaults();
void SetSolenoids(int mask, int values) override;
int GetSolenoids() const override;
int GetModuleNumber() const override;
int GetSolenoidDisabledList() const override;
void FireOneShot(int index) override;
void SetOneShotDuration(int index, units::second_t duration) override;
bool CheckSolenoidChannel(int channel) const override;
int CheckAndReserveSolenoids(int mask) override;
void UnreserveSolenoids(int mask) override;
bool ReserveCompressor() override;
void UnreserveCompressor() override;
/**
* Unsupported by the CTRE PCM.
*
* @param channel Unsupported.
* @return 0
*/
units::volt_t GetAnalogVoltage(int channel) const override;
/**
* Unsupported by the CTRE PCM.
*
* @param channel Unsupported.
* @return 0
*/
units::pounds_per_square_inch_t GetPressure(int channel) const override;
Solenoid MakeSolenoid(int channel) override;
DoubleSolenoid MakeDoubleSolenoid(int forwardChannel,
int reverseChannel) override;
Compressor MakeCompressor() override;
private:
class DataStore;
friend class DataStore;
friend class PneumaticsBase;
PneumaticsControlModule(HAL_CTREPCMHandle handle, int module);
static std::shared_ptr<PneumaticsBase> GetForModule(int module);
std::shared_ptr<DataStore> m_dataStore;
HAL_CTREPCMHandle m_handle;
int m_module;
static wpi::mutex m_handleLock;
static std::unique_ptr<wpi::DenseMap<int, std::weak_ptr<DataStore>>>
m_handleMap;
static std::weak_ptr<DataStore>& GetDataStore(int module);
};
} // namespace frc