Class Gamepad

java.lang.Object
frc.spectrumLib.gamepads.Gamepad
All Implemented Interfaces:
Subsystem
Direct Known Subclasses:
Operator, Pilot

public abstract class Gamepad extends Object implements 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.

  • Field Details

    • kFalse

      public static final Trigger kFalse
      A trigger that is always false; the default for every button before wiring.
    • A

      protected Trigger A
      Xbox A, the cross glyph.
    • B

      protected Trigger B
      Xbox B, the circle glyph.
    • X

      protected Trigger X
      Xbox X, the square glyph.
    • Y

      protected Trigger Y
      Xbox Y, the triangle glyph.
    • leftBumper

      protected Trigger leftBumper
    • rightBumper

      protected Trigger rightBumper
    • leftTrigger

      protected Trigger leftTrigger
      Fires once the left analog trigger passes the configured trigger deadzone.
    • rightTrigger

      protected Trigger rightTrigger
      Fires once the right analog trigger passes the configured trigger deadzone.
    • leftStickClick

      protected Trigger leftStickClick
    • rightStickClick

      protected Trigger rightStickClick
    • start

      protected Trigger start
      Xbox Menu, exposed by WPILib as the start button.
    • select

      protected Trigger select
      Xbox View, exposed by WPILib as the back button.
    • upDpad

      protected Trigger upDpad
    • downDpad

      protected Trigger downDpad
    • leftDpad

      protected Trigger leftDpad
      Fires for left, up-left, or down-left on the D-pad.
    • rightDpad

      protected Trigger rightDpad
      Fires for right, up-right, or down-right on the D-pad.
    • leftStickY

      protected Trigger leftStickY
      Fires when the left stick's Y axis leaves the configured deadzone in either direction.
    • leftStickX

      protected Trigger leftStickX
      Fires when the left stick's X axis leaves the configured deadzone in either direction.
    • rightStickY

      protected Trigger rightStickY
      Fires when the right stick's Y axis leaves the configured deadzone in either direction.
    • rightStickX

      protected Trigger rightStickX
      Fires when the right stick's X axis leaves the configured deadzone in either direction.
    • noBumpers

      public Trigger noBumpers
    • leftBumperOnly

      public Trigger leftBumperOnly
    • rightBumperOnly

      public Trigger rightBumperOnly
    • bothBumpers

      public Trigger bothBumpers
    • noTriggers

      public Trigger noTriggers
    • leftTriggerOnly

      public Trigger leftTriggerOnly
    • rightTriggerOnly

      public Trigger rightTriggerOnly
    • bothTriggers

      public Trigger bothTriggers
    • noModifiers

      public Trigger noModifiers
    • leftStickCurve

      protected final ExpCurve leftStickCurve
      Exponential response curve applied to both left-stick axes.
    • rightStickCurve

      protected final ExpCurve rightStickCurve
      Exponential response curve applied to both right-stick axes.
    • triggersCurve

      protected final ExpCurve triggersCurve
    • teleop

      protected Trigger teleop
    • autoMode

      protected Trigger autoMode
    • testMode

      protected Trigger testMode
    • disabled

      protected Trigger disabled
  • Constructor Details

  • Method Details

    • periodic

      public void periodic()
      Calls configure() once per robot loop.
      Specified by:
      periodic in interface Subsystem
    • configure

      public void configure()
      Raises the disconnect alert, and the first time the gamepad is seen connected, prints a confirmation. Called from periodic().
    • resetConfig

      public void resetConfig()
      Clears the connection state so configure() runs its detection again. Pair it with CommandScheduler.getInstance().clearButtons().
    • getLeftStickDirection

      public Rotation2d 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

      public Rotation2d getRightStickDirection()
      Direction of the right stick, keeping the last non-zero value when the stick is released. Unlike getLeftStickDirection(), 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

      public Trigger leftYTrigger(Gamepad.Threshold t, double threshold)
    • leftXTrigger

      public Trigger leftXTrigger(Gamepad.Threshold t, double threshold)
    • rightYTrigger

      public Trigger rightYTrigger(Gamepad.Threshold t, double threshold)
    • rightXTrigger

      public Trigger rightXTrigger(Gamepad.Threshold t, double threshold)
    • rightStick

      public Trigger rightStick(double threshold)
      Fires when either right-stick axis is at or beyond threshold in absolute value.
    • leftStick

      public Trigger leftStick(double threshold)
      Fires when either left-stick axis is at or beyond threshold in absolute value.
    • rumbleCommand

      public Command rumbleCommand(double leftIntensity, double rightIntensity, double durationSeconds)
      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.0
      rightIntensity - right rumble motor intensity, 0.0 to 1.0
      durationSeconds - how long to rumble, in seconds
    • rumbleCommand

      public Command rumbleCommand(double intensity, double durationSeconds)
      Rumble command with the same intensity on both motors.
      Parameters:
      intensity - rumble motor intensity, 0.0 to 1.0
      durationSeconds - how long to rumble, in seconds
    • rumbleCommand

      public Command rumbleCommand(Command command)
      Runs command alongside 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

      protected GenericHID getHID()
      The raw HID device for low-level access, or null when this gamepad is not attached.
    • getRumbleHID

      protected GenericHID 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. Use rumbleCommand(double, double, double) for a timed burst.
      Parameters:
      leftIntensity - left rumble motor intensity, 0.0 to 1.0
      rightIntensity - right rumble motor intensity, 0.0 to 1.0
    • getLeftStickCurve

      public ExpCurve getLeftStickCurve()
      Exponential response curve applied to both left-stick axes.
    • getRightStickCurve

      public ExpCurve getRightStickCurve()
      Exponential response curve applied to both right-stick axes.
    • getTriggersCurve

      public ExpCurve getTriggersCurve()