Class PS4Controller


  • public class PS4Controller
    extends GenericHID
    Handle input from PS4 controllers connected to the Driver Station.

    This class handles PS4 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.

    • Constructor Detail

      • PS4Controller

        public PS4Controller​(int port)
        Construct an instance of a device.
        Parameters:
        port - The port index on the Driver Station that the device is plugged into.
    • Method Detail

      • getLeftX

        public double getLeftX()
        Get the X axis value of left side of the controller.
        Returns:
        the axis value.
      • getRightX

        public double getRightX()
        Get the X axis value of right side of the controller.
        Returns:
        the axis value.
      • getLeftY

        public double getLeftY()
        Get the Y axis value of left side of the controller.
        Returns:
        the axis value.
      • getRightY

        public double getRightY()
        Get the Y axis value of right side of the controller.
        Returns:
        the axis value.
      • getL2Axis

        public double getL2Axis()
        Get the L2 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.
      • getR2Axis

        public double getR2Axis()
        Get the R2 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.
      • getL2Button

        public boolean getL2Button()
        Read the value of the left trigger button on the controller.
        Returns:
        The state of the button.
      • getR2Button

        public boolean getR2Button()
        Read the value of the right trigger button on the controller.
        Returns:
        The state of the button.
      • getL2ButtonPressed

        public boolean getL2ButtonPressed()
        Whether the L2 button was pressed since the last check.
        Returns:
        Whether the button was pressed since the last check.
      • getR2ButtonPressed

        public boolean getR2ButtonPressed()
        Whether the R2 button was pressed since the last check.
        Returns:
        Whether the button was pressed since the last check.
      • getL2ButtonReleased

        public boolean getL2ButtonReleased()
        Whether the L2 button was released since the last check.
        Returns:
        Whether the button was released since the last check.
      • getR2ButtonReleased

        public boolean getR2ButtonReleased()
        Whether the R2 button was released since the last check.
        Returns:
        Whether the button was released since the last check.
      • getL1Button

        public boolean getL1Button()
        Read the value of the L1 button on the controller.
        Returns:
        The state of the button.
      • getR1Button

        public boolean getR1Button()
        Read the value of the R1 button on the controller.
        Returns:
        The state of the button.
      • getL1ButtonPressed

        public boolean getL1ButtonPressed()
        Whether the L1 button was pressed since the last check.
        Returns:
        Whether the button was pressed since the last check.
      • getR1ButtonPressed

        public boolean getR1ButtonPressed()
        Whether the R1 button was pressed since the last check.
        Returns:
        Whether the button was pressed since the last check.
      • getL1ButtonReleased

        public boolean getL1ButtonReleased()
        Whether the L1 button was released since the last check.
        Returns:
        Whether the button was released since the last check.
      • getR1ButtonReleased

        public boolean getR1ButtonReleased()
        Whether the R1 button was released since the last check.
        Returns:
        Whether the button was released since the last check.
      • getL3Button

        public boolean getL3Button()
        Read the value of the L3 button (pressing the left analog stick) on the controller.
        Returns:
        The state of the button.
      • getR3Button

        public boolean getR3Button()
        Read the value of the R3 button (pressing the right analog stick) on the controller.
        Returns:
        The state of the button.
      • getL3ButtonPressed

        public boolean getL3ButtonPressed()
        Whether the L3 (left stick) button was pressed since the last check.
        Returns:
        Whether the button was pressed since the last check.
      • getR3ButtonPressed

        public boolean getR3ButtonPressed()
        Whether the R3 (right stick) button was pressed since the last check.
        Returns:
        Whether the button was pressed since the last check.
      • getL3ButtonReleased

        public boolean getL3ButtonReleased()
        Whether the L3 (left stick) button was released since the last check.
        Returns:
        Whether the button was released since the last check.
      • getR3ButtonReleased

        public boolean getR3ButtonReleased()
        Whether the R3 (right stick) button was released since the last check.
        Returns:
        Whether the button was released since the last check.
      • getSquareButton

        public boolean getSquareButton()
        Read the value of the Square button on the controller.
        Returns:
        The state of the button.
      • getSquareButtonPressed

        public boolean getSquareButtonPressed()
        Whether the Square button was pressed since the last check.
        Returns:
        Whether the button was pressed since the last check.
      • getSquareButtonReleased

        public boolean getSquareButtonReleased()
        Whether the Square button was released since the last check.
        Returns:
        Whether the button was released since the last check.
      • getCrossButton

        public boolean getCrossButton()
        Read the value of the Cross button on the controller.
        Returns:
        The state of the button.
      • getCrossButtonPressed

        public boolean getCrossButtonPressed()
        Whether the Cross button was pressed since the last check.
        Returns:
        Whether the button was pressed since the last check.
      • getCrossButtonReleased

        public boolean getCrossButtonReleased()
        Whether the Cross button was released since the last check.
        Returns:
        Whether the button was released since the last check.
      • getTriangleButton

        public boolean getTriangleButton()
        Read the value of the Triangle button on the controller.
        Returns:
        The state of the button.
      • getTriangleButtonPressed

        public boolean getTriangleButtonPressed()
        Whether the Triangle button was pressed since the last check.
        Returns:
        Whether the button was pressed since the last check.
      • getTriangleButtonReleased

        public boolean getTriangleButtonReleased()
        Whether the Triangle button was released since the last check.
        Returns:
        Whether the button was released since the last check.
      • getCircleButton

        public boolean getCircleButton()
        Read the value of the Circle button on the controller.
        Returns:
        The state of the button.
      • getCircleButtonPressed

        public boolean getCircleButtonPressed()
        Whether the Circle button was pressed since the last check.
        Returns:
        Whether the button was pressed since the last check.
      • getCircleButtonReleased

        public boolean getCircleButtonReleased()
        Whether the Circle button was released since the last check.
        Returns:
        Whether the button was released since the last check.
      • getShareButton

        public boolean getShareButton()
        Read the value of the share button on the controller.
        Returns:
        The state of the button.
      • getShareButtonPressed

        public boolean getShareButtonPressed()
        Whether the share button was pressed since the last check.
        Returns:
        Whether the button was pressed since the last check.
      • getShareButtonReleased

        public boolean getShareButtonReleased()
        Whether the share button was released since the last check.
        Returns:
        Whether the button was released since the last check.
      • getPSButton

        public boolean getPSButton()
        Read the value of the PS button on the controller.
        Returns:
        The state of the button.
      • getPSButtonPressed

        public boolean getPSButtonPressed()
        Whether the PS button was pressed since the last check.
        Returns:
        Whether the button was pressed since the last check.
      • getPSButtonReleased

        public boolean getPSButtonReleased()
        Whether the PS button was released since the last check.
        Returns:
        Whether the button was released since the last check.
      • getOptionsButton

        public boolean getOptionsButton()
        Read the value of the options button on the controller.
        Returns:
        The state of the button.
      • getOptionsButtonPressed

        public boolean getOptionsButtonPressed()
        Whether the options button was pressed since the last check.
        Returns:
        Whether the button was pressed since the last check.
      • getOptionsButtonReleased

        public boolean getOptionsButtonReleased()
        Whether the options button was released since the last check.
        Returns:
        Whether the button was released since the last check.
      • getTouchpad

        public boolean getTouchpad()
        Read the value of the touchpad on the controller.
        Returns:
        The state of the touchpad.
      • getTouchpadPressed

        public boolean getTouchpadPressed()
        Whether the touchpad was pressed since the last check.
        Returns:
        Whether the touchpad was pressed since the last check.
      • getTouchpadReleased

        public boolean getTouchpadReleased()
        Whether the touchpad was released since the last check.
        Returns:
        Whether the touchpad was released since the last check.