Package edu.wpi.first.wpilibj
Class PS4Controller
java.lang.Object
edu.wpi.first.wpilibj.GenericHID
edu.wpi.first.wpilibj.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.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PS4Controller.Axis
Represents an axis on a PS4Controller.static class
PS4Controller.Button
Represents a digital button on a PS4Controller.Nested classes/interfaces inherited from class edu.wpi.first.wpilibj.GenericHID
GenericHID.HIDType, GenericHID.RumbleType
-
Constructor Summary
Constructors Constructor Description PS4Controller(int port)
Construct an instance of a device. -
Method Summary
Modifier and Type Method Description boolean
getCircleButton()
Read the value of the Circle button on the controller.boolean
getCircleButtonPressed()
Whether the Circle button was pressed since the last check.boolean
getCircleButtonReleased()
Whether the Circle button was released since the last check.boolean
getCrossButton()
Read the value of the Cross button on the controller.boolean
getCrossButtonPressed()
Whether the Cross button was pressed since the last check.boolean
getCrossButtonReleased()
Whether the Cross button was released since the last check.boolean
getL1Button()
Read the value of the L1 button on the controller.boolean
getL1ButtonPressed()
Whether the L1 button was pressed since the last check.boolean
getL1ButtonReleased()
Whether the L1 button was released since the last check.double
getL2Axis()
Get the L2 axis value of the controller.boolean
getL2Button()
Read the value of the left trigger button on the controller.boolean
getL2ButtonPressed()
Whether the L2 button was pressed since the last check.boolean
getL2ButtonReleased()
Whether the L2 button was released since the last check.boolean
getL3Button()
Read the value of the L3 button (pressing the left analog stick) on the controller.boolean
getL3ButtonPressed()
Whether the L3 (left stick) button was pressed since the last check.boolean
getL3ButtonReleased()
Whether the L3 (left stick) button was released since the last check.double
getLeftX()
Get the X axis value of left side of the controller.double
getLeftY()
Get the Y axis value of left side of the controller.boolean
getOptionsButton()
Read the value of the options button on the controller.boolean
getOptionsButtonPressed()
Whether the options button was pressed since the last check.boolean
getOptionsButtonReleased()
Whether the options button was released since the last check.boolean
getPSButton()
Read the value of the PS button on the controller.boolean
getPSButtonPressed()
Whether the PS button was pressed since the last check.boolean
getPSButtonReleased()
Whether the PS button was released since the last check.boolean
getR1Button()
Read the value of the R1 button on the controller.boolean
getR1ButtonPressed()
Whether the R1 button was pressed since the last check.boolean
getR1ButtonReleased()
Whether the R1 button was released since the last check.double
getR2Axis()
Get the R2 axis value of the controller.boolean
getR2Button()
Read the value of the right trigger button on the controller.boolean
getR2ButtonPressed()
Whether the R2 button was pressed since the last check.boolean
getR2ButtonReleased()
Whether the R2 button was released since the last check.boolean
getR3Button()
Read the value of the R3 button (pressing the right analog stick) on the controller.boolean
getR3ButtonPressed()
Whether the R3 (right stick) button was pressed since the last check.boolean
getR3ButtonReleased()
Whether the R3 (right stick) button was released since the last check.double
getRightX()
Get the X axis value of right side of the controller.double
getRightY()
Get the Y axis value of right side of the controller.boolean
getShareButton()
Read the value of the share button on the controller.boolean
getShareButtonPressed()
Whether the share button was pressed since the last check.boolean
getShareButtonReleased()
Whether the share button was released since the last check.boolean
getSquareButton()
Read the value of the Square button on the controller.boolean
getSquareButtonPressed()
Whether the Square button was pressed since the last check.boolean
getSquareButtonReleased()
Whether the Square button was released since the last check.boolean
getTouchpad()
Read the value of the touchpad on the controller.boolean
getTouchpadPressed()
Whether the touchpad was pressed since the last check.boolean
getTouchpadReleased()
Whether the touchpad was released since the last check.boolean
getTriangleButton()
Read the value of the Triangle button on the controller.boolean
getTriangleButtonPressed()
Whether the Triangle button was pressed since the last check.boolean
getTriangleButtonReleased()
Whether the Triangle button was released since the last check.Methods inherited from class edu.wpi.first.wpilibj.GenericHID
getAxisCount, getAxisType, getButtonCount, getName, getPort, getPOV, getPOV, getPOVCount, getRawAxis, getRawButton, getRawButtonPressed, getRawButtonReleased, getType, isConnected, setOutput, setOutputs, setRumble
-
Constructor Details
-
PS4Controller
Construct an instance of a device.- Parameters:
port
- The port index on the Driver Station that the device is plugged into.
-
-
Method Details
-
getLeftX
Get the X axis value of left side of the controller.- Returns:
- the axis value.
-
getRightX
Get the X axis value of right side of the controller.- Returns:
- the axis value.
-
getLeftY
Get the Y axis value of left side of the controller.- Returns:
- the axis value.
-
getRightY
Get the Y axis value of right side of the controller.- Returns:
- the axis value.
-
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
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
Read the value of the left trigger button on the controller.- Returns:
- The state of the button.
-
getR2Button
Read the value of the right trigger button on the controller.- Returns:
- The state of the button.
-
getL2ButtonPressed
Whether the L2 button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getR2ButtonPressed
Whether the R2 button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getL2ButtonReleased
Whether the L2 button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
getR2ButtonReleased
Whether the R2 button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
getL1Button
Read the value of the L1 button on the controller.- Returns:
- The state of the button.
-
getR1Button
Read the value of the R1 button on the controller.- Returns:
- The state of the button.
-
getL1ButtonPressed
Whether the L1 button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getR1ButtonPressed
Whether the R1 button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getL1ButtonReleased
Whether the L1 button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
getR1ButtonReleased
Whether the R1 button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
getL3Button
Read the value of the L3 button (pressing the left analog stick) on the controller.- Returns:
- The state of the button.
-
getR3Button
Read the value of the R3 button (pressing the right analog stick) on the controller.- Returns:
- The state of the button.
-
getL3ButtonPressed
Whether the L3 (left stick) button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getR3ButtonPressed
Whether the R3 (right stick) button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getL3ButtonReleased
Whether the L3 (left stick) button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
getR3ButtonReleased
Whether the R3 (right stick) button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
getSquareButton
Read the value of the Square button on the controller.- Returns:
- The state of the button.
-
getSquareButtonPressed
Whether the Square button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getSquareButtonReleased
Whether the Square button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
getCrossButton
Read the value of the Cross button on the controller.- Returns:
- The state of the button.
-
getCrossButtonPressed
Whether the Cross button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getCrossButtonReleased
Whether the Cross button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
getTriangleButton
Read the value of the Triangle button on the controller.- Returns:
- The state of the button.
-
getTriangleButtonPressed
Whether the Triangle button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getTriangleButtonReleased
Whether the Triangle button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
getCircleButton
Read the value of the Circle button on the controller.- Returns:
- The state of the button.
-
getCircleButtonPressed
Whether the Circle button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getCircleButtonReleased
Whether the Circle button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
getShareButton
Read the value of the share button on the controller.- Returns:
- The state of the button.
-
getShareButtonPressed
Whether the share button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getShareButtonReleased
Whether the share button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
getPSButton
Read the value of the PS button on the controller.- Returns:
- The state of the button.
-
getPSButtonPressed
Whether the PS button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getPSButtonReleased
Whether the PS button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
getOptionsButton
Read the value of the options button on the controller.- Returns:
- The state of the button.
-
getOptionsButtonPressed
Whether the options button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getOptionsButtonReleased
Whether the options button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
getTouchpad
Read the value of the touchpad on the controller.- Returns:
- The state of the touchpad.
-
getTouchpadPressed
Whether the touchpad was pressed since the last check.- Returns:
- Whether the touchpad was pressed since the last check.
-
getTouchpadReleased
Whether the touchpad was released since the last check.- Returns:
- Whether the touchpad was released since the last check.
-