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