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
All Methods Instance Methods Concrete Methods 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 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.
-
-