public class Joystick extends GenericHID
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.
Modifier and Type | Class and Description |
---|---|
static class |
Joystick.AxisType
Represents an analog axis on a joystick.
|
static class |
Joystick.ButtonType
Represents a digital button on a joystick.
|
GenericHID.Hand, GenericHID.HIDType, GenericHID.RumbleType
Constructor and Description |
---|
Joystick(int port)
Construct an instance of a joystick.
|
Modifier and Type | Method and Description |
---|---|
double |
getAxis(Joystick.AxisType axis)
Deprecated.
Use the more specific axis getter functions.
|
int |
getAxisChannel(Joystick.AxisType axis)
Deprecated.
Use the more specific axis channel getter functions.
|
boolean |
getButton(Joystick.ButtonType button)
Deprecated.
Use Button enum values instead of ButtonType.
|
double |
getDirectionDegrees()
Get the direction of the vector formed by the joystick and its origin in degrees.
|
double |
getDirectionRadians()
Get the direction of the vector formed by the joystick and its origin in radians.
|
double |
getMagnitude()
Get the magnitude of the direction vector formed by the joystick's current position relative to
its origin.
|
double |
getThrottle()
Get the throttle value of the current joystick.
|
int |
getThrottleChannel()
Get the channel currently associated with the throttle axis.
|
boolean |
getTop()
Read the state of the top button on the joystick.
|
boolean |
getTopPressed()
Whether the top button was pressed since the last check.
|
boolean |
getTopReleased()
Whether the top button was released since the last check.
|
boolean |
getTrigger()
Read the state of the trigger on the joystick.
|
boolean |
getTriggerPressed()
Whether the trigger was pressed since the last check.
|
boolean |
getTriggerReleased()
Whether the trigger was released since the last check.
|
double |
getTwist()
Get the twist value of the current joystick.
|
int |
getTwistChannel()
Get the channel currently associated with the twist axis.
|
double |
getX(GenericHID.Hand hand)
Get the X value of the joystick.
|
int |
getXChannel()
Get the channel currently associated with the X axis.
|
double |
getY(GenericHID.Hand hand)
Get the Y value of the joystick.
|
int |
getYChannel()
Get the channel currently associated with the Y axis.
|
double |
getZ()
Get the z position of the HID.
|
int |
getZChannel()
Get the channel currently associated with the Z axis.
|
void |
setAxisChannel(Joystick.AxisType axis,
int channel)
Deprecated.
Use the more specific axis channel setter functions.
|
void |
setThrottleChannel(int channel)
Set the channel associated with the throttle axis.
|
void |
setTwistChannel(int channel)
Set the channel associated with the twist axis.
|
void |
setXChannel(int channel)
Set the channel associated with the X axis.
|
void |
setYChannel(int channel)
Set the channel associated with the Y axis.
|
void |
setZChannel(int channel)
Set the channel associated with the Z axis.
|
getAxisCount, getAxisType, getButtonCount, getName, getPort, getPOV, getPOV, getPOVCount, getRawAxis, getRawButton, getRawButtonPressed, getRawButtonReleased, getType, getX, getY, setOutput, setOutputs, setRumble
public Joystick(int port)
port
- The port on the Driver Station that the joystick is plugged into.public void setXChannel(int channel)
channel
- The channel to set the axis to.public void setYChannel(int channel)
channel
- The channel to set the axis to.public void setZChannel(int channel)
channel
- The channel to set the axis to.public void setThrottleChannel(int channel)
channel
- The channel to set the axis to.public void setTwistChannel(int channel)
channel
- The channel to set the axis to.@Deprecated public void setAxisChannel(Joystick.AxisType axis, int channel)
axis
- The axis to set the channel for.channel
- The channel to set the axis to.public int getXChannel()
public int getYChannel()
public int getZChannel()
public int getTwistChannel()
public int getThrottleChannel()
@Deprecated public int getAxisChannel(Joystick.AxisType axis)
axis
- The axis to look up the channel for.public final double getX(GenericHID.Hand hand)
getX
in class GenericHID
hand
- Unusedpublic final double getY(GenericHID.Hand hand)
getY
in class GenericHID
hand
- Unusedpublic double getZ()
public double getTwist()
public double getThrottle()
@Deprecated public double getAxis(Joystick.AxisType axis)
This is for cases where the joystick axis is returned programmatically, otherwise one of the previous functions would be preferable (for example getX()).
axis
- The axis to read.public boolean getTrigger()
public boolean getTriggerPressed()
public boolean getTriggerReleased()
public boolean getTop()
public boolean getTopPressed()
public boolean getTopReleased()
@Deprecated public boolean getButton(Joystick.ButtonType button)
The button type will be looked up in the list of buttons and then read.
button
- The type of button to read.public double getMagnitude()
public double getDirectionRadians()
public double getDirectionDegrees()