public class Joystick
extends java.lang.Object
Joystick
object represents one of the physical game controllers that are
connected to the driver station.
Due to a currently existant problem in the way that the control system handles the
controllers, a new joystick object is contructed every hardware cycle. References
to joysticks should not be kept for any reason. Instead, all joysticks should be
accessed through Lightning.getJoystick(int)
Modifier and Type | Field and Description |
---|---|
private com.qualcomm.robotcore.hardware.Gamepad |
baseGamepad
The
Gamepad that this object should receive information from. |
static double |
JOYSTICK_PRESS_THRESHOLD
The threshold that is used to determine if a joystick is sufficiently 'fully' pressed.
|
static double |
THUMBSTICK_MAX
The maximum value that can be expected from the thumb stick values.
|
static double |
THUMBSTICK_MIN
The minimum value that can be expected from the thumb stick values.
|
static double |
THUMBSTICK_REST
The value that should be expected from the thumb sticks when the thumb stick is at
rest.
|
static double |
THUMBSTICK_THRESHOLD
The threshold that must be exceeded by the raw thumb stick values before it should
register at all.
|
static double |
TRIGGER_MAX
The maximum value that can be expected from the trigger values.
|
static double |
TRIGGER_MIN
The minimum value that can be expected from the trigger values.
|
static double |
TRIGGER_PRESS_THRESHOLD
The threshold that is used to determine if a trigger is sufficiently 'fully' pressed.
|
Constructor and Description |
---|
Joystick(com.qualcomm.robotcore.hardware.Gamepad baseGamepad)
Constructs a new
Joystick with the given Gamepad as a base. |
Modifier and Type | Method and Description |
---|---|
boolean |
aButton()
Returns
true if the A-button on the joystick is currently being pressed. |
boolean |
bButton()
Returns
true if the B-button on the joystick is currently being pressed. |
boolean |
downButton()
Returns
true if down-direction button on the joystick is
currently being pressed. |
boolean |
leftBumper()
Returns
true if the left bumper on the joystick is currently
being pressed. |
boolean |
leftButton()
Returns
true if the left-direction button on the joystick is
currently being pressed. |
boolean |
leftStickButton()
Returns
true if the left-stick button on the joystick is
currently being pressed. |
boolean |
leftStickNegativeX()
Returns
true if the x-position of the left stick is below a set threshold, or
false otherwise. |
boolean |
leftStickNegativeY()
Returns
true if the y-position of the left stick is below a set threshold, or
false otherwise. |
boolean |
leftStickPositiveX()
Returns
true if the x-position of the left stick is above a set threshold, or
false otherwise. |
boolean |
leftStickPositiveY()
Returns
true if the y-position of the left stick is above a set threshold, or
false otherwise. |
double |
leftStickX()
Returns the current x-position of the left thumb stick.
|
double |
leftStickY()
Returns the current y-position of the left thumb stick.
|
double |
leftTrigger()
Returns the current position of the left trigger on the joystick.
|
boolean |
leftTriggerPressed()
Returns
true if the left trigger value is above the set threshold, or
false otherwise. |
boolean |
rightBumper()
Returns
true if the right bumper on the joystick is currently
being pressed. |
boolean |
rightButton()
Returns
true if the right-direction button on the joystick is
currently being pressed. |
boolean |
rightStickButton()
Returns
true if the right-stick button on the joystick is
currently being pressed. |
boolean |
rightStickNegativeX()
Returns
true if the x-position of the right stick is below a set threshold, or
false otherwise. |
boolean |
rightStickNegativeY()
Returns
true if the y-position of the right stick is below a set threshold, or
false otherwise. |
boolean |
rightStickPositiveX()
Returns
true if the x-position of the right stick is above a set threshold, or
false otherwise. |
boolean |
rightStickPositiveY()
Returns
true if the y-position of the right stick is above a set threshold, or
false otherwise. |
double |
rightStickX()
Returns the current x-position of the right thumb stick.
|
double |
rightStickY()
Returns the current y-position of the right thumb stick.
|
double |
rightTrigger()
Returns the current position of the right trigger on the joystick.
|
boolean |
rightTriggerPressed()
Returns
true if the right trigger value is above the set threshold, or
false otherwise. |
private static double |
scaleJoystickInput(double raw)
Scales the given input value to a number between the rest position and the maximum
position of the thumb stick, based on its relative position between the minimum and
maximum positions.
|
java.util.List<JoystickButton> |
toButtonList()
Generates a list of
JoystickButton s that represent all the buttons that are
currently pressed on this joystick. |
boolean |
upButton()
Returns
true if the up-direction button on the joystick is
currently being pressed. |
boolean |
xButton()
Returns
true if the X-button on the joystick is currently being
pressed. |
boolean |
yButton()
Returns
true if the Y-button on the joystick is currently being
pressed. |
private com.qualcomm.robotcore.hardware.Gamepad baseGamepad
Gamepad
that this object should receive information from.Gamepad
public static final double THUMBSTICK_THRESHOLD
public static final double THUMBSTICK_MAX
public static final double THUMBSTICK_REST
public static final double THUMBSTICK_MIN
public static final double TRIGGER_MAX
public static final double TRIGGER_MIN
public static final double JOYSTICK_PRESS_THRESHOLD
public static final double TRIGGER_PRESS_THRESHOLD
public Joystick(com.qualcomm.robotcore.hardware.Gamepad baseGamepad)
Joystick
with the given Gamepad
as a base.baseGamepad
- the base Gamepad
private static double scaleJoystickInput(double raw)
This method acts as a delegate to
MathUtil.scaleToRange()
, but supplies the thumbstick constants as the range bounds.
raw
- the raw input value from the joystick, between the threshold and maximum
positions.MathUtil.scaleToRange(double, double[], double[])
public boolean aButton()
true
if the A-button on the joystick is currently being pressed.public boolean bButton()
true
if the B-button on the joystick is currently being pressed.public boolean xButton()
true
if the X-button on the joystick is currently being
pressed.public boolean yButton()
true
if the Y-button on the joystick is currently being
pressed.public boolean upButton()
true
if the up-direction button on the joystick is
currently being pressed.public boolean downButton()
true
if down-direction button on the joystick is
currently being pressed.public boolean leftButton()
true
if the left-direction button on the joystick is
currently being pressed.public boolean rightButton()
true
if the right-direction button on the joystick is
currently being pressed.public boolean leftBumper()
true
if the left bumper on the joystick is currently
being pressed.public boolean rightBumper()
true
if the right bumper on the joystick is currently
being pressed.public boolean leftStickButton()
true
if the left-stick button on the joystick is
currently being pressed.public boolean rightStickButton()
true
if the right-stick button on the joystick is
currently being pressed.public double leftTrigger()
public boolean leftTriggerPressed()
true
if the left trigger value is above the set threshold, or
false
otherwise.true
if the left trigger value is above the set threshold.TRIGGER_PRESS_THRESHOLD
public double rightTrigger()
public boolean rightTriggerPressed()
true
if the right trigger value is above the set threshold, or
false
otherwise.true
if the right trigger value is above the set threshold.TRIGGER_PRESS_THRESHOLD
public double leftStickX()
public boolean leftStickNegativeX()
true
if the x-position of the left stick is below a set threshold, or
false
otherwise.true
if the x-position of the left stick is below a set threshold.JOYSTICK_PRESS_THRESHOLD
public boolean leftStickPositiveX()
true
if the x-position of the left stick is above a set threshold, or
false
otherwise.true
if the x-position of the left stick is above a set threshold.JOYSTICK_PRESS_THRESHOLD
public double leftStickY()
public boolean leftStickNegativeY()
true
if the y-position of the left stick is below a set threshold, or
false
otherwise.true
if the y-position of the left stick is below a set threshold.JOYSTICK_PRESS_THRESHOLD
public boolean leftStickPositiveY()
true
if the y-position of the left stick is above a set threshold, or
false
otherwise.true
if the y-position of the left stick is above a set threshold.JOYSTICK_PRESS_THRESHOLD
public double rightStickX()
public boolean rightStickNegativeX()
true
if the x-position of the right stick is below a set threshold, or
false
otherwise.true
if the x-position of the right stick is below a set threshold.JOYSTICK_PRESS_THRESHOLD
public boolean rightStickPositiveX()
true
if the x-position of the right stick is above a set threshold, or
false
otherwise.true
if the x-position of the right stick is above a set threshold.JOYSTICK_PRESS_THRESHOLD
public double rightStickY()
public boolean rightStickNegativeY()
true
if the y-position of the right stick is below a set threshold, or
false
otherwise.true
if the y-position of the right stick is below a set threshold.JOYSTICK_PRESS_THRESHOLD
public boolean rightStickPositiveY()
true
if the y-position of the right stick is above a set threshold, or
false
otherwise.true
if the y-position of the right stick is above a set threshold.JOYSTICK_PRESS_THRESHOLD
public java.util.List<JoystickButton> toButtonList()
JoystickButton
s that represent all the buttons that are
currently pressed on this joystick.