Class RobotState

java.lang.Object
org.wpilib.driverstation.RobotState

public final class RobotState extends Object
Provides access to robot state information from the Driver Station.
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    addOpMode(RobotMode mode, String name)
    Adds an operating mode option.
    static long
    addOpMode(RobotMode mode, String name, String group)
    Adds an operating mode option.
    static long
    addOpMode(RobotMode mode, String name, String group, String description)
    Adds an operating mode option.
    static long
    addOpMode(RobotMode mode, String name, String group, String description, Color textColor, Color backgroundColor)
    Adds an operating mode option.
    static void
    Clears all operating mode options and publishes an empty list to the driver station.
    static String
    Gets the operating mode selected on the driver station.
    static long
    Gets the operating mode selected on the driver station.
    static RobotMode
    Gets the current robot mode.
    static boolean
    Gets a value indicating whether the Driver Station requires the robot to be running in autonomous mode.
    static boolean
    Gets a value indicating whether the Driver Station requires the robot to be running in autonomous mode and enabled.
    static boolean
    Gets a value indicating whether the Driver Station requires the robot to be disabled.
    static boolean
    Gets a value indicating whether the Driver Station is attached.
    static boolean
    Gets a value indicating whether the Driver Station requires the robot to be enabled.
    static boolean
    Gets a value indicating whether the Robot is e-stopped.
    static boolean
    Gets if the driver station attached to a Field Management System.
    static boolean
    isOpMode(long id)
    Check to see if the selected operating mode is a particular value.
    static boolean
    Check to see if the selected operating mode is a particular value.
    static boolean
    Gets a value indicating whether the Driver Station requires the robot to be running in operator-controlled mode.
    static boolean
    Gets a value indicating whether the Driver Station requires the robot to be running in operator-controller mode and enabled.
    static boolean
    Gets a value indicating whether the Driver Station requires the robot to be running in Utility mode.
    static boolean
    Gets a value indicating whether the Driver Station requires the robot to be running in Utility mode and enabled.
    static void
    Publishes the operating mode options to the driver station.
    static long
    Removes an operating mode option.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isEnabled

      public static boolean isEnabled()
      Gets a value indicating whether the Driver Station requires the robot to be enabled.
      Returns:
      True if the robot is enabled, false otherwise.
    • isDisabled

      public static boolean isDisabled()
      Gets a value indicating whether the Driver Station requires the robot to be disabled.
      Returns:
      True if the robot should be disabled, false otherwise.
    • isEStopped

      public static boolean isEStopped()
      Gets a value indicating whether the Robot is e-stopped.
      Returns:
      True if the robot is e-stopped, false otherwise.
    • getRobotMode

      public static RobotMode getRobotMode()
      Gets the current robot mode.

      Note that this does not indicate whether the robot is enabled or disabled.

      Returns:
      robot mode
    • isAutonomous

      public static boolean isAutonomous()
      Gets a value indicating whether the Driver Station requires the robot to be running in autonomous mode.
      Returns:
      True if autonomous mode should be enabled, false otherwise.
    • isAutonomousEnabled

      public static boolean isAutonomousEnabled()
      Gets a value indicating whether the Driver Station requires the robot to be running in autonomous mode and enabled.
      Returns:
      True if autonomous should be set and the robot should be enabled.
    • isTeleop

      public static boolean isTeleop()
      Gets a value indicating whether the Driver Station requires the robot to be running in operator-controlled mode.
      Returns:
      True if operator-controlled mode should be enabled, false otherwise.
    • isTeleopEnabled

      public static boolean isTeleopEnabled()
      Gets a value indicating whether the Driver Station requires the robot to be running in operator-controller mode and enabled.
      Returns:
      True if operator-controlled mode should be set and the robot should be enabled.
    • isUtility

      public static boolean isUtility()
      Gets a value indicating whether the Driver Station requires the robot to be running in Utility mode.
      Returns:
      True if utility mode should be enabled, false otherwise.
    • isUtilityEnabled

      public static boolean isUtilityEnabled()
      Gets a value indicating whether the Driver Station requires the robot to be running in Utility mode and enabled.
      Returns:
      True if utility mode should be set and the robot should be enabled.
    • addOpMode

      public static long addOpMode(RobotMode mode, String name, String group, String description, Color textColor, Color backgroundColor)
      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, or null for default
      backgroundColor - background color, or null for default
      Returns:
      unique ID used to later identify the operating mode
      Throws:
      IllegalArgumentException - if name is empty or an operating mode with the same robot mode and name already exists
    • addOpMode

      public static long addOpMode(RobotMode mode, String name, String group, String description)
      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
      Throws:
      IllegalArgumentException - if name is empty or an operating mode with the same name already exists
    • addOpMode

      public static long addOpMode(RobotMode mode, String name, String group)
      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
      Returns:
      unique ID used to later identify the operating mode
      Throws:
      IllegalArgumentException - if name is empty or an operating mode with the same name already exists
    • addOpMode

      public static long addOpMode(RobotMode mode, String name)
      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
      Returns:
      unique ID used to later identify the operating mode
      Throws:
      IllegalArgumentException - if name is empty or an operating mode with the same name already exists
    • removeOpMode

      public static long removeOpMode(RobotMode mode, String name)
      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
    • publishOpModes

      public static void publishOpModes()
      Publishes the operating mode options to the driver station.
    • clearOpModes

      public static void clearOpModes()
      Clears all operating mode options and publishes an empty list to the driver station.
    • getOpModeId

      public static long getOpModeId()
      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
    • getOpMode

      public static String getOpMode()
      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
    • isOpMode

      public static boolean isOpMode(long id)
      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
    • isOpMode

      public static boolean isOpMode(String mode)
      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
    • isDSAttached

      public static boolean isDSAttached()
      Gets a value indicating whether the Driver Station is attached.
      Returns:
      True if Driver Station is attached, false otherwise.
    • isFMSAttached

      public static boolean isFMSAttached()
      Gets if 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