WPILibC++ 2023.4.3-108-ge5452e3
RoboRioSim.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#include <string>
9
10#include <units/current.h>
11#include <units/voltage.h>
12
14
15namespace frc::sim {
16
17/**
18 * A utility class to control a simulated RoboRIO.
19 */
21 public:
22 /**
23 * Register a callback to be run when the FPGA button state changes.
24 *
25 * @param callback the callback
26 * @param initialNotify whether to run the callback with the initial state
27 * @return the CallbackStore object associated with this callback
28 */
29 [[nodiscard]]
30 static std::unique_ptr<CallbackStore> RegisterFPGAButtonCallback(
31 NotifyCallback callback, bool initialNotify);
32
33 /**
34 * Query the state of the FPGA button.
35 *
36 * @return the FPGA button state
37 */
38 static bool GetFPGAButton();
39
40 /**
41 * Define the state of the FPGA button.
42 *
43 * @param fPGAButton the new state
44 */
45 static void SetFPGAButton(bool fPGAButton);
46
47 /**
48 * Register a callback to be run whenever the Vin voltage changes.
49 *
50 * @param callback the callback
51 * @param initialNotify whether to call the callback with the initial state
52 * @return the CallbackStore object associated with this callback
53 */
54 [[nodiscard]]
55 static std::unique_ptr<CallbackStore> RegisterVInVoltageCallback(
56 NotifyCallback callback, bool initialNotify);
57
58 /**
59 * Measure the Vin voltage.
60 *
61 * @return the Vin voltage
62 */
63 static units::volt_t GetVInVoltage();
64
65 /**
66 * Define the Vin voltage.
67 *
68 * @param vInVoltage the new voltage
69 */
70 static void SetVInVoltage(units::volt_t vInVoltage);
71
72 /**
73 * Register a callback to be run whenever the Vin current changes.
74 *
75 * @param callback the callback
76 * @param initialNotify whether the callback should be called with the
77 * initial value
78 * @return the CallbackStore object associated with this callback
79 */
80 [[nodiscard]]
81 static std::unique_ptr<CallbackStore> RegisterVInCurrentCallback(
82 NotifyCallback callback, bool initialNotify);
83
84 /**
85 * Measure the Vin current.
86 *
87 * @return the Vin current
88 */
89 static units::ampere_t GetVInCurrent();
90
91 /**
92 * Define the Vin current.
93 *
94 * @param vInCurrent the new current
95 */
96 static void SetVInCurrent(units::ampere_t vInCurrent);
97
98 /**
99 * Register a callback to be run whenever the 6V rail voltage changes.
100 *
101 * @param callback the callback
102 * @param initialNotify whether the callback should be called with the
103 * initial value
104 * @return the CallbackStore object associated with this callback
105 */
106 [[nodiscard]]
107 static std::unique_ptr<CallbackStore> RegisterUserVoltage6VCallback(
108 NotifyCallback callback, bool initialNotify);
109
110 /**
111 * Measure the 6V rail voltage.
112 *
113 * @return the 6V rail voltage
114 */
115 static units::volt_t GetUserVoltage6V();
116
117 /**
118 * Define the 6V rail voltage.
119 *
120 * @param userVoltage6V the new voltage
121 */
122 static void SetUserVoltage6V(units::volt_t userVoltage6V);
123
124 /**
125 * Register a callback to be run whenever the 6V rail current changes.
126 *
127 * @param callback the callback
128 * @param initialNotify whether the callback should be called with the
129 * initial value
130 * @return the CallbackStore object associated with this callback
131 */
132 [[nodiscard]]
133 static std::unique_ptr<CallbackStore> RegisterUserCurrent6VCallback(
134 NotifyCallback callback, bool initialNotify);
135
136 /**
137 * Measure the 6V rail current.
138 *
139 * @return the 6V rail current
140 */
141 static units::ampere_t GetUserCurrent6V();
142
143 /**
144 * Define the 6V rail current.
145 *
146 * @param userCurrent6V the new current
147 */
148 static void SetUserCurrent6V(units::ampere_t userCurrent6V);
149
150 /**
151 * Register a callback to be run whenever the 6V rail active state changes.
152 *
153 * @param callback the callback
154 * @param initialNotify whether the callback should be called with the
155 * initial state
156 * @return the CallbackStore object associated with this callback
157 */
158 [[nodiscard]]
159 static std::unique_ptr<CallbackStore> RegisterUserActive6VCallback(
160 NotifyCallback callback, bool initialNotify);
161
162 /**
163 * Get the 6V rail active state.
164 *
165 * @return true if the 6V rail is active
166 */
167 static bool GetUserActive6V();
168
169 /**
170 * Set the 6V rail active state.
171 *
172 * @param userActive6V true to make rail active
173 */
174 static void SetUserActive6V(bool userActive6V);
175
176 /**
177 * Register a callback to be run whenever the 5V rail voltage changes.
178 *
179 * @param callback the callback
180 * @param initialNotify whether the callback should be called with the
181 * initial value
182 * @return the CallbackStore object associated with this callback
183 */
184 [[nodiscard]]
185 static std::unique_ptr<CallbackStore> RegisterUserVoltage5VCallback(
186 NotifyCallback callback, bool initialNotify);
187
188 /**
189 * Measure the 5V rail voltage.
190 *
191 * @return the 5V rail voltage
192 */
193 static units::volt_t GetUserVoltage5V();
194
195 /**
196 * Define the 5V rail voltage.
197 *
198 * @param userVoltage5V the new voltage
199 */
200 static void SetUserVoltage5V(units::volt_t userVoltage5V);
201
202 /**
203 * Register a callback to be run whenever the 5V rail current changes.
204 *
205 * @param callback the callback
206 * @param initialNotify whether the callback should be called with the
207 * initial value
208 * @return the CallbackStore object associated with this callback
209 */
210 [[nodiscard]]
211 static std::unique_ptr<CallbackStore> RegisterUserCurrent5VCallback(
212 NotifyCallback callback, bool initialNotify);
213
214 /**
215 * Measure the 5V rail current.
216 *
217 * @return the 5V rail current
218 */
219 static units::ampere_t GetUserCurrent5V();
220
221 /**
222 * Define the 5V rail current.
223 *
224 * @param userCurrent5V the new current
225 */
226 static void SetUserCurrent5V(units::ampere_t userCurrent5V);
227
228 /**
229 * Register a callback to be run whenever the 5V rail active state changes.
230 *
231 * @param callback the callback
232 * @param initialNotify whether the callback should be called with the
233 * initial state
234 * @return the CallbackStore object associated with this callback
235 */
236 [[nodiscard]]
237 static std::unique_ptr<CallbackStore> RegisterUserActive5VCallback(
238 NotifyCallback callback, bool initialNotify);
239
240 /**
241 * Get the 5V rail active state.
242 *
243 * @return true if the 5V rail is active
244 */
245 static bool GetUserActive5V();
246
247 /**
248 * Set the 5V rail active state.
249 *
250 * @param userActive5V true to make rail active
251 */
252 static void SetUserActive5V(bool userActive5V);
253
254 /**
255 * Register a callback to be run whenever the 3.3V rail voltage changes.
256 *
257 * @param callback the callback
258 * @param initialNotify whether the callback should be called with the
259 * initial value
260 * @return the CallbackStore object associated with this callback
261 */
262 [[nodiscard]]
263 static std::unique_ptr<CallbackStore> RegisterUserVoltage3V3Callback(
264 NotifyCallback callback, bool initialNotify);
265
266 /**
267 * Measure the 3.3V rail voltage.
268 *
269 * @return the 3.3V rail voltage
270 */
271 static units::volt_t GetUserVoltage3V3();
272
273 /**
274 * Define the 3.3V rail voltage.
275 *
276 * @param userVoltage3V3 the new voltage
277 */
278 static void SetUserVoltage3V3(units::volt_t userVoltage3V3);
279
280 /**
281 * Register a callback to be run whenever the 3.3V rail current changes.
282 *
283 * @param callback the callback
284 * @param initialNotify whether the callback should be called with the
285 * initial value
286 * @return the CallbackStore object associated with this callback
287 */
288 [[nodiscard]]
289 static std::unique_ptr<CallbackStore> RegisterUserCurrent3V3Callback(
290 NotifyCallback callback, bool initialNotify);
291
292 /**
293 * Measure the 3.3V rail current.
294 *
295 * @return the 3.3V rail current
296 */
297 static units::ampere_t GetUserCurrent3V3();
298
299 /**
300 * Define the 3.3V rail current.
301 *
302 * @param userCurrent3V3 the new current
303 */
304 static void SetUserCurrent3V3(units::ampere_t userCurrent3V3);
305
306 /**
307 * Register a callback to be run whenever the 3.3V rail active state changes.
308 *
309 * @param callback the callback
310 * @param initialNotify whether the callback should be called with the
311 * initial state
312 * @return the CallbackStore object associated with this callback
313 */
314 [[nodiscard]]
315 static std::unique_ptr<CallbackStore> RegisterUserActive3V3Callback(
316 NotifyCallback callback, bool initialNotify);
317
318 /**
319 * Get the 3.3V rail active state.
320 *
321 * @return true if the 3.3V rail is active
322 */
323 static bool GetUserActive3V3();
324
325 /**
326 * Set the 3.3V rail active state.
327 *
328 * @param userActive3V3 true to make rail active
329 */
330 static void SetUserActive3V3(bool userActive3V3);
331
332 /**
333 * Register a callback to be run whenever the 6V rail number of faults
334 * changes.
335 *
336 * @param callback the callback
337 * @param initialNotify whether the callback should be called with the
338 * initial value
339 * @return the CallbackStore object associated with this callback
340 */
341 [[nodiscard]]
342 static std::unique_ptr<CallbackStore> RegisterUserFaults6VCallback(
343 NotifyCallback callback, bool initialNotify);
344
345 /**
346 * Get the 6V rail number of faults.
347 *
348 * @return number of faults
349 */
350 static int GetUserFaults6V();
351
352 /**
353 * Set the 6V rail number of faults.
354 *
355 * @param userFaults6V number of faults
356 */
357 static void SetUserFaults6V(int userFaults6V);
358
359 /**
360 * Register a callback to be run whenever the 5V rail number of faults
361 * changes.
362 *
363 * @param callback the callback
364 * @param initialNotify whether the callback should be called with the
365 * initial value
366 * @return the CallbackStore object associated with this callback
367 */
368 [[nodiscard]]
369 static std::unique_ptr<CallbackStore> RegisterUserFaults5VCallback(
370 NotifyCallback callback, bool initialNotify);
371
372 /**
373 * Get the 5V rail number of faults.
374 *
375 * @return number of faults
376 */
377 static int GetUserFaults5V();
378
379 /**
380 * Set the 5V rail number of faults.
381 *
382 * @param userFaults5V number of faults
383 */
384 static void SetUserFaults5V(int userFaults5V);
385
386 /**
387 * Register a callback to be run whenever the 3.3V rail number of faults
388 * changes.
389 *
390 * @param callback the callback
391 * @param initialNotify whether the callback should be called with the
392 * initial value
393 * @return the CallbackStore object associated with this callback
394 */
395 [[nodiscard]]
396 static std::unique_ptr<CallbackStore> RegisterUserFaults3V3Callback(
397 NotifyCallback callback, bool initialNotify);
398
399 /**
400 * Get the 3.3V rail number of faults.
401 *
402 * @return number of faults
403 */
404 static int GetUserFaults3V3();
405
406 /**
407 * Set the 3.3V rail number of faults.
408 *
409 * @param userFaults3V3 number of faults
410 */
411 static void SetUserFaults3V3(int userFaults3V3);
412
413 /**
414 * Register a callback to be run whenever the brownout voltage changes.
415 *
416 * @param callback the callback
417 * @param initialNotify whether to call the callback with the initial state
418 * @return the CallbackStore object associated with this callback
419 */
420 [[nodiscard]]
421 static std::unique_ptr<CallbackStore> RegisterBrownoutVoltageCallback(
422 NotifyCallback callback, bool initialNotify);
423
424 /**
425 * Measure the brownout voltage.
426 *
427 * @return the brownout voltage
428 */
429 static units::volt_t GetBrownoutVoltage();
430
431 /**
432 * Define the brownout voltage.
433 *
434 * @param brownoutVoltage the new voltage
435 */
436 static void SetBrownoutVoltage(units::volt_t brownoutVoltage);
437
438 /**
439 * Get the serial number.
440 *
441 * @return The serial number.
442 */
443 static std::string GetSerialNumber();
444
445 /**
446 * Set the serial number.
447 *
448 * @param serialNumber The serial number.
449 */
450 static void SetSerialNumber(std::string_view serialNumber);
451
452 /**
453 * Get the comments.
454 *
455 * @return The comments.
456 */
457 static std::string GetComments();
458
459 /**
460 * Set the comments.
461 *
462 * @param comments The comments.
463 */
464 static void SetComments(std::string_view comments);
465
466 /**
467 * Reset all simulation data.
468 */
469 static void ResetData();
470};
471} // namespace frc::sim
A utility class to control a simulated RoboRIO.
Definition: RoboRioSim.h:20
static std::string GetComments()
Get the comments.
static units::ampere_t GetUserCurrent3V3()
Measure the 3.3V rail current.
static void SetSerialNumber(std::string_view serialNumber)
Set the serial number.
static std::unique_ptr< CallbackStore > RegisterUserVoltage5VCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the 5V rail voltage changes.
static std::unique_ptr< CallbackStore > RegisterVInCurrentCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the Vin current changes.
static void SetUserActive3V3(bool userActive3V3)
Set the 3.3V rail active state.
static void SetFPGAButton(bool fPGAButton)
Define the state of the FPGA button.
static units::volt_t GetUserVoltage3V3()
Measure the 3.3V rail voltage.
static void SetVInCurrent(units::ampere_t vInCurrent)
Define the Vin current.
static void ResetData()
Reset all simulation data.
static std::unique_ptr< CallbackStore > RegisterUserFaults3V3Callback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the 3.3V rail number of faults changes.
static std::unique_ptr< CallbackStore > RegisterUserVoltage6VCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the 6V rail voltage changes.
static bool GetUserActive5V()
Get the 5V rail active state.
static int GetUserFaults5V()
Get the 5V rail number of faults.
static std::unique_ptr< CallbackStore > RegisterFPGAButtonCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run when the FPGA button state changes.
static void SetUserFaults6V(int userFaults6V)
Set the 6V rail number of faults.
static std::unique_ptr< CallbackStore > RegisterBrownoutVoltageCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the brownout voltage changes.
static units::ampere_t GetUserCurrent5V()
Measure the 5V rail current.
static void SetUserFaults5V(int userFaults5V)
Set the 5V rail number of faults.
static void SetUserFaults3V3(int userFaults3V3)
Set the 3.3V rail number of faults.
static void SetUserCurrent6V(units::ampere_t userCurrent6V)
Define the 6V rail current.
static bool GetUserActive3V3()
Get the 3.3V rail active state.
static units::ampere_t GetVInCurrent()
Measure the Vin current.
static units::volt_t GetUserVoltage6V()
Measure the 6V rail voltage.
static units::volt_t GetVInVoltage()
Measure the Vin voltage.
static void SetUserVoltage3V3(units::volt_t userVoltage3V3)
Define the 3.3V rail voltage.
static void SetUserActive6V(bool userActive6V)
Set the 6V rail active state.
static units::volt_t GetBrownoutVoltage()
Measure the brownout voltage.
static std::string GetSerialNumber()
Get the serial number.
static int GetUserFaults3V3()
Get the 3.3V rail number of faults.
static std::unique_ptr< CallbackStore > RegisterUserFaults5VCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the 5V rail number of faults changes.
static units::volt_t GetUserVoltage5V()
Measure the 5V rail voltage.
static std::unique_ptr< CallbackStore > RegisterUserVoltage3V3Callback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the 3.3V rail voltage changes.
static units::ampere_t GetUserCurrent6V()
Measure the 6V rail current.
static std::unique_ptr< CallbackStore > RegisterUserActive5VCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the 5V rail active state changes.
static std::unique_ptr< CallbackStore > RegisterUserActive3V3Callback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the 3.3V rail active state changes.
static void SetVInVoltage(units::volt_t vInVoltage)
Define the Vin voltage.
static std::unique_ptr< CallbackStore > RegisterUserActive6VCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the 6V rail active state changes.
static void SetUserActive5V(bool userActive5V)
Set the 5V rail active state.
static void SetUserVoltage5V(units::volt_t userVoltage5V)
Define the 5V rail voltage.
static bool GetFPGAButton()
Query the state of the FPGA button.
static void SetBrownoutVoltage(units::volt_t brownoutVoltage)
Define the brownout voltage.
static void SetUserCurrent5V(units::ampere_t userCurrent5V)
Define the 5V rail current.
static std::unique_ptr< CallbackStore > RegisterVInVoltageCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the Vin voltage changes.
static void SetComments(std::string_view comments)
Set the comments.
static void SetUserVoltage6V(units::volt_t userVoltage6V)
Define the 6V rail voltage.
static std::unique_ptr< CallbackStore > RegisterUserCurrent5VCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the 5V rail current changes.
static std::unique_ptr< CallbackStore > RegisterUserFaults6VCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the 6V rail number of faults changes.
static int GetUserFaults6V()
Get the 6V rail number of faults.
static bool GetUserActive6V()
Get the 6V rail active state.
static void SetUserCurrent3V3(units::ampere_t userCurrent3V3)
Define the 3.3V rail current.
static std::unique_ptr< CallbackStore > RegisterUserCurrent3V3Callback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the 3.3V rail current changes.
static std::unique_ptr< CallbackStore > RegisterUserCurrent6VCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the 6V rail current changes.
basic_string_view< char > string_view
Definition: core.h:520
Definition: BatterySim.h:14
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14