WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
wpi::internal::DriverStationBackend Class Referencefinal

Provide access to the network communication data to / from the Driver Station. More...

#include <wpi/driverstation/internal/DriverStationBackend.hpp>

Static Public Member Functions

static bool GetStickButton (int stick, int button)
 The state of one joystick button.
static std::optional< bool > GetStickButtonIfAvailable (int stick, int button)
 The state of one joystick button, only if available.
static bool GetStickButtonPressed (int stick, int button)
 Whether one joystick button was pressed since the last check.
static bool GetStickButtonReleased (int stick, int button)
 Whether one joystick button was released since the last check.
static double GetStickAxis (int stick, int axis)
 Get the value of the axis on a joystick.
static TouchpadFinger GetStickTouchpadFinger (int stick, int touchpad, int finger)
 Get the finger data of a touchpad on a joystick, if available.
static bool GetStickTouchpadFingerAvailable (int stick, int touchpad, int finger)
 Whether a finger on a touchpad is available.
static std::optional< double > GetStickAxisIfAvailable (int stick, int axis)
 Get the value of the axis on a joystick, if available.
static POVDirection GetStickPOV (int stick, int pov)
 Get the state of a POV on the joystick.
static uint64_t GetStickButtons (int stick)
 The state of the buttons on the joystick.
static int GetStickAxesMaximumIndex (int stick)
 Returns the maximum axis index on a given joystick port.
static int GetStickAxesAvailable (int stick)
 Returns the mask of available axes on a given joystick port.
static int GetStickPOVsMaximumIndex (int stick)
 Returns the maximum POV index on a given joystick port.
static int GetStickPOVsAvailable (int stick)
 Returns the mask of available POVs on a given joystick port.
static int GetStickButtonsMaximumIndex (int stick)
 Returns the maximum button index on a given joystick port.
static uint64_t GetStickButtonsAvailable (int stick)
 Returns the mask of available buttons on a given joystick port.
static bool GetJoystickIsGamepad (int stick)
 Returns a boolean indicating if the controller is an xbox controller.
static int GetJoystickGamepadType (int stick)
 Returns the type of joystick at a given port.
static int GetJoystickSupportedOutputs (int stick)
 Returns the number of outputs supported by the joystick at the given port.
static std::string GetJoystickName (int stick)
 Returns the name of the joystick at the given port.
static bool IsJoystickConnected (int stick)
 Returns if a joystick is connected to the Driver Station.
static bool IsEnabled ()
 Check if the DS has enabled the robot.
static bool IsDisabled ()
 Check if the robot is disabled.
static bool IsEStopped ()
 Check if the robot is e-stopped.
static RobotMode GetRobotMode ()
 Gets the current robot mode.
static bool IsAutonomous ()
 Check if the DS is commanding autonomous mode.
static bool IsAutonomousEnabled ()
 Check if the DS is commanding autonomous mode and if it has enabled the robot.
static bool IsTeleop ()
 Check if the DS is commanding teleop mode.
static bool IsTeleopEnabled ()
 Check if the DS is commanding teleop mode and if it has enabled the robot.
static bool IsUtility ()
 Check if the DS is commanding utility mode.
static bool IsUtilityEnabled ()
 Check if the DS is commanding Utility mode and if it has enabled the robot.
static int64_t AddOpMode (RobotMode mode, std::string_view name, std::string_view group, std::string_view description, const wpi::util::Color &textColor, const wpi::util::Color &backgroundColor)
 Adds an operating mode option.
static int64_t AddOpMode (RobotMode mode, std::string_view name, std::string_view group={}, std::string_view description={})
 Adds an operating mode option.
static int64_t RemoveOpMode (RobotMode mode, std::string_view name)
 Removes an operating mode option.
static void PublishOpModes ()
 Publishes the operating mode options to the driver station.
static void ClearOpModes ()
 Clears all operating mode options and publishes an empty list to the driver station.
static void ObserveUserProgramStarting ()
 Sets the program starting flag in the DS.
static int64_t GetOpModeId ()
 Gets the operating mode selected on the driver station.
static std::string GetOpMode ()
 Gets the operating mode selected on the driver station.
static bool IsOpMode (int64_t id)
 Check to see if the selected operating mode is a particular value.
static bool IsOpMode (std::string_view mode)
 Check to see if the selected operating mode is a particular value.
static bool IsDSAttached ()
 Check if the DS is attached.
static bool IsFMSAttached ()
 Is the driver station attached to a Field Management System?
static std::optional< std::string > GetGameData ()
 Returns the game specific message provided by the FMS.
static std::string GetEventName ()
 Returns the name of the competition event provided by the FMS.
static MatchType GetMatchType ()
 Returns the type of match being played provided by the FMS.
static int GetMatchNumber ()
 Returns the match number provided by the FMS.
static int GetReplayNumber ()
 Returns the number of times the current match has been replayed from the FMS.
static std::optional< AllianceGetAlliance ()
 Get the current alliance from the FMS.
static std::optional< int > GetLocation ()
 Return the driver station location from the FMS.
static wpi::units::second_t GetMatchTime ()
 Return the approximate match time.
static double GetBatteryVoltage ()
 Read the battery voltage.
static hal::ControlWord GetControlWord ()
 Get the current control word.
static void RefreshData ()
 Copy data from the DS task for the user.
static void ProvideRefreshedDataEventHandle (WPI_EventHandle handle)
 Registers the given handle for DS data refresh notifications.
static void RemoveRefreshedDataEventHandle (WPI_EventHandle handle)
 Unregisters the given handle from DS data refresh notifications.
static void SilenceJoystickConnectionWarning (bool silence)
 Allows the user to specify whether they want joystick connection warnings to be printed to the console.
static bool IsJoystickConnectionWarningSilenced ()
 Returns whether joystick connection warnings are silenced.
static void StartDataLog (wpi::log::DataLog &log, bool logJoysticks=true)
 Starts logging DriverStation data to data log.

Static Public Attributes

static constexpr int JOYSTICK_PORTS = 6
 Number of Joystick ports.

Detailed Description

Provide access to the network communication data to / from the Driver Station.

Member Function Documentation

◆ AddOpMode() [1/2]

int64_t wpi::internal::DriverStationBackend::AddOpMode ( RobotMode mode,
std::string_view name,
std::string_view group,
std::string_view description,
const wpi::util::Color & textColor,
const wpi::util::Color & backgroundColor )
static

Adds an operating mode option.

It's necessary to call PublishOpModes() to make the added modes visible to the driver station.

Parameters
moderobot mode
namename of the operating mode
groupgroup of the operating mode
descriptiondescription of the operating mode
textColortext color
backgroundColorbackground color
Returns
unique ID used to later identify the operating mode; if a blank name is passed, 0 is returned; identical names for the same robot mode result in a 0 return value

◆ AddOpMode() [2/2]

int64_t wpi::internal::DriverStationBackend::AddOpMode ( RobotMode mode,
std::string_view name,
std::string_view group = {},
std::string_view description = {} )
static

Adds an operating mode option.

It's necessary to call PublishOpModes() to make the added modes visible to the driver station.

Parameters
moderobot mode
namename of the operating mode
groupgroup of the operating mode
descriptiondescription of the operating mode
Returns
unique ID used to later identify the operating mode; if a blank name is passed, 0 is returned; identical names for the same robot mode result in a 0 return value

◆ ClearOpModes()

void wpi::internal::DriverStationBackend::ClearOpModes ( )
static

Clears all operating mode options and publishes an empty list to the driver station.

◆ GetAlliance()

std::optional< Alliance > wpi::internal::DriverStationBackend::GetAlliance ( )
static

Get the current alliance from the FMS.

If the FMS is not connected, it is set from the team alliance setting on the driver station.

Returns
The alliance (red or blue) or an empty optional if the alliance is invalid

◆ GetBatteryVoltage()

double wpi::internal::DriverStationBackend::GetBatteryVoltage ( )
static

Read the battery voltage.

Returns
The battery voltage in Volts.

◆ GetControlWord()

hal::ControlWord wpi::internal::DriverStationBackend::GetControlWord ( )
inlinestatic

Get the current control word.

Returns
control word

◆ GetEventName()

std::string wpi::internal::DriverStationBackend::GetEventName ( )
static

Returns the name of the competition event provided by the FMS.

Returns
A string containing the event name

◆ GetGameData()

std::optional< std::string > wpi::internal::DriverStationBackend::GetGameData ( )
static

Returns the game specific message provided by the FMS.

If the FMS is not connected, it is set from the game data setting on the driver station.

Returns
A string containing the game specific message.

◆ GetJoystickGamepadType()

int wpi::internal::DriverStationBackend::GetJoystickGamepadType ( int stick)
static

Returns the type of joystick at a given port.

This maps to SDL_GamepadType

Parameters
stickThe joystick port number
Returns
The HID type of joystick at the given port

◆ GetJoystickIsGamepad()

bool wpi::internal::DriverStationBackend::GetJoystickIsGamepad ( int stick)
static

Returns a boolean indicating if the controller is an xbox controller.

Parameters
stickThe joystick port number
Returns
A boolean that is true if the controller is an xbox controller.

◆ GetJoystickName()

std::string wpi::internal::DriverStationBackend::GetJoystickName ( int stick)
static

Returns the name of the joystick at the given port.

Parameters
stickThe joystick port number
Returns
The name of the joystick at the given port

◆ GetJoystickSupportedOutputs()

int wpi::internal::DriverStationBackend::GetJoystickSupportedOutputs ( int stick)
static

Returns the number of outputs supported by the joystick at the given port.

Parameters
stickThe joystick port number
Returns
The number of outputs supported by the joystick at the given port

◆ GetLocation()

std::optional< int > wpi::internal::DriverStationBackend::GetLocation ( )
static

Return the driver station location from the FMS.

If the FMS is not connected, it is set from the team alliance setting on the driver station.

This could return 1, 2, or 3.

Returns
The location of the driver station (1-3, 0 for invalid)

◆ GetMatchNumber()

int wpi::internal::DriverStationBackend::GetMatchNumber ( )
static

Returns the match number provided by the FMS.

Returns
The number of the match

◆ GetMatchTime()

wpi::units::second_t wpi::internal::DriverStationBackend::GetMatchTime ( )
static

Return the approximate match time.

The FMS does not send an official match time to the robots, but does send an approximate match time. The value will count down the time remaining in the current period (auto or teleop). Warning: This is not an official time (so it cannot be used to dispute ref calls or guarantee that a function will trigger before the match ends).

When connected to the real field, this number only changes in full integer increments, and always counts down.

When the DS is in practice mode, this number is a floating point number, and counts down.

When the DS is in teleop or autonomous mode, this number returns -1.0.

Simulation matches DS behavior without an FMS connected.

Returns
Time remaining in current match period (auto or teleop) in seconds

◆ GetMatchType()

MatchType wpi::internal::DriverStationBackend::GetMatchType ( )
static

Returns the type of match being played provided by the FMS.

Returns
The match type enum (kNone, kPractice, kQualification, kElimination)

◆ GetOpMode()

std::string wpi::internal::DriverStationBackend::GetOpMode ( )
static

Gets the operating mode selected on the driver station.

Note this does not mean the robot is enabled; use IsEnabled() for that. In a match, this will indicate the operating mode selected for auto before the match starts (i.e., while the robot is disabled in auto mode); after the auto period ends, this will change to reflect the operating mode selected for teleop.

Returns
Operating mode string; may return a string not in the list of options, so callers should be prepared to handle that case

◆ GetOpModeId()

int64_t wpi::internal::DriverStationBackend::GetOpModeId ( )
static

Gets the operating mode selected on the driver station.

Note this does not mean the robot is enabled; use IsEnabled() for that. In a match, this will indicate the operating mode selected for auto before the match starts (i.e., while the robot is disabled in auto mode); after the auto period ends, this will change to reflect the operating mode selected for teleop.

Returns
the unique ID provided by the AddOpMode() function; may return 0 or a unique ID not added, so callers should be prepared to handle that case

◆ GetReplayNumber()

int wpi::internal::DriverStationBackend::GetReplayNumber ( )
static

Returns the number of times the current match has been replayed from the FMS.

Returns
The number of replays

◆ GetRobotMode()

RobotMode wpi::internal::DriverStationBackend::GetRobotMode ( )
inlinestatic

Gets the current robot mode.

Note that this does not indicate whether the robot is enabled or disabled.

Returns
robot mode

◆ GetStickAxesAvailable()

int wpi::internal::DriverStationBackend::GetStickAxesAvailable ( int stick)
static

Returns the mask of available axes on a given joystick port.

Parameters
stickThe joystick port number
Returns
The mask of available axes on the indicated joystick

◆ GetStickAxesMaximumIndex()

int wpi::internal::DriverStationBackend::GetStickAxesMaximumIndex ( int stick)
static

Returns the maximum axis index on a given joystick port.

Parameters
stickThe joystick port number
Returns
The maximum axis index on the indicated joystick

◆ GetStickAxis()

double wpi::internal::DriverStationBackend::GetStickAxis ( int stick,
int axis )
static

Get the value of the axis on a joystick.

This depends on the mapping of the joystick connected to the specified port.

Parameters
stickThe joystick to read.
axisThe analog axis value to read from the joystick.
Returns
The value of the axis on the joystick.

◆ GetStickAxisIfAvailable()

std::optional< double > wpi::internal::DriverStationBackend::GetStickAxisIfAvailable ( int stick,
int axis )
static

Get the value of the axis on a joystick, if available.

This depends on the mapping of the joystick connected to the specified port.

Parameters
stickThe joystick to read.
axisThe analog axis value to read from the joystick.
Returns
The value of the axis on the joystick, or empty if not available.

◆ GetStickButton()

bool wpi::internal::DriverStationBackend::GetStickButton ( int stick,
int button )
static

The state of one joystick button.

Button indexes begin at 0.

Parameters
stickThe joystick to read.
buttonThe button index, beginning at 0.
Returns
The state of the joystick button.

◆ GetStickButtonIfAvailable()

std::optional< bool > wpi::internal::DriverStationBackend::GetStickButtonIfAvailable ( int stick,
int button )
static

The state of one joystick button, only if available.

Button indexes begin at 0.

Parameters
stickThe joystick to read.
buttonThe button index, beginning at 0.
Returns
The state of the joystick button, or empty if unavailable.

◆ GetStickButtonPressed()

bool wpi::internal::DriverStationBackend::GetStickButtonPressed ( int stick,
int button )
static

Whether one joystick button was pressed since the last check.

Button indexes begin at 1.

Parameters
stickThe joystick to read.
buttonThe button index, beginning at 0.
Returns
Whether the joystick button was pressed since the last check.

◆ GetStickButtonReleased()

bool wpi::internal::DriverStationBackend::GetStickButtonReleased ( int stick,
int button )
static

Whether one joystick button was released since the last check.

Button indexes begin at 1.

Parameters
stickThe joystick to read.
buttonThe button index, beginning at 0.
Returns
Whether the joystick button was released since the last check.

◆ GetStickButtons()

uint64_t wpi::internal::DriverStationBackend::GetStickButtons ( int stick)
static

The state of the buttons on the joystick.

Parameters
stickThe joystick to read.
Returns
The state of the buttons on the joystick.

◆ GetStickButtonsAvailable()

uint64_t wpi::internal::DriverStationBackend::GetStickButtonsAvailable ( int stick)
static

Returns the mask of available buttons on a given joystick port.

Parameters
stickThe joystick port number
Returns
The mask of available buttons on the indicated joystick

◆ GetStickButtonsMaximumIndex()

int wpi::internal::DriverStationBackend::GetStickButtonsMaximumIndex ( int stick)
static

Returns the maximum button index on a given joystick port.

Parameters
stickThe joystick port number
Returns
The maximum button index on the indicated joystick

◆ GetStickPOV()

POVDirection wpi::internal::DriverStationBackend::GetStickPOV ( int stick,
int pov )
static

Get the state of a POV on the joystick.

Returns
the angle of the POV.

◆ GetStickPOVsAvailable()

int wpi::internal::DriverStationBackend::GetStickPOVsAvailable ( int stick)
static

Returns the mask of available POVs on a given joystick port.

Parameters
stickThe joystick port number
Returns
The mask of available POVs on the indicated joystick

◆ GetStickPOVsMaximumIndex()

int wpi::internal::DriverStationBackend::GetStickPOVsMaximumIndex ( int stick)
static

Returns the maximum POV index on a given joystick port.

Parameters
stickThe joystick port number
Returns
The maximum POV index on the indicated joystick

◆ GetStickTouchpadFinger()

TouchpadFinger wpi::internal::DriverStationBackend::GetStickTouchpadFinger ( int stick,
int touchpad,
int finger )
static

Get the finger data of a touchpad on a joystick, if available.

Parameters
stickThe joystick to read.
touchpadThe touchpad index to read from the joystick.
fingerThe finger index to read from the touchpad.
Returns
The finger data of the touchpad on the joystick.

◆ GetStickTouchpadFingerAvailable()

bool wpi::internal::DriverStationBackend::GetStickTouchpadFingerAvailable ( int stick,
int touchpad,
int finger )
static

Whether a finger on a touchpad is available.

Parameters
stickThe joystick to read.
touchpadThe touchpad index to read from the joystick.
fingerThe finger index to read from the touchpad.
Returns
True if the finger data is available.

◆ IsAutonomous()

bool wpi::internal::DriverStationBackend::IsAutonomous ( )
inlinestatic

Check if the DS is commanding autonomous mode.

Returns
True if the robot is being commanded to be in autonomous mode

◆ IsAutonomousEnabled()

bool wpi::internal::DriverStationBackend::IsAutonomousEnabled ( )
inlinestatic

Check if the DS is commanding autonomous mode and if it has enabled the robot.

Returns
True if the robot is being commanded to be in autonomous mode and enabled.

◆ IsDisabled()

bool wpi::internal::DriverStationBackend::IsDisabled ( )
inlinestatic

Check if the robot is disabled.

Returns
True if the robot is explicitly disabled or the DS is not connected

◆ IsDSAttached()

bool wpi::internal::DriverStationBackend::IsDSAttached ( )
inlinestatic

Check if the DS is attached.

Returns
True if the DS is connected to the robot

◆ IsEnabled()

bool wpi::internal::DriverStationBackend::IsEnabled ( )
inlinestatic

Check if the DS has enabled the robot.

Returns
True if the robot is enabled and the DS is connected

◆ IsEStopped()

bool wpi::internal::DriverStationBackend::IsEStopped ( )
inlinestatic

Check if the robot is e-stopped.

Returns
True if the robot is e-stopped

◆ IsFMSAttached()

bool wpi::internal::DriverStationBackend::IsFMSAttached ( )
inlinestatic

Is the driver station attached to a Field Management System?

Returns
True if the robot is competing on a field being controlled by a Field Management System

◆ IsJoystickConnected()

bool wpi::internal::DriverStationBackend::IsJoystickConnected ( int stick)
static

Returns if a joystick is connected to the Driver Station.

This makes a best effort guess by looking at the reported number of axis, buttons, and POVs attached.

Parameters
stickThe joystick port number
Returns
true if a joystick is connected

◆ IsJoystickConnectionWarningSilenced()

bool wpi::internal::DriverStationBackend::IsJoystickConnectionWarningSilenced ( )
static

Returns whether joystick connection warnings are silenced.

This will always return false when connected to the FMS.

Returns
Whether joystick connection warnings are silenced.

◆ IsOpMode() [1/2]

bool wpi::internal::DriverStationBackend::IsOpMode ( int64_t id)
inlinestatic

Check to see if the selected operating mode is a particular value.

Note this does not mean the robot is enabled; use IsEnabled() for that.

Parameters
idoperating mode unique ID
Returns
True if that mode is the current mode

◆ IsOpMode() [2/2]

bool wpi::internal::DriverStationBackend::IsOpMode ( std::string_view mode)
inlinestatic

Check to see if the selected operating mode is a particular value.

Note this does not mean the robot is enabled; use IsEnabled() for that.

Parameters
modeoperating mode
Returns
True if that mode is the current mode

◆ IsTeleop()

bool wpi::internal::DriverStationBackend::IsTeleop ( )
inlinestatic

Check if the DS is commanding teleop mode.

Returns
True if the robot is being commanded to be in teleop mode

◆ IsTeleopEnabled()

bool wpi::internal::DriverStationBackend::IsTeleopEnabled ( )
inlinestatic

Check if the DS is commanding teleop mode and if it has enabled the robot.

Returns
True if the robot is being commanded to be in teleop mode and enabled.

◆ IsUtility()

bool wpi::internal::DriverStationBackend::IsUtility ( )
inlinestatic

Check if the DS is commanding utility mode.

Returns
True if the robot is being commanded to be in utility mode

◆ IsUtilityEnabled()

bool wpi::internal::DriverStationBackend::IsUtilityEnabled ( )
inlinestatic

Check if the DS is commanding Utility mode and if it has enabled the robot.

Returns
True if the robot is being commanded to be in Utility mode and enabled.

◆ ObserveUserProgramStarting()

void wpi::internal::DriverStationBackend::ObserveUserProgramStarting ( )
static

Sets the program starting flag in the DS.

This will also allow getOpModeId() and getOpMode() to return values for the selected OpMode in the DS application, if the DS is connected by the time this method is called.

Most users will not need to use this method; the TimedRobot and OpModeRobot robot framework classes will call it automatically after the main robot class is instantiated.

This is what changes the DS to showing robot code ready.

◆ ProvideRefreshedDataEventHandle()

void wpi::internal::DriverStationBackend::ProvideRefreshedDataEventHandle ( WPI_EventHandle handle)
static

Registers the given handle for DS data refresh notifications.

Parameters
handleThe event handle.

◆ PublishOpModes()

void wpi::internal::DriverStationBackend::PublishOpModes ( )
static

Publishes the operating mode options to the driver station.

◆ RefreshData()

void wpi::internal::DriverStationBackend::RefreshData ( )
static

Copy data from the DS task for the user.

If no new data exists, it will just be returned, otherwise the data will be copied from the DS polling loop.

◆ RemoveOpMode()

int64_t wpi::internal::DriverStationBackend::RemoveOpMode ( RobotMode mode,
std::string_view name )
static

Removes an operating mode option.

It's necessary to call PublishOpModes() to make the removed mode no longer visible to the driver station.

Parameters
moderobot mode
namename of the operating mode
Returns
unique ID for the opmode, or 0 if not found

◆ RemoveRefreshedDataEventHandle()

void wpi::internal::DriverStationBackend::RemoveRefreshedDataEventHandle ( WPI_EventHandle handle)
static

Unregisters the given handle from DS data refresh notifications.

Parameters
handleThe event handle.

◆ SilenceJoystickConnectionWarning()

void wpi::internal::DriverStationBackend::SilenceJoystickConnectionWarning ( bool silence)
static

Allows the user to specify whether they want joystick connection warnings to be printed to the console.

This setting is ignored when the FMS is connected – warnings will always be on in that scenario.

Parameters
silenceWhether warning messages should be silenced.

◆ StartDataLog()

void wpi::internal::DriverStationBackend::StartDataLog ( wpi::log::DataLog & log,
bool logJoysticks = true )
static

Starts logging DriverStation data to data log.

Repeated calls are ignored.

Parameters
logdata log
logJoysticksif true, log joystick data

Member Data Documentation

◆ JOYSTICK_PORTS

int wpi::internal::DriverStationBackend::JOYSTICK_PORTS = 6
staticconstexpr

Number of Joystick ports.


The documentation for this class was generated from the following file: