Class Gamepad

java.lang.Object
org.wpilib.driverstation.GenericHID
org.wpilib.driverstation.Gamepad
All Implemented Interfaces:
Sendable

public class Gamepad extends GenericHID implements Sendable
Handle input from Gamepad controllers connected to the Driver Station.

This class handles Gamepad 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 controller and the mapping of ports to hardware buttons depends on the code in the Driver Station.

Only first party controllers from Generic are guaranteed to have the correct mapping, and only through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any 3rd party controllers.

  • Constructor Details

    • Gamepad

      public Gamepad(int port)
      Construct an instance of a controller.
      Parameters:
      port - The port index on the Driver Station that the controller is plugged into (0-5).
  • Method Details

    • getLeftX

      public double getLeftX()
      Get the X axis value of left side of the controller. Right is positive.
      Returns:
      The axis value.
    • getLeftY

      public double getLeftY()
      Get the Y axis value of left side of the controller. Back is positive.
      Returns:
      The axis value.
    • getRightX

      public double getRightX()
      Get the X axis value of right side of the controller. Right is positive.
      Returns:
      The axis value.
    • getRightY

      public double getRightY()
      Get the Y axis value of right side of the controller. Back is positive.
      Returns:
      The axis value.
    • getLeftTriggerAxis

      public double getLeftTriggerAxis()
      Get the left trigger axis value of the controller. Note that this axis is bound to the range of [0, 1] as opposed to the usual [-1, 1].
      Returns:
      The axis value.
    • leftTrigger

      public BooleanEvent leftTrigger(double threshold, EventLoop loop)
      Constructs an event instance around the axis value of the left trigger. The returned trigger will be true when the axis value is greater than threshold.
      Parameters:
      threshold - the minimum axis value for the returned BooleanEvent to be true. This value should be in the range [0, 1] where 0 is the unpressed state of the axis.
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance that is true when the left trigger's axis exceeds the provided threshold, attached to the given event loop
    • leftTrigger

      Constructs an event instance around the axis value of the left trigger. The returned trigger will be true when the axis value is greater than 0.5.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance that is true when the left trigger's axis exceeds the provided threshold, attached to the given event loop
    • getRightTriggerAxis

      public double getRightTriggerAxis()
      Get the right trigger axis value of the controller. Note that this axis is bound to the range of [0, 1] as opposed to the usual [-1, 1].
      Returns:
      The axis value.
    • rightTrigger

      public BooleanEvent rightTrigger(double threshold, EventLoop loop)
      Constructs an event instance around the axis value of the right trigger. The returned trigger will be true when the axis value is greater than threshold.
      Parameters:
      threshold - the minimum axis value for the returned BooleanEvent to be true. This value should be in the range [0, 1] where 0 is the unpressed state of the axis.
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance that is true when the right trigger's axis exceeds the provided threshold, attached to the given event loop
    • rightTrigger

      Constructs an event instance around the axis value of the right trigger. The returned trigger will be true when the axis value is greater than 0.5.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance that is true when the right trigger's axis exceeds the provided threshold, attached to the given event loop
    • getSouthFaceButton

      public boolean getSouthFaceButton()
      Read the value of the South Face button on the controller.
      Returns:
      The state of the button.
    • getSouthFaceButtonPressed

      public boolean getSouthFaceButtonPressed()
      Whether the South Face button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getSouthFaceButtonReleased

      public boolean getSouthFaceButtonReleased()
      Whether the South Face button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • southFace

      Constructs an event instance around the South Face button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the South Face button's digital signal attached to the given loop.
    • getEastFaceButton

      public boolean getEastFaceButton()
      Read the value of the East Face button on the controller.
      Returns:
      The state of the button.
    • getEastFaceButtonPressed

      public boolean getEastFaceButtonPressed()
      Whether the East Face button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getEastFaceButtonReleased

      public boolean getEastFaceButtonReleased()
      Whether the East Face button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • eastFace

      Constructs an event instance around the East Face button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the East Face button's digital signal attached to the given loop.
    • getWestFaceButton

      public boolean getWestFaceButton()
      Read the value of the West Face button on the controller.
      Returns:
      The state of the button.
    • getWestFaceButtonPressed

      public boolean getWestFaceButtonPressed()
      Whether the West Face button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getWestFaceButtonReleased

      public boolean getWestFaceButtonReleased()
      Whether the West Face button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • westFace

      Constructs an event instance around the West Face button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the West Face button's digital signal attached to the given loop.
    • getNorthFaceButton

      public boolean getNorthFaceButton()
      Read the value of the North Face button on the controller.
      Returns:
      The state of the button.
    • getNorthFaceButtonPressed

      public boolean getNorthFaceButtonPressed()
      Whether the North Face button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getNorthFaceButtonReleased

      public boolean getNorthFaceButtonReleased()
      Whether the North Face button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • northFace

      Constructs an event instance around the North Face button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the North Face button's digital signal attached to the given loop.
    • getBackButton

      public boolean getBackButton()
      Read the value of the Back button on the controller.
      Returns:
      The state of the button.
    • getBackButtonPressed

      public boolean getBackButtonPressed()
      Whether the Back button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getBackButtonReleased

      public boolean getBackButtonReleased()
      Whether the Back button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • back

      public BooleanEvent back(EventLoop loop)
      Constructs an event instance around the Back button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the Back button's digital signal attached to the given loop.
    • getGuideButton

      public boolean getGuideButton()
      Read the value of the Guide button on the controller.
      Returns:
      The state of the button.
    • getGuideButtonPressed

      public boolean getGuideButtonPressed()
      Whether the Guide button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getGuideButtonReleased

      public boolean getGuideButtonReleased()
      Whether the Guide button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • guide

      public BooleanEvent guide(EventLoop loop)
      Constructs an event instance around the Guide button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the Guide button's digital signal attached to the given loop.
    • getStartButton

      public boolean getStartButton()
      Read the value of the Start button on the controller.
      Returns:
      The state of the button.
    • getStartButtonPressed

      public boolean getStartButtonPressed()
      Whether the Start button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getStartButtonReleased

      public boolean getStartButtonReleased()
      Whether the Start button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • start

      public BooleanEvent start(EventLoop loop)
      Constructs an event instance around the Start button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the Start button's digital signal attached to the given loop.
    • getLeftStickButton

      public boolean getLeftStickButton()
      Read the value of the left stick button on the controller.
      Returns:
      The state of the button.
    • getLeftStickButtonPressed

      public boolean getLeftStickButtonPressed()
      Whether the left stick button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getLeftStickButtonReleased

      public boolean getLeftStickButtonReleased()
      Whether the left stick button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • leftStick

      Constructs an event instance around the left stick button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the left stick button's digital signal attached to the given loop.
    • getRightStickButton

      public boolean getRightStickButton()
      Read the value of the right stick button on the controller.
      Returns:
      The state of the button.
    • getRightStickButtonPressed

      public boolean getRightStickButtonPressed()
      Whether the right stick button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getRightStickButtonReleased

      public boolean getRightStickButtonReleased()
      Whether the right stick button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • rightStick

      Constructs an event instance around the right stick button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the right stick button's digital signal attached to the given loop.
    • getLeftBumperButton

      public boolean getLeftBumperButton()
      Read the value of the right bumper button on the controller.
      Returns:
      The state of the button.
    • getLeftBumperButtonPressed

      public boolean getLeftBumperButtonPressed()
      Whether the right bumper button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getLeftBumperButtonReleased

      public boolean getLeftBumperButtonReleased()
      Whether the right bumper button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • leftBumper

      Constructs an event instance around the right bumper button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the right bumper button's digital signal attached to the given loop.
    • getRightBumperButton

      public boolean getRightBumperButton()
      Read the value of the right bumper button on the controller.
      Returns:
      The state of the button.
    • getRightBumperButtonPressed

      public boolean getRightBumperButtonPressed()
      Whether the right bumper button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getRightBumperButtonReleased

      public boolean getRightBumperButtonReleased()
      Whether the right bumper button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • rightBumper

      Constructs an event instance around the right bumper button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the right bumper button's digital signal attached to the given loop.
    • getDpadUpButton

      public boolean getDpadUpButton()
      Read the value of the D-pad up button on the controller.
      Returns:
      The state of the button.
    • getDpadUpButtonPressed

      public boolean getDpadUpButtonPressed()
      Whether the D-pad up button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getDpadUpButtonReleased

      public boolean getDpadUpButtonReleased()
      Whether the D-pad up button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • dpadUp

      public BooleanEvent dpadUp(EventLoop loop)
      Constructs an event instance around the D-pad up button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the D-pad up button's digital signal attached to the given loop.
    • getDpadDownButton

      public boolean getDpadDownButton()
      Read the value of the D-pad down button on the controller.
      Returns:
      The state of the button.
    • getDpadDownButtonPressed

      public boolean getDpadDownButtonPressed()
      Whether the D-pad down button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getDpadDownButtonReleased

      public boolean getDpadDownButtonReleased()
      Whether the D-pad down button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • dpadDown

      Constructs an event instance around the D-pad down button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the D-pad down button's digital signal attached to the given loop.
    • getDpadLeftButton

      public boolean getDpadLeftButton()
      Read the value of the D-pad left button on the controller.
      Returns:
      The state of the button.
    • getDpadLeftButtonPressed

      public boolean getDpadLeftButtonPressed()
      Whether the D-pad left button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getDpadLeftButtonReleased

      public boolean getDpadLeftButtonReleased()
      Whether the D-pad left button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • dpadLeft

      Constructs an event instance around the D-pad left button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the D-pad left button's digital signal attached to the given loop.
    • getDpadRightButton

      public boolean getDpadRightButton()
      Read the value of the D-pad right button on the controller.
      Returns:
      The state of the button.
    • getDpadRightButtonPressed

      public boolean getDpadRightButtonPressed()
      Whether the D-pad right button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getDpadRightButtonReleased

      public boolean getDpadRightButtonReleased()
      Whether the D-pad right button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • dpadRight

      Constructs an event instance around the D-pad right button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the D-pad right button's digital signal attached to the given loop.
    • getMisc1Button

      public boolean getMisc1Button()
      Read the value of the Miscellaneous 1 button on the controller.
      Returns:
      The state of the button.
    • getMisc1ButtonPressed

      public boolean getMisc1ButtonPressed()
      Whether the Miscellaneous 1 button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getMisc1ButtonReleased

      public boolean getMisc1ButtonReleased()
      Whether the Miscellaneous 1 button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • misc1

      public BooleanEvent misc1(EventLoop loop)
      Constructs an event instance around the Miscellaneous 1 button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the Miscellaneous 1 button's digital signal attached to the given loop.
    • getRightPaddle1Button

      public boolean getRightPaddle1Button()
      Read the value of the Right Paddle 1 button on the controller.
      Returns:
      The state of the button.
    • getRightPaddle1ButtonPressed

      public boolean getRightPaddle1ButtonPressed()
      Whether the Right Paddle 1 button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getRightPaddle1ButtonReleased

      Whether the Right Paddle 1 button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • rightPaddle1

      Constructs an event instance around the Right Paddle 1 button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the Right Paddle 1 button's digital signal attached to the given loop.
    • getLeftPaddle1Button

      public boolean getLeftPaddle1Button()
      Read the value of the Left Paddle 1 button on the controller.
      Returns:
      The state of the button.
    • getLeftPaddle1ButtonPressed

      public boolean getLeftPaddle1ButtonPressed()
      Whether the Left Paddle 1 button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getLeftPaddle1ButtonReleased

      public boolean getLeftPaddle1ButtonReleased()
      Whether the Left Paddle 1 button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • leftPaddle1

      Constructs an event instance around the Left Paddle 1 button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the Left Paddle 1 button's digital signal attached to the given loop.
    • getRightPaddle2Button

      public boolean getRightPaddle2Button()
      Read the value of the Right Paddle 2 button on the controller.
      Returns:
      The state of the button.
    • getRightPaddle2ButtonPressed

      public boolean getRightPaddle2ButtonPressed()
      Whether the Right Paddle 2 button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getRightPaddle2ButtonReleased

      Whether the Right Paddle 2 button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • rightPaddle2

      Constructs an event instance around the Right Paddle 2 button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the Right Paddle 2 button's digital signal attached to the given loop.
    • getLeftPaddle2Button

      public boolean getLeftPaddle2Button()
      Read the value of the Left Paddle 2 button on the controller.
      Returns:
      The state of the button.
    • getLeftPaddle2ButtonPressed

      public boolean getLeftPaddle2ButtonPressed()
      Whether the Left Paddle 2 button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getLeftPaddle2ButtonReleased

      public boolean getLeftPaddle2ButtonReleased()
      Whether the Left Paddle 2 button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • leftPaddle2

      Constructs an event instance around the Left Paddle 2 button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the Left Paddle 2 button's digital signal attached to the given loop.
    • getTouchpadButton

      public boolean getTouchpadButton()
      Read the value of the Touchpad button on the controller.
      Returns:
      The state of the button.
    • getTouchpadButtonPressed

      public boolean getTouchpadButtonPressed()
      Whether the Touchpad button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getTouchpadButtonReleased

      public boolean getTouchpadButtonReleased()
      Whether the Touchpad button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • touchpad

      Constructs an event instance around the Touchpad button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the Touchpad button's digital signal attached to the given loop.
    • getMisc2Button

      public boolean getMisc2Button()
      Read the value of the Miscellaneous 2 button on the controller.
      Returns:
      The state of the button.
    • getMisc2ButtonPressed

      public boolean getMisc2ButtonPressed()
      Whether the Miscellaneous 2 button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getMisc2ButtonReleased

      public boolean getMisc2ButtonReleased()
      Whether the Miscellaneous 2 button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • misc2

      public BooleanEvent misc2(EventLoop loop)
      Constructs an event instance around the Miscellaneous 2 button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the Miscellaneous 2 button's digital signal attached to the given loop.
    • getMisc3Button

      public boolean getMisc3Button()
      Read the value of the Miscellaneous 3 button on the controller.
      Returns:
      The state of the button.
    • getMisc3ButtonPressed

      public boolean getMisc3ButtonPressed()
      Whether the Miscellaneous 3 button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getMisc3ButtonReleased

      public boolean getMisc3ButtonReleased()
      Whether the Miscellaneous 3 button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • misc3

      public BooleanEvent misc3(EventLoop loop)
      Constructs an event instance around the Miscellaneous 3 button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the Miscellaneous 3 button's digital signal attached to the given loop.
    • getMisc4Button

      public boolean getMisc4Button()
      Read the value of the Miscellaneous 4 button on the controller.
      Returns:
      The state of the button.
    • getMisc4ButtonPressed

      public boolean getMisc4ButtonPressed()
      Whether the Miscellaneous 4 button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getMisc4ButtonReleased

      public boolean getMisc4ButtonReleased()
      Whether the Miscellaneous 4 button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • misc4

      public BooleanEvent misc4(EventLoop loop)
      Constructs an event instance around the Miscellaneous 4 button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the Miscellaneous 4 button's digital signal attached to the given loop.
    • getMisc5Button

      public boolean getMisc5Button()
      Read the value of the Miscellaneous 5 button on the controller.
      Returns:
      The state of the button.
    • getMisc5ButtonPressed

      public boolean getMisc5ButtonPressed()
      Whether the Miscellaneous 5 button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getMisc5ButtonReleased

      public boolean getMisc5ButtonReleased()
      Whether the Miscellaneous 5 button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • misc5

      public BooleanEvent misc5(EventLoop loop)
      Constructs an event instance around the Miscellaneous 5 button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the Miscellaneous 5 button's digital signal attached to the given loop.
    • getMisc6Button

      public boolean getMisc6Button()
      Read the value of the Miscellaneous 6 button on the controller.
      Returns:
      The state of the button.
    • getMisc6ButtonPressed

      public boolean getMisc6ButtonPressed()
      Whether the Miscellaneous 6 button was pressed since the last check.
      Returns:
      Whether the button was pressed since the last check.
    • getMisc6ButtonReleased

      public boolean getMisc6ButtonReleased()
      Whether the Miscellaneous 6 button was released since the last check.
      Returns:
      Whether the button was released since the last check.
    • misc6

      public BooleanEvent misc6(EventLoop loop)
      Constructs an event instance around the Miscellaneous 6 button's digital signal.
      Parameters:
      loop - the event loop instance to attach the event to.
      Returns:
      an event instance representing the Miscellaneous 6 button's digital signal attached to the given loop.
    • initSendable

      public void initSendable(SendableBuilder builder)
      Description copied from interface: Sendable
      Initializes this Sendable object.
      Specified by:
      initSendable in interface Sendable
      Parameters:
      builder - sendable builder