PS4Controller
- class wpilib.PS4Controller(port: int)
Bases:
GenericHID
,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.
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 (0-5).
- class Axis
Bases:
pybind11_object
Represents an axis on an PS4Controller.
- kL2 = 3
- kLeftX = 0
- kLeftY = 1
- kR2 = 4
- kRightX = 2
- kRightY = 5
- class Button
Bases:
pybind11_object
Represents a digital button on an PS4Controller.
- kCircle = 3
- kCross = 2
- kL1 = 5
- kL2 = 7
- kL3 = 11
- kOptions = 10
- kPS = 13
- kR1 = 6
- kR2 = 8
- kR3 = 12
- kSquare = 1
- kTouchpad = 14
- kTriangle = 4
- L1(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent
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.
- L2(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent
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.
- L3(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent
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.
- PS(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent
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.
- R1(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent
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.
- R2(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent
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.
- R3(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent
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.
- circle(loop: wpilib.event._event.EventLoop) wpilib.event._event.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.event._event.EventLoop) wpilib.event._event.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.
- getCircleButton() bool
Read the value of the circle button on the controller.
- Returns:
The state of the button.
- getCircleButtonPressed() bool
Whether the circle button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- getCircleButtonReleased() bool
Whether the circle button was released since the last check.
- Returns:
Whether the button was released since the last check.
- getCrossButton() bool
Read the value of the cross button on the controller.
- Returns:
The state of the button.
- getCrossButtonPressed() bool
Whether the cross button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- getCrossButtonReleased() bool
Whether the cross button was released since the last check.
- Returns:
Whether the button was released since the last check.
- getL1Button() bool
Read the value of the left trigger 1 button on the controller.
- Returns:
The state of the button.
- getL1ButtonPressed() bool
Whether the left trigger 1 button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- getL1ButtonReleased() bool
Whether the left trigger 1 button was released since the last check.
- Returns:
Whether the button was released since the last check.
- getL2Axis() float
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.
- getL2Button() bool
Read the value of the left trigger 2 button on the controller.
- Returns:
The state of the button.
- getL2ButtonPressed() bool
Whether the left trigger 2 button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- getL2ButtonReleased() bool
Whether the left trigger 2 button was released since the last check.
- Returns:
Whether the button was released since the last check.
- getL3Button() bool
Read the value of the L3 (left stick) button on the controller.
- Returns:
The state of the button.
- getL3ButtonPressed() bool
Whether the L3 (left stick) button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- getL3ButtonReleased() bool
Whether the L3 (left stick) button was released since the last check.
- Returns:
Whether the button was released since the last check.
- getLeftX() float
Get the X axis value of left side of the controller. Right is positive.
- Returns:
the axis value.
- getLeftY() float
Get the Y axis value of left side of the controller. Back is positive.
- Returns:
the axis value.
- getOptionsButton() bool
Read the value of the options button on the controller.
- Returns:
The state of the button.
- getOptionsButtonPressed() bool
Whether the options button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- getOptionsButtonReleased() bool
Whether the options button was released since the last check.
- Returns:
Whether the button was released since the last check.
- getPSButton() bool
Read the value of the PlayStation button on the controller.
- Returns:
The state of the button.
- getPSButtonPressed() bool
Whether the PlayStation button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- getPSButtonReleased() bool
Whether the PlayStation button was released since the last check.
- Returns:
Whether the button was released since the last check.
- getR1Button() bool
Read the value of the right trigger 1 button on the controller.
- Returns:
The state of the button.
- getR1ButtonPressed() bool
Whether the right trigger 1 button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- getR1ButtonReleased() bool
Whether the right trigger 1 button was released since the last check.
- Returns:
Whether the button was released since the last check.
- getR2Axis() float
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.
- getR2Button() bool
Read the value of the right trigger 2 button on the controller.
- Returns:
The state of the button.
- getR2ButtonPressed() bool
Whether the right trigger 2 button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- getR2ButtonReleased() bool
Whether the right trigger 2 button was released since the last check.
- Returns:
Whether the button was released since the last check.
- getR3Button() bool
Read the value of the R3 (right stick) button on the controller.
- Returns:
The state of the button.
- getR3ButtonPressed() bool
Whether the R3 (right stick) button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- getR3ButtonReleased() bool
Whether the R3 (right stick) button was released since the last check.
- Returns:
Whether the button was released since the last check.
- getRightX() float
Get the X axis value of right side of the controller. Right is positive.
- Returns:
the axis value.
- getRightY() float
Get the Y axis value of right side of the controller. Back is positive.
- Returns:
the axis value.
Read the value of the share button on the controller.
- Returns:
The state of the button.
Whether the share button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
Whether the share button was released since the last check.
- Returns:
Whether the button was released since the last check.
- getSquareButton() bool
Read the value of the square button on the controller.
- Returns:
The state of the button.
- getSquareButtonPressed() bool
Whether the square button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- getSquareButtonReleased() bool
Whether the square button was released since the last check.
- Returns:
Whether the button was released since the last check.
- getTouchpad() bool
Read the value of the touchpad button on the controller.
- Deprecated:
Use GetTouchpadButton instead. This function is deprecated for removal to make function names consistent to allow the HID classes to be automatically generated.
- Returns:
The state of the button.
- getTouchpadButton() bool
Read the value of the touchpad button on the controller.
- Returns:
The state of the button.
- getTouchpadButtonPressed() bool
Whether the touchpad button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- getTouchpadButtonReleased() bool
Whether the touchpad button was released since the last check.
- Returns:
Whether the button was released since the last check.
- getTouchpadPressed() bool
Whether the touchpad was pressed since the last check.
- Deprecated:
Use GetTouchpadButtonPressed instead. This function is deprecated for removal to make function names consistent to allow the HID classes to be automatically generated.
- Returns:
Whether the touchpad was pressed since the last check.
- getTouchpadReleased() bool
Whether the touchpad was released since the last check.
- Deprecated:
Use GetLeftBumperButton instead. This function is deprecated for removal to make function names consistent to allow the HID classes to be automatically generated.
- Returns:
Whether the touchpad was released since the last check.
- getTriangleButton() bool
Read the value of the triangle button on the controller.
- Returns:
The state of the button.
- getTriangleButtonPressed() bool
Whether the triangle button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- getTriangleButtonReleased() bool
Whether the triangle button was released since the last check.
- Returns:
Whether the button was released since the last check.
- initSendable(builder: wpiutil._wpiutil.SendableBuilder) None
- options(loop: wpilib.event._event.EventLoop) wpilib.event._event.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.
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.event._event.EventLoop) wpilib.event._event.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.event._event.EventLoop) wpilib.event._event.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.event._event.EventLoop) wpilib.event._event.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.