WPILibC++ 2024.3.1
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 * Returns whether the compressor is active or not.
62 *
63 * @return true if the compressor is on - otherwise false.
64 */
65 bool IsEnabled() const;
66
67 /**
68 * Returns the state of the pressure switch.
69 *
70 * @return True if pressure switch indicates that the system is not full,
71 * otherwise false.
72 */
74
75 /**
76 * Get the current drawn by the compressor.
77 *
78 * @return Current drawn by the compressor.
79 */
80 units::ampere_t GetCurrent() const;
81
82 /**
83 * If supported by the device, returns the analog input voltage (on channel
84 * 0).
85 *
86 * This function is only supported by the REV PH. On CTRE PCM, this will
87 * return 0.
88 *
89 * @return The analog input voltage, in volts.
90 */
91 units::volt_t GetAnalogVoltage() const;
92
93 /**
94 * If supported by the device, returns the pressure read by the analog
95 * pressure sensor (on channel 0).
96 *
97 * This function is only supported by the REV PH with the REV Analog Pressure
98 * Sensor. On CTRE PCM, this will return 0.
99 *
100 * @return The pressure read by the analog pressure sensor.
101 */
102 units::pounds_per_square_inch_t GetPressure() const;
103
104 /**
105 * Disable the compressor.
106 */
107 void Disable();
108
109 /**
110 * Enables the compressor in digital mode using the digital pressure switch.
111 * The compressor will turn on when the pressure switch indicates that the
112 * system is not full, and will turn off when the pressure switch indicates
113 * that the system is full.
114 */
116
117 /**
118 * If supported by the device, enables the compressor in analog mode. This
119 * mode uses an analog pressure sensor connected to analog channel 0 to cycle
120 * the compressor. The compressor will turn on when the pressure drops below
121 * {@code minPressure} and will turn off when the pressure reaches {@code
122 * maxPressure}. This mode is only supported by the REV PH with the REV Analog
123 * Pressure Sensor connected to analog channel 0.
124 *
125 * On CTRE PCM, this will enable digital control.
126 *
127 * @param minPressure The minimum pressure. The compressor will turn on when
128 * the pressure drops below this value.
129 * @param maxPressure The maximum pressure. The compressor will turn off when
130 * the pressure reaches this value.
131 */
132 void EnableAnalog(units::pounds_per_square_inch_t minPressure,
133 units::pounds_per_square_inch_t maxPressure);
134
135 /**
136 * If supported by the device, enables the compressor in hybrid mode. This
137 * mode uses both a digital pressure switch and an analog pressure sensor
138 * connected to analog channel 0 to cycle the compressor. This mode is only
139 * supported by the REV PH with the REV Analog Pressure Sensor connected to
140 * analog channel 0.
141 *
142 * The compressor will turn on when \a both:
143 *
144 * - The digital pressure switch indicates the system is not full AND
145 * - The analog pressure sensor indicates that the pressure in the system
146 * is below the specified minimum pressure.
147 *
148 * The compressor will turn off when \a either:
149 *
150 * - The digital pressure switch is disconnected or indicates that the system
151 * is full OR
152 * - The pressure detected by the analog sensor is greater than the specified
153 * maximum pressure.
154 *
155 * On CTRE PCM, this will enable digital control.
156 *
157 * @param minPressure The minimum pressure. The compressor will turn on
158 * when the pressure drops below this value and the pressure switch indicates
159 * that the system is not full.
160 * @param maxPressure The maximum pressure. The compressor will turn
161 * off when the pressure reaches this value or the pressure switch is
162 * disconnected or indicates that the system is full.
163 */
164 void EnableHybrid(units::pounds_per_square_inch_t minPressure,
165 units::pounds_per_square_inch_t maxPressure);
166
167 /**
168 * Returns the active compressor configuration.
169 *
170 * @return The active compressor configuration.
171 */
173
174 void InitSendable(wpi::SendableBuilder& builder) override;
175
176 private:
177 std::shared_ptr<PneumaticsBase> m_module;
178};
179
180} // 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.
Compressor(const Compressor &)=delete
Compressor & operator=(Compressor &&)=default
void Disable()
Disable the compressor.
Helper class for building Sendable dashboard representations.
Definition: SendableBuilder.h:21
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: AprilTagDetector_cv.h:11
CompressorConfigType
Compressor config type.
Definition: CompressorConfigType.h:11
PneumaticsModuleType
Pneumatics module type.
Definition: PneumaticsModuleType.h:11