Class DriverStationBackend
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic longAdds an operating mode option.static longAdds an operating mode option.static longAdds an operating mode option.static longaddOpMode(RobotMode mode, String name, String group, String description, Color textColor, Color backgroundColor) Adds an operating mode option.static voidClears all operating mode options and publishes an empty list to the driver station.Get the current alliance from the FMS.static StringGet the event name from the FMS.Get the game specific message from the FMS.static intgetJoystickGamepadType(int stick) Gets the value of type on a gamepad.static booleangetJoystickIsGamepad(int stick) Gets the value of isGamepad on a joystick.static StringgetJoystickName(int stick) Gets the name of the joystick at a port.static intgetJoystickSupportedOutputs(int stick) Gets the value of supported outputs on a joystick.static OptionalIntGets the location of the team's driver station controls from the FMS.static intGet the match number from the FMS.static doubleReturn the approximate match time.static MatchTypeGet the match type from the FMS.static StringGets the operating mode selected on the driver station.static longGets the operating mode selected on the driver station.static AllianceStationIDGets the raw alliance station of the teams driver station.static intGet the replay number from the FMS.static RobotModeGets the current robot mode.static intgetStickAxesAvailable(int stick) Returns the available bitmask of axes on a given joystick port.static intgetStickAxesMaximumIndex(int stick) Gets the maximum index of axes on a given joystick port.static doublegetStickAxis(int stick, int axis) Get the value of the axis on a joystick.static OptionalDoublegetStickAxisIfAvailable(int stick, int axis) Get the value of the axis on a joystick if available.static booleangetStickButton(int stick, int button) The state of one joystick button.getStickButtonIfAvailable(int stick, int button) The state of one joystick button if available.static booleangetStickButtonPressed(int stick, int button) Whether one joystick button was pressed since the last check.static booleangetStickButtonReleased(int stick, int button) Whether one joystick button was released since the last check.static longgetStickButtons(int stick) The state of the buttons on the joystick.static longgetStickButtonsAvailable(int stick) Gets the bitmask of buttons available.static intgetStickButtonsMaximumIndex(int stick) Gets the maximum index of buttons on a given joystick port.static POVDirectiongetStickPOV(int stick, int pov) Get the state of a POV on the joystick.static intgetStickPOVsAvailable(int stick) Returns the available bitmask of povs on a given joystick port.static intgetStickPOVsMaximumIndex(int stick) Gets the maximum index of povs on a given joystick port.static TouchpadFingergetStickTouchpadFinger(int stick, int touchpad, int finger) Get the state of a touchpad finger on the joystick.static booleangetStickTouchpadFingerAvailable(int stick, int touchpad, int finger) Get whether a touchpad finger on the joystick is available.static booleanGets a value indicating whether the Driver Station requires the robot to be running in autonomous mode.static booleanGets a value indicating whether the Driver Station requires the robot to be running in autonomous mode and enabled.static booleanGets a value indicating whether the Driver Station requires the robot to be disabled.static booleanGets a value indicating whether the Driver Station is attached.static booleanGets a value indicating whether the Driver Station requires the robot to be enabled.static booleanGets a value indicating whether the Robot is e-stopped.static booleanGets if the driver station attached to a Field Management System.static booleanisJoystickConnected(int stick) Returns if a joystick is connected to the Driver Station.static booleanReturns whether joystick connection alerts are silenced.static booleanisOpMode(long id) Check to see if the selected operating mode is a particular value.static booleanCheck to see if the selected operating mode is a particular value.static booleanisTeleop()Gets a value indicating whether the Driver Station requires the robot to be running in operator-controlled mode.static booleanGets a value indicating whether the Driver Station requires the robot to be running in operator-controller mode and enabled.static booleanGets a value indicating whether the Driver Station requires the robot to be running in Utility mode.static booleanGets a value indicating whether the Driver Station requires the robot to be running in Utility mode and enabled.static voidSets the program starting flag in the DS.static voidprovideRefreshedDataEventHandle(int handle) Registers the given handle for DS data refresh notifications.static voidPublishes the operating mode options to the driver station.static voidRefresh the passed in control word to contain the current control word cache.static voidCopy data from the DS task for the user.static longremoveOpMode(RobotMode mode, String name) Removes an operating mode option.static voidremoveRefreshedDataEventHandle(int handle) Unregisters the given handle from DS data refresh notifications.static voidreportCrash(String error, StackTraceElement[] stackTrace) Report crash to Driver Station.static voidreportError(String error, boolean printTrace) Report error to Driver Station.static voidreportError(String error, StackTraceElement[] stackTrace) Report error to Driver Station.static voidreportWarning(String warning, boolean printTrace) Report warning to Driver Station.static voidreportWarning(String warning, StackTraceElement[] stackTrace) Report warning to Driver Station.static voidsilenceJoystickConnectionAlert(boolean silence) Allows the user to specify whether they want joystick connection alerts to be shown.static voidstartDataLog(DataLog log) Starts logging DriverStation data to data log, including joystick data.static voidstartDataLog(DataLog log, boolean logJoysticks) Starts logging DriverStation data to data log.
-
Field Details
-
JOYSTICK_PORTS
public static final int JOYSTICK_PORTSNumber of Joystick ports.- See Also:
-
-
Method Details
-
reportError
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
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
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
Report warning to Driver Station. Appends provided stack trace to warning message.- Parameters:
warning- The warning to report.stackTrace- The stack trace to append
-
reportCrash
Report crash to Driver Station. Appends provided stack trace to crash message.- Parameters:
error- The error messagestackTrace- 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
-
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
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
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
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
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
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 modename- name of the operating modegroup- group of the operating modedescription- description of the operating modetextColor- text color, or null for defaultbackgroundColor- 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
Adds an operating mode option. It's necessary to call publishOpModes() to make the added modes visible to the driver station.- Parameters:
mode- robot modename- name of the operating modegroup- group of the operating modedescription- 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
Adds an operating mode option. It's necessary to call publishOpModes() to make the added modes visible to the driver station.- Parameters:
mode- robot modename- name of the operating modegroup- 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
Adds an operating mode option. It's necessary to call publishOpModes() to make the added modes visible to the driver station.- Parameters:
mode- robot modename- 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
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 modename- 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. -
observeUserProgramStarting
public static void observeUserProgramStarting()Sets the program starting flag in the DS. This will also allowgetOpModeId()andgetOpMode()to return values for the selected OpMode in the DS application, if the DS is connected by the time this method is called.Most users will not need to use this method; the
TimedRobotandOpModeRobotrobot framework classes will call it automatically after the main robot class is instantiated. However, teams using the commandsv3 library and a custom main robot class need to be careful to only call this method after all mechanisms and global trigger bindings are set up. If not, any setup performed in the main robot class may be incorrectly bound to the opmode selected in the DS if it's connected by the time the robot program boots up.This is what changes the DS to showing robot code ready.
- See Also:
-
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.This method always returns
0while the main robot class is being constructed and initialized (more specifically, it returns0untilobserveUserProgramStarting()is called, which the WPILib framework will automatically call duringTimedRobot.startCompetition()andOpModeRobot.startCompetition()).- 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
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.This method always returns an empty string
""while the main robot class is being constructed and initialized (more specifically, it returns""untilobserveUserProgramStarting()is called, which the WPILib framework will automatically call duringTimedRobot.startCompetition()andOpModeRobot.startCompetition()).- 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
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
-
getEventName
-
getMatchType
-
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
-
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
-
silenceJoystickConnectionAlert
public static void silenceJoystickConnectionAlert(boolean silence) Allows the user to specify whether they want joystick connection alerts to be shown. This setting is ignored when the FMS is connected -- alerts will always be on in that scenario.- Parameters:
silence- Whether joystick connection alerts should be silenced.
-
isJoystickConnectionAlertSilenced
public static boolean isJoystickConnectionAlertSilenced()Returns whether joystick connection alerts are silenced. This will always return false when connected to the FMS.- Returns:
- Whether joystick connection alerts are silenced.
-
refreshControlWordFromCache
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
Starts logging DriverStation data to data log. Repeated calls are ignored.- Parameters:
log- data loglogJoysticks- if true, log joystick data
-
startDataLog
Starts logging DriverStation data to data log, including joystick data. Repeated calls are ignored.- Parameters:
log- data log
-