Package frc.spectrumLib.gamepads
Class Gamepad
java.lang.Object
frc.spectrumLib.gamepads.Gamepad
- All Implemented Interfaces:
Subsystem
Base class for the robot's Xbox-compatible gamepads. Wraps a WPILib
CommandXboxController
and exposes the buttons, bumper and trigger combinations, stick axis helpers, and rumble commands
that bindings need.
Subclass once per operator role (pilot, copilot) and bind subsystem commands to the triggers that are set up here.
When Gamepad.Config.isAttached() returns false, every trigger stays false for
the life of the object and axis reads return 0.0, because no controller is constructed.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDriverStation USB port, axis curve parameters, and whether this robot uses the controller.static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TriggerXbox A, the cross glyph.protected Triggerprotected TriggerXbox B, the circle glyph.protected Triggerprotected Triggerstatic final TriggerA trigger that is alwaysfalse; the default for every button before wiring.protected Triggerprotected TriggerFires for left, up-left, or down-left on the D-pad.protected Triggerprotected final ExpCurveExponential response curve applied to both left-stick axes.protected TriggerFires when the left stick's X axis leaves the configured deadzone in either direction.protected TriggerFires when the left stick's Y axis leaves the configured deadzone in either direction.protected TriggerFires once the left analog trigger passes the configured trigger deadzone.protected Triggerprotected TriggerFires for right, up-right, or down-right on the D-pad.protected Triggerprotected final ExpCurveExponential response curve applied to both right-stick axes.protected TriggerFires when the right stick's X axis leaves the configured deadzone in either direction.protected TriggerFires when the right stick's Y axis leaves the configured deadzone in either direction.protected TriggerFires once the right analog trigger passes the configured trigger deadzone.protected TriggerXbox View, exposed by WPILib as the back button.protected TriggerXbox Menu, exposed by WPILib as the start button.protected Triggerprotected Triggerprotected final ExpCurveprotected Triggerprotected TriggerXbox X, the square glyph.protected TriggerXbox Y, the triangle glyph. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleCardinal stick angles rotated to match the current alliance's driver viewpoint.voidRaises the disconnect alert, and the first time the gamepad is seen connected, prints a confirmation.doubleSnaps the right stick to the nearest 45 degree increment, with forward as 0 rad.protected GenericHIDgetHID()The raw HID device for low-level access, or null when this gamepad is not attached.doubleSnaps the left-stick direction to the nearest of 0, ±π/2 and π radians.Exponential response curve applied to both left-stick axes.Direction of the left stick, zero pointing up toward positive Y and 90 degrees pointing left.doubleEuclidean magnitude of the left stick deflection: up to √2 before the curve and scalar, 1.0 after.protected doubleRaw left-trigger axis, 0.0 to 1.0, or 0.0 when the gamepad is not connected.protected doublegetLeftX()Raw left-stick X axis, -1.0 to 1.0, or 0.0 when not connected.protected doublegetLeftY()Raw left-stick Y axis, -1.0 to 1.0, or 0.0 when not connected.doubleReturns the blue-alliance cardinals rotated by pi, for red-alliance driving.doubleSnaps the right-stick direction to the nearest of 0, ±π/2 and π radians.Exponential response curve applied to both right-stick axes.Direction of the right stick, keeping the last non-zero value when the stick is released.doubleprotected doubleRaw right-trigger axis, 0.0 to 1.0, or 0.0 when the gamepad is not connected.protected doubleRaw right-stick X axis, -1.0 to 1.0, or 0.0 when not connected.protected doubleRaw right-stick Y axis, -1.0 to 1.0, or 0.0 when not connected.protected GenericHIDThe raw HID device for rumble output, or null unless the gamepad is attached and up.protected doublegetTwist()rightTrigger minus leftTrigger, usable as a single twist axis in [-1, 1].booleanleftStick(double threshold) Fires when either left-stick axis is at or beyondthresholdin absolute value.leftXTrigger(Gamepad.Threshold t, double threshold) leftYTrigger(Gamepad.Threshold t, double threshold) voidperiodic()Callsconfigure()once per robot loop.voidClears the connection state soconfigure()runs its detection again.rightStick(double threshold) Fires when either right-stick axis is at or beyondthresholdin absolute value.rightXTrigger(Gamepad.Threshold t, double threshold) rightYTrigger(Gamepad.Threshold t, double threshold) rumbleCommand(double intensity, double durationSeconds) Rumble command with the same intensity on both motors.rumbleCommand(double leftIntensity, double rightIntensity, double durationSeconds) Rumble command that holds the given intensities for a fixed time and then stops.rumbleCommand(Command command) Runscommandalongside a fixed 0.5 s full-strength rumble, under the same name.voidrumbleController(double leftIntensity, double rightIntensity) Sets both rumble motors immediately.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem
defer, getCurrentCommand, getDefaultCommand, getName, idle, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
-
Field Details
-
kFalse
A trigger that is alwaysfalse; the default for every button before wiring. -
A
Xbox A, the cross glyph. -
B
Xbox B, the circle glyph. -
X
Xbox X, the square glyph. -
Y
Xbox Y, the triangle glyph. -
leftBumper
-
rightBumper
-
leftTrigger
Fires once the left analog trigger passes the configured trigger deadzone. -
rightTrigger
Fires once the right analog trigger passes the configured trigger deadzone. -
leftStickClick
-
rightStickClick
-
start
Xbox Menu, exposed by WPILib as the start button. -
select
Xbox View, exposed by WPILib as the back button. -
upDpad
-
downDpad
-
leftDpad
Fires for left, up-left, or down-left on the D-pad. -
rightDpad
Fires for right, up-right, or down-right on the D-pad. -
leftStickY
Fires when the left stick's Y axis leaves the configured deadzone in either direction. -
leftStickX
Fires when the left stick's X axis leaves the configured deadzone in either direction. -
rightStickY
Fires when the right stick's Y axis leaves the configured deadzone in either direction. -
rightStickX
Fires when the right stick's X axis leaves the configured deadzone in either direction. -
noBumpers
-
leftBumperOnly
-
rightBumperOnly
-
bothBumpers
-
noTriggers
-
leftTriggerOnly
-
rightTriggerOnly
-
bothTriggers
-
noModifiers
-
leftStickCurve
Exponential response curve applied to both left-stick axes. -
rightStickCurve
Exponential response curve applied to both right-stick axes. -
triggersCurve
-
teleop
-
autoMode
-
testMode
-
disabled
-
-
Constructor Details
-
Gamepad
-
-
Method Details
-
periodic
public void periodic()Callsconfigure()once per robot loop. -
configure
public void configure()Raises the disconnect alert, and the first time the gamepad is seen connected, prints a confirmation. Called fromperiodic(). -
resetConfig
public void resetConfig()Clears the connection state soconfigure()runs its detection again. Pair it withCommandScheduler.getInstance().clearButtons(). -
getLeftStickDirection
Direction of the left stick, zero pointing up toward positive Y and 90 degrees pointing left. The last non-zero direction is kept when the stick is released. -
getRightStickDirection
Direction of the right stick, keeping the last non-zero value when the stick is released. UnlikegetLeftStickDirection(), the axis values are not negated. -
getLeftStickCardinals
public double getLeftStickCardinals()Snaps the left-stick direction to the nearest of 0, ±π/2 and π radians. -
getRightStickCardinals
public double getRightStickCardinals()Snaps the right-stick direction to the nearest of 0, ±π/2 and π radians. -
getLeftStickMagnitude
public double getLeftStickMagnitude()Euclidean magnitude of the left stick deflection: up to √2 before the curve and scalar, 1.0 after. -
getRightStickMagnitude
public double getRightStickMagnitude() -
chooseCardinalDirections
public double chooseCardinalDirections()Cardinal stick angles rotated to match the current alliance's driver viewpoint. -
getBlueAllianceStickCardinals
public double getBlueAllianceStickCardinals()Snaps the right stick to the nearest 45 degree increment, with forward as 0 rad. -
getRedAllianceStickCardinals
public double getRedAllianceStickCardinals()Returns the blue-alliance cardinals rotated by pi, for red-alliance driving. -
leftYTrigger
-
leftXTrigger
-
rightYTrigger
-
rightXTrigger
-
rightStick
Fires when either right-stick axis is at or beyondthresholdin absolute value. -
leftStick
Fires when either left-stick axis is at or beyondthresholdin absolute value. -
rumbleCommand
Rumble command that holds the given intensities for a fixed time and then stops. It keeps running while the robot is disabled.- Parameters:
leftIntensity- left rumble motor intensity, 0.0 to 1.0rightIntensity- right rumble motor intensity, 0.0 to 1.0durationSeconds- how long to rumble, in seconds
-
rumbleCommand
Rumble command with the same intensity on both motors.- Parameters:
intensity- rumble motor intensity, 0.0 to 1.0durationSeconds- how long to rumble, in seconds
-
rumbleCommand
Runscommandalongside a fixed 0.5 s full-strength rumble, under the same name.- Parameters:
command- command to run alongside the rumble
-
isConnected
public boolean isConnected() -
getRightTriggerAxis
protected double getRightTriggerAxis()Raw right-trigger axis, 0.0 to 1.0, or 0.0 when the gamepad is not connected. -
getLeftTriggerAxis
protected double getLeftTriggerAxis()Raw left-trigger axis, 0.0 to 1.0, or 0.0 when the gamepad is not connected. -
getTwist
protected double getTwist()rightTrigger minus leftTrigger, usable as a single twist axis in [-1, 1]. -
getLeftX
protected double getLeftX()Raw left-stick X axis, -1.0 to 1.0, or 0.0 when not connected. -
getLeftY
protected double getLeftY()Raw left-stick Y axis, -1.0 to 1.0, or 0.0 when not connected. Negative is up. -
getRightX
protected double getRightX()Raw right-stick X axis, -1.0 to 1.0, or 0.0 when not connected. -
getRightY
protected double getRightY()Raw right-stick Y axis, -1.0 to 1.0, or 0.0 when not connected. Negative is up. -
getHID
The raw HID device for low-level access, or null when this gamepad is not attached. -
getRumbleHID
The raw HID device for rumble output, or null unless the gamepad is attached and up. -
rumbleController
public void rumbleController(double leftIntensity, double rightIntensity) Sets both rumble motors immediately. UserumbleCommand(double, double, double)for a timed burst.- Parameters:
leftIntensity- left rumble motor intensity, 0.0 to 1.0rightIntensity- right rumble motor intensity, 0.0 to 1.0
-
getLeftStickCurve
Exponential response curve applied to both left-stick axes. -
getRightStickCurve
Exponential response curve applied to both right-stick axes. -
getTriggersCurve
-