WPILibC++ 2027.0.0-alpha-2
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
26 public:
27 RobotController() = delete;
28
29 /**
30 * Return the FPGA Version number.
31 *
32 * For now, expect this to be competition year.
33 *
34 * @return FPGA Version number.
35 */
36 static int GetFPGAVersion();
37
38 /**
39 * Return the FPGA Revision number.
40 *
41 * The format of the revision is 3 numbers. The 12 most significant bits are
42 * the Major Revision. The next 8 bits are the Minor Revision. The 12 least
43 * significant bits are the Build Number.
44 *
45 * @return FPGA Revision number.
46 */
47 static int64_t GetFPGARevision();
48
49 /**
50 * Return the serial number of the roboRIO.
51 *
52 * @return The serial number of the roboRIO.
53 */
54 static std::string GetSerialNumber();
55
56 /**
57 * Return the comments from the roboRIO web interface.
58 *
59 * The comments string is cached after the first call to this function on the
60 * RoboRIO - restart the robot code to reload the comments string after
61 * changing it in the web interface.
62 *
63 * @return The comments from the roboRIO web interface.
64 */
65 static std::string GetComments();
66
67 /**
68 * Returns the team number configured for the robot controller.
69 *
70 * @return team number, or 0 if not found.
71 */
72 static int32_t GetTeamNumber();
73
74 /**
75 * Sets a new source to provide the clock time in microseconds. Changing this
76 * affects the return value of {@code GetTime}.
77 *
78 * @param supplier Function to return the time in microseconds.
79 */
80 static void SetTimeSource(std::function<uint64_t()> supplier);
81
82 /**
83 * Read the microsecond timestamp. By default, the time is based on the FPGA
84 * hardware clock in microseconds since the FPGA started. However, the return
85 * value of this method may be modified to use any time base, including
86 * non-monotonic and non-continuous time bases.
87 *
88 * @return The current time in microseconds.
89 */
90 static uint64_t GetTime();
91
92 /**
93 * Read the microsecond-resolution timer on the FPGA.
94 *
95 * @return The current time in microseconds according to the FPGA (since FPGA
96 * reset).
97 */
98 static uint64_t GetFPGATime();
99
100 /**
101 * Read the battery voltage.
102 *
103 * @return The battery voltage in Volts.
104 */
105 static units::volt_t GetBatteryVoltage();
106
107 /**
108 * Check if the FPGA outputs are enabled.
109 *
110 * The outputs may be disabled if the robot is disabled or e-stopped, the
111 * watchdog has expired, or if the roboRIO browns out.
112 *
113 * @return True if the FPGA outputs are enabled.
114 */
115 static bool IsSysActive();
116
117 /**
118 * Check if the system is browned out.
119 *
120 * @return True if the system is browned out
121 */
122 static bool IsBrownedOut();
123
124 /**
125 * Gets the number of times the system has been disabled due to communication
126 * errors with the Driver Station.
127 *
128 * @return number of disables due to communication errors.
129 */
131
132 /**
133 * Gets the current state of the Robot Signal Light (RSL)
134 * @return The current state of the RSL- true if on, false if off
135 */
136 static bool GetRSLState();
137
138 /**
139 * Gets if the system time is valid.
140 *
141 * @return True if the system time is valid, false otherwise
142 */
143 static bool IsSystemTimeValid();
144
145 /**
146 * Get the input voltage to the robot controller.
147 *
148 * @return The controller input voltage value in Volts
149 */
150 static double GetInputVoltage();
151
152 /**
153 * Get the voltage of the 3.3V rail.
154 *
155 * @return The controller 3.3V rail voltage value in Volts
156 */
157 static double GetVoltage3V3();
158
159 /**
160 * Get the current output of the 3.3V rail.
161 *
162 * @return The controller 3.3V rail output current value in Amps
163 */
164 static double GetCurrent3V3();
165
166 /**
167 * Enables or disables the 3.3V rail.
168 *
169 * @param enabled whether to enable the 3.3V rail.
170 */
171 static void SetEnabled3V3(bool enabled);
172
173 /**
174 * Get the enabled state of the 3.3V rail. The rail may be disabled due to
175 * calling SetEnabled3V3(), a controller brownout, a short circuit on the
176 * rail, or controller over-voltage.
177 *
178 * @return The controller 3.3V rail enabled value. True for enabled.
179 */
180 static bool GetEnabled3V3();
181
182 /**
183 * Get the count of the total current faults on the 3.3V rail since the
184 * code started.
185 *
186 * @return The number of faults
187 */
188 static int GetFaultCount3V3();
189
190 /** Reset the overcurrent fault counters for all user rails to 0. */
191 static void ResetRailFaultCounts();
192
193 /**
194 * Get the current brownout voltage setting.
195 *
196 * @return The brownout voltage
197 */
198 static units::volt_t GetBrownoutVoltage();
199
200 /**
201 * Set the voltage the roboRIO will brownout and disable all outputs.
202 *
203 * Note that this only does anything on the roboRIO 2.
204 * On the roboRIO it is a no-op.
205 *
206 * @param brownoutVoltage The brownout voltage
207 */
208 static void SetBrownoutVoltage(units::volt_t brownoutVoltage);
209
210 /**
211 * Get the current CPU temperature.
212 *
213 * @return current CPU temperature
214 */
215 static units::celsius_t GetCPUTemp();
216
217 /**
218 * Get the current status of the CAN bus.
219 *
220 * @param busId The bus ID.
221 * @return The status of the CAN bus
222 */
223 static CANStatus GetCANStatus(int busId);
224
225 private:
226 static std::function<uint64_t()> m_timeSource;
227};
228
229} // namespace frc
Definition RobotController.h:25
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 CANStatus GetCANStatus(int busId)
Get the current status of the CAN bus.
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 int GetCommsDisableCount()
Gets the number of times the system has been disabled due to communication errors with the Driver Sta...
static bool IsBrownedOut()
Check if the system is browned out.
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 units::volt_t GetBrownoutVoltage()
Get the current brownout voltage setting.
static std::string GetSerialNumber()
Return the serial number of the roboRIO.
static double GetInputVoltage()
Get the input voltage to the robot controller.
static void SetTimeSource(std::function< uint64_t()> supplier)
Sets a new source to provide the clock time in microseconds.
static double GetCurrent3V3()
Get the current output of the 3.3V rail.
static units::celsius_t GetCPUTemp()
Get the current CPU temperature.
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 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 uint64_t GetTime()
Read the microsecond timestamp.
Definition SystemServer.h:9
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