WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::DriverStation Class Referencefinal

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

#include <wpi/driverstation/DriverStation.hpp>

Classes

struct  TouchpadFinger

Public Types

enum  Alliance { kRed , kBlue }
 The robot alliance that the robot is a part of. More...
enum  MatchType { kNone , kPractice , kQualification , kElimination }
 The type of robot match that the robot is part of. More...
enum  POVDirection : uint8_t {
  kCenter = HAL_JoystickPOV_kCentered , kUp = HAL_JoystickPOV_kUp , kUpRight = HAL_JoystickPOV_kRightUp , kRight = HAL_JoystickPOV_kRight ,
  kDownRight = HAL_JoystickPOV_kRightDown , kDown = HAL_JoystickPOV_kDown , kDownLeft = HAL_JoystickPOV_kLeftDown , kLeft = HAL_JoystickPOV_kLeft ,
  kUpLeft = HAL_JoystickPOV_kLeftUp
}
 A controller POV direction. More...

Static Public Member Functions

static constexpr std::optional< wpi::math::Rotation2dGetAngle (POVDirection angle)
 Gets the angle of a POVDirection.
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 IsTest ()
 Check if the DS is commanding test mode.
static bool IsTestEnabled ()
 Check if the DS is commanding Test 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 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 kJoystickPorts = 6
 Number of Joystick ports.

Detailed Description

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

Member Enumeration Documentation

◆ Alliance

The robot alliance that the robot is a part of.

Enumerator
kRed 

Red alliance.

kBlue 

Blue alliance.

◆ MatchType

The type of robot match that the robot is part of.

Enumerator
kNone 

None.

kPractice 

Practice.

kQualification 

Qualification.

kElimination 

Elimination.

◆ POVDirection

A controller POV direction.

Enumerator
kCenter 

POV center.

kUp 

POV up.

kUpRight 

POV up right.

kRight 

POV right.

kDownRight 

POV down right.

kDown 

POV down.

kDownLeft 

POV down left.

kLeft 

POV left.

kUpLeft 

POV up left.

Member Function Documentation

◆ AddOpMode() [1/2]

int64_t wpi::DriverStation::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::DriverStation::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::DriverStation::ClearOpModes ( )
static

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

◆ GetAlliance()

std::optional< Alliance > wpi::DriverStation::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

◆ GetAngle()

constexpr std::optional< wpi::math::Rotation2d > wpi::DriverStation::GetAngle ( POVDirection angle)
inlinestaticconstexpr

Gets the angle of a POVDirection.

Parameters
angleThe POVDirection to convert.
Returns
The angle clockwise from straight up, or std::nullopt if the POVDirection is kCenter.

◆ GetBatteryVoltage()

double wpi::DriverStation::GetBatteryVoltage ( )
static

Read the battery voltage.

Returns
The battery voltage in Volts.

◆ GetControlWord()

hal::ControlWord wpi::DriverStation::GetControlWord ( )
inlinestatic

Get the current control word.

Returns
control word

◆ GetEventName()

std::string wpi::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::GetMatchNumber ( )
static

Returns the match number provided by the FMS.

Returns
The number of the match

◆ GetMatchTime()

wpi::units::second_t wpi::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::GetOpModeId ( )
inlinestatic

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::DriverStation::GetReplayNumber ( )
static

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

Returns
The number of replays

◆ GetRobotMode()

RobotMode wpi::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::GetStickPOV ( int stick,
int pov )
static

Get the state of a POV on the joystick.

Returns
the angle of the POV.

◆ GetStickPOVsAvailable()

int wpi::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::IsDSAttached ( )
inlinestatic

Check if the DS is attached.

Returns
True if the DS is connected to the robot

◆ IsEnabled()

bool wpi::DriverStation::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::DriverStation::IsEStopped ( )
inlinestatic

Check if the robot is e-stopped.

Returns
True if the robot is e-stopped

◆ IsFMSAttached()

bool wpi::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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::DriverStation::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.

◆ IsTest()

bool wpi::DriverStation::IsTest ( )
inlinestatic

Check if the DS is commanding test mode.

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

◆ IsTestEnabled()

bool wpi::DriverStation::IsTestEnabled ( )
inlinestatic

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

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

◆ ProvideRefreshedDataEventHandle()

void wpi::DriverStation::ProvideRefreshedDataEventHandle ( WPI_EventHandle handle)
static

Registers the given handle for DS data refresh notifications.

Parameters
handleThe event handle.

◆ PublishOpModes()

void wpi::DriverStation::PublishOpModes ( )
static

Publishes the operating mode options to the driver station.

◆ RefreshData()

void wpi::DriverStation::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::DriverStation::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::DriverStation::RemoveRefreshedDataEventHandle ( WPI_EventHandle handle)
static

Unregisters the given handle from DS data refresh notifications.

Parameters
handleThe event handle.

◆ SilenceJoystickConnectionWarning()

void wpi::DriverStation::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::DriverStation::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

◆ kJoystickPorts

int wpi::DriverStation::kJoystickPorts = 6
staticconstexpr

Number of Joystick ports.


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