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