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