Class DriverStation

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

public final 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.
    static String getEventName()
    Get the event name from the FMS.
    static String getGameSpecificMessage()
    Get the game specific message from the FMS.
    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 from the FMS.
    static int getMatchNumber()
    Get the match number from the FMS.
    static double getMatchTime()
    Return the approximate match time.
    static DriverStation.MatchType getMatchType()
    Get the match type from the FMS.
    static int getReplayNumber()
    Get the replay number from the FMS.
    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 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 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 provideRefreshedDataEventHandle​(int handle)  
    static void refreshControlWordFromCache​(ControlWord word)
    Refresh the passed in control word to contain the current control word cache.
    static void refreshData()
    Copy data from the DS task for the user.
    static void removeRefreshedDataEventHandle​(int handle)  
    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 startDataLog​(DataLog log)
    Starts logging DriverStation data to data log, including joystick data.
    static void startDataLog​(DataLog log, boolean logJoysticks)
    Starts logging DriverStation data to data log.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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. 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.
    • 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.
    • 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
    • getGameSpecificMessage

      public static String getGameSpecificMessage()
      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 current alliance
    • getLocation

      public static int 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
    • 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
    • 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)
    • removeRefreshedDataEventHandle

      public static void removeRefreshedDataEventHandle​(int 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