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