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