Class NiDsPS4Controller
java.lang.Object
org.wpilib.driverstation.NiDsPS4Controller
- All Implemented Interfaces:
HIDDevice, TelemetryLoggable
Handle input from NiDsPS4 controllers connected to the Driver Station.
This class handles NiDsPS4 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 NiDsPS4Controller.static enumRepresents a digital button on a NiDsPS4Controller. -
Constructor Summary
ConstructorsConstructorDescriptionNiDsPS4Controller(int port) Construct an instance of a controller.Construct an instance of a controller with a GenericHID object. -
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.Get the type of the controller.getHID()Get the underlying GenericHID object.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.getName()Get the name 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.intgetPort()Get the port number of the controller.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.Get the supported outputs of the controller.Gets the telemetry table type.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.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.booleanGet if the controller is connected.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.voidlogTo(TelemetryTable table) Logs the object to aTelemetryTable.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.voidsetRumble(GenericHID.RumbleType type, double value) Set the rumble output for the HID.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.
-
Constructor Details
-
NiDsPS4Controller
public NiDsPS4Controller(int port) Construct an instance of a controller.- Parameters:
port- The port index on the Driver Station that the controller is plugged into (0-5).
-
NiDsPS4Controller
Construct an instance of a controller with a GenericHID object.- Parameters:
hid- The GenericHID object to use for this controller.
-
-
Method Details
-
getHID
Get the underlying GenericHID object. -
getLeftX
public double getLeftX()Get the X axis value of left side of the controller. Right is positive.- Returns:
- The axis value.
-
getLeftY
public double getLeftY()Get the Y axis value of left side of the controller. Back is positive.- Returns:
- The axis value.
-
getRightX
public double getRightX()Get the X axis value of right side of the controller. Right is positive.- Returns:
- The axis value.
-
getRightY
public double getRightY()Get the Y axis value of right side of the controller. Back is positive.- Returns:
- The axis value.
-
getL2Axis
public double 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
public double 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
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.
-
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
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.
-
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
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.
-
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
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.
-
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
public boolean getL1Button()Read the value of the left trigger 1 button on the controller.- Returns:
- The state of the button.
-
getL1ButtonPressed
public boolean getL1ButtonPressed()Whether the left trigger 1 button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getL1ButtonReleased
public boolean 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
public boolean getR1Button()Read the value of the right trigger 1 button on the controller.- Returns:
- The state of the button.
-
getR1ButtonPressed
public boolean getR1ButtonPressed()Whether the right trigger 1 button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getR1ButtonReleased
public boolean 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
public boolean getL2Button()Read the value of the left trigger 2 button on the controller.- Returns:
- The state of the button.
-
getL2ButtonPressed
public boolean getL2ButtonPressed()Whether the left trigger 2 button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getL2ButtonReleased
public boolean 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
public boolean getR2Button()Read the value of the right trigger 2 button on the controller.- Returns:
- The state of the button.
-
getR2ButtonPressed
public boolean getR2ButtonPressed()Whether the right trigger 2 button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getR2ButtonReleased
public boolean 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
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.
-
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
public boolean getL3Button()Read the value of the L3 (left stick) button 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.
-
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.
-
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
public boolean getR3Button()Read the value of the R3 (right stick) button on the controller.- Returns:
- The state of the button.
-
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.
-
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.
-
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
public boolean getPSButton()Read the value of the PlayStation button on the controller.- Returns:
- The state of the button.
-
getPSButtonPressed
public boolean getPSButtonPressed()Whether the PlayStation button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getPSButtonReleased
public boolean 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
public boolean getTouchpadButton()Read the value of the touchpad button on the controller.- Returns:
- The state of the button.
-
getTouchpadButtonPressed
public boolean getTouchpadButtonPressed()Whether the touchpad button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getTouchpadButtonReleased
public boolean 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.
-
isConnected
public boolean isConnected()Get if the controller is connected.- Returns:
- true if the controller is connected
-
getGamepadType
Get the type of the controller.- Returns:
- the type of the controller.
-
getSupportedOutputs
Get the supported outputs of the controller.- Returns:
- the supported outputs of the controller.
-
getName
-
getPort
public int getPort()Get the port number of the controller.- Returns:
- The port number of the controller.
-
setRumble
Set the rumble output for the HID.The DS currently supports 4 rumble values: left rumble, right rumble, left trigger rumble, and right trigger rumble.
- Parameters:
type- Which rumble value to setvalue- The normalized value (0 to 1) to set the rumble to
-
getTelemetryType
Description copied from interface:TelemetryLoggableGets the telemetry table type. Default is no specified table type (null). A mismatch in type during logging results in a reported warning, so this should always return the same value.- Specified by:
getTelemetryTypein interfaceTelemetryLoggable- Returns:
- Table type
-
logTo
Description copied from interface:TelemetryLoggableLogs the object to aTelemetryTable.- Specified by:
logToin interfaceTelemetryLoggable- Parameters:
table- telemetry table
-