Class DriverStation

java.lang.Object
edu.wpi.first.wpilibj.DriverStation

public class DriverStation
extends Object
Provide access to the network communication data to / from the Driver Station.
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  DriverStation.Alliance
    The robot alliance that the robot is a part of.
    static class  DriverStation.MatchType  
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int kJoystickPorts
    Number of Joystick Ports.
  • Method Summary

    Modifier and Type Method Description
    static DriverStation.Alliance getAlliance()
    Get the current alliance from the FMS.
    protected static void getData()
    Copy data from the DS task for the user.
    static String getEventName()
    Get the event name.
    static String getGameSpecificMessage()
    Get the game specific message.
    static DriverStation getInstance()
    Deprecated.
    Use the static methods
    static int getJoystickAxisType​(int stick, int axis)
    Returns the types of Axes on a given joystick port.
    static boolean getJoystickIsXbox​(int stick)
    Gets the value of isXbox on a joystick.
    static String getJoystickName​(int stick)
    Gets the name of the joystick at a port.
    static int getJoystickType​(int stick)
    Gets the value of type on a joystick.
    static int getLocation()
    Gets the location of the team's driver station controls.
    static int getMatchNumber()
    Get the match number.
    static double getMatchTime()
    Return the approximate match time.
    static DriverStation.MatchType getMatchType()
    Get the match type.
    static int getReplayNumber()
    Get the replay number.
    static double getStickAxis​(int stick, int axis)
    Get the value of the axis on a joystick.
    static int getStickAxisCount​(int stick)
    Returns the number of axes on a given joystick port.
    static boolean getStickButton​(int stick, int button)
    The state of one joystick button.
    static int getStickButtonCount​(int stick)
    Gets the number of buttons on a joystick.
    static boolean getStickButtonPressed​(int stick, int button)
    Whether one joystick button was pressed since the last check.
    static boolean getStickButtonReleased​(int stick, int button)
    Whether one joystick button was released since the last check.
    static int getStickButtons​(int stick)
    The state of the buttons on the joystick.
    static int getStickPOV​(int stick, int pov)
    Get the state of a POV on the joystick.
    static int getStickPOVCount​(int stick)
    Returns the number of POVs on a given joystick port.
    static void inAutonomous​(boolean entering)
    Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.
    static void inDisabled​(boolean entering)
    Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.
    static void inOperatorControl​(boolean entering)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use inTeleop(boolean) instead.
    static void inTeleop​(boolean entering)
    Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.
    static void inTest​(boolean entering)
    Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.
    static boolean isAutonomous()
    Gets a value indicating whether the Driver Station requires the robot to be running in autonomous mode.
    static boolean isAutonomousEnabled()
    Gets a value indicating whether the Driver Station requires the robot to be running in autonomous mode and enabled.
    static boolean isDisabled()
    Gets a value indicating whether the Driver Station requires the robot to be disabled.
    static boolean isDSAttached()
    Gets a value indicating whether the Driver Station is attached.
    static boolean isEnabled()
    Gets a value indicating whether the Driver Station requires the robot to be enabled.
    static boolean isEStopped()
    Gets a value indicating whether the Robot is e-stopped.
    static boolean isFMSAttached()
    Gets if the driver station attached to a Field Management System.
    static boolean isJoystickConnected​(int stick)
    Returns if a joystick is connected to the Driver Station.
    static boolean isJoystickConnectionWarningSilenced()
    Returns whether joystick connection warnings are silenced.
    static boolean isNewControlData()
    Gets if a new control packet from the driver station arrived since the last time this function was called.
    static boolean isOperatorControl()
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use isTeleop() instead.
    static boolean isOperatorControlEnabled()
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use isTeleopEnabled() instead.
    static boolean isTeleop()
    Gets a value indicating whether the Driver Station requires the robot to be running in operator-controlled mode.
    static boolean isTeleopEnabled()
    Gets a value indicating whether the Driver Station requires the robot to be running in operator-controller mode and enabled.
    static boolean isTest()
    Gets a value indicating whether the Driver Station requires the robot to be running in test mode.
    static void release()
    Kill the thread.
    static void reportError​(String error, boolean printTrace)
    Report error to Driver Station.
    static void reportError​(String error, StackTraceElement[] stackTrace)
    Report error to Driver Station.
    static void reportWarning​(String warning, boolean printTrace)
    Report warning to Driver Station.
    static void reportWarning​(String warning, StackTraceElement[] stackTrace)
    Report warning to Driver Station.
    static void silenceJoystickConnectionWarning​(boolean silence)
    Allows the user to specify whether they want joystick connection warnings to be printed to the console.
    static void updateControlWordFromCache​(ControlWord word)
    Forces a control word cache update, and update the passed in control word.
    static void waitForData()
    Wait for new data from the driver station.
    static boolean waitForData​(double timeoutSeconds)
    Wait for new data or for timeout, which ever comes first.
    static void wakeupWaitForData()
    Forces waitForData() to return immediately.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • getInstance

      Deprecated.
      Use the static methods
      Gets an instance of the DriverStation.
      Returns:
      The DriverStation.
    • release

      public static void release()
      Kill the thread.
    • 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. Button indexes begin at 1.
      Parameters:
      stick - The joystick to read.
      button - The button index, beginning at 1.
      Returns:
      The state of the joystick button.
    • getStickButtonPressed

      public static boolean getStickButtonPressed​(int stick, int button)
      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 1.
      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. Button indexes begin at 1.
      Parameters:
      stick - The joystick to read.
      button - The button index, beginning at 1.
      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.
    • getStickPOV

      public static int 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 in degrees, or -1 if the POV is not pressed.
    • getStickButtons

      public static int 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.
    • getStickAxisCount

      public static int getStickAxisCount​(int stick)
      Returns the number of axes on a given joystick port.
      Parameters:
      stick - The joystick port number
      Returns:
      The number of axes on the indicated joystick
    • getStickPOVCount

      public static int getStickPOVCount​(int stick)
      Returns the number of POVs on a given joystick port.
      Parameters:
      stick - The joystick port number
      Returns:
      The number of POVs on the indicated joystick
    • getStickButtonCount

      public static int getStickButtonCount​(int stick)
      Gets the number of buttons on a joystick.
      Parameters:
      stick - The joystick port number
      Returns:
      The number of buttons on the indicated joystick
    • getJoystickIsXbox

      public static boolean getJoystickIsXbox​(int stick)
      Gets the value of isXbox on a joystick.
      Parameters:
      stick - The joystick port number
      Returns:
      A boolean that returns the value of isXbox
    • getJoystickType

      public static int getJoystickType​(int stick)
      Gets the value of type on a joystick.
      Parameters:
      stick - The joystick port number
      Returns:
      The value of type
    • 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
    • getJoystickAxisType

      public static int getJoystickAxisType​(int stick, int axis)
      Returns the types of Axes on a given joystick port.
      Parameters:
      stick - The joystick port number
      axis - The target axis
      Returns:
      What type of axis the axis is reporting to be
    • 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.
    • 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.
    • isOperatorControl

      @Deprecated(since="2022", forRemoval=true) public static boolean isOperatorControl()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use isTeleop() instead.
      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.
    • 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.
    • isOperatorControlEnabled

      @Deprecated(since="2022", forRemoval=true) public static boolean isOperatorControlEnabled()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use isTeleopEnabled() instead.
      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.
    • 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.
    • isDSAttached

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

      public static boolean isNewControlData()
      Gets if a new control packet from the driver station arrived since the last time this function was called.
      Returns:
      True if the control data has been updated since the last call.
    • 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
    • getGameSpecificMessage

      public static String getGameSpecificMessage()
      Get the game specific message.
      Returns:
      the game specific message
    • getEventName

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

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

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

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

      Get the current alliance from the FMS.
      Returns:
      the current alliance
    • getLocation

      public static int getLocation()
      Gets the location of the team's driver station controls.
      Returns:
      the location of the team's driver station controls: 1, 2, or 3
    • waitForData

      public static void waitForData()
      Wait for new data from the driver station.

      Checks if new control data has arrived since the last waitForData call on the current thread. If new data has not arrived, returns immediately.

    • waitForData

      public static boolean waitForData​(double timeoutSeconds)
      Wait for new data or for timeout, which ever comes first. If timeout is 0, wait for new data only.

      Checks if new control data has arrived since the last waitForData call on the current thread. If new data has not arrived, returns immediately.

      Parameters:
      timeoutSeconds - The maximum time in seconds to wait.
      Returns:
      true if there is new data, otherwise false
    • 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) The Practice Match function of the DS approximates the behavior seen on the field.
      Returns:
      Time remaining in current match period (auto or teleop) in seconds
    • inDisabled

      public static void inDisabled​(boolean entering)
      Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.
      Parameters:
      entering - If true, starting disabled code; if false, leaving disabled code
    • inAutonomous

      public static void inAutonomous​(boolean entering)
      Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.
      Parameters:
      entering - If true, starting autonomous code; if false, leaving autonomous code
    • inOperatorControl

      @Deprecated(since="2022", forRemoval=true) public static void inOperatorControl​(boolean entering)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use inTeleop(boolean) instead.
      Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.
      Parameters:
      entering - If true, starting teleop code; if false, leaving teleop code
    • inTeleop

      public static void inTeleop​(boolean entering)
      Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.
      Parameters:
      entering - If true, starting teleop code; if false, leaving teleop code
    • inTest

      public static void inTest​(boolean entering)
      Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.
      Parameters:
      entering - If true, starting test code; if false, leaving test code
    • wakeupWaitForData

      public static void wakeupWaitForData()
      Forces waitForData() to return immediately.
    • 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.
    • getData

      protected static void getData()
      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.
    • updateControlWordFromCache

      public static void updateControlWordFromCache​(ControlWord word)
      Forces a control word cache update, and update the passed in control word.
      Parameters:
      word - Word to update.