WPILibC++ 2023.4.3
frc::DriverStation Class Referencefinal

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

#include <frc/DriverStation.h>

Public Types

enum  Alliance { kRed , kBlue , kInvalid }
 
enum  MatchType { kNone , kPractice , kQualification , kElimination }
 

Static Public Member Functions

static bool GetStickButton (int stick, int button)
 The state of one joystick button. More...
 
static bool GetStickButtonPressed (int stick, int button)
 Whether one joystick button was pressed since the last check. More...
 
static bool GetStickButtonReleased (int stick, int button)
 Whether one joystick button was released since the last check. More...
 
static double GetStickAxis (int stick, int axis)
 Get the value of the axis on a joystick. More...
 
static int GetStickPOV (int stick, int pov)
 Get the state of a POV on the joystick. More...
 
static int GetStickButtons (int stick)
 The state of the buttons on the joystick. More...
 
static int GetStickAxisCount (int stick)
 Returns the number of axes on a given joystick port. More...
 
static int GetStickPOVCount (int stick)
 Returns the number of POVs on a given joystick port. More...
 
static int GetStickButtonCount (int stick)
 Returns the number of buttons on a given joystick port. More...
 
static bool GetJoystickIsXbox (int stick)
 Returns a boolean indicating if the controller is an xbox controller. More...
 
static int GetJoystickType (int stick)
 Returns the type of joystick at a given port. More...
 
static std::string GetJoystickName (int stick)
 Returns the name of the joystick at the given port. More...
 
static int GetJoystickAxisType (int stick, int axis)
 Returns the types of Axes on a given joystick port. More...
 
static bool IsJoystickConnected (int stick)
 Returns if a joystick is connected to the Driver Station. More...
 
static bool IsEnabled ()
 Check if the DS has enabled the robot. More...
 
static bool IsDisabled ()
 Check if the robot is disabled. More...
 
static bool IsEStopped ()
 Check if the robot is e-stopped. More...
 
static bool IsAutonomous ()
 Check if the DS is commanding autonomous mode. More...
 
static bool IsAutonomousEnabled ()
 Check if the DS is commanding autonomous mode and if it has enabled the robot. More...
 
static bool IsTeleop ()
 Check if the DS is commanding teleop mode. More...
 
static bool IsTeleopEnabled ()
 Check if the DS is commanding teleop mode and if it has enabled the robot. More...
 
static bool IsTest ()
 Check if the DS is commanding test mode. More...
 
static bool IsTestEnabled ()
 Check if the DS is commanding Test mode and if it has enabled the robot. More...
 
static bool IsDSAttached ()
 Check if the DS is attached. More...
 
static bool IsFMSAttached ()
 Is the driver station attached to a Field Management System? More...
 
static std::string GetGameSpecificMessage ()
 Returns the game specific message provided by the FMS. More...
 
static std::string GetEventName ()
 Returns the name of the competition event provided by the FMS. More...
 
static MatchType GetMatchType ()
 Returns the type of match being played provided by the FMS. More...
 
static int GetMatchNumber ()
 Returns the match number provided by the FMS. More...
 
static int GetReplayNumber ()
 Returns the number of times the current match has been replayed from the FMS. More...
 
static Alliance GetAlliance ()
 Return the alliance that the driver station says it is on from the FMS. More...
 
static int GetLocation ()
 Return the driver station location from the FMS. More...
 
static double GetMatchTime ()
 Return the approximate match time. More...
 
static double GetBatteryVoltage ()
 Read the battery voltage. More...
 
static void RefreshData ()
 
static void ProvideRefreshedDataEventHandle (WPI_EventHandle handle)
 
static void RemoveRefreshedDataEventHandle (WPI_EventHandle handle)
 
static void SilenceJoystickConnectionWarning (bool silence)
 Allows the user to specify whether they want joystick connection warnings to be printed to the console. More...
 
static bool IsJoystickConnectionWarningSilenced ()
 Returns whether joystick connection warnings are silenced. More...
 
static void StartDataLog (wpi::log::DataLog &log, bool logJoysticks=true)
 Starts logging DriverStation data to data log. More...
 

Static Public Attributes

static constexpr int kJoystickPorts = 6
 

Detailed Description

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

Member Enumeration Documentation

◆ Alliance

Enumerator
kRed 
kBlue 
kInvalid 

◆ MatchType

Enumerator
kNone 
kPractice 
kQualification 
kElimination 

Member Function Documentation

◆ GetAlliance()

static Alliance frc::DriverStation::GetAlliance ( )
static

Return the alliance that the driver station says it is on from the FMS.

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

This could return kRed or kBlue.

Returns
The Alliance enum (kRed, kBlue or kInvalid)

◆ GetBatteryVoltage()

static double frc::DriverStation::GetBatteryVoltage ( )
static

Read the battery voltage.

Returns
The battery voltage in Volts.

◆ GetEventName()

static std::string frc::DriverStation::GetEventName ( )
static

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

Returns
A string containing the event name

◆ GetGameSpecificMessage()

static std::string frc::DriverStation::GetGameSpecificMessage ( )
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.

◆ GetJoystickAxisType()

static int frc::DriverStation::GetJoystickAxisType ( int  stick,
int  axis 
)
static

Returns the types of Axes on a given joystick port.

Parameters
stickThe joystick port number and the target axis
axisThe analog axis value to read from the joystick.
Returns
What type of axis the axis is reporting to be

◆ GetJoystickIsXbox()

static bool frc::DriverStation::GetJoystickIsXbox ( 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()

static std::string frc::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

◆ GetJoystickType()

static int frc::DriverStation::GetJoystickType ( int  stick)
static

Returns the type of joystick at a given port.

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

◆ GetLocation()

static int frc::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()

static int frc::DriverStation::GetMatchNumber ( )
static

Returns the match number provided by the FMS.

Returns
The number of the match

◆ GetMatchTime()

static double frc::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).

The Practice Match function of the DS approximates the behavior seen on the field.

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

◆ GetMatchType()

static MatchType frc::DriverStation::GetMatchType ( )
static

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

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

◆ GetReplayNumber()

static int frc::DriverStation::GetReplayNumber ( )
static

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

Returns
The number of replays

◆ GetStickAxis()

static double frc::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.

◆ GetStickAxisCount()

static int frc::DriverStation::GetStickAxisCount ( int  stick)
static

Returns the number of axes on a given joystick port.

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

◆ GetStickButton()

static bool frc::DriverStation::GetStickButton ( int  stick,
int  button 
)
static

The state of one joystick button.

Button indexes begin at 1.

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

◆ GetStickButtonCount()

static int frc::DriverStation::GetStickButtonCount ( int  stick)
static

Returns the number of buttons on a given joystick port.

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

◆ GetStickButtonPressed()

static bool frc::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 1.
Returns
Whether the joystick button was pressed since the last check.

◆ GetStickButtonReleased()

static bool frc::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 1.
Returns
Whether the joystick button was released since the last check.

◆ GetStickButtons()

static int frc::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.

◆ GetStickPOV()

static int frc::DriverStation::GetStickPOV ( int  stick,
int  pov 
)
static

Get the state of a POV on the joystick.

Returns
the angle of the POV in degrees, or -1 if the POV is not pressed.

◆ GetStickPOVCount()

static int frc::DriverStation::GetStickPOVCount ( int  stick)
static

Returns the number of POVs on a given joystick port.

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

◆ IsAutonomous()

static bool frc::DriverStation::IsAutonomous ( )
static

Check if the DS is commanding autonomous mode.

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

◆ IsAutonomousEnabled()

static bool frc::DriverStation::IsAutonomousEnabled ( )
static

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()

static bool frc::DriverStation::IsDisabled ( )
static

Check if the robot is disabled.

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

◆ IsDSAttached()

static bool frc::DriverStation::IsDSAttached ( )
static

Check if the DS is attached.

Returns
True if the DS is connected to the robot

◆ IsEnabled()

static bool frc::DriverStation::IsEnabled ( )
static

Check if the DS has enabled the robot.

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

◆ IsEStopped()

static bool frc::DriverStation::IsEStopped ( )
static

Check if the robot is e-stopped.

Returns
True if the robot is e-stopped

◆ IsFMSAttached()

static bool frc::DriverStation::IsFMSAttached ( )
static

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()

static bool frc::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()

static bool frc::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.

◆ IsTeleop()

static bool frc::DriverStation::IsTeleop ( )
static

Check if the DS is commanding teleop mode.

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

◆ IsTeleopEnabled()

static bool frc::DriverStation::IsTeleopEnabled ( )
static

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()

static bool frc::DriverStation::IsTest ( )
static

Check if the DS is commanding test mode.

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

◆ IsTestEnabled()

static bool frc::DriverStation::IsTestEnabled ( )
static

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()

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

◆ RefreshData()

static void frc::DriverStation::RefreshData ( )
static

◆ RemoveRefreshedDataEventHandle()

static void frc::DriverStation::RemoveRefreshedDataEventHandle ( WPI_EventHandle  handle)
static

◆ SilenceJoystickConnectionWarning()

static void frc::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()

static void frc::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

constexpr int frc::DriverStation::kJoystickPorts = 6
staticconstexpr

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