2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2017-12-10 21:52:49 -08:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2022-12-09 00:58:55 -05:00
|
|
|
#include <string>
|
|
|
|
|
|
2023-08-04 02:48:29 -04:00
|
|
|
#include <units/temperature.h>
|
2021-02-16 18:03:25 -08:00
|
|
|
#include <units/voltage.h>
|
|
|
|
|
|
2017-12-10 21:52:49 -08:00
|
|
|
namespace frc {
|
|
|
|
|
|
|
|
|
|
struct CANStatus {
|
|
|
|
|
float percentBusUtilization;
|
|
|
|
|
int busOffCount;
|
|
|
|
|
int txFullCount;
|
|
|
|
|
int receiveErrorCount;
|
|
|
|
|
int transmitErrorCount;
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-22 13:57:52 -05:00
|
|
|
enum RadioLEDState { kOff = 0, kGreen = 1, kRed = 2, kOrange = 3 };
|
|
|
|
|
|
2017-12-10 21:52:49 -08:00
|
|
|
class RobotController {
|
|
|
|
|
public:
|
|
|
|
|
RobotController() = delete;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the FPGA Version number.
|
|
|
|
|
*
|
|
|
|
|
* For now, expect this to be competition year.
|
|
|
|
|
*
|
|
|
|
|
* @return FPGA Version number.
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static int GetFPGAVersion();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the FPGA Revision number.
|
|
|
|
|
*
|
|
|
|
|
* The format of the revision is 3 numbers. The 12 most significant bits are
|
|
|
|
|
* the Major Revision. The next 8 bits are the Minor Revision. The 12 least
|
|
|
|
|
* significant bits are the Build Number.
|
|
|
|
|
*
|
|
|
|
|
* @return FPGA Revision number.
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static int64_t GetFPGARevision();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2022-12-09 00:58:55 -05:00
|
|
|
/**
|
2022-12-26 14:39:51 -05:00
|
|
|
* Return the serial number of the roboRIO.
|
2022-12-09 00:58:55 -05:00
|
|
|
*
|
|
|
|
|
* @return The serial number of the roboRIO.
|
|
|
|
|
*/
|
|
|
|
|
static std::string GetSerialNumber();
|
|
|
|
|
|
2022-12-26 14:39:51 -05:00
|
|
|
/**
|
|
|
|
|
* Return the comments from the roboRIO web interface.
|
|
|
|
|
*
|
2022-12-30 07:15:37 -05:00
|
|
|
* The comments string is cached after the first call to this function on the
|
|
|
|
|
* RoboRIO - restart the robot code to reload the comments string after
|
|
|
|
|
* changing it in the web interface.
|
|
|
|
|
*
|
2022-12-26 14:39:51 -05:00
|
|
|
* @return The comments from the roboRIO web interface.
|
|
|
|
|
*/
|
|
|
|
|
static std::string GetComments();
|
|
|
|
|
|
2023-09-02 02:34:18 -04:00
|
|
|
/**
|
|
|
|
|
* Returns the team number configured for the robot controller.
|
|
|
|
|
*
|
|
|
|
|
* @return team number, or 0 if not found.
|
|
|
|
|
*/
|
|
|
|
|
static int32_t GetTeamNumber();
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Read the microsecond-resolution timer on the FPGA.
|
|
|
|
|
*
|
|
|
|
|
* @return The current time in microseconds according to the FPGA (since FPGA
|
|
|
|
|
* reset).
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static uint64_t GetFPGATime();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the state of the "USER" button on the roboRIO.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the button is currently pressed down
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static bool GetUserButton();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2021-02-16 18:03:25 -08:00
|
|
|
/**
|
|
|
|
|
* Read the battery voltage.
|
|
|
|
|
*
|
|
|
|
|
* @return The battery voltage in Volts.
|
|
|
|
|
*/
|
|
|
|
|
static units::volt_t GetBatteryVoltage();
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Check if the FPGA outputs are enabled.
|
|
|
|
|
*
|
|
|
|
|
* The outputs may be disabled if the robot is disabled or e-stopped, the
|
|
|
|
|
* watchdog has expired, or if the roboRIO browns out.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the FPGA outputs are enabled.
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static bool IsSysActive();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the system is browned out.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the system is browned out
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static bool IsBrownedOut();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2023-05-13 00:30:19 -04:00
|
|
|
/**
|
|
|
|
|
* Gets the current state of the Robot Signal Light (RSL)
|
|
|
|
|
* @return The current state of the RSL- true if on, false if off
|
|
|
|
|
*/
|
|
|
|
|
static bool GetRSLState();
|
|
|
|
|
|
2023-09-30 09:22:51 -07:00
|
|
|
/**
|
|
|
|
|
* Gets if the system time is valid.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the system time is valid, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
static bool IsSystemTimeValid();
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Get the input voltage to the robot controller.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller input voltage value in Volts
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static double GetInputVoltage();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the input current to the robot controller.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller input current value in Amps
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static double GetInputCurrent();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the voltage of the 3.3V rail.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller 3.3V rail voltage value in Volts
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static double GetVoltage3V3();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the current output of the 3.3V rail.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller 3.3V rail output current value in Amps
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static double GetCurrent3V3();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
2023-08-04 02:48:29 -04:00
|
|
|
* Enables or disables the 3.3V rail.
|
|
|
|
|
*
|
|
|
|
|
* @param enabled whether to enable the 3.3V rail.
|
|
|
|
|
*/
|
|
|
|
|
static void SetEnabled3V3(bool enabled);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the enabled state of the 3.3V rail. The rail may be disabled due to
|
|
|
|
|
* calling SetEnabled3V3(), a controller brownout, a short circuit on the
|
|
|
|
|
* rail, or controller over-voltage.
|
2018-05-31 20:47:15 -07:00
|
|
|
*
|
|
|
|
|
* @return The controller 3.3V rail enabled value. True for enabled.
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static bool GetEnabled3V3();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the count of the total current faults on the 3.3V rail since the
|
|
|
|
|
* controller has booted.
|
|
|
|
|
*
|
|
|
|
|
* @return The number of faults
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static int GetFaultCount3V3();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the voltage of the 5V rail.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller 5V rail voltage value in Volts
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static double GetVoltage5V();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the current output of the 5V rail.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller 5V rail output current value in Amps
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static double GetCurrent5V();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
2023-08-04 02:48:29 -04:00
|
|
|
* Enables or disables the 5V rail.
|
|
|
|
|
*
|
|
|
|
|
* @param enabled whether to enable the 5V rail.
|
|
|
|
|
*/
|
|
|
|
|
static void SetEnabled5V(bool enabled);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the enabled state of the 5V rail. The rail may be disabled due to
|
|
|
|
|
* calling SetEnabled5V(), a controller brownout, a short circuit on the rail,
|
|
|
|
|
* or controller over-voltage.
|
2018-05-31 20:47:15 -07:00
|
|
|
*
|
|
|
|
|
* @return The controller 5V rail enabled value. True for enabled.
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static bool GetEnabled5V();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the count of the total current faults on the 5V rail since the
|
|
|
|
|
* controller has booted.
|
|
|
|
|
*
|
|
|
|
|
* @return The number of faults
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static int GetFaultCount5V();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the voltage of the 6V rail.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller 6V rail voltage value in Volts
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static double GetVoltage6V();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the current output of the 6V rail.
|
|
|
|
|
*
|
|
|
|
|
* @return The controller 6V rail output current value in Amps
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static double GetCurrent6V();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
2023-08-04 02:48:29 -04:00
|
|
|
* Enables or disables the 6V rail.
|
|
|
|
|
*
|
|
|
|
|
* @param enabled whether to enable the 6V rail.
|
|
|
|
|
*/
|
|
|
|
|
static void SetEnabled6V(bool enabled);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the enabled state of the 6V rail. The rail may be disabled due to
|
|
|
|
|
* calling SetEnabled6V(), a controller brownout, a short circuit on the rail,
|
|
|
|
|
* or controller over-voltage.
|
2018-05-31 20:47:15 -07:00
|
|
|
*
|
|
|
|
|
* @return The controller 6V rail enabled value. True for enabled.
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static bool GetEnabled6V();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the count of the total current faults on the 6V rail since the
|
|
|
|
|
* controller has booted.
|
|
|
|
|
*
|
|
|
|
|
* @return The number of faults.
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static int GetFaultCount6V();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2021-10-13 19:14:27 -07:00
|
|
|
/**
|
2021-10-14 07:28:21 -07:00
|
|
|
* Get the current brownout voltage setting.
|
2021-10-13 19:14:27 -07:00
|
|
|
*
|
|
|
|
|
* @return The brownout voltage
|
|
|
|
|
*/
|
|
|
|
|
static units::volt_t GetBrownoutVoltage();
|
|
|
|
|
|
|
|
|
|
/**
|
2021-10-14 07:28:21 -07:00
|
|
|
* Set the voltage the roboRIO will brownout and disable all outputs.
|
2021-10-13 19:14:27 -07:00
|
|
|
*
|
|
|
|
|
* Note that this only does anything on the roboRIO 2.
|
|
|
|
|
* On the roboRIO it is a no-op.
|
|
|
|
|
*
|
|
|
|
|
* @param brownoutVoltage The brownout voltage
|
|
|
|
|
*/
|
|
|
|
|
static void SetBrownoutVoltage(units::volt_t brownoutVoltage);
|
|
|
|
|
|
2023-08-04 02:48:29 -04:00
|
|
|
/**
|
|
|
|
|
* Get the current CPU temperature.
|
|
|
|
|
*
|
|
|
|
|
* @return current CPU temperature
|
|
|
|
|
*/
|
|
|
|
|
static units::celsius_t GetCPUTemp();
|
|
|
|
|
|
2023-12-22 13:57:52 -05:00
|
|
|
/**
|
|
|
|
|
* Set the state of the "Radio" LED. On the RoboRIO, this writes to sysfs, so
|
|
|
|
|
* this function should not be called multiple times per loop cycle to avoid
|
|
|
|
|
* overruns.
|
|
|
|
|
* @param state The state to set the LED to.
|
|
|
|
|
*/
|
|
|
|
|
static void SetRadioLEDState(RadioLEDState state);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the state of the "Radio" LED. On the RoboRIO, this reads from sysfs, so
|
|
|
|
|
* this function should not be called multiple times per loop cycle to avoid
|
|
|
|
|
* overruns.
|
|
|
|
|
*
|
|
|
|
|
* @return The state of the LED.
|
|
|
|
|
*/
|
|
|
|
|
static RadioLEDState GetRadioLEDState();
|
|
|
|
|
|
2021-10-13 19:14:27 -07:00
|
|
|
/**
|
|
|
|
|
* Get the current status of the CAN bus.
|
|
|
|
|
*
|
|
|
|
|
* @return The status of the CAN bus
|
|
|
|
|
*/
|
2017-12-10 21:52:49 -08:00
|
|
|
static CANStatus GetCANStatus();
|
|
|
|
|
};
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2017-12-10 21:52:49 -08:00
|
|
|
} // namespace frc
|