WPILibC++ 2023.4.3
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]] virtual std::unique_ptr<CallbackStore>
46 RegisterInitializedCallback(NotifyCallback callback, bool initialNotify) = 0;
47
48 /**
49 * Check if the compressor is on.
50 *
51 * @return true if the compressor is active
52 */
53 virtual bool GetCompressorOn() const = 0;
54
55 /**
56 * Set whether the compressor is active.
57 *
58 * @param compressorOn the new value
59 */
60 virtual void SetCompressorOn(bool compressorOn) = 0;
61
62 /**
63 * Register a callback to be run when the compressor activates.
64 *
65 * @param callback the callback
66 * @param initialNotify whether to run the callback with the initial state
67 * @return the {@link CallbackStore} object associated with this callback.
68 * Save a reference to this object; it being deconstructed cancels the
69 * callback.
70 */
71 [[nodiscard]] virtual std::unique_ptr<CallbackStore>
72 RegisterCompressorOnCallback(NotifyCallback callback, bool initialNotify) = 0;
73
74 /**
75 * Check the solenoid output on a specific channel.
76 *
77 * @param channel the channel to check
78 * @return the solenoid output
79 */
80 virtual bool GetSolenoidOutput(int channel) const = 0;
81
82 /**
83 * Change the solenoid output on a specific channel.
84 *
85 * @param channel the channel to check
86 * @param solenoidOutput the new solenoid output
87 */
88 virtual void SetSolenoidOutput(int channel, bool solenoidOutput) = 0;
89
90 /**
91 * Register a callback to be run when the solenoid output on a channel
92 * changes.
93 *
94 * @param channel the channel to monitor
95 * @param callback the callback
96 * @param initialNotify should the callback be run with the initial value
97 * @return the {@link CallbackStore} object associated with this callback.
98 * Save a reference to this object; it being deconstructed cancels the
99 * callback.
100 */
101 [[nodiscard]] virtual std::unique_ptr<CallbackStore>
103 bool initialNotify) = 0;
104
105 /**
106 * Check the value of the pressure switch.
107 *
108 * @return the pressure switch value
109 */
110 virtual bool GetPressureSwitch() const = 0;
111
112 /**
113 * Set the value of the pressure switch.
114 *
115 * @param pressureSwitch the new value
116 */
117 virtual void SetPressureSwitch(bool pressureSwitch) = 0;
118
119 /**
120 * Register a callback to be run whenever the pressure switch value changes.
121 *
122 * @param callback the callback
123 * @param initialNotify whether the callback should be called with the initial
124 * value
125 * @return the {@link CallbackStore} object associated with this callback.
126 * Save a reference to this object; it being deconstructed cancels the
127 * callback.
128 */
129 [[nodiscard]] virtual std::unique_ptr<CallbackStore>
131 bool initialNotify) = 0;
132
133 /**
134 * Read the compressor current.
135 *
136 * @return the current of the compressor connected to this module
137 */
138 virtual double GetCompressorCurrent() const = 0;
139
140 /**
141 * Set the compressor current.
142 *
143 * @param compressorCurrent the new compressor current
144 */
145 virtual void SetCompressorCurrent(double compressorCurrent) = 0;
146
147 /**
148 * Register a callback to be run whenever the compressor current changes.
149 *
150 * @param callback the callback
151 * @param initialNotify whether to call the callback with the initial state
152 * @return the {@link CallbackStore} object associated with this callback.
153 * Save a reference to this object; it being deconstructed cancels the
154 * callback.
155 */
156 [[nodiscard]] virtual std::unique_ptr<CallbackStore>
158 bool initialNotify) = 0;
159
160 /**
161 * Get the current value of all solenoid outputs.
162 *
163 * @return the solenoid outputs (1 bit per output)
164 */
165 virtual uint8_t GetAllSolenoidOutputs() const = 0;
166
167 /**
168 * Change all of the solenoid outputs.
169 *
170 * @param outputs the new solenoid outputs (1 bit per output)
171 */
172 virtual void SetAllSolenoidOutputs(uint8_t outputs) = 0;
173
174 /** Reset all simulation data for this object. */
175 virtual void ResetData() = 0;
176
177 protected:
178 const int m_index;
179 explicit PneumaticsBaseSim(const PneumaticsBase& module);
180 explicit PneumaticsBaseSim(const int index);
181};
182
183} // namespace frc::sim
Definition: PneumaticsBase.h:21
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)
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)
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
Definition: PneumaticsBaseSim.h:178
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:575
::uint8_t uint8_t
Definition: Meta.h:52
Definition: AnalogOutputSim.h:15
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14
PneumaticsModuleType
Definition: PneumaticsModuleType.h:8