RobotState

class wpilib.RobotState

Bases: pybind11_object

Provides access to robot state information from the Driver Station.

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 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 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 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 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 publishOpModes() None

Publishes the operating mode options to the driver station.

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