WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
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 whenever the Vin voltage changes.
26 *
27 * @param callback the callback
28 * @param initialNotify whether to call the callback with the initial state
29 * @return the CallbackStore object associated with this callback
30 */
31 [[nodiscard]]
32 static std::unique_ptr<CallbackStore> RegisterVInVoltageCallback(
33 NotifyCallback callback, bool initialNotify);
34
35 /**
36 * Measure the Vin voltage.
37 *
38 * @return the Vin voltage
39 */
40 static units::volt_t GetVInVoltage();
41
42 /**
43 * Define the Vin voltage.
44 *
45 * @param vInVoltage the new voltage
46 */
47 static void SetVInVoltage(units::volt_t vInVoltage);
48
49 /**
50 * Register a callback to be run whenever the 3.3V rail voltage changes.
51 *
52 * @param callback the callback
53 * @param initialNotify whether the callback should be called with the
54 * initial value
55 * @return the CallbackStore object associated with this callback
56 */
57 [[nodiscard]]
58 static std::unique_ptr<CallbackStore> RegisterUserVoltage3V3Callback(
59 NotifyCallback callback, bool initialNotify);
60
61 /**
62 * Measure the 3.3V rail voltage.
63 *
64 * @return the 3.3V rail voltage
65 */
66 static units::volt_t GetUserVoltage3V3();
67
68 /**
69 * Define the 3.3V rail voltage.
70 *
71 * @param userVoltage3V3 the new voltage
72 */
73 static void SetUserVoltage3V3(units::volt_t userVoltage3V3);
74
75 /**
76 * Register a callback to be run whenever the 3.3V rail current changes.
77 *
78 * @param callback the callback
79 * @param initialNotify whether the callback should be called with the
80 * initial value
81 * @return the CallbackStore object associated with this callback
82 */
83 [[nodiscard]]
84 static std::unique_ptr<CallbackStore> RegisterUserCurrent3V3Callback(
85 NotifyCallback callback, bool initialNotify);
86
87 /**
88 * Measure the 3.3V rail current.
89 *
90 * @return the 3.3V rail current
91 */
92 static units::ampere_t GetUserCurrent3V3();
93
94 /**
95 * Define the 3.3V rail current.
96 *
97 * @param userCurrent3V3 the new current
98 */
99 static void SetUserCurrent3V3(units::ampere_t userCurrent3V3);
100
101 /**
102 * Register a callback to be run whenever the 3.3V rail active state changes.
103 *
104 * @param callback the callback
105 * @param initialNotify whether the callback should be called with the
106 * initial state
107 * @return the CallbackStore object associated with this callback
108 */
109 [[nodiscard]]
110 static std::unique_ptr<CallbackStore> RegisterUserActive3V3Callback(
111 NotifyCallback callback, bool initialNotify);
112
113 /**
114 * Get the 3.3V rail active state.
115 *
116 * @return true if the 3.3V rail is active
117 */
118 static bool GetUserActive3V3();
119
120 /**
121 * Set the 3.3V rail active state.
122 *
123 * @param userActive3V3 true to make rail active
124 */
125 static void SetUserActive3V3(bool userActive3V3);
126
127 /**
128 * Register a callback to be run whenever the 3.3V rail number of faults
129 * changes.
130 *
131 * @param callback the callback
132 * @param initialNotify whether the callback should be called with the
133 * initial value
134 * @return the CallbackStore object associated with this callback
135 */
136 [[nodiscard]]
137 static std::unique_ptr<CallbackStore> RegisterUserFaults3V3Callback(
138 NotifyCallback callback, bool initialNotify);
139
140 /**
141 * Get the 3.3V rail number of faults.
142 *
143 * @return number of faults
144 */
145 static int GetUserFaults3V3();
146
147 /**
148 * Set the 3.3V rail number of faults.
149 *
150 * @param userFaults3V3 number of faults
151 */
152 static void SetUserFaults3V3(int userFaults3V3);
153
154 /**
155 * Register a callback to be run whenever the brownout voltage changes.
156 *
157 * @param callback the callback
158 * @param initialNotify whether to call the callback with the initial state
159 * @return the CallbackStore object associated with this callback
160 */
161 [[nodiscard]]
162 static std::unique_ptr<CallbackStore> RegisterBrownoutVoltageCallback(
163 NotifyCallback callback, bool initialNotify);
164
165 /**
166 * Measure the brownout voltage.
167 *
168 * @return the brownout voltage
169 */
170 static units::volt_t GetBrownoutVoltage();
171
172 /**
173 * Define the brownout voltage.
174 *
175 * @param brownoutVoltage the new voltage
176 */
177 static void SetBrownoutVoltage(units::volt_t brownoutVoltage);
178
179 /**
180 * Register a callback to be run whenever the cpu temp changes.
181 *
182 * @param callback the callback
183 * @param initialNotify whether to call the callback with the initial state
184 * @return the CallbackStore object associated with this callback
185 */
186 [[nodiscard]]
187 static std::unique_ptr<CallbackStore> RegisterCPUTempCallback(
188 NotifyCallback callback, bool initialNotify);
189
190 /**
191 * Get the cpu temp.
192 *
193 * @return the cpu temp.
194 */
195 static units::celsius_t GetCPUTemp();
196
197 /**
198 * Define the cpu temp.
199 *
200 * @param cpuTemp the new cpu temp.
201 */
202 static void SetCPUTemp(units::celsius_t cpuTemp);
203
204 /**
205 * Register a callback to be run whenever the team number changes.
206 *
207 * @param callback the callback
208 * @param initialNotify whether to call the callback with the initial state
209 * @return the CallbackStore object associated with this callback
210 */
211 [[nodiscard]]
212 static std::unique_ptr<CallbackStore> RegisterTeamNumberCallback(
213 NotifyCallback callback, bool initialNotify);
214
215 /**
216 * Get the team number.
217 *
218 * @return the team number.
219 */
220 static int32_t GetTeamNumber();
221
222 /**
223 * Set the team number.
224 *
225 * @param teamNumber the new team number.
226 */
227 static void SetTeamNumber(int32_t teamNumber);
228
229 /**
230 * Get the serial number.
231 *
232 * @return The serial number.
233 */
234 static std::string GetSerialNumber();
235
236 /**
237 * Set the serial number.
238 *
239 * @param serialNumber The serial number.
240 */
241 static void SetSerialNumber(std::string_view serialNumber);
242
243 /**
244 * Get the comments.
245 *
246 * @return The comments.
247 */
248 static std::string GetComments();
249
250 /**
251 * Set the comments.
252 *
253 * @param comments The comments.
254 */
255 static void SetComments(std::string_view comments);
256
257 /**
258 * Reset all simulation data.
259 */
260 static void ResetData();
261};
262} // namespace frc::sim
A utility class to control a simulated RoboRIO.
Definition RoboRioSim.h:22
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 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 units::volt_t GetUserVoltage3V3()
Measure the 3.3V rail voltage.
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 > RegisterBrownoutVoltageCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run whenever the brownout voltage changes.
static void SetUserFaults3V3(int userFaults3V3)
Set the 3.3V rail number of faults.
static void SetTeamNumber(int32_t teamNumber)
Set the team number.
static bool GetUserActive3V3()
Get the 3.3V rail active state.
static units::volt_t GetVInVoltage()
Measure the Vin voltage.
static void SetUserVoltage3V3(units::volt_t userVoltage3V3)
Define the 3.3V rail voltage.
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 > 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 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 void SetBrownoutVoltage(units::volt_t brownoutVoltage)
Define the brownout voltage.
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 int32_t GetTeamNumber()
Get the team number.
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.
Definition SimHooks.h:12
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition CallbackStore.h:14