DualShock4Controller

class wpilib.DualShock4Controller(*args, **kwargs)

Bases: HIDDevice, Sendable

Handle input from DualShock4 controllers connected to the Driver Station.

This class handles DualShock4 input that comes from the Driver Station. Each time a value is requested the most recent value is returned.

Overloaded function.

  1. __init__(self: wpilib._wpilib.DualShock4Controller, port: typing.SupportsInt | typing.SupportsIndex) -> None

Construct an instance of a controller.

The controller index is the USB port on the Driver Station.

Parameters:

port – The port on the Driver Station that the controller is plugged into.

  1. __init__(self: wpilib._wpilib.DualShock4Controller, hid: wpilib._wpilib.GenericHID) -> None

Construct an instance of a controller with a GenericHID object.

Parameters:

hid – The GenericHID object to use for this controller.

class Axis(value: SupportsInt | SupportsIndex)

Bases: pybind11_object

Represents an axis on a DualShock4Controller.

Members:

LEFT_X : Left X.

LEFT_Y : Left Y.

RIGHT_X : Right X.

RIGHT_Y : Right Y.

L2 : L 2.

R2 : R 2.

L2 = <Axis.L2: 4>
LEFT_X = <Axis.LEFT_X: 0>
LEFT_Y = <Axis.LEFT_Y: 1>
R2 = <Axis.R2: 5>
RIGHT_X = <Axis.RIGHT_X: 2>
RIGHT_Y = <Axis.RIGHT_Y: 3>
DualShock4Controller.Axis.name -> str
property value
class Button(value: SupportsInt | SupportsIndex)

Bases: pybind11_object

Represents a digital button on a DualShock4Controller.

Members:

CROSS : Cross button.

CIRCLE : Circle button.

SQUARE : Square button.

TRIANGLE : Triangle button.

SHARE : Share button.

PS : PS button.

OPTIONS : Options button.

L3 : L 3 button.

R3 : R 3 button.

L1 : L 1 button.

R1 : R 1 button.

DPAD_UP : Dpad Up button.

DPAD_DOWN : Dpad Down button.

DPAD_LEFT : Dpad Left button.

DPAD_RIGHT : Dpad Right button.

TOUCHPAD : Touchpad button.

CIRCLE = <Button.CIRCLE: 1>
CROSS = <Button.CROSS: 0>
DPAD_DOWN = <Button.DPAD_DOWN: 12>
DPAD_LEFT = <Button.DPAD_LEFT: 13>
DPAD_RIGHT = <Button.DPAD_RIGHT: 14>
DPAD_UP = <Button.DPAD_UP: 11>
L1 = <Button.L1: 9>
L3 = <Button.L3: 7>
OPTIONS = <Button.OPTIONS: 6>
PS = <Button.PS: 5>
R1 = <Button.R1: 10>
R3 = <Button.R3: 8>
SHARE = <Button.SHARE: 4>
SQUARE = <Button.SQUARE: 2>
TOUCHPAD = <Button.TOUCHPAD: 20>
TRIANGLE = <Button.TRIANGLE: 3>
DualShock4Controller.Button.name -> str
property value
SUPPORTED_OUTPUTS = <SupportedOutputs.???: 10>
SUPPORTS_MONO_LED = False
SUPPORTS_RGB_LED = True
SUPPORTS_RUMBLE = True
SUPPORTS_TRIGGER_RUMBLE = False
TOUCHPAD_COUNT = 1
axis_greater_than(axis: wpilib._wpilib.DualShock4Controller.Axis, threshold: SupportsFloat | SupportsIndex, loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

Constructs an event instance that is true when the axis value is greater than threshold.

Parameters:
  • axis – The axis to read.

  • threshold – The value above which this event should return true.

  • loop – the event loop instance to attach the event to.

Returns:

an event instance that is true when the axis value is greater than the provided threshold.

axis_less_than(axis: wpilib._wpilib.DualShock4Controller.Axis, threshold: SupportsFloat | SupportsIndex, loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

Constructs an event instance that is true when the axis value is less than threshold.

Parameters:
  • axis – The axis to read.

  • threshold – The value below which this event should return true.

  • loop – the event loop instance to attach the event to.

Returns:

an event instance that is true when the axis value is less than the provided threshold.

button(button: wpilib._wpilib.DualShock4Controller.Button, loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

Constructs an event instance around this button’s digital signal.

Parameters:
  • button – the button

  • loop – the event loop instance to attach the event to.

Returns:

an event instance representing the button’s digital signal attached to the given loop.

circle(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

cross(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

dpad_down(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

Constructs an event instance around the Dpad Down button’s digital signal.

Parameters:

loop – the event loop instance to attach the event to.

Returns:

an event instance representing the Dpad Down button’s digital signal attached to the given loop.

dpad_left(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

Constructs an event instance around the Dpad Left button’s digital signal.

Parameters:

loop – the event loop instance to attach the event to.

Returns:

an event instance representing the Dpad Left button’s digital signal attached to the given loop.

dpad_right(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

Constructs an event instance around the Dpad Right button’s digital signal.

Parameters:

loop – the event loop instance to attach the event to.

Returns:

an event instance representing the Dpad Right button’s digital signal attached to the given loop.

dpad_up(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

Constructs an event instance around the Dpad Up button’s digital signal.

Parameters:

loop – the event loop instance to attach the event to.

Returns:

an event instance representing the Dpad Up button’s digital signal attached to the given loop.

get_axis(axis: wpilib._wpilib.DualShock4Controller.Axis) float

Get the value of the axis.

Parameters:

axis – The axis to read

Returns:

the axis value.

get_button(button: wpilib._wpilib.DualShock4Controller.Button) bool

Get the button value.

Parameters:

button – The button to read

Returns:

The state of the button.

get_button_pressed(button: wpilib._wpilib.DualShock4Controller.Button) bool

Whether the button was pressed since the last check.

Parameters:

button – The button to read

Returns:

Whether the button was pressed since the last check.

get_button_released(button: wpilib._wpilib.DualShock4Controller.Button) bool

Whether the button was released since the last check.

Parameters:

button – The button to read

Returns:

Whether the button was released since the last check.

get_circle_button() bool

Read the value of the Circle button on the controller.

Returns:

The state of the button.

get_circle_button_pressed() bool

Whether the Circle button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_circle_button_released() bool

Whether the Circle button was released since the last check.

Returns:

Whether the button was released since the last check.

get_cross_button() bool

Read the value of the Cross button on the controller.

Returns:

The state of the button.

get_cross_button_pressed() bool

Whether the Cross button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_cross_button_released() bool

Whether the Cross button was released since the last check.

Returns:

Whether the button was released since the last check.

get_dpad_down_button() bool

Read the value of the Dpad Down button on the controller.

Returns:

The state of the button.

get_dpad_down_button_pressed() bool

Whether the Dpad Down button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_dpad_down_button_released() bool

Whether the Dpad Down button was released since the last check.

Returns:

Whether the button was released since the last check.

get_dpad_left_button() bool

Read the value of the Dpad Left button on the controller.

Returns:

The state of the button.

get_dpad_left_button_pressed() bool

Whether the Dpad Left button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_dpad_left_button_released() bool

Whether the Dpad Left button was released since the last check.

Returns:

Whether the button was released since the last check.

get_dpad_right_button() bool

Read the value of the Dpad Right button on the controller.

Returns:

The state of the button.

get_dpad_right_button_pressed() bool

Whether the Dpad Right button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_dpad_right_button_released() bool

Whether the Dpad Right button was released since the last check.

Returns:

Whether the button was released since the last check.

get_dpad_up_button() bool

Read the value of the Dpad Up button on the controller.

Returns:

The state of the button.

get_dpad_up_button_pressed() bool

Whether the Dpad Up button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_dpad_up_button_released() bool

Whether the Dpad Up button was released since the last check.

Returns:

Whether the button was released since the last check.

get_hid() wpilib._wpilib.GenericHID

Get the underlying GenericHID object.

Returns:

the wrapped GenericHID object

get_l1_button() bool

Read the value of the L 1 button on the controller.

Returns:

The state of the button.

get_l1_button_pressed() bool

Whether the L 1 button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_l1_button_released() bool

Whether the L 1 button was released since the last check.

Returns:

Whether the button was released since the last check.

get_l2() float

Get the L 2 value of the controller.

Returns:

the axis value.

get_l3_button() bool

Read the value of the L 3 button on the controller.

Returns:

The state of the button.

get_l3_button_pressed() bool

Whether the L 3 button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_l3_button_released() bool

Whether the L 3 button was released since the last check.

Returns:

Whether the button was released since the last check.

get_left_x() float

Get the Left X value of the controller.

Returns:

the axis value.

get_left_y() float

Get the Left Y value of the controller.

Returns:

the axis value.

get_options_button() bool

Read the value of the Options button on the controller.

Returns:

The state of the button.

get_options_button_pressed() bool

Whether the Options button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_options_button_released() bool

Whether the Options button was released since the last check.

Returns:

Whether the button was released since the last check.

get_port() int

Get the port number of the HID.

Returns:

The port number of the HID.

get_ps_button() bool

Read the value of the PS button on the controller.

Returns:

The state of the button.

get_ps_button_pressed() bool

Whether the PS button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_ps_button_released() bool

Whether the PS button was released since the last check.

Returns:

Whether the button was released since the last check.

get_r1_button() bool

Read the value of the R 1 button on the controller.

Returns:

The state of the button.

get_r1_button_pressed() bool

Whether the R 1 button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_r1_button_released() bool

Whether the R 1 button was released since the last check.

Returns:

Whether the button was released since the last check.

get_r2() float

Get the R 2 value of the controller.

Returns:

the axis value.

get_r3_button() bool

Read the value of the R 3 button on the controller.

Returns:

The state of the button.

get_r3_button_pressed() bool

Whether the R 3 button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_r3_button_released() bool

Whether the R 3 button was released since the last check.

Returns:

Whether the button was released since the last check.

get_right_x() float

Get the Right X value of the controller.

Returns:

the axis value.

get_right_y() float

Get the Right Y value of the controller.

Returns:

the axis value.

get_share_button() bool

Read the value of the Share button on the controller.

Returns:

The state of the button.

get_share_button_pressed() bool

Whether the Share button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_share_button_released() bool

Whether the Share button was released since the last check.

Returns:

Whether the button was released since the last check.

get_square_button() bool

Read the value of the Square button on the controller.

Returns:

The state of the button.

get_square_button_pressed() bool

Whether the Square button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_square_button_released() bool

Whether the Square button was released since the last check.

Returns:

Whether the button was released since the last check.

get_touchpad_button() bool

Read the value of the Touchpad button on the controller.

Returns:

The state of the button.

get_touchpad_button_pressed() bool

Whether the Touchpad button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_touchpad_button_released() bool

Whether the Touchpad button was released since the last check.

Returns:

Whether the button was released since the last check.

get_touchpad_finger(finger: SupportsInt | SupportsIndex) wpilib._wpilib.TouchpadFinger

Get the touchpad finger data.

Parameters:

finger – The finger to read.

Returns:

The touchpad finger data.

get_touchpad_finger_available(finger: SupportsInt | SupportsIndex) bool

Check if a touchpad finger is available.

Parameters:

finger – The finger to check.

Returns:

true if the touchpad finger is available.

get_triangle_button() bool

Read the value of the Triangle button on the controller.

Returns:

The state of the button.

get_triangle_button_pressed() bool

Whether the Triangle button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

get_triangle_button_released() bool

Whether the Triangle button was released since the last check.

Returns:

Whether the button was released since the last check.

init_sendable(builder: wpiutil._wpiutil.SendableBuilder) None
is_connected() bool

Get if the HID is connected.

Returns:

true if the HID is connected

l1(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

Constructs an event instance around the L 1 button’s digital signal.

Parameters:

loop – the event loop instance to attach the event to.

Returns:

an event instance representing the L 1 button’s digital signal attached to the given loop.

l3(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

Constructs an event instance around the L 3 button’s digital signal.

Parameters:

loop – the event loop instance to attach the event to.

Returns:

an event instance representing the L 3 button’s digital signal attached to the given loop.

options(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

ps(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

r1(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

Constructs an event instance around the R 1 button’s digital signal.

Parameters:

loop – the event loop instance to attach the event to.

Returns:

an event instance representing the R 1 button’s digital signal attached to the given loop.

r3(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

Constructs an event instance around the R 3 button’s digital signal.

Parameters:

loop – the event loop instance to attach the event to.

Returns:

an event instance representing the R 3 button’s digital signal attached to the given loop.

set_leds(r: SupportsInt | SupportsIndex, g: SupportsInt | SupportsIndex, b: SupportsInt | SupportsIndex) None

Set leds on the controller.

Parameters:
  • r – Red value from 0-255

  • g – Green value from 0-255

  • b – Blue value from 0-255

set_rumble(type: wpilib._wpilib.GenericHID.RumbleType, value: SupportsFloat | SupportsIndex) None

Set the rumble output for the HID.

Parameters:
  • type – Which rumble value to set

  • value – The normalized value (0 to 1) to set the rumble to

share(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

square(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

touchpad(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.

triangle(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent

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.