Package edu.wpi.first.wpilibj
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 classDriverStation.AllianceThe robot alliance that the robot is a part of.static classDriverStation.MatchType -
Field Summary
Fields Modifier and Type Field Description static intkJoystickPortsNumber of Joystick Ports. -
Method Summary
Modifier and Type Method Description static DriverStation.AlliancegetAlliance()Get the current alliance from the FMS.protected static voidgetData()Copy data from the DS task for the user.static StringgetEventName()Get the event name.static StringgetGameSpecificMessage()Get the game specific message.static DriverStationgetInstance()Deprecated.Use the static methodsstatic intgetJoystickAxisType(int stick, int axis)Returns the types of Axes on a given joystick port.static booleangetJoystickIsXbox(int stick)Gets the value of isXbox on a joystick.static StringgetJoystickName(int stick)Gets the name of the joystick at a port.static intgetJoystickType(int stick)Gets the value of type on a joystick.static intgetLocation()Gets the location of the team's driver station controls.static intgetMatchNumber()Get the match number.static doublegetMatchTime()Return the approximate match time.static DriverStation.MatchTypegetMatchType()Get the match type.static intgetReplayNumber()Get the replay number.static doublegetStickAxis(int stick, int axis)Get the value of the axis on a joystick.static intgetStickAxisCount(int stick)Returns the number of axes on a given joystick port.static booleangetStickButton(int stick, int button)The state of one joystick button.static intgetStickButtonCount(int stick)Gets the number of buttons on a joystick.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 intgetStickButtons(int stick)The state of the buttons on the joystick.static intgetStickPOV(int stick, int pov)Get the state of a POV on the joystick.static intgetStickPOVCount(int stick)Returns the number of POVs on a given joystick port.static voidinAutonomous(boolean entering)Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.static voidinDisabled(boolean entering)Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.static voidinOperatorControl(boolean entering)Deprecated, for removal: This API element is subject to removal in a future version.UseinTeleop(boolean)instead.static voidinTeleop(boolean entering)Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.static voidinTest(boolean entering)Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.static booleanisAutonomous()Gets a value indicating whether the Driver Station requires the robot to be running in autonomous mode.static booleanisAutonomousEnabled()Gets a value indicating whether the Driver Station requires the robot to be running in autonomous mode and enabled.static booleanisDisabled()Gets a value indicating whether the Driver Station requires the robot to be disabled.static booleanisDSAttached()Gets a value indicating whether the Driver Station is attached.static booleanisEnabled()Gets a value indicating whether the Driver Station requires the robot to be enabled.static booleanisEStopped()Gets a value indicating whether the Robot is e-stopped.static booleanisFMSAttached()Gets 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 booleanisJoystickConnectionWarningSilenced()Returns whether joystick connection warnings are silenced.static booleanisNewControlData()Gets if a new control packet from the driver station arrived since the last time this function was called.static booleanisOperatorControl()Deprecated, for removal: This API element is subject to removal in a future version.Use isTeleop() instead.static booleanisOperatorControlEnabled()Deprecated, for removal: This API element is subject to removal in a future version.Use isTeleopEnabled() instead.static booleanisTeleop()Gets a value indicating whether the Driver Station requires the robot to be running in operator-controlled mode.static booleanisTeleopEnabled()Gets 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 voidrelease()Kill the thread.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 voidupdateControlWordFromCache(ControlWord word)Forces a control word cache update, and update the passed in control word.static voidwaitForData()Wait for new data from the driver station.static booleanwaitForData(double timeoutSeconds)Wait for new data or for timeout, which ever comes first.static voidwakeupWaitForData()Forces waitForData() to return immediately.
-
Field Details
-
kJoystickPorts
Number of Joystick Ports.- See Also:
- Constant Field Values
-
-
Method Details
-
getInstance
Deprecated.Use the static methodsGets an instance of the DriverStation.- Returns:
- The DriverStation.
-
release
Kill the thread. -
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. 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
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
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
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
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
The state of the buttons on the joystick.- Parameters:
stick- The joystick to read.- Returns:
- The state of the buttons on the joystick.
-
getStickAxisCount
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
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
Gets the number of buttons on a joystick.- Parameters:
stick- The joystick port number- Returns:
- The number of buttons on the indicated joystick
-
getJoystickIsXbox
Gets the value of isXbox on a joystick.- Parameters:
stick- The joystick port number- Returns:
- A boolean that returns the value of isXbox
-
getJoystickType
Gets the value of type on a joystick.- Parameters:
stick- The joystick port number- Returns:
- The value of type
-
getJoystickName
Gets the name of the joystick at a port.- Parameters:
stick- The joystick port number- Returns:
- The value of name
-
getJoystickAxisType
Returns the types of Axes on a given joystick port.- Parameters:
stick- The joystick port numberaxis- The target axis- Returns:
- What type of axis the axis is reporting to be
-
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.
-
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.
-
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
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, 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
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.
-
isDSAttached
Gets a value indicating whether the Driver Station is attached.- Returns:
- True if Driver Station is attached, false otherwise.
-
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
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
Get the game specific message.- Returns:
- the game specific message
-
getEventName
Get the event name.- Returns:
- the event name
-
getMatchType
Get the match type.- Returns:
- the match type
-
getMatchNumber
Get the match number.- Returns:
- the match number
-
getReplayNumber
Get the replay number.- Returns:
- the replay number
-
getAlliance
Get the current alliance from the FMS.- Returns:
- the current alliance
-
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
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
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
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
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
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, for removal: This API element is subject to removal in a future version.UseinTeleop(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
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
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
Forces waitForData() to return immediately. -
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.
-
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
Forces a control word cache update, and update the passed in control word.- Parameters:
word- Word to update.
-