WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
RobotController.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 <stdint.h>
8
9#include <functional>
10#include <string>
11
12#include <units/temperature.h>
13#include <units/voltage.h>
14
15namespace frc {
16
24
25/** State for the radio led. */
27 kOff = 0, ///< Off.
28 kGreen = 1, ///< Green.
29 kRed = 2, ///< Red.
30 kOrange = 3 ///< Orange.
31};
32
34 public:
35 RobotController() = delete;
36
37 /**
38 * Return the FPGA Version number.
39 *
40 * For now, expect this to be competition year.
41 *
42 * @return FPGA Version number.
43 */
44 static int GetFPGAVersion();
45
46 /**
47 * Return the FPGA Revision number.
48 *
49 * The format of the revision is 3 numbers. The 12 most significant bits are
50 * the Major Revision. The next 8 bits are the Minor Revision. The 12 least
51 * significant bits are the Build Number.
52 *
53 * @return FPGA Revision number.
54 */
55 static int64_t GetFPGARevision();
56
57 /**
58 * Return the serial number of the roboRIO.
59 *
60 * @return The serial number of the roboRIO.
61 */
62 static std::string GetSerialNumber();
63
64 /**
65 * Return the comments from the roboRIO web interface.
66 *
67 * The comments string is cached after the first call to this function on the
68 * RoboRIO - restart the robot code to reload the comments string after
69 * changing it in the web interface.
70 *
71 * @return The comments from the roboRIO web interface.
72 */
73 static std::string GetComments();
74
75 /**
76 * Returns the team number configured for the robot controller.
77 *
78 * @return team number, or 0 if not found.
79 */
80 static int32_t GetTeamNumber();
81
82 /**
83 * Sets a new source to provide the clock time in microseconds. Changing this
84 * affects the return value of {@code GetTime}.
85 *
86 * @param supplier Function to return the time in microseconds.
87 */
88 static void SetTimeSource(std::function<uint64_t()> supplier);
89
90 /**
91 * Read the microsecond timestamp. By default, the time is based on the FPGA
92 * hardware clock in microseconds since the FPGA started. However, the return
93 * value of this method may be modified to use any time base, including
94 * non-monotonic and non-continuous time bases.
95 *
96 * @return The current time in microseconds.
97 */
98 static uint64_t GetTime();
99
100 /**
101 * Read the microsecond-resolution timer on the FPGA.
102 *
103 * @return The current time in microseconds according to the FPGA (since FPGA
104 * reset).
105 */
106 static uint64_t GetFPGATime();
107
108 /**
109 * Get the state of the "USER" button on the roboRIO.
110 *
111 * @warning the User Button is used to stop user programs from automatically
112 * loading if it is held for more then 5 seconds. Because of this, it's not
113 * recommended to be used by teams for any other purpose.
114 *
115 * @return True if the button is currently pressed down
116 */
117 static bool GetUserButton();
118
119 /**
120 * Read the battery voltage.
121 *
122 * @return The battery voltage in Volts.
123 */
124 static units::volt_t GetBatteryVoltage();
125
126 /**
127 * Check if the FPGA outputs are enabled.
128 *
129 * The outputs may be disabled if the robot is disabled or e-stopped, the
130 * watchdog has expired, or if the roboRIO browns out.
131 *
132 * @return True if the FPGA outputs are enabled.
133 */
134 static bool IsSysActive();
135
136 /**
137 * Check if the system is browned out.
138 *
139 * @return True if the system is browned out
140 */
141 static bool IsBrownedOut();
142
143 /**
144 * Gets the number of times the system has been disabled due to communication
145 * errors with the Driver Station.
146 *
147 * @return number of disables due to communication errors.
148 */
150
151 /**
152 * Gets the current state of the Robot Signal Light (RSL)
153 * @return The current state of the RSL- true if on, false if off
154 */
155 static bool GetRSLState();
156
157 /**
158 * Gets if the system time is valid.
159 *
160 * @return True if the system time is valid, false otherwise
161 */
162 static bool IsSystemTimeValid();
163
164 /**
165 * Get the input voltage to the robot controller.
166 *
167 * @return The controller input voltage value in Volts
168 */
169 static double GetInputVoltage();
170
171 /**
172 * Get the input current to the robot controller.
173 *
174 * @return The controller input current value in Amps
175 */
176 static double GetInputCurrent();
177
178 /**
179 * Get the voltage of the 3.3V rail.
180 *
181 * @return The controller 3.3V rail voltage value in Volts
182 */
183 static double GetVoltage3V3();
184
185 /**
186 * Get the current output of the 3.3V rail.
187 *
188 * @return The controller 3.3V rail output current value in Amps
189 */
190 static double GetCurrent3V3();
191
192 /**
193 * Enables or disables the 3.3V rail.
194 *
195 * @param enabled whether to enable the 3.3V rail.
196 */
197 static void SetEnabled3V3(bool enabled);
198
199 /**
200 * Get the enabled state of the 3.3V rail. The rail may be disabled due to
201 * calling SetEnabled3V3(), a controller brownout, a short circuit on the
202 * rail, or controller over-voltage.
203 *
204 * @return The controller 3.3V rail enabled value. True for enabled.
205 */
206 static bool GetEnabled3V3();
207
208 /**
209 * Get the count of the total current faults on the 3.3V rail since the
210 * code started.
211 *
212 * @return The number of faults
213 */
214 static int GetFaultCount3V3();
215
216 /**
217 * Get the voltage of the 5V rail.
218 *
219 * @return The controller 5V rail voltage value in Volts
220 */
221 static double GetVoltage5V();
222
223 /**
224 * Get the current output of the 5V rail.
225 *
226 * @return The controller 5V rail output current value in Amps
227 */
228 static double GetCurrent5V();
229
230 /**
231 * Enables or disables the 5V rail.
232 *
233 * @param enabled whether to enable the 5V rail.
234 */
235 static void SetEnabled5V(bool enabled);
236
237 /**
238 * Get the enabled state of the 5V rail. The rail may be disabled due to
239 * calling SetEnabled5V(), a controller brownout, a short circuit on the rail,
240 * or controller over-voltage.
241 *
242 * @return The controller 5V rail enabled value. True for enabled.
243 */
244 static bool GetEnabled5V();
245
246 /**
247 * Get the count of the total current faults on the 5V rail since the
248 * code started.
249 *
250 * @return The number of faults
251 */
252 static int GetFaultCount5V();
253
254 /**
255 * Get the voltage of the 6V rail.
256 *
257 * @return The controller 6V rail voltage value in Volts
258 */
259 static double GetVoltage6V();
260
261 /**
262 * Get the current output of the 6V rail.
263 *
264 * @return The controller 6V rail output current value in Amps
265 */
266 static double GetCurrent6V();
267
268 /**
269 * Enables or disables the 6V rail.
270 *
271 * @param enabled whether to enable the 6V rail.
272 */
273 static void SetEnabled6V(bool enabled);
274
275 /**
276 * Get the enabled state of the 6V rail. The rail may be disabled due to
277 * calling SetEnabled6V(), a controller brownout, a short circuit on the rail,
278 * or controller over-voltage.
279 *
280 * @return The controller 6V rail enabled value. True for enabled.
281 */
282 static bool GetEnabled6V();
283
284 /**
285 * Get the count of the total current faults on the 6V rail since the
286 * code started.
287 *
288 * @return The number of faults.
289 */
290 static int GetFaultCount6V();
291
292 /** Reset the overcurrent fault counters for all user rails to 0. */
293 static void ResetRailFaultCounts();
294
295 /**
296 * Get the current brownout voltage setting.
297 *
298 * @return The brownout voltage
299 */
300 static units::volt_t GetBrownoutVoltage();
301
302 /**
303 * Set the voltage the roboRIO will brownout and disable all outputs.
304 *
305 * Note that this only does anything on the roboRIO 2.
306 * On the roboRIO it is a no-op.
307 *
308 * @param brownoutVoltage The brownout voltage
309 */
310 static void SetBrownoutVoltage(units::volt_t brownoutVoltage);
311
312 /**
313 * Get the current CPU temperature.
314 *
315 * @return current CPU temperature
316 */
317 static units::celsius_t GetCPUTemp();
318
319 /**
320 * Set the state of the "Radio" LED. On the RoboRIO, this writes to sysfs, so
321 * this function should not be called multiple times per loop cycle to avoid
322 * overruns.
323 * @param state The state to set the LED to.
324 */
325 static void SetRadioLEDState(RadioLEDState state);
326
327 /**
328 * Get the state of the "Radio" LED. On the RoboRIO, this reads from sysfs, so
329 * this function should not be called multiple times per loop cycle to avoid
330 * overruns.
331 *
332 * @return The state of the LED.
333 */
335
336 /**
337 * Get the current status of the CAN bus.
338 *
339 * @return The status of the CAN bus
340 */
342
343 private:
344 static std::function<uint64_t()> m_timeSource;
345};
346
347} // namespace frc
Definition RobotController.h:33
static bool IsSysActive()
Check if the FPGA outputs are enabled.
static void SetBrownoutVoltage(units::volt_t brownoutVoltage)
Set the voltage the roboRIO will brownout and disable all outputs.
static int GetFaultCount3V3()
Get the count of the total current faults on the 3.3V rail since the code started.
static std::string GetComments()
Return the comments from the roboRIO web interface.
static uint64_t GetFPGATime()
Read the microsecond-resolution timer on the FPGA.
static bool GetEnabled3V3()
Get the enabled state of the 3.3V rail.
static units::volt_t GetBatteryVoltage()
Read the battery voltage.
static double GetVoltage5V()
Get the voltage of the 5V rail.
static int GetFaultCount5V()
Get the count of the total current faults on the 5V rail since the code started.
static int GetCommsDisableCount()
Gets the number of times the system has been disabled due to communication errors with the Driver Sta...
static CANStatus GetCANStatus()
Get the current status of the CAN bus.
static bool IsBrownedOut()
Check if the system is browned out.
static RadioLEDState GetRadioLEDState()
Get the state of the "Radio" LED.
static bool IsSystemTimeValid()
Gets if the system time is valid.
static int GetFPGAVersion()
Return the FPGA Version number.
static int64_t GetFPGARevision()
Return the FPGA Revision number.
static double GetVoltage3V3()
Get the voltage of the 3.3V rail.
static int GetFaultCount6V()
Get the count of the total current faults on the 6V rail since the code started.
static units::volt_t GetBrownoutVoltage()
Get the current brownout voltage setting.
static void SetEnabled6V(bool enabled)
Enables or disables the 6V rail.
static std::string GetSerialNumber()
Return the serial number of the roboRIO.
static double GetInputVoltage()
Get the input voltage to the robot controller.
static double GetVoltage6V()
Get the voltage of the 6V rail.
static bool GetEnabled5V()
Get the enabled state of the 5V rail.
static void SetTimeSource(std::function< uint64_t()> supplier)
Sets a new source to provide the clock time in microseconds.
static void SetEnabled5V(bool enabled)
Enables or disables the 5V rail.
static double GetCurrent3V3()
Get the current output of the 3.3V rail.
static units::celsius_t GetCPUTemp()
Get the current CPU temperature.
static bool GetUserButton()
Get the state of the "USER" button on the roboRIO.
static int32_t GetTeamNumber()
Returns the team number configured for the robot controller.
static bool GetRSLState()
Gets the current state of the Robot Signal Light (RSL)
static bool GetEnabled6V()
Get the enabled state of the 6V rail.
static void ResetRailFaultCounts()
Reset the overcurrent fault counters for all user rails to 0.
static void SetEnabled3V3(bool enabled)
Enables or disables the 3.3V rail.
static double GetCurrent6V()
Get the current output of the 6V rail.
static uint64_t GetTime()
Read the microsecond timestamp.
static double GetCurrent5V()
Get the current output of the 5V rail.
static void SetRadioLEDState(RadioLEDState state)
Set the state of the "Radio" LED.
static double GetInputCurrent()
Get the input current to the robot controller.
Definition CAN.h:11
RadioLEDState
State for the radio led.
Definition RobotController.h:26
@ kOff
Off.
Definition RobotController.h:27
@ kGreen
Green.
Definition RobotController.h:28
@ kRed
Red.
Definition RobotController.h:29
@ kOrange
Orange.
Definition RobotController.h:30
Definition RobotController.h:17
int busOffCount
Definition RobotController.h:19
int receiveErrorCount
Definition RobotController.h:21
float percentBusUtilization
Definition RobotController.h:18
int txFullCount
Definition RobotController.h:20
int transmitErrorCount
Definition RobotController.h:22