Package ftclib.driverio
Class FtcGamepad
java.lang.Object
trclib.driverio.TrcGameController
ftclib.driverio.FtcGamepad
This class implements the platform dependent gamepad. It provides monitoring of the gamepad buttons. If the caller
of this class provides a button notification handler, it will call it when there are button events.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
This interface, if provided, will allow this class to do a notification callback when there are button activities.static enum
Nested classes/interfaces inherited from class trclib.driverio.TrcGameController
TrcGameController.DriveMode
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate FtcGamepad.ButtonEventHandler
private static HashMap<Integer,
FtcGamepad.ButtonType> private static final double
final com.qualcomm.robotcore.hardware.Gamepad
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private int
private int
private int
private int
Fields inherited from class trclib.driverio.TrcGameController
instanceName, tracer
-
Constructor Summary
ConstructorsConstructorDescriptionFtcGamepad
(String instanceName, com.qualcomm.robotcore.hardware.Gamepad gamepad) Constructor: Create an instance of the object.FtcGamepad
(String instanceName, com.qualcomm.robotcore.hardware.Gamepad gamepad, double deadbandThreshold) Constructor: Create an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionint
This method returns the button states in an integer by combining all the button states.double[]
getDriveInputs
(TrcGameController.DriveMode driveMode, boolean doExp) This method reads various joystick/gamepad control values and returns the drive powers for all three degrees of robot movement.double[]
getDriveInputs
(TrcGameController.DriveMode driveMode, boolean doExp, double drivePowerScale, double turnPowerScale) This method reads various joystick/gamepad control values and returns the drive powers for all three degrees of robot movement.double
This method returns the x-axis value of the left stick.double
getLeftStickX
(boolean doExp) This method returns the x-axis value of the left stick.double
getLeftStickX
(double cubicCoefficient) This method returns the x-axis value of the left stick using the cubic polynomial curve.double
This method returns the y-axis value of the left stick.double
getLeftStickY
(boolean doExp) This method returns the y-axis value of the left stick.double
getLeftStickY
(double cubicCoefficient) This method returns the y-axis value of the left stick using the cubic polynomial curve.double
This method returns the left trigger value.double
getLeftTrigger
(boolean doExp) This method returns the left trigger value.double
getLeftTrigger
(double cubicCoefficient) This method returns the left trigger value using the cubic polynomial curve.double
This method returns the x-axis value of the right stick.double
getRightStickX
(boolean doExp) This method returns the x-axis value of the right stick.double
getRightStickX
(double cubicCoefficient) This method returns the x-axis value of the right stick using the cubic polynomial curve.double
This method returns the y-axis value of the right stick.double
getRightStickY
(boolean doExp) This method returns the y-axis value of the right stick.double
getRightStickY
(double cubicCoefficient) This method returns the y-axis value of the right stick using the cubic polynomial curve.double
This method returns the right trigger value.double
getRightTrigger
(boolean doExp) This method returns the right trigger value.double
getRightTrigger
(double cubicCoefficient) This method returns the right trigger value using the cubic polynomial curve.double
This method combines the left trigger and right trigger values to a value with a range of -1.0 to 1.0.double
getTrigger
(boolean doExp) This method combines the left trigger and right trigger values to a value with a range of -1.0 to 1.0.double
getTrigger
(double cubicCoefficient) This method combines the left trigger and right trigger values to a value with a range of -1.0 to 1.0 using the cubic polynomial curve.protected void
notifyButtonEvent
(int buttonValue, boolean pressed) This method is called when a button event is detected.void
setButtonEventHandler
(FtcGamepad.ButtonEventHandler buttonEventHandler) This method sets the button event handler.void
setLeftStickInverted
(boolean xInverted, boolean yInverted) This method inverts the left analog stick axes.void
setRightStickInverted
(boolean xInverted, boolean yInverted) This method inverts the right analog stick axes.Methods inherited from class trclib.driverio.TrcGameController
adjustAnalogControl, adjustAnalogControl, getDirectionDegrees, getDirectionRadians, getMagnitude, init, setButtonEventEnabled, setExponent, setSamplingPeriod, toString
-
Field Details
-
GAMEPAD_A
private static final int GAMEPAD_A- See Also:
-
GAMEPAD_B
private static final int GAMEPAD_B- See Also:
-
GAMEPAD_X
private static final int GAMEPAD_X- See Also:
-
GAMEPAD_Y
private static final int GAMEPAD_Y- See Also:
-
GAMEPAD_LBUMPER
private static final int GAMEPAD_LBUMPER- See Also:
-
GAMEPAD_RBUMPER
private static final int GAMEPAD_RBUMPER- See Also:
-
GAMEPAD_DPAD_UP
private static final int GAMEPAD_DPAD_UP- See Also:
-
GAMEPAD_DPAD_DOWN
private static final int GAMEPAD_DPAD_DOWN- See Also:
-
GAMEPAD_DPAD_LEFT
private static final int GAMEPAD_DPAD_LEFT- See Also:
-
GAMEPAD_DPAD_RIGHT
private static final int GAMEPAD_DPAD_RIGHT- See Also:
-
GAMEPAD_BACK
private static final int GAMEPAD_BACK- See Also:
-
GAMEPAD_START
private static final int GAMEPAD_START- See Also:
-
GAMEPAD_GUIDE
private static final int GAMEPAD_GUIDE- See Also:
-
GAMEPAD_LSTICK_BTN
private static final int GAMEPAD_LSTICK_BTN- See Also:
-
GAMEPAD_RSTICK_BTN
private static final int GAMEPAD_RSTICK_BTN- See Also:
-
DEF_DEADBAND_THRESHOLD
private static final double DEF_DEADBAND_THRESHOLD- See Also:
-
buttonTypeMap
-
gamepad
public final com.qualcomm.robotcore.hardware.Gamepad gamepad -
buttonEventHandler
-
leftXSign
private int leftXSign -
leftYSign
private int leftYSign -
rightXSign
private int rightXSign -
rightYSign
private int rightYSign
-
-
Constructor Details
-
FtcGamepad
public FtcGamepad(String instanceName, com.qualcomm.robotcore.hardware.Gamepad gamepad, double deadbandThreshold) Constructor: Create an instance of the object.- Parameters:
instanceName
- specifies the instance name.gamepad
- specifies the gamepad associated with this instance.deadbandThreshold
- specifies the deadband of the gamepad analog sticks.
-
FtcGamepad
Constructor: Create an instance of the object.- Parameters:
instanceName
- specifies the instance name.gamepad
- specifies the gamepad associated with this instance.
-
-
Method Details
-
setButtonEventHandler
This method sets the button event handler.- Parameters:
buttonEventHandler
- specifies button event notification handler, null to disable event notification.
-
setLeftStickInverted
public void setLeftStickInverted(boolean xInverted, boolean yInverted) This method inverts the left analog stick axes.- Parameters:
xInverted
- specifies true if inverting the x-axis, false otherwise.yInverted
- specifies true if inverting the y-axis, false otherwise.
-
setRightStickInverted
public void setRightStickInverted(boolean xInverted, boolean yInverted) This method inverts the right analog stick axes.- Parameters:
xInverted
- specifies true if inverting the x-axis, false otherwise.yInverted
- specifies true if inverting the y-axis, false otherwise.
-
getLeftStickX
public double getLeftStickX(double cubicCoefficient) This method returns the x-axis value of the left stick using the cubic polynomial curve.- Parameters:
cubicCoefficient
- specifies the cubic coefficient.- Returns:
- x-axis value of the left stick.
-
getLeftStickX
public double getLeftStickX(boolean doExp) This method returns the x-axis value of the left stick.- Parameters:
doExp
- specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.- Returns:
- x-axis value of the left stick.
-
getLeftStickX
public double getLeftStickX()This method returns the x-axis value of the left stick.- Returns:
- x-axis value of the left stick.
-
getLeftStickY
public double getLeftStickY(double cubicCoefficient) This method returns the y-axis value of the left stick using the cubic polynomial curve.- Parameters:
cubicCoefficient
- specifies the cubic coefficient.- Returns:
- y-axis value of the left stick.
-
getLeftStickY
public double getLeftStickY(boolean doExp) This method returns the y-axis value of the left stick.- Parameters:
doExp
- specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.- Returns:
- y-axis value of the left stick.
-
getLeftStickY
public double getLeftStickY()This method returns the y-axis value of the left stick.- Returns:
- y-axis value of the left stick.
-
getRightStickX
public double getRightStickX(double cubicCoefficient) This method returns the x-axis value of the right stick using the cubic polynomial curve.- Parameters:
cubicCoefficient
- specifies the cubic coefficient.- Returns:
- x-axis value of the right stick.
-
getRightStickX
public double getRightStickX(boolean doExp) This method returns the x-axis value of the right stick.- Parameters:
doExp
- specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.- Returns:
- x-axis value of the right stick.
-
getRightStickX
public double getRightStickX()This method returns the x-axis value of the right stick.- Returns:
- x-axis value of the right stick.
-
getRightStickY
public double getRightStickY(double cubicCoefficient) This method returns the y-axis value of the right stick using the cubic polynomial curve.- Parameters:
cubicCoefficient
- specifies the cubic coefficient.- Returns:
- y-axis value of the right stick.
-
getRightStickY
public double getRightStickY(boolean doExp) This method returns the y-axis value of the right stick.- Parameters:
doExp
- specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.- Returns:
- y-axis value of the right stick.
-
getRightStickY
public double getRightStickY()This method returns the y-axis value of the right stick.- Returns:
- y-axis value of the right stick.
-
getLeftTrigger
public double getLeftTrigger(double cubicCoefficient) This method returns the left trigger value using the cubic polynomial curve.- Parameters:
cubicCoefficient
- specifies the cubic coefficient.- Returns:
- left trigger value.
-
getLeftTrigger
public double getLeftTrigger(boolean doExp) This method returns the left trigger value.- Parameters:
doExp
- specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.- Returns:
- left trigger value.
-
getLeftTrigger
public double getLeftTrigger()This method returns the left trigger value.- Returns:
- left trigger value.
-
getRightTrigger
public double getRightTrigger(double cubicCoefficient) This method returns the right trigger value using the cubic polynomial curve.- Parameters:
cubicCoefficient
- specifies the cubic coefficient.- Returns:
- right trigger value.
-
getRightTrigger
public double getRightTrigger(boolean doExp) This method returns the right trigger value.- Parameters:
doExp
- specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.- Returns:
- right trigger value.
-
getRightTrigger
public double getRightTrigger()This method returns the right trigger value.- Returns:
- right trigger value.
-
getTrigger
public double getTrigger(double cubicCoefficient) This method combines the left trigger and right trigger values to a value with a range of -1.0 to 1.0 using the cubic polynomial curve.- Parameters:
cubicCoefficient
- specifies the cubic coefficient.- Returns:
- combined left and right trigger value.
-
getTrigger
public double getTrigger(boolean doExp) This method combines the left trigger and right trigger values to a value with a range of -1.0 to 1.0.- Parameters:
doExp
- specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.- Returns:
- combined left and right trigger value.
-
getTrigger
public double getTrigger()This method combines the left trigger and right trigger values to a value with a range of -1.0 to 1.0.- Returns:
- combined left and right trigger value.
-
getDriveInputs
public double[] getDriveInputs(TrcGameController.DriveMode driveMode, boolean doExp, double drivePowerScale, double turnPowerScale) This method reads various joystick/gamepad control values and returns the drive powers for all three degrees of robot movement.- Parameters:
driveMode
- specifies the drive mode which determines the control mappings.doExp
- specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.drivePowerScale
- specifies the scaling factor for drive power.turnPowerScale
- specifies the scaling factor for turn power.- Returns:
- an array of 3 values for x, y and rotation power.
-
getDriveInputs
This method reads various joystick/gamepad control values and returns the drive powers for all three degrees of robot movement.- Parameters:
driveMode
- specifies the drive mode which determines the control mappings.doExp
- specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.- Returns:
- an array of 3 values for x, y and rotation power.
-
getButtons
public int getButtons()This method returns the button states in an integer by combining all the button states.- Specified by:
getButtons
in classTrcGameController
- Returns:
- button states.
-
notifyButtonEvent
protected void notifyButtonEvent(int buttonValue, boolean pressed) This method is called when a button event is detected. It translates the button value into button type and calls the button event handler.- Specified by:
notifyButtonEvent
in classTrcGameController
- Parameters:
buttonValue
- specifies the button value that generated the event.pressed
- specifies true if the button is pressed, false if it is released.
-