WPILibC++ 2024.3.2
AnalogInputSim.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
10
11namespace frc {
12
13class AnalogInput;
14
15namespace sim {
16
17/**
18 * Class to control a simulated analog input.
19 */
21 public:
22 /**
23 * Constructs from an AnalogInput object.
24 *
25 * @param analogInput AnalogInput to simulate
26 */
27 explicit AnalogInputSim(const AnalogInput& analogInput);
28
29 /**
30 * Constructs from an analog input channel number.
31 *
32 * @param channel Channel number
33 */
34 explicit AnalogInputSim(int channel);
35
36 /**
37 * Register a callback on whether the analog input is initialized.
38 *
39 * @param callback the callback that will be called whenever the analog input
40 * is initialized
41 * @param initialNotify if true, the callback will be run on the initial value
42 * @return the CallbackStore object associated with this callback
43 */
44 [[nodiscard]]
45 std::unique_ptr<CallbackStore> RegisterInitializedCallback(
46 NotifyCallback callback, bool initialNotify);
47
48 /**
49 * Check if this analog input has been initialized.
50 *
51 * @return true if initialized
52 */
53 bool GetInitialized() const;
54
55 /**
56 * Change whether this analog input has been initialized.
57 *
58 * @param initialized the new value
59 */
60 void SetInitialized(bool initialized);
61
62 /**
63 * Register a callback on the number of average bits.
64 *
65 * @param callback the callback that will be called whenever the number of
66 * average bits is changed
67 * @param initialNotify if true, the callback will be run on the initial value
68 * @return the CallbackStore object associated with this callback
69 */
70 [[nodiscard]]
71 std::unique_ptr<CallbackStore> RegisterAverageBitsCallback(
72 NotifyCallback callback, bool initialNotify);
73
74 /**
75 * Get the number of average bits.
76 *
77 * @return the number of average bits
78 */
79 int GetAverageBits() const;
80
81 /**
82 * Change the number of average bits.
83 *
84 * @param averageBits the new value
85 */
86 void SetAverageBits(int averageBits);
87
88 /**
89 * Register a callback on the amount of oversampling bits.
90 *
91 * @param callback the callback that will be called whenever the oversampling
92 * bits are changed
93 * @param initialNotify if true, the callback will be run on the initial value
94 * @return the CallbackStore object associated with this callback
95 */
96 [[nodiscard]]
97 std::unique_ptr<CallbackStore> RegisterOversampleBitsCallback(
98 NotifyCallback callback, bool initialNotify);
99
100 /**
101 * Get the amount of oversampling bits.
102 *
103 * @return the amount of oversampling bits
104 */
105 int GetOversampleBits() const;
106
107 /**
108 * Change the amount of oversampling bits.
109 *
110 * @param oversampleBits the new value
111 */
112 void SetOversampleBits(int oversampleBits);
113
114 /**
115 * Register a callback on the voltage.
116 *
117 * @param callback the callback that will be called whenever the voltage is
118 * changed
119 * @param initialNotify if true, the callback will be run on the initial value
120 * @return the CallbackStore object associated with this callback
121 */
122 [[nodiscard]]
123 std::unique_ptr<CallbackStore> RegisterVoltageCallback(
124 NotifyCallback callback, bool initialNotify);
125
126 /**
127 * Get the voltage.
128 *
129 * @return the voltage
130 */
131 double GetVoltage() const;
132
133 /**
134 * Change the voltage.
135 *
136 * @param voltage the new value
137 */
138 void SetVoltage(double voltage);
139
140 /**
141 * Register a callback on whether the accumulator is initialized.
142 *
143 * @param callback the callback that will be called whenever the accumulator
144 * is initialized
145 * @param initialNotify if true, the callback will be run on the initial value
146 * @return the CallbackStore object associated with this callback
147 */
148 [[nodiscard]]
149 std::unique_ptr<CallbackStore> RegisterAccumulatorInitializedCallback(
150 NotifyCallback callback, bool initialNotify);
151
152 /**
153 * Check if the accumulator has been initialized.
154 *
155 * @return true if initialized
156 */
158
159 /**
160 * Change whether the accumulator has been initialized.
161 *
162 * @param accumulatorInitialized the new value
163 */
164 void SetAccumulatorInitialized(bool accumulatorInitialized);
165
166 /**
167 * Register a callback on the accumulator value.
168 *
169 * @param callback the callback that will be called whenever the accumulator
170 * value is changed
171 * @param initialNotify if true, the callback will be run on the initial value
172 * @return the CallbackStore object associated with this callback
173 */
174 [[nodiscard]]
175 std::unique_ptr<CallbackStore> RegisterAccumulatorValueCallback(
176 NotifyCallback callback, bool initialNotify);
177
178 /**
179 * Get the accumulator value.
180 *
181 * @return the accumulator value
182 */
183 int64_t GetAccumulatorValue() const;
184
185 /**
186 * Change the accumulator value.
187 *
188 * @param accumulatorValue the new value
189 */
190 void SetAccumulatorValue(int64_t accumulatorValue);
191
192 /**
193 * Register a callback on the accumulator count.
194 *
195 * @param callback the callback that will be called whenever the accumulator
196 * count is changed
197 * @param initialNotify if true, the callback will be run on the initial value
198 * @return the CallbackStore object associated with this callback
199 */
200 [[nodiscard]]
201 std::unique_ptr<CallbackStore> RegisterAccumulatorCountCallback(
202 NotifyCallback callback, bool initialNotify);
203
204 /**
205 * Get the accumulator count.
206 *
207 * @return the accumulator count.
208 */
209 int64_t GetAccumulatorCount() const;
210
211 /**
212 * Change the accumulator count.
213 *
214 * @param accumulatorCount the new count.
215 */
216 void SetAccumulatorCount(int64_t accumulatorCount);
217
218 /**
219 * Register a callback on the accumulator center.
220 *
221 * @param callback the callback that will be called whenever the accumulator
222 * center is changed
223 * @param initialNotify if true, the callback will be run on the initial value
224 * @return the CallbackStore object associated with this callback
225 */
226 [[nodiscard]]
227 std::unique_ptr<CallbackStore> RegisterAccumulatorCenterCallback(
228 NotifyCallback callback, bool initialNotify);
229
230 /**
231 * Get the accumulator center.
232 *
233 * @return the accumulator center
234 */
236
237 /**
238 * Change the accumulator center.
239 *
240 * @param accumulatorCenter the new center
241 */
242 void SetAccumulatorCenter(int accumulatorCenter);
243
244 /**
245 * Register a callback on the accumulator deadband.
246 *
247 * @param callback the callback that will be called whenever the accumulator
248 * deadband is changed
249 * @param initialNotify if true, the callback will be run on the initial value
250 * @return the CallbackStore object associated with this callback
251 */
252 [[nodiscard]]
253 std::unique_ptr<CallbackStore> RegisterAccumulatorDeadbandCallback(
254 NotifyCallback callback, bool initialNotify);
255
256 /**
257 * Get the accumulator deadband.
258 *
259 * @return the accumulator deadband
260 */
262
263 /**
264 * Change the accumulator deadband.
265 *
266 * @param accumulatorDeadband the new deadband
267 */
268 void SetAccumulatorDeadband(int accumulatorDeadband);
269
270 /**
271 * Reset all simulation data for this object.
272 */
273 void ResetData();
274
275 private:
276 int m_index;
277};
278} // namespace sim
279} // namespace frc
Analog input class.
Definition: AnalogInput.h:31
Class to control a simulated analog input.
Definition: AnalogInputSim.h:20
std::unique_ptr< CallbackStore > RegisterAccumulatorValueCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the accumulator value.
std::unique_ptr< CallbackStore > RegisterAverageBitsCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the number of average bits.
int GetAccumulatorDeadband() const
Get the accumulator deadband.
int GetAverageBits() const
Get the number of average bits.
bool GetInitialized() const
Check if this analog input has been initialized.
void SetAccumulatorCount(int64_t accumulatorCount)
Change the accumulator count.
std::unique_ptr< CallbackStore > RegisterAccumulatorDeadbandCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the accumulator deadband.
int GetAccumulatorCenter() const
Get the accumulator center.
double GetVoltage() const
Get the voltage.
int GetOversampleBits() const
Get the amount of oversampling bits.
std::unique_ptr< CallbackStore > RegisterAccumulatorCenterCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the accumulator center.
void SetVoltage(double voltage)
Change the voltage.
void SetAccumulatorInitialized(bool accumulatorInitialized)
Change whether the accumulator has been initialized.
std::unique_ptr< CallbackStore > RegisterInitializedCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the analog input is initialized.
void SetInitialized(bool initialized)
Change whether this analog input has been initialized.
int64_t GetAccumulatorCount() const
Get the accumulator count.
std::unique_ptr< CallbackStore > RegisterOversampleBitsCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the amount of oversampling bits.
std::unique_ptr< CallbackStore > RegisterAccumulatorCountCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the accumulator count.
int64_t GetAccumulatorValue() const
Get the accumulator value.
AnalogInputSim(const AnalogInput &analogInput)
Constructs from an AnalogInput object.
void SetAccumulatorValue(int64_t accumulatorValue)
Change the accumulator value.
std::unique_ptr< CallbackStore > RegisterVoltageCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the voltage.
void SetAccumulatorCenter(int accumulatorCenter)
Change the accumulator center.
void SetAccumulatorDeadband(int accumulatorDeadband)
Change the accumulator deadband.
AnalogInputSim(int channel)
Constructs from an analog input channel number.
bool GetAccumulatorInitialized() const
Check if the accumulator has been initialized.
void SetOversampleBits(int oversampleBits)
Change the amount of oversampling bits.
void SetAverageBits(int averageBits)
Change the number of average bits.
void ResetData()
Reset all simulation data for this object.
std::unique_ptr< CallbackStore > RegisterAccumulatorInitializedCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the accumulator is initialized.
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14
Definition: AprilTagPoseEstimator.h:15