DriverStationBackend

class wpilib.DriverStationBackend

Bases: pybind11_object

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

JOYSTICK_PORTS = 6
static addOpMode(*args, **kwargs)

Overloaded function.

  1. addOpMode(mode: hal._wpiHal.RobotMode, name: str, group: str, description: str, textColor: wpiutil._wpiutil.Color, backgroundColor: wpiutil._wpiutil.Color) -> int

Adds an operating mode option. It’s necessary to call PublishOpModes() to make the added modes visible to the driver station.

Parameters:
  • mode – robot mode

  • name – name of the operating mode

  • group – group of the operating mode

  • description – description of the operating mode

  • textColor – text color

  • backgroundColor – background 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

  1. addOpMode(mode: hal._wpiHal.RobotMode, name: str, group: str = ‘’, description: str = ‘’) -> int

Adds an operating mode option. It’s necessary to call PublishOpModes() to make the added modes visible to the driver station.

Parameters:
  • mode – robot mode

  • name – name of the operating mode

  • group – group of the operating mode

  • description – description 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

static clearOpModes() None

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

static getAlliance() wpilib._wpilib.Alliance | None

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

static getBatteryVoltage() float

Read the battery voltage.

Returns:

The battery voltage in Volts.

static getControlWord() hal._wpiHal.ControlWord

Get the current control word.

Returns:

control word

static getEventName() str

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

Returns:

A string containing the event name

static getGameData() str | None

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.

static getJoystickGamepadType(stick: SupportsInt | SupportsIndex) int

Returns the type of joystick at a given port.

This maps to SDL_GamepadType

Parameters:

stick – The joystick port number

Returns:

The HID type of joystick at the given port

static getJoystickIsGamepad(stick: SupportsInt | SupportsIndex) bool

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

Parameters:

stick – The joystick port number

Returns:

A boolean that is true if the controller is an xbox controller.

static getJoystickName(stick: SupportsInt | SupportsIndex) str

Returns the name of the joystick at the given port.

Parameters:

stick – The joystick port number

Returns:

The name of the joystick at the given port

static getJoystickSupportedOutputs(stick: SupportsInt | SupportsIndex) int

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

Parameters:

stick – The joystick port number

Returns:

The number of outputs supported by the joystick at the given port

static getLocation() int | None

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)

static getMatchNumber() int

Returns the match number provided by the FMS.

Returns:

The number of the match

static getMatchTime() wpimath.units.seconds

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

static getMatchType() wpilib._wpilib.MatchType

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

Returns:

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

static getOpMode() str

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

static getOpModeId() int

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

static getReplayNumber() int

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

Returns:

The number of replays

static getRobotMode() hal._wpiHal.RobotMode

Gets the current robot mode.

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

Returns:

robot mode

static getStickAxesAvailable(stick: SupportsInt | SupportsIndex) int

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

Parameters:

stick – The joystick port number

Returns:

The mask of available axes on the indicated joystick

static getStickAxesMaximumIndex(stick: SupportsInt | SupportsIndex) int

Returns the maximum axis index on a given joystick port.

Parameters:

stick – The joystick port number

Returns:

The maximum axis index on the indicated joystick

static getStickAxis(stick: SupportsInt | SupportsIndex, axis: SupportsInt | SupportsIndex) float

Get the value of the axis on a joystick.

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

Parameters:
  • stick – The joystick to read.

  • axis – The analog axis value to read from the joystick.

Returns:

The value of the axis on the joystick.

static getStickAxisIfAvailable(stick: SupportsInt | SupportsIndex, axis: SupportsInt | SupportsIndex) float | None

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:
  • stick – The joystick to read.

  • axis – The analog axis value to read from the joystick.

Returns:

The value of the axis on the joystick, or empty if not available.

static getStickButton(stick: SupportsInt | SupportsIndex, button: SupportsInt | SupportsIndex) bool

The state of one joystick button. Button indexes begin at 0.

Parameters:
  • stick – The joystick to read.

  • button – The button index, beginning at 0.

Returns:

The state of the joystick button.

static getStickButtonIfAvailable(stick: SupportsInt | SupportsIndex, button: SupportsInt | SupportsIndex) bool | None

The state of one joystick button, only if available. Button indexes begin at 0.

Parameters:
  • stick – The joystick to read.

  • button – The button index, beginning at 0.

Returns:

The state of the joystick button, or empty if unavailable.

static getStickButtonPressed(stick: SupportsInt | SupportsIndex, button: SupportsInt | SupportsIndex) bool

Whether one joystick button was pressed since the last check. %Button indexes begin at 1.

Parameters:
  • stick – The joystick to read.

  • button – The button index, beginning at 0.

Returns:

Whether the joystick button was pressed since the last check.

static getStickButtonReleased(stick: SupportsInt | SupportsIndex, button: SupportsInt | SupportsIndex) bool

Whether one joystick button was released since the last check. %Button indexes begin at 1.

Parameters:
  • stick – The joystick to read.

  • button – The button index, beginning at 0.

Returns:

Whether the joystick button was released since the last check.

static getStickButtons(stick: SupportsInt | SupportsIndex) int

The state of the buttons on the joystick.

Parameters:

stick – The joystick to read.

Returns:

The state of the buttons on the joystick.

static getStickButtonsAvailable(stick: SupportsInt | SupportsIndex) int

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

Parameters:

stick – The joystick port number

Returns:

The mask of available buttons on the indicated joystick

static getStickButtonsMaximumIndex(stick: SupportsInt | SupportsIndex) int

Returns the maximum button index on a given joystick port.

Parameters:

stick – The joystick port number

Returns:

The maximum button index on the indicated joystick

static getStickPOV(stick: SupportsInt | SupportsIndex, pov: SupportsInt | SupportsIndex) wpilib._wpilib.POVDirection

Get the state of a POV on the joystick.

Returns:

the angle of the POV.

static getStickPOVsAvailable(stick: SupportsInt | SupportsIndex) int

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

Parameters:

stick – The joystick port number

Returns:

The mask of available POVs on the indicated joystick

static getStickPOVsMaximumIndex(stick: SupportsInt | SupportsIndex) int

Returns the maximum POV index on a given joystick port.

Parameters:

stick – The joystick port number

Returns:

The maximum POV index on the indicated joystick

static getStickTouchpadFinger(stick: SupportsInt | SupportsIndex, touchpad: SupportsInt | SupportsIndex, finger: SupportsInt | SupportsIndex) wpilib._wpilib.TouchpadFinger

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

Parameters:
  • stick – The joystick to read.

  • touchpad – The touchpad index to read from the joystick.

  • finger – The finger index to read from the touchpad.

Returns:

The finger data of the touchpad on the joystick.

static getStickTouchpadFingerAvailable(stick: SupportsInt | SupportsIndex, touchpad: SupportsInt | SupportsIndex, finger: SupportsInt | SupportsIndex) bool

Whether a finger on a touchpad is available.

Parameters:
  • stick – The joystick to read.

  • touchpad – The touchpad index to read from the joystick.

  • finger – The finger index to read from the touchpad.

Returns:

True if the finger data is available.

static isAutonomous() bool

Check if the DS is commanding autonomous mode.

Returns:

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

static isAutonomousEnabled() bool

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.

static isDSAttached() bool

Check if the DS is attached.

Returns:

True if the DS is connected to the robot

static isDisabled() bool

Check if the robot is disabled.

Returns:

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

static isEStopped() bool

Check if the robot is e-stopped.

Returns:

True if the robot is e-stopped

static isEnabled() bool

Check if the DS has enabled the robot.

Returns:

True if the robot is enabled and the DS is connected

static isFMSAttached() bool

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

static isJoystickConnected(stick: SupportsInt | SupportsIndex) bool

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:

stick – The joystick port number

Returns:

true if a joystick is connected

static isJoystickConnectionWarningSilenced() bool

Returns whether joystick connection warnings are silenced. This will always return false when connected to the FMS.

Returns:

Whether joystick connection warnings are silenced.

static isOpMode(*args, **kwargs)

Overloaded function.

  1. isOpMode(id: typing.SupportsInt | typing.SupportsIndex) -> bool

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:

id – operating mode unique ID

Returns:

True if that mode is the current mode

  1. isOpMode(mode: str) -> bool

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:

mode – operating mode

Returns:

True if that mode is the current mode

static isTeleop() bool

Check if the DS is commanding teleop mode.

Returns:

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

static isTeleopEnabled() bool

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.

static isUtility() bool

Check if the DS is commanding utility mode.

Returns:

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

static isUtilityEnabled() bool

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.

static observeUserProgramStarting() None

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.

static provideRefreshedDataEventHandle(handle: SupportsInt | SupportsIndex) None

Registers the given handle for DS data refresh notifications.

Parameters:

handle – The event handle.

static publishOpModes() None

Publishes the operating mode options to the driver station.

static refreshData() None

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.

static removeOpMode(mode: hal._wpiHal.RobotMode, name: str) int

Removes an operating mode option. It’s necessary to call PublishOpModes() to make the removed mode no longer visible to the driver station.

Parameters:
  • mode – robot mode

  • name – name of the operating mode

Returns:

unique ID for the opmode, or 0 if not found

static removeRefreshedDataEventHandle(handle: SupportsInt | SupportsIndex) None

Unregisters the given handle from DS data refresh notifications.

Parameters:

handle – The event handle.

static silenceJoystickConnectionWarning(silence: bool) None

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:

silence – Whether warning messages should be silenced.

static startDataLog(log: wpilog._wpilog.DataLog, logJoysticks: bool = True) None

Starts logging DriverStation data to data log. Repeated calls are ignored.

Parameters:
  • log – data log

  • logJoysticks – if true, log joystick data