Package edu.wpi.first.wpilibj
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 boolean
isTestEnabled()
Gets a value indicating whether the Driver Station requires the robot to be running in Test mode and enabled.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.static boolean
waitForDsConnection(double timeoutSeconds)
Wait for a DS connection.
-
Field Details
-
kJoystickPorts
Number of Joystick Ports.- See Also:
- Constant Field Values
-
-
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. 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.
-
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.
-
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
-
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
Get the event name from the FMS.- Returns:
- the event name
-
getMatchType
Get the match type from the FMS.- Returns:
- the match type
-
getMatchNumber
Get the match number from the FMS.- Returns:
- the match number
-
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
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
-
waitForDsConnection
Wait for a DS connection.- Parameters:
timeoutSeconds
- timeout in seconds. 0 for infinite.- Returns:
- true if connected, false if timeout
-
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
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
-
removeRefreshedDataEventHandle
-
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
-