Package edu.wpi.first.wpilibj
Class Joystick
java.lang.Object
edu.wpi.first.wpilibj.GenericHID
edu.wpi.first.wpilibj.Joystick
Handle input from Flight Joysticks connected to the Driver Station.
This class handles standard input that comes from the Driver Station. Each time a value is requested the most recent value is returned. There is a single class instance for each joystick and the mapping of ports to hardware buttons depends on the code in the Driver Station.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents an analog axis on a joystick.static enumRepresents a digital button on a joystick.Nested classes/interfaces inherited from class edu.wpi.first.wpilibj.GenericHID
GenericHID.HIDType, GenericHID.RumbleType -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byteDefault throttle axis channel.static final byteDefault twist axis channel.static final byteDefault X axis channel.static final byteDefault Y axis channel.static final byteDefault Z axis channel. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleGet the direction of the vector formed by the joystick and its origin in degrees.doubleGet the direction of the vector formed by the joystick and its origin in radians.doubleGet the magnitude of the vector formed by the joystick's current position relative to its origin.final doubleGet the throttle value of the current joystick.intGet the channel currently associated with the throttle axis.booleangetTop()Read the state of the top button on the joystick.booleanWhether the top button was pressed since the last check.booleanWhether the top button was released since the last check.booleanRead the state of the trigger on the joystick.booleanWhether the trigger was pressed since the last check.booleanWhether the trigger was released since the last check.final doublegetTwist()Get the twist value of the current joystick.intGet the channel currently associated with the twist axis.final doublegetX()Get the X value of the joystick.intGet the channel currently associated with the X axis.final doublegetY()Get the Y value of the joystick.intGet the channel currently associated with the Y axis.final doublegetZ()Get the z position of the HID.intGet the channel currently associated with the Z axis.voidsetThrottleChannel(int channel) Set the channel associated with the throttle axis.voidsetTwistChannel(int channel) Set the channel associated with the twist axis.voidsetXChannel(int channel) Set the channel associated with the X axis.voidsetYChannel(int channel) Set the channel associated with the Y axis.voidsetZChannel(int channel) Set the channel associated with the Z axis.Constructs an event instance around the top button's digital signal.Constructs an event instance around the trigger button's digital signal.Methods inherited from class edu.wpi.first.wpilibj.GenericHID
axisGreaterThan, axisLessThan, button, getAxisCount, getAxisType, getButtonCount, getName, getPort, getPOV, getPOV, getPOVCount, getRawAxis, getRawButton, getRawButtonPressed, getRawButtonReleased, getType, isConnected, pov, pov, povCenter, povDown, povDownLeft, povDownRight, povLeft, povRight, povUp, povUpLeft, povUpRight, setOutput, setOutputs, setRumble
-
Field Details
-
kDefaultXChannel
Default X axis channel.- See Also:
-
kDefaultYChannel
Default Y axis channel.- See Also:
-
kDefaultZChannel
Default Z axis channel.- See Also:
-
kDefaultTwistChannel
Default twist axis channel.- See Also:
-
kDefaultThrottleChannel
Default throttle axis channel.- See Also:
-
-
Constructor Details
-
Joystick
Construct an instance of a joystick.- Parameters:
port- The port index on the Driver Station that the joystick is plugged into.
-
-
Method Details
-
setXChannel
Set the channel associated with the X axis.- Parameters:
channel- The channel to set the axis to.
-
setYChannel
Set the channel associated with the Y axis.- Parameters:
channel- The channel to set the axis to.
-
setZChannel
Set the channel associated with the Z axis.- Parameters:
channel- The channel to set the axis to.
-
setThrottleChannel
Set the channel associated with the throttle axis.- Parameters:
channel- The channel to set the axis to.
-
setTwistChannel
Set the channel associated with the twist axis.- Parameters:
channel- The channel to set the axis to.
-
getXChannel
Get the channel currently associated with the X axis.- Returns:
- The channel for the axis.
-
getYChannel
Get the channel currently associated with the Y axis.- Returns:
- The channel for the axis.
-
getZChannel
Get the channel currently associated with the Z axis.- Returns:
- The channel for the axis.
-
getTwistChannel
Get the channel currently associated with the twist axis.- Returns:
- The channel for the axis.
-
getThrottleChannel
Get the channel currently associated with the throttle axis.- Returns:
- The channel for the axis.
-
getX
Get the X value of the joystick. This depends on the mapping of the joystick connected to the current port. On most joysticks, positive is to the right.- Returns:
- The X value of the joystick.
-
getY
Get the Y value of the joystick. This depends on the mapping of the joystick connected to the current port. On most joysticks, positive is to the back.- Returns:
- The Y value of the joystick.
-
getZ
Get the z position of the HID.- Returns:
- the z position
-
getTwist
Get the twist value of the current joystick. This depends on the mapping of the joystick connected to the current port.- Returns:
- The Twist value of the joystick.
-
getThrottle
Get the throttle value of the current joystick. This depends on the mapping of the joystick connected to the current port.- Returns:
- The Throttle value of the joystick.
-
getTrigger
Read the state of the trigger on the joystick.- Returns:
- The state of the trigger.
-
getTriggerPressed
Whether the trigger was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getTriggerReleased
Whether the trigger was released since the last check.- Returns:
- Whether the button was released since the last check.
-
trigger
Constructs an event instance around the trigger button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the trigger button's digital signal attached to the given loop.
-
getTop
Read the state of the top button on the joystick.- Returns:
- The state of the top button.
-
getTopPressed
Whether the top button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getTopReleased
Whether the top button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
top
Constructs an event instance around the top button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the top button's digital signal attached to the given loop.
-
getMagnitude
Get the magnitude of the vector formed by the joystick's current position relative to its origin.- Returns:
- The magnitude of the direction vector
-
getDirectionRadians
Get the direction of the vector formed by the joystick and its origin in radians. 0 is forward and clockwise is positive. (Straight right is π/2.)- Returns:
- The direction of the vector in radians
-
getDirectionDegrees
Get the direction of the vector formed by the joystick and its origin in degrees. 0 is forward and clockwise is positive. (Straight right is 90.)- Returns:
- The direction of the vector in degrees
-