DriverStation

class wpilib.DriverStation

Bases: pybind11_object

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

class Alliance(value: int)

Bases: pybind11_object

Members:

kRed

kBlue

kInvalid

kBlue = <Alliance.kBlue: 1>
kInvalid = <Alliance.kInvalid: 2>
kRed = <Alliance.kRed: 0>
property name
property value
class MatchType(value: int)

Bases: pybind11_object

Members:

kNone

kPractice

kQualification

kElimination

kElimination = <MatchType.kElimination: 3>
kNone = <MatchType.kNone: 0>
kPractice = <MatchType.kPractice: 1>
kQualification = <MatchType.kQualification: 2>
property name
property value
static getAlliance() wpilib._wpilib.DriverStation.Alliance

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)

static getBatteryVoltage() float

Read the battery voltage.

Returns:

The battery voltage in Volts.

getControlState() Tuple[bool, bool, bool]

More efficient way to determine what state the robot is in.

Returns:

booleans representing enabled, isautonomous, istest

New in version 2019.2.1.

Note

This function only exists in RobotPy

static getEventName() str

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

Returns:

A string containing the event name

static getGameSpecificMessage() str

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 getJoystickAxisType(stick: int, axis: int) int

Returns the types of Axes on a given joystick port.

Parameters:
  • stick – The joystick port number and the target axis

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

Returns:

What type of axis the axis is reporting to be

static getJoystickIsXbox(stick: int) 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: int) 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 getJoystickType(stick: int) int

Returns the type of joystick at a given port.

Parameters:

stick – The joystick port number

Returns:

The HID type of joystick at the given port

static getLocation() int

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

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)

static getMatchType() wpilib._wpilib.DriverStation.MatchType

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

Returns:

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

static getReplayNumber() int

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

Returns:

The number of replays

static getStickAxis(stick: int, axis: int) 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 getStickAxisCount(stick: int) int

Returns the number of axes on a given joystick port.

Parameters:

stick – The joystick port number

Returns:

The number of axes on the indicated joystick

static getStickButton(stick: int, button: int) bool

The state of one joystick button. %Button indexes begin at 1.

Parameters:
  • stick – The joystick to read.

  • button – The button index, beginning at 1.

Returns:

The state of the joystick button.

static getStickButtonCount(stick: int) int

Returns the number of buttons on a given joystick port.

Parameters:

stick – The joystick port number

Returns:

The number of buttons on the indicated joystick

static getStickButtonPressed(stick: int, button: int) 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 1.

Returns:

Whether the joystick button was pressed since the last check.

static getStickButtonReleased(stick: int, button: int) 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 1.

Returns:

Whether the joystick button was released since the last check.

static getStickButtons(stick: int) 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 getStickPOV(stick: int, pov: int) int

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.

static getStickPOVCount(stick: int) int

Returns the number of POVs on a given joystick port.

Parameters:

stick – The joystick port number

Returns:

The number of POVs on the indicated joystick

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: int) 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 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 isTest() bool

Check if the DS is commanding test mode.

Returns:

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

static isTestEnabled() bool

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.

kJoystickPorts = 6
static provideRefreshedDataEventHandle(handle: int) None
static refreshData() None
static removeRefreshedDataEventHandle(handle: int) None
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: wpiutil._wpiutil.log.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