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 BooleanEvent
circle(EventLoop loop)
Constructs an event instance around the circle button's digital signal.BooleanEvent
cross(EventLoop loop)
Constructs an event instance around the cross button's digital signal.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.BooleanEvent
L1(EventLoop loop)
Constructs an event instance around the L1 button's digital signal.BooleanEvent
L2(EventLoop loop)
Constructs an event instance around the L2 button's digital signal.BooleanEvent
L3(EventLoop loop)
Constructs an event instance around the L3 button's digital signal.BooleanEvent
options(EventLoop loop)
Constructs an event instance around the options button's digital signal.BooleanEvent
PS(EventLoop loop)
Constructs an event instance around the PS button's digital signal.BooleanEvent
R1(EventLoop loop)
Constructs an event instance around the R1 button's digital signal.BooleanEvent
R2(EventLoop loop)
Constructs an event instance around the R2 button's digital signal.BooleanEvent
R3(EventLoop loop)
Constructs an event instance around the R3 button's digital signal.BooleanEvent
share(EventLoop loop)
Constructs an event instance around the share button's digital signal.BooleanEvent
square(EventLoop loop)
Constructs an event instance around the square button's digital signal.BooleanEvent
touchpad(EventLoop loop)
Constructs an event instance around the touchpad's digital signal.BooleanEvent
triangle(EventLoop loop)
Constructs an event instance around the triangle button's digital signal.Methods inherited from class edu.wpi.first.wpilibj.GenericHID
axisGreaterThan, axisLessThan, button, getAxisCount, getAxisType, getButtonCount, getName, getPort, getPOV, getPOV, getPOVCount, getRawAxis, getRawButton, getRawButtonPressed, getRawButtonReleased, getType, isConnected, pov, pov, povCenter, povDown, povDownLeft, povDownRight, povLeft, povRight, povUp, povUpLeft, povUpRight, 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.
-
L2
Constructs an event instance around the L2 button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the L2 button's digital signal attached to the given loop.
-
R2
Constructs an event instance around the R2 button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the R2 button's digital signal attached to the given loop.
-
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.
-
L1
Constructs an event instance around the L1 button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the L1 button's digital signal attached to the given loop.
-
R1
Constructs an event instance around the R1 button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the R1 button's digital signal attached to the given loop.
-
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.
-
L3
Constructs an event instance around the L3 button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the L3 button's digital signal attached to the given loop.
-
R3
Constructs an event instance around the R3 button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the R3 button's digital signal attached to the given loop.
-
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.
-
square
Constructs an event instance around the square button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the square button's digital signal attached to the given loop.
-
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.
-
cross
Constructs an event instance around the cross button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the cross button's digital signal attached to the given loop.
-
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.
-
triangle
Constructs an event instance around the triangle button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the triangle button's digital signal attached to the given loop.
-
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.
-
circle
Constructs an event instance around the circle button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the circle button's digital signal attached to the given loop.
-
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.
-
share
Constructs an event instance around the share button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the share button's digital signal attached to the given loop.
-
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.
-
PS
Constructs an event instance around the PS button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the PS button's digital signal attached to the given loop.
-
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.
-
options
Constructs an event instance around the options button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the options button's digital signal attached to the given loop.
-
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.
-
touchpad
Constructs an event instance around the touchpad's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the touchpad's digital signal attached to the given loop.
-