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