RobotState

class wpilib.RobotState

Bases: pybind11_object

Provides access to robot state information from the Driver Station.

static add_opmode(*args, **kwargs)

Overloaded function.

  1. 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

  1. 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 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_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 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_opmode(*args, **kwargs)

Overloaded function.

  1. 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

  1. 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 publish_opmodes() None

Publishes the operating mode options to the driver station.

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