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