DriverStation

class wpilib.DriverStation

Bases: wpilib.ErrorBase

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

class Alliance(self: wpilib._wpilib.DriverStation.Alliance, value: int) → None

Bases: pybind11_builtins.pybind11_object

Members:

kRed

kBlue

kInvalid

kBlue = <Alliance.kBlue: 1>
kInvalid = <Alliance.kInvalid: 2>
kRed = <Alliance.kRed: 0>
property name
class MatchType(self: wpilib._wpilib.DriverStation.MatchType, value: int) → None

Bases: pybind11_builtins.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
getAlliance(self: wpilib.DriverStation) → wpilib._wpilib.DriverStation.Alliance

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

This could return kRed or kBlue.

Returns

The Alliance enum (kRed, kBlue or kInvalid)

getBatteryVoltage(self: wpilib.DriverStation) → float

Read the battery voltage.

Returns

The battery voltage in Volts.

getControlState(self: wpilib.DriverStation) → 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

getEventName(self: wpilib.DriverStation) → str

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

Returns

A string containing the event name

getGameSpecificMessage(self: wpilib.DriverStation) → str

Returns the game specific message provided by the FMS.

Returns

A string containing the game specific message.

static getInstance()wpilib.DriverStation

Return a reference to the singleton DriverStation.

Returns

Reference to the DS instance

getJoystickAxisType(self: wpilib.DriverStation, 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

Returns

What type of axis the axis is reporting to be

getJoystickIsXbox(self: wpilib.DriverStation, 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.

getJoystickName(self: wpilib.DriverStation, 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

getJoystickType(self: wpilib.DriverStation, 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

getLocation(self: wpilib.DriverStation) → int

Return the driver station location on the field.

This could return 1, 2, or 3.

Returns

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

getMatchNumber(self: wpilib.DriverStation) → int

Returns the match number provided by the FMS.

Returns

The number of the match

getMatchTime(self: wpilib.DriverStation) → 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)

getMatchType(self: wpilib.DriverStation) → wpilib._wpilib.DriverStation.MatchType

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

Returns

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

getReplayNumber(self: wpilib.DriverStation) → int

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

Returns

The number of replays

getStickAxis(self: wpilib.DriverStation, 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.

getStickAxisCount(self: wpilib.DriverStation, 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

getStickButton(self: wpilib.DriverStation, 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.

getStickButtonCount(self: wpilib.DriverStation, 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

getStickButtonPressed(self: wpilib.DriverStation, 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.

getStickButtonReleased(self: wpilib.DriverStation, 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.

getStickButtons(self: wpilib.DriverStation, 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.

getStickPOV(self: wpilib.DriverStation, 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.

getStickPOVCount(self: wpilib.DriverStation, 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

inAutonomous(self: wpilib.DriverStation, entering: bool) → None

Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.

Parameters

entering – If true, starting autonomous code; if false, leaving autonomous code.

inDisabled(self: wpilib.DriverStation, entering: bool) → None

Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.

Parameters

entering – If true, starting disabled code; if false, leaving disabled code.

inOperatorControl(self: wpilib.DriverStation, entering: bool) → None

Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.

Parameters

entering – If true, starting teleop code; if false, leaving teleop code.

inTest(self: wpilib.DriverStation, entering: bool) → None

Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.

Parameters

entering – If true, starting test code; if false, leaving test code.

isAutonomous(self: wpilib.DriverStation) → bool

Check if the DS is commanding autonomous mode.

Returns

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

isAutonomousEnabled(self: wpilib.DriverStation) → 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.

isDSAttached(self: wpilib.DriverStation) → bool

Check if the DS is attached.

Returns

True if the DS is connected to the robot

isDisabled(self: wpilib.DriverStation) → bool

Check if the robot is disabled.

Returns

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

isEStopped(self: wpilib.DriverStation) → bool

Check if the robot is e-stopped.

Returns

True if the robot is e-stopped

isEnabled(self: wpilib.DriverStation) → bool

Check if the DS has enabled the robot.

Returns

True if the robot is enabled and the DS is connected

isFMSAttached(self: wpilib.DriverStation) → 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

isJoystickConnected(self: wpilib.DriverStation, 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

isJoystickConnectionWarningSilenced(self: wpilib.DriverStation) → 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.

isNewControlData(self: wpilib.DriverStation) → bool

Has a new control packet from the driver station arrived since the last time this function was called?

Warning: If you call this function from more than one place at the same time, you will not get the intended behavior.

Returns

True if the control data has been updated since the last call.

isOperatorControl(self: wpilib.DriverStation) → bool

Check if the DS is commanding teleop mode.

Returns

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

isOperatorControlEnabled(self: wpilib.DriverStation) → 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.

isTest(self: wpilib.DriverStation) → bool

Check if the DS is commanding test mode.

Returns

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

kJoystickPorts = 6
static reportError(error: str, printTrace: bool_) → object

Report error to Driver Station, and also prints error to sys.stderr. Optionally appends stack trace to error message.

Parameters

printTrace – If True, append stack trace to error string

The error is also printed to the program console.

static reportWarning(error: str, printTrace: bool_) → object

Report warning to Driver Station, and also prints error to sys.stderr. Optionally appends stack trace to error message.

Parameters

printTrace – If True, append stack trace to error string

The error is also printed to the program console.

silenceJoystickConnectionWarning(self: wpilib.DriverStation, 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.

waitForData(*args, **kwargs)

Overloaded function.

  1. waitForData(self: wpilib._wpilib.DriverStation) -> None

Wait until a new packet comes from the driver station.

This blocks on a semaphore, so the waiting is efficient.

This is a good way to delay processing until there is new driver station data to act on.

Checks if new control data has arrived since the last waitForData call on the current thread. If new data has not arrived, returns immediately.

  1. waitForData(self: wpilib._wpilib.DriverStation, timeout: float) -> bool

Wait until a new packet comes from the driver station, or wait for a timeout.

Checks if new control data has arrived since the last waitForData call on the current thread. If new data has not arrived, returns immediately.

If the timeout is less then or equal to 0, wait indefinitely.

Timeout is in milliseconds

This blocks on a semaphore, so the waiting is efficient.

This is a good way to delay processing until there is new driver station data to act on.

Parameters

timeout – Timeout time in seconds

Returns

true if new data, otherwise false

wakeupWaitForData(self: wpilib.DriverStation) → None

Forces WaitForData() to return immediately.