Class DriverStation

java.lang.Object
org.wpilib.driverstation.DriverStation

public final class DriverStation extends Object
Provide access to the network communication data to / from the Driver Station.
  • Field Details

  • Method Details

    • reportError

      public static void reportError(String error, boolean printTrace)
      Report error to Driver Station. Optionally appends Stack trace to error message.
      Parameters:
      error - The error to report.
      printTrace - If true, append stack trace to error string
    • reportError

      public static void reportError(String error, StackTraceElement[] stackTrace)
      Report error to Driver Station. Appends provided stack trace to error message.
      Parameters:
      error - The error to report.
      stackTrace - The stack trace to append
    • reportWarning

      public static void reportWarning(String warning, boolean printTrace)
      Report warning to Driver Station. Optionally appends Stack trace to warning message.
      Parameters:
      warning - The warning to report.
      printTrace - If true, append stack trace to warning string
    • reportWarning

      public static void reportWarning(String warning, StackTraceElement[] stackTrace)
      Report warning to Driver Station. Appends provided stack trace to warning message.
      Parameters:
      warning - The warning to report.
      stackTrace - The stack trace to append
    • getStickButton

      public static boolean getStickButton(int stick, int button)
      The state of one joystick button.
      Parameters:
      stick - The joystick to read.
      button - The button index.
      Returns:
      The state of the joystick button.
    • getStickButtonIfAvailable

      public static Optional<Boolean> getStickButtonIfAvailable(int stick, int button)
      The state of one joystick button if available.
      Parameters:
      stick - The joystick to read.
      button - The button index.
      Returns:
      The state of the joystick button, or false if the button is not available.
    • getStickButtonPressed

      public static boolean getStickButtonPressed(int stick, int button)
      Whether one joystick button was pressed since the last check.
      Parameters:
      stick - The joystick to read.
      button - The button index.
      Returns:
      Whether the joystick button was pressed since the last check.
    • getStickButtonReleased

      public static boolean getStickButtonReleased(int stick, int button)
      Whether one joystick button was released since the last check.
      Parameters:
      stick - The joystick to read.
      button - The button index, beginning at 0.
      Returns:
      Whether the joystick button was released since the last check.
    • getStickAxis

      public static double getStickAxis(int stick, int axis)
      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.
    • getStickTouchpadFinger

      public static DriverStation.TouchpadFinger getStickTouchpadFinger(int stick, int touchpad, int finger)
      Get the state of a touchpad finger on the joystick.
      Parameters:
      stick - The joystick to read.
      touchpad - The touchpad to read.
      finger - The finger to read.
      Returns:
      the state of the touchpad finger.
    • getStickTouchpadFingerAvailable

      public static boolean getStickTouchpadFingerAvailable(int stick, int touchpad, int finger)
      Get whether a touchpad finger on the joystick is available.
      Parameters:
      stick - The joystick to read.
      touchpad - The touchpad to read.
      finger - The finger to read.
      Returns:
      whether the touchpad finger is available.
    • getStickAxisIfAvailable

      public static OptionalDouble getStickAxisIfAvailable(int stick, int axis)
      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 0 if the axis is not available.
    • getStickPOV

      public static DriverStation.POVDirection getStickPOV(int stick, int pov)
      Get the state of a POV on the joystick.
      Parameters:
      stick - The joystick to read.
      pov - The POV to read.
      Returns:
      the angle of the POV.
    • getStickButtons

      public static long getStickButtons(int stick)
      The state of the buttons on the joystick.
      Parameters:
      stick - The joystick to read.
      Returns:
      The state of the buttons on the joystick.
    • getStickAxesMaximumIndex

      public static int getStickAxesMaximumIndex(int stick)
      Gets the maximum index of axes on a given joystick port.
      Parameters:
      stick - The joystick port number
      Returns:
      The maximum index of axes on the indicated joystick
    • getStickAxesAvailable

      public static int getStickAxesAvailable(int stick)
      Returns the available bitmask of axes on a given joystick port.
      Parameters:
      stick - The joystick port number
      Returns:
      The number of axes available on the indicated joystick
    • getStickPOVsMaximumIndex

      public static int getStickPOVsMaximumIndex(int stick)
      Gets the maximum index of povs on a given joystick port.
      Parameters:
      stick - The joystick port number
      Returns:
      The maximum index of povs on the indicated joystick
    • getStickPOVsAvailable

      public static int getStickPOVsAvailable(int stick)
      Returns the available bitmask of povs on a given joystick port.
      Parameters:
      stick - The joystick port number
      Returns:
      The number of povs available on the indicated joystick
    • getStickButtonsMaximumIndex

      public static int getStickButtonsMaximumIndex(int stick)
      Gets the maximum index of buttons on a given joystick port.
      Parameters:
      stick - The joystick port number
      Returns:
      The maximum index of buttons on the indicated joystick
    • getStickButtonsAvailable

      public static long getStickButtonsAvailable(int stick)
      Gets the bitmask of buttons available.
      Parameters:
      stick - The joystick port number
      Returns:
      The buttons available on the indicated joystick
    • getJoystickIsGamepad

      public static boolean getJoystickIsGamepad(int stick)
      Gets the value of isGamepad on a joystick.
      Parameters:
      stick - The joystick port number
      Returns:
      A boolean that returns the value of isGamepad
    • getJoystickGamepadType

      public static int getJoystickGamepadType(int stick)
      Gets the value of type on a gamepad.
      Parameters:
      stick - The joystick port number
      Returns:
      The value of type
    • getJoystickSupportedOutputs

      public static int getJoystickSupportedOutputs(int stick)
      Gets the value of supported outputs on a joystick.
      Parameters:
      stick - The joystick port number
      Returns:
      The value of supported outputs
    • getJoystickName

      public static String getJoystickName(int stick)
      Gets the name of the joystick at a port.
      Parameters:
      stick - The joystick port number
      Returns:
      The value of name
    • isJoystickConnected

      public static boolean isJoystickConnected(int stick)
      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
    • 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.
    • isTest

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

      public static boolean isTestEnabled()
      Gets a value indicating whether the Driver Station requires the robot to be running in Test mode and enabled.
      Returns:
      True if test 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
    • getGameData

      public static Optional<String> getGameData()
      Get the game specific message from the FMS.

      If the FMS is not connected, it is set from the game data setting on the driver station.

      Returns:
      the game specific message
    • getEventName

      public static String getEventName()
      Get the event name from the FMS.
      Returns:
      the event name
    • getMatchType

      Get the match type from the FMS.
      Returns:
      the match type
    • getMatchNumber

      public static int getMatchNumber()
      Get the match number from the FMS.
      Returns:
      the match number
    • getReplayNumber

      public static int getReplayNumber()
      Get the replay number from the FMS.
      Returns:
      the replay number
    • getAlliance

      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
    • getLocation

      public static OptionalInt getLocation()
      Gets the location of the team's driver station controls from the FMS.

      If the FMS is not connected, it is set from the team alliance setting on the driver station.

      Returns:
      the location of the team's driver station controls: 1, 2, or 3
    • getRawAllianceStation

      Gets the raw alliance station of the teams driver station.

      This returns the raw low level value. Prefer getLocation or getAlliance unless necessary for performance.

      Returns:
      The raw alliance station id.
    • getMatchTime

      public static double getMatchTime()
      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
    • silenceJoystickConnectionWarning

      public static void silenceJoystickConnectionWarning(boolean silence)
      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.
    • isJoystickConnectionWarningSilenced

      public static boolean isJoystickConnectionWarningSilenced()
      Returns whether joystick connection warnings are silenced. This will always return false when connected to the FMS.
      Returns:
      Whether joystick connection warnings are silenced.
    • refreshControlWordFromCache

      public static void refreshControlWordFromCache(ControlWord word)
      Refresh the passed in control word to contain the current control word cache.
      Parameters:
      word - Word to refresh.
    • refreshData

      public static void refreshData()
      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.
    • provideRefreshedDataEventHandle

      public static void provideRefreshedDataEventHandle(int handle)
      Registers the given handle for DS data refresh notifications.
      Parameters:
      handle - The event handle.
    • removeRefreshedDataEventHandle

      public static void removeRefreshedDataEventHandle(int handle)
      Unregisters the given handle from DS data refresh notifications.
      Parameters:
      handle - The event handle.
    • startDataLog

      public static void startDataLog(DataLog log, boolean logJoysticks)
      Starts logging DriverStation data to data log. Repeated calls are ignored.
      Parameters:
      log - data log
      logJoysticks - if true, log joystick data
    • startDataLog

      public static void startDataLog(DataLog log)
      Starts logging DriverStation data to data log, including joystick data. Repeated calls are ignored.
      Parameters:
      log - data log