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 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 methodsstatic 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.UseinTeleop(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.
-
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.
-