DriverStationBackend
- class wpilib.DriverStationBackend
Bases:
pybind11_objectProvide access to the network communication data to / from the Driver Station.
- JOYSTICK_PORTS = 6
- static add_opmode(*args, **kwargs)
Overloaded function.
add_opmode(mode: hal._wpi_hal.RobotMode, name: str, group: str, description: str, text_color: wpiutil._wpiutil.Color, background_color: 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
text_color – text color
background_color – 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
add_opmode(mode: hal._wpi_hal.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 clear_opmodes() None
Clears all operating mode options and publishes an empty list to the driver station.
- static construct_generic_hid(port: SupportsInt | SupportsIndex) wpilib._wpilib.GenericHID
Constructs a GenericHID for the given port.
- Parameters:
port – The port index on the Driver Station.
- Returns:
The GenericHID object for the given port.
- static get_alliance() 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 get_battery_voltage() float
Read the battery voltage.
- Returns:
The battery voltage in Volts.
- static get_control_word() hal._wpi_hal.ControlWord
Get the current control word.
- Returns:
control word
- static get_event_name() str
Returns the name of the competition event provided by the FMS.
- Returns:
A string containing the event name
- static get_game_data() 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 get_joystick_gamepad_type(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 get_joystick_is_gamepad(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 get_joystick_name(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 get_joystick_supported_outputs(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 get_location() 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 get_match_number() int
Returns the match number provided by the FMS.
- Returns:
The number of the match
- static get_match_time() 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 get_match_type() wpilib._wpilib.MatchType
Returns the type of match being played provided by the FMS.
- Returns:
The match type enum (kNone, kPractice, kQualification, kElimination)
- static get_opmode() 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 get_opmode_id() 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 get_replay_number() int
Returns the number of times the current match has been replayed from the FMS.
- Returns:
The number of replays
- static get_robot_mode() hal._wpi_hal.RobotMode
Gets the current robot mode.
Note that this does not indicate whether the robot is enabled or disabled.
- Returns:
robot mode
- static get_stick_axes_available(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 get_stick_axes_maximum_index(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 get_stick_axis(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 get_stick_axis_if_available(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 get_stick_button(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 get_stick_button_if_available(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 get_stick_button_pressed(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 get_stick_button_released(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 get_stick_buttons(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 get_stick_buttons_available(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 get_stick_buttons_maximum_index(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 get_stick_pov(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 get_stick_povs_available(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 get_stick_povs_maximum_index(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 get_stick_touchpad_finger(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 get_stick_touchpad_finger_available(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 is_autonomous() bool
Check if the DS is commanding autonomous mode.
- Returns:
True if the robot is being commanded to be in autonomous mode
- static is_autonomous_enabled() 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 is_disabled() bool
Check if the robot is disabled.
- Returns:
True if the robot is explicitly disabled or the DS is not connected
- static is_ds_attached() bool
Check if the DS is attached.
- Returns:
True if the DS is connected to the robot
- static is_e_stopped() bool
Check if the robot is e-stopped.
- Returns:
True if the robot is e-stopped
- static is_enabled() bool
Check if the DS has enabled the robot.
- Returns:
True if the robot is enabled and the DS is connected
- static is_fms_attached() 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 is_joystick_connected(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 is_joystick_connection_warning_silenced() 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 is_opmode(*args, **kwargs)
Overloaded function.
is_opmode(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
is_opmode(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 is_teleop() bool
Check if the DS is commanding teleop mode.
- Returns:
True if the robot is being commanded to be in teleop mode
- static is_teleop_enabled() 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 is_utility() bool
Check if the DS is commanding utility mode.
- Returns:
True if the robot is being commanded to be in utility mode
- static is_utility_enabled() 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 observe_user_program_starting() 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 provide_refreshed_data_event_handle(handle: SupportsInt | SupportsIndex) None
Registers the given handle for DS data refresh notifications.
- Parameters:
handle – The event handle.
- static publish_opmodes() None
Publishes the operating mode options to the driver station.
- static refresh_data() 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 remove_opmode(mode: hal._wpi_hal.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 remove_refreshed_data_event_handle(handle: SupportsInt | SupportsIndex) None
Unregisters the given handle from DS data refresh notifications.
- Parameters:
handle – The event handle.
- static reset_cached_hid_data() None
Resets cached DriverStation HID wrapper objects.
This is intended for test cleanup only. Any existing references to cached GenericHID or Gamepad objects become invalid after this call.
- static silence_joystick_connection_warning(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 start_data_log(log: wpilog._wpilog.DataLog, log_joysticks: bool = True) None
Starts logging DriverStation data to data log. Repeated calls are ignored.
- Parameters:
log – data log
log_joysticks – if true, log joystick data