Class DriverStation
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe robot alliance that the robot is a part of.static enumThe type of robot match that the robot is part of.static enumA controller POV direction.static classRepresents a finger on a touchpad. -
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.static Optional<DriverStation.Alliance> 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 DriverStation.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 DriverStation.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 DriverStation.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 warnings 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 booleanisTest()Gets a value indicating whether the Driver Station requires the robot to be running in Test mode.static booleanGets a value indicating whether the Driver Station requires the robot to be running in Test mode and enabled.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 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 voidsilenceJoystickConnectionWarning(boolean silence) Allows the user to specify whether they want joystick connection warnings to be printed to the console.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
-
kJoystickPorts
-
-
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
-
getStickButton
The state of one joystick button.- Parameters:
stick- The joystick to read.button- The button index.- Returns:
- The state of the joystick button.
-
getStickButtonIfAvailable
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
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
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
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
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
The state of the buttons on the joystick.- Parameters:
stick- The joystick to read.- Returns:
- The state of the buttons on the joystick.
-
getStickAxesMaximumIndex
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
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
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
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
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
Gets the bitmask of buttons available.- Parameters:
stick- The joystick port number- Returns:
- The buttons available on the indicated joystick
-
getJoystickIsGamepad
Gets the value of isGamepad on a joystick.- Parameters:
stick- The joystick port number- Returns:
- A boolean that returns the value of isGamepad
-
getJoystickGamepadType
Gets the value of type on a gamepad.- Parameters:
stick- The joystick port number- Returns:
- The value of type
-
getJoystickSupportedOutputs
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
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
Gets a value indicating whether the Driver Station requires the robot to be enabled.- Returns:
- True if the robot is enabled, false otherwise.
-
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
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
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
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
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
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
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
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 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
Publishes the operating mode options to the driver station. -
clearOpModes
Clears all operating mode options and publishes an empty list to the driver station. -
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
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
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
-
isDSAttached
Gets a value indicating whether the Driver Station is attached.- Returns:
- True if Driver Station is attached, false otherwise.
-
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
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
-
getMatchType
Get the match type from the FMS.- Returns:
- the match type
-
getMatchNumber
-
getReplayNumber
-
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
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
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
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
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
Refresh the passed in control word to contain the current control word cache.- Parameters:
word- Word to refresh.
-
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
Registers the given handle for DS data refresh notifications.- Parameters:
handle- The event handle.
-
removeRefreshedDataEventHandle
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
-