Package edu.wpi.first.wpilibj
Class PS4Controller
java.lang.Object
edu.wpi.first.wpilibj.GenericHID
edu.wpi.first.wpilibj.PS4Controller
- All Implemented Interfaces:
Sendable
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.
Only first party controllers from Sony 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents an axis on an PS4Controller.static enumRepresents a digital button on a PS4Controller.Nested classes/interfaces inherited from class edu.wpi.first.wpilibj.GenericHID
GenericHID.HIDType, GenericHID.RumbleType -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConstructs an event instance around the circle button's digital signal.Constructs an event instance around the cross button's digital signal.booleanRead the value of the circle button on the controller.booleanWhether the circle button was pressed since the last check.booleanWhether the circle button was released since the last check.booleanRead the value of the cross button on the controller.booleanWhether the cross button was pressed since the last check.booleanWhether the cross button was released since the last check.booleanRead the value of the left trigger 1 button on the controller.booleanWhether the left trigger 1 button was pressed since the last check.booleanWhether the left trigger 1 button was released since the last check.doubleGet the left trigger 2 axis value of the controller.booleanRead the value of the left trigger 2 button on the controller.booleanWhether the left trigger 2 button was pressed since the last check.booleanWhether the left trigger 2 button was released since the last check.booleanRead the value of the L3 (left stick) button on the controller.booleanWhether the L3 (left stick) button was pressed since the last check.booleanWhether the L3 (left stick) button was released since the last check.doublegetLeftX()Get the X axis value of left side of the controller.doublegetLeftY()Get the Y axis value of left side of the controller.booleanRead the value of the options button on the controller.booleanWhether the options button was pressed since the last check.booleanWhether the options button was released since the last check.booleanRead the value of the PlayStation button on the controller.booleanWhether the PlayStation button was pressed since the last check.booleanWhether the PlayStation button was released since the last check.booleanRead the value of the right trigger 1 button on the controller.booleanWhether the right trigger 1 button was pressed since the last check.booleanWhether the right trigger 1 button was released since the last check.doubleGet the right trigger 2 axis value of the controller.booleanRead the value of the right trigger 2 button on the controller.booleanWhether the right trigger 2 button was pressed since the last check.booleanWhether the right trigger 2 button was released since the last check.booleanRead the value of the R3 (right stick) button on the controller.booleanWhether the R3 (right stick) button was pressed since the last check.booleanWhether the R3 (right stick) button was released since the last check.doubleGet the X axis value of right side of the controller.doubleGet the Y axis value of right side of the controller.booleanRead the value of the share button on the controller.booleanWhether the share button was pressed since the last check.booleanWhether the share button was released since the last check.booleanRead the value of the square button on the controller.booleanWhether the square button was pressed since the last check.booleanWhether the square button was released since the last check.booleanDeprecated, for removal: This API element is subject to removal in a future version.booleanRead the value of the touchpad button on the controller.booleanWhether the touchpad button was pressed since the last check.booleanWhether the touchpad button was released since the last check.booleanDeprecated, for removal: This API element is subject to removal in a future version.UsegetTouchpadButtonPressed()instead.booleanDeprecated, for removal: This API element is subject to removal in a future version.UsegetTouchpadButtonReleased()instead.booleanRead the value of the triangle button on the controller.booleanWhether the triangle button was pressed since the last check.booleanWhether the triangle button was released since the last check.voidinitSendable(SendableBuilder builder) Initializes thisSendableobject.Constructs an event instance around the left trigger 1 button's digital signal.Constructs an event instance around the left trigger 2 button's digital signal.Constructs an event instance around the L3 (left stick) button's digital signal.Constructs an event instance around the options button's digital signal.Constructs an event instance around the PlayStation button's digital signal.Constructs an event instance around the right trigger 1 button's digital signal.Constructs an event instance around the right trigger 2 button's digital signal.Constructs an event instance around the R3 (right stick) button's digital signal.Constructs an event instance around the share button's digital signal.Constructs an event instance around the square button's digital signal.Constructs an event instance around the touchpad button's digital signal.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 controller.- Parameters:
port- The port index on the Driver Station that the controller is plugged into (0-5).
-
-
Method Details
-
getLeftX
Get the X axis value of left side of the controller. Right is positive.- Returns:
- The axis value.
-
getLeftY
Get the Y axis value of left side of the controller. Back is positive.- Returns:
- The axis value.
-
getRightX
Get the X axis value of right side of the controller. Right is positive.- Returns:
- The axis value.
-
getRightY
Get the Y axis value of right side of the controller. Back is positive.- Returns:
- The axis value.
-
getL2Axis
Get the left trigger 2 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 right trigger 2 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.
-
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.
-
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.
-
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.
-
getL1Button
Read the value of the left trigger 1 button on the controller.- Returns:
- The state of the button.
-
getL1ButtonPressed
Whether the left trigger 1 button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getL1ButtonReleased
Whether the left trigger 1 button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
L1
Constructs an event instance around the left trigger 1 button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the left trigger 1 button's digital signal attached to the given loop.
-
getR1Button
Read the value of the right trigger 1 button on the controller.- Returns:
- The state of the button.
-
getR1ButtonPressed
Whether the right trigger 1 button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getR1ButtonReleased
Whether the right trigger 1 button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
R1
Constructs an event instance around the right trigger 1 button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the right trigger 1 button's digital signal attached to the given loop.
-
getL2Button
Read the value of the left trigger 2 button on the controller.- Returns:
- The state of the button.
-
getL2ButtonPressed
Whether the left trigger 2 button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getL2ButtonReleased
Whether the left trigger 2 button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
L2
Constructs an event instance around the left trigger 2 button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the left trigger 2 button's digital signal attached to the given loop.
-
getR2Button
Read the value of the right trigger 2 button on the controller.- Returns:
- The state of the button.
-
getR2ButtonPressed
Whether the right trigger 2 button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getR2ButtonReleased
Whether the right trigger 2 button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
R2
Constructs an event instance around the right trigger 2 button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the right trigger 2 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.
-
getL3Button
Read the value of the L3 (left stick) button 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.
-
getL3ButtonReleased
Whether the L3 (left 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 (left stick) button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the L3 (left stick) button's digital signal attached to the given loop.
-
getR3Button
Read the value of the R3 (right stick) button on the controller.- Returns:
- The state of the button.
-
getR3ButtonPressed
Whether the R3 (right stick) button was pressed since the last check.- Returns:
- Whether the button was pressed 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.
-
R3
Constructs an event instance around the R3 (right stick) button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the R3 (right stick) button's digital signal attached to the given loop.
-
getPSButton
Read the value of the PlayStation button on the controller.- Returns:
- The state of the button.
-
getPSButtonPressed
Whether the PlayStation button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getPSButtonReleased
Whether the PlayStation button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
PS
Constructs an event instance around the PlayStation button's digital signal.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- an event instance representing the PlayStation button's digital signal attached to the given loop.
-
getTouchpadButton
Read the value of the touchpad button on the controller.- Returns:
- The state of the button.
-
getTouchpadButtonPressed
Whether the touchpad button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
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.
-
getTouchpad
Deprecated, for removal: This API element is subject to removal in a future version.UsegetTouchpadButton()instead. This function is deprecated for removal to make function names consistent to allow the HID classes to be automatically generated.Read the value of the touchpad on the controller.- Returns:
- The state of the touchpad.
-
getTouchpadPressed
Deprecated, for removal: This API element is subject to removal in a future version.UsegetTouchpadButtonPressed()instead. This function is deprecated for removal to make function names consistent to allow the HID classes to be automatically generated.Whether the touchpad was pressed since the last check.- Returns:
- Whether the touchpad was pressed since the last check.
-
getTouchpadReleased
Deprecated, for removal: This API element is subject to removal in a future version.UsegetTouchpadButtonReleased()instead. This function is deprecated for removal to make function names consistent to allow the HID classes to be automatically generated.Whether the touchpad was released since the last check.- Returns:
- Whether the touchpad was released since the last check.
-
initSendable
Description copied from interface:SendableInitializes thisSendableobject.- Specified by:
initSendablein interfaceSendable- Parameters:
builder- sendable builder
-
getTouchpadButton()instead.