WPILibC++ 2023.4.3-108-ge5452e3
Compressor.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>
12
14#include "frc/PneumaticsBase.h"
16#include "frc/SensorUtil.h"
17
18namespace frc {
19
20/**
21 * Class for operating a compressor connected to a pneumatics module.
22 *
23 * The module will automatically run in closed loop mode by default whenever a
24 * Solenoid object is created. For most cases, a Compressor object does not need
25 * to be instantiated or used in a robot program. This class is only required in
26 * cases where the robot program needs a more detailed status of the compressor
27 * or to enable/disable closed loop control.
28 *
29 * Note: you cannot operate the compressor directly from this class as doing so
30 * would circumvent the safety provided by using the pressure switch and closed
31 * loop control. You can only turn off closed loop control, thereby stopping
32 * the compressor from operating.
33 */
35 public wpi::SendableHelper<Compressor> {
36 public:
37 /**
38 * Constructs a compressor for a specified module and type.
39 *
40 * @param module The module ID to use.
41 * @param moduleType The module type to use.
42 */
43 Compressor(int module, PneumaticsModuleType moduleType);
44
45 /**
46 * Constructs a compressor for a default module and specified type.
47 *
48 * @param moduleType The module type to use.
49 */
50 explicit Compressor(PneumaticsModuleType moduleType);
51
52 ~Compressor() override;
53
54 Compressor(const Compressor&) = delete;
55 Compressor& operator=(const Compressor&) = delete;
56
57 Compressor(Compressor&&) = default;
59
60 /**
61 * Check if compressor output is active.
62 * To (re)enable the compressor use EnableDigital() or EnableAnalog(...).
63 *
64 * @return true if the compressor is on.
65 * @deprecated To avoid confusion in thinking this (re)enables the compressor
66 * use IsEnabled().
67 */
68 [[deprecated(
69 "To avoid confusion in thinking this (re)enables the compressor use "
70 "IsEnabled()")]]
71 bool Enabled() const;
72
73 /**
74 * Returns whether the compressor is active or not.
75 *
76 * @return true if the compressor is on - otherwise false.
77 */
78 bool IsEnabled() const;
79
80 /**
81 * Returns the state of the pressure switch.
82 *
83 * @return True if pressure switch indicates that the system is not full,
84 * otherwise false.
85 */
87
88 /**
89 * Get the current drawn by the compressor.
90 *
91 * @return Current drawn by the compressor.
92 */
93 units::ampere_t GetCurrent() const;
94
95 /**
96 * If supported by the device, returns the analog input voltage (on channel
97 * 0).
98 *
99 * This function is only supported by the REV PH. On CTRE PCM, this will
100 * return 0.
101 *
102 * @return The analog input voltage, in volts.
103 */
104 units::volt_t GetAnalogVoltage() const;
105
106 /**
107 * If supported by the device, returns the pressure read by the analog
108 * pressure sensor (on channel 0).
109 *
110 * This function is only supported by the REV PH with the REV Analog Pressure
111 * Sensor. On CTRE PCM, this will return 0.
112 *
113 * @return The pressure read by the analog pressure sensor.
114 */
115 units::pounds_per_square_inch_t GetPressure() const;
116
117 /**
118 * Disable the compressor.
119 */
120 void Disable();
121
122 /**
123 * Enables the compressor in digital mode using the digital pressure switch.
124 * The compressor will turn on when the pressure switch indicates that the
125 * system is not full, and will turn off when the pressure switch indicates
126 * that the system is full.
127 */
129
130 /**
131 * If supported by the device, enables the compressor in analog mode. This
132 * mode uses an analog pressure sensor connected to analog channel 0 to cycle
133 * the compressor. The compressor will turn on when the pressure drops below
134 * {@code minPressure} and will turn off when the pressure reaches {@code
135 * maxPressure}. This mode is only supported by the REV PH with the REV Analog
136 * Pressure Sensor connected to analog channel 0.
137 *
138 * On CTRE PCM, this will enable digital control.
139 *
140 * @param minPressure The minimum pressure. The compressor will turn on when
141 * the pressure drops below this value.
142 * @param maxPressure The maximum pressure. The compressor will turn off when
143 * the pressure reaches this value.
144 */
145 void EnableAnalog(units::pounds_per_square_inch_t minPressure,
146 units::pounds_per_square_inch_t maxPressure);
147
148 /**
149 * If supported by the device, enables the compressor in hybrid mode. This
150 * mode uses both a digital pressure switch and an analog pressure sensor
151 * connected to analog channel 0 to cycle the compressor. This mode is only
152 * supported by the REV PH with the REV Analog Pressure Sensor connected to
153 * analog channel 0.
154 *
155 * The compressor will turn on when \a both:
156 *
157 * - The digital pressure switch indicates the system is not full AND
158 * - The analog pressure sensor indicates that the pressure in the system
159 * is below the specified minimum pressure.
160 *
161 * The compressor will turn off when \a either:
162 *
163 * - The digital pressure switch is disconnected or indicates that the system
164 * is full OR
165 * - The pressure detected by the analog sensor is greater than the specified
166 * maximum pressure.
167 *
168 * On CTRE PCM, this will enable digital control.
169 *
170 * @param minPressure The minimum pressure. The compressor will turn on
171 * when the pressure drops below this value and the pressure switch indicates
172 * that the system is not full.
173 * @param maxPressure The maximum pressure. The compressor will turn
174 * off when the pressure reaches this value or the pressure switch is
175 * disconnected or indicates that the system is full.
176 */
177 void EnableHybrid(units::pounds_per_square_inch_t minPressure,
178 units::pounds_per_square_inch_t maxPressure);
179
180 /**
181 * Returns the active compressor configuration.
182 *
183 * @return The active compressor configuration.
184 */
186
187 void InitSendable(wpi::SendableBuilder& builder) override;
188
189 private:
190 std::shared_ptr<PneumaticsBase> m_module;
191};
192
193} // namespace frc
Class for operating a compressor connected to a pneumatics module.
Definition: Compressor.h:35
~Compressor() override
bool GetPressureSwitchValue() const
Returns the state of the pressure switch.
void EnableDigital()
Enables the compressor in digital mode using the digital pressure switch.
Compressor(PneumaticsModuleType moduleType)
Constructs a compressor for a default module and specified type.
units::volt_t GetAnalogVoltage() const
If supported by the device, returns the analog input voltage (on channel 0).
units::pounds_per_square_inch_t GetPressure() const
If supported by the device, returns the pressure read by the analog pressure sensor (on channel 0).
CompressorConfigType GetConfigType() const
Returns the active compressor configuration.
bool IsEnabled() const
Returns whether the compressor is active or not.
Compressor(int module, PneumaticsModuleType moduleType)
Constructs a compressor for a specified module and type.
Compressor & operator=(const Compressor &)=delete
units::ampere_t GetCurrent() const
Get the current drawn by the compressor.
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
Compressor(Compressor &&)=default
void EnableHybrid(units::pounds_per_square_inch_t minPressure, units::pounds_per_square_inch_t maxPressure)
If supported by the device, enables the compressor in hybrid mode.
void EnableAnalog(units::pounds_per_square_inch_t minPressure, units::pounds_per_square_inch_t maxPressure)
If supported by the device, enables the compressor in analog mode.
bool Enabled() const
Check if compressor output is active.
Compressor(const Compressor &)=delete
Compressor & operator=(Compressor &&)=default
void Disable()
Disable the compressor.
Definition: SendableBuilder.h:18
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:19
Interface for Sendable objects.
Definition: Sendable.h:16
Definition: AprilTagPoseEstimator.h:15
CompressorConfigType
Definition: CompressorConfigType.h:8
PneumaticsModuleType
Definition: PneumaticsModuleType.h:8