WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
RobotController.hpp
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 "wpi/units/temperature.hpp"
13#include "wpi/units/voltage.hpp"
14
15namespace wpi {
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
64 * monotonic clock. However, the return value of this method may be modified
65 * to use any time base, including non-monotonic and non-continuous time
66 * bases.
67 *
68 * @return The current time in microseconds.
69 */
70 static uint64_t GetTime();
71
72 /**
73 * Read the microsecond-resolution monotonic timer.
74 *
75 * @return The current monotonic time in microseconds.
76 */
77 static uint64_t GetMonotonicTime();
78
79 /**
80 * Read the battery voltage.
81 *
82 * @return The battery voltage in Volts.
83 */
84 static wpi::units::volt_t GetBatteryVoltage();
85
86 /**
87 * Check if the FPGA outputs are enabled.
88 *
89 * The outputs may be disabled if the robot is disabled or e-stopped, the
90 * watchdog has expired, or if the roboRIO browns out.
91 *
92 * @return True if the FPGA outputs are enabled.
93 */
94 static bool IsSysActive();
95
96 /**
97 * Check if the system is browned out.
98 *
99 * @return True if the system is browned out
100 */
101 static bool IsBrownedOut();
102
103 /**
104 * Gets the number of times the system has been disabled due to communication
105 * errors with the Driver Station.
106 *
107 * @return number of disables due to communication errors.
108 */
110
111 /**
112 * Gets the current state of the Robot Signal Light (RSL)
113 * @return The current state of the RSL- true if on, false if off
114 */
115 static bool GetRSLState();
116
117 /**
118 * Gets if the system time is valid.
119 *
120 * @return True if the system time is valid, false otherwise
121 */
122 static bool IsSystemTimeValid();
123
124 /**
125 * Get the input voltage to the robot controller.
126 *
127 * @return The controller input voltage value in Volts
128 */
129 static double GetInputVoltage();
130
131 /**
132 * Get the voltage of the 3.3V rail.
133 *
134 * @return The controller 3.3V rail voltage value in Volts
135 */
136 static double GetVoltage3V3();
137
138 /**
139 * Get the current output of the 3.3V rail.
140 *
141 * @return The controller 3.3V rail output current value in Amps
142 */
143 static double GetCurrent3V3();
144
145 /**
146 * Enables or disables the 3.3V rail.
147 *
148 * @param enabled whether to enable the 3.3V rail.
149 */
150 static void SetEnabled3V3(bool enabled);
151
152 /**
153 * Get the enabled state of the 3.3V rail. The rail may be disabled due to
154 * calling SetEnabled3V3(), a controller brownout, a short circuit on the
155 * rail, or controller over-voltage.
156 *
157 * @return The controller 3.3V rail enabled value. True for enabled.
158 */
159 static bool GetEnabled3V3();
160
161 /**
162 * Get the count of the total current faults on the 3.3V rail since the
163 * code started.
164 *
165 * @return The number of faults
166 */
167 static int GetFaultCount3V3();
168
169 /** Reset the overcurrent fault counters for all user rails to 0. */
170 static void ResetRailFaultCounts();
171
172 /**
173 * Get the current brownout voltage setting.
174 *
175 * @return The brownout voltage
176 */
177 static wpi::units::volt_t GetBrownoutVoltage();
178
179 /**
180 * Set the voltage the roboRIO will brownout and disable all outputs.
181 *
182 * Note that this only does anything on the roboRIO 2.
183 * On the roboRIO it is a no-op.
184 *
185 * @param brownoutVoltage The brownout voltage
186 */
187 static void SetBrownoutVoltage(wpi::units::volt_t brownoutVoltage);
188
189 /**
190 * Get the current CPU temperature.
191 *
192 * @return current CPU temperature
193 */
194 static wpi::units::celsius_t GetCPUTemp();
195
196 /**
197 * Get the current status of the CAN bus.
198 *
199 * @param busId The bus ID.
200 * @return The status of the CAN bus
201 */
202 static CANStatus GetCANStatus(int busId);
203
204 private:
205 static std::function<uint64_t()> m_timeSource;
206};
207
208} // namespace wpi
static CANStatus GetCANStatus(int busId)
Get the current status of the CAN bus.
static uint64_t GetMonotonicTime()
Read the microsecond-resolution monotonic timer.
static wpi::units::volt_t GetBrownoutVoltage()
Get the current brownout voltage setting.
static bool IsSysActive()
Check if the FPGA outputs are enabled.
static void SetTimeSource(std::function< uint64_t()> supplier)
Sets a new source to provide the clock time in microseconds.
static uint64_t GetTime()
Read the microsecond timestamp.
static bool IsSystemTimeValid()
Gets if the system time is valid.
static void SetBrownoutVoltage(wpi::units::volt_t brownoutVoltage)
Set the voltage the roboRIO will brownout and disable all outputs.
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 std::string GetComments()
Return the comments from the roboRIO web interface.
static wpi::units::volt_t GetBatteryVoltage()
Read the battery voltage.
static double GetInputVoltage()
Get the input voltage to the robot controller.
static std::string GetSerialNumber()
Return the serial number of the roboRIO.
static int GetCommsDisableCount()
Gets the number of times the system has been disabled due to communication errors with the Driver Sta...
static int GetFaultCount3V3()
Get the count of the total current faults on the 3.3V rail since the code started.
static int32_t GetTeamNumber()
Returns the team number configured for the robot controller.
static bool IsBrownedOut()
Check if the system is browned out.
static double GetVoltage3V3()
Get the voltage of the 3.3V rail.
static void SetEnabled3V3(bool enabled)
Enables or disables the 3.3V rail.
static wpi::units::celsius_t GetCPUTemp()
Get the current CPU temperature.
static bool GetEnabled3V3()
Get the enabled state of the 3.3V rail.
static double GetCurrent3V3()
Get the current output of the 3.3V rail.
Definition CvSource.hpp:15
Definition RobotController.hpp:17
int txFullCount
Definition RobotController.hpp:20
int transmitErrorCount
Definition RobotController.hpp:22
float percentBusUtilization
Definition RobotController.hpp:18
int busOffCount
Definition RobotController.hpp:19
int receiveErrorCount
Definition RobotController.hpp:21