WPILibC++ 2025.0.0-alpha-1-9-ga2beb75
PneumaticsBaseSim.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
12
13namespace frc::sim {
14
16 public:
17 virtual ~PneumaticsBaseSim() = default;
18
19 static std::shared_ptr<PneumaticsBaseSim> GetForType(
20 int module, PneumaticsModuleType type);
21
22 /**
23 * Check whether the PCM/PH has been initialized.
24 *
25 * @return true if initialized
26 */
27 virtual bool GetInitialized() const = 0;
28
29 /**
30 * Define whether the PCM/PH has been initialized.
31 *
32 * @param initialized true for initialized
33 */
34 virtual void SetInitialized(bool initialized) = 0;
35
36 /**
37 * Register a callback to be run when the PCM/PH is initialized.
38 *
39 * @param callback the callback
40 * @param initialNotify whether to run the callback with the initial state
41 * @return the {@link CallbackStore} object associated with this callback.
42 * Save a reference to this object; it being deconstructed cancels the
43 * callback.
44 */
45 [[nodiscard]]
46 virtual std::unique_ptr<CallbackStore> RegisterInitializedCallback(
47 NotifyCallback callback, bool initialNotify) = 0;
48
49 /**
50 * Check if the compressor is on.
51 *
52 * @return true if the compressor is active
53 */
54 virtual bool GetCompressorOn() const = 0;
55
56 /**
57 * Set whether the compressor is active.
58 *
59 * @param compressorOn the new value
60 */
61 virtual void SetCompressorOn(bool compressorOn) = 0;
62
63 /**
64 * Register a callback to be run when the compressor activates.
65 *
66 * @param callback the callback
67 * @param initialNotify whether to run the callback with the initial state
68 * @return the {@link CallbackStore} object associated with this callback.
69 * Save a reference to this object; it being deconstructed cancels the
70 * callback.
71 */
72 [[nodiscard]]
73 virtual std::unique_ptr<CallbackStore> RegisterCompressorOnCallback(
74 NotifyCallback callback, bool initialNotify) = 0;
75
76 /**
77 * Check the solenoid output on a specific channel.
78 *
79 * @param channel the channel to check
80 * @return the solenoid output
81 */
82 virtual bool GetSolenoidOutput(int channel) const = 0;
83
84 /**
85 * Change the solenoid output on a specific channel.
86 *
87 * @param channel the channel to check
88 * @param solenoidOutput the new solenoid output
89 */
90 virtual void SetSolenoidOutput(int channel, bool solenoidOutput) = 0;
91
92 /**
93 * Register a callback to be run when the solenoid output on a channel
94 * changes.
95 *
96 * @param channel the channel to monitor
97 * @param callback the callback
98 * @param initialNotify should the callback be run with the initial value
99 * @return the {@link CallbackStore} object associated with this callback.
100 * Save a reference to this object; it being deconstructed cancels the
101 * callback.
102 */
103 [[nodiscard]]
104 virtual std::unique_ptr<CallbackStore> RegisterSolenoidOutputCallback(
105 int channel, NotifyCallback callback, bool initialNotify) = 0;
106
107 /**
108 * Check the value of the pressure switch.
109 *
110 * @return the pressure switch value
111 */
112 virtual bool GetPressureSwitch() const = 0;
113
114 /**
115 * Set the value of the pressure switch.
116 *
117 * @param pressureSwitch the new value
118 */
119 virtual void SetPressureSwitch(bool pressureSwitch) = 0;
120
121 /**
122 * Register a callback to be run whenever the pressure switch value changes.
123 *
124 * @param callback the callback
125 * @param initialNotify whether the callback should be called with the initial
126 * value
127 * @return the {@link CallbackStore} object associated with this callback.
128 * Save a reference to this object; it being deconstructed cancels the
129 * callback.
130 */
131 [[nodiscard]]
132 virtual std::unique_ptr<CallbackStore> RegisterPressureSwitchCallback(
133 NotifyCallback callback, bool initialNotify) = 0;
134
135 /**
136 * Read the compressor current.
137 *
138 * @return the current of the compressor connected to this module
139 */
140 virtual double GetCompressorCurrent() const = 0;
141
142 /**
143 * Set the compressor current.
144 *
145 * @param compressorCurrent the new compressor current
146 */
147 virtual void SetCompressorCurrent(double compressorCurrent) = 0;
148
149 /**
150 * Register a callback to be run whenever the compressor current changes.
151 *
152 * @param callback the callback
153 * @param initialNotify whether to call the callback with the initial state
154 * @return the {@link CallbackStore} object associated with this callback.
155 * Save a reference to this object; it being deconstructed cancels the
156 * callback.
157 */
158 [[nodiscard]]
159 virtual std::unique_ptr<CallbackStore> RegisterCompressorCurrentCallback(
160 NotifyCallback callback, bool initialNotify) = 0;
161
162 /**
163 * Get the current value of all solenoid outputs.
164 *
165 * @return the solenoid outputs (1 bit per output)
166 */
167 virtual uint8_t GetAllSolenoidOutputs() const = 0;
168
169 /**
170 * Change all of the solenoid outputs.
171 *
172 * @param outputs the new solenoid outputs (1 bit per output)
173 */
174 virtual void SetAllSolenoidOutputs(uint8_t outputs) = 0;
175
176 /** Reset all simulation data for this object. */
177 virtual void ResetData() = 0;
178
179 protected:
180 /// PneumaticsBase index.
181 const int m_index;
182
183 /**
184 * Constructs a PneumaticsBaseSim with the given index.
185 *
186 * @param index The index.
187 */
188 explicit PneumaticsBaseSim(const int index);
189
190 /**
191 * Constructs a PneumaticsBaseSim for the given module.
192 *
193 * @param module The module.
194 */
195 explicit PneumaticsBaseSim(const PneumaticsBase& module);
196};
197
198} // namespace frc::sim
Base class for pneumatics devices.
Definition: PneumaticsBase.h:25
Definition: PneumaticsBaseSim.h:15
virtual ~PneumaticsBaseSim()=default
virtual double GetCompressorCurrent() const =0
Read the compressor current.
virtual bool GetCompressorOn() const =0
Check if the compressor is on.
virtual std::unique_ptr< CallbackStore > RegisterSolenoidOutputCallback(int channel, NotifyCallback callback, bool initialNotify)=0
Register a callback to be run when the solenoid output on a channel changes.
virtual void SetSolenoidOutput(int channel, bool solenoidOutput)=0
Change the solenoid output on a specific channel.
virtual void SetAllSolenoidOutputs(uint8_t outputs)=0
Change all of the solenoid outputs.
virtual void SetPressureSwitch(bool pressureSwitch)=0
Set the value of the pressure switch.
PneumaticsBaseSim(const PneumaticsBase &module)
Constructs a PneumaticsBaseSim for the given module.
virtual void SetInitialized(bool initialized)=0
Define whether the PCM/PH has been initialized.
virtual std::unique_ptr< CallbackStore > RegisterInitializedCallback(NotifyCallback callback, bool initialNotify)=0
Register a callback to be run when the PCM/PH is initialized.
virtual void ResetData()=0
Reset all simulation data for this object.
virtual void SetCompressorCurrent(double compressorCurrent)=0
Set the compressor current.
PneumaticsBaseSim(const int index)
Constructs a PneumaticsBaseSim with the given index.
virtual bool GetPressureSwitch() const =0
Check the value of the pressure switch.
virtual uint8_t GetAllSolenoidOutputs() const =0
Get the current value of all solenoid outputs.
virtual bool GetSolenoidOutput(int channel) const =0
Check the solenoid output on a specific channel.
virtual std::unique_ptr< CallbackStore > RegisterCompressorCurrentCallback(NotifyCallback callback, bool initialNotify)=0
Register a callback to be run whenever the compressor current changes.
virtual std::unique_ptr< CallbackStore > RegisterCompressorOnCallback(NotifyCallback callback, bool initialNotify)=0
Register a callback to be run when the compressor activates.
const int m_index
PneumaticsBase index.
Definition: PneumaticsBaseSim.h:181
virtual bool GetInitialized() const =0
Check whether the PCM/PH has been initialized.
static std::shared_ptr< PneumaticsBaseSim > GetForType(int module, PneumaticsModuleType type)
virtual void SetCompressorOn(bool compressorOn)=0
Set whether the compressor is active.
virtual std::unique_ptr< CallbackStore > RegisterPressureSwitchCallback(NotifyCallback callback, bool initialNotify)=0
Register a callback to be run whenever the pressure switch value changes.
type
Definition: core.h:573
Definition: ADXL345Sim.h:14
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14
PneumaticsModuleType
Pneumatics module type.
Definition: PneumaticsModuleType.h:11