WPILibC++ 2024.3.2
frc::PS4Controller Class Reference

Handle input from PS4 controllers connected to the Driver Station. More...

#include <frc/PS4Controller.h>

Inheritance diagram for frc::PS4Controller:
frc::GenericHID frc2::CommandPS4Controller

Classes

struct  Axis
 Represents an axis on a PS4Controller. More...
 
struct  Button
 Represents a digital button on a PS4Controller. More...
 

Public Member Functions

 PS4Controller (int port)
 Construct an instance of an PS4 controller. More...
 
 ~PS4Controller () override=default
 
 PS4Controller (PS4Controller &&)=default
 
PS4Controlleroperator= (PS4Controller &&)=default
 
double GetLeftX () const
 Get the X axis value of left side of the controller. More...
 
double GetRightX () const
 Get the X axis value of right side of the controller. More...
 
double GetLeftY () const
 Get the Y axis value of left side of the controller. More...
 
double GetRightY () const
 Get the Y axis value of right side of the controller. More...
 
double GetL2Axis () const
 Get the L2 axis value of the controller. More...
 
double GetR2Axis () const
 Get the R2 axis value of the controller. More...
 
bool GetSquareButton () const
 Read the value of the Square button on the controller. More...
 
bool GetSquareButtonPressed ()
 Whether the Square button was pressed since the last check. More...
 
bool GetSquareButtonReleased ()
 Whether the Square button was released since the last check. More...
 
BooleanEvent Square (EventLoop *loop) const
 Constructs an event instance around the square button's digital signal. More...
 
bool GetCrossButton () const
 Read the value of the Cross button on the controller. More...
 
bool GetCrossButtonPressed ()
 Whether the Cross button was pressed since the last check. More...
 
bool GetCrossButtonReleased ()
 Whether the Cross button was released since the last check. More...
 
BooleanEvent Cross (EventLoop *loop) const
 Constructs an event instance around the cross button's digital signal. More...
 
bool GetCircleButton () const
 Read the value of the Circle button on the controller. More...
 
bool GetCircleButtonPressed ()
 Whether the Circle button was pressed since the last check. More...
 
bool GetCircleButtonReleased ()
 Whether the Circle button was released since the last check. More...
 
BooleanEvent Circle (EventLoop *loop) const
 Constructs an event instance around the circle button's digital signal. More...
 
bool GetTriangleButton () const
 Read the value of the Triangle button on the controller. More...
 
bool GetTriangleButtonPressed ()
 Whether the Triangle button was pressed since the last check. More...
 
bool GetTriangleButtonReleased ()
 Whether the Triangle button was released since the last check. More...
 
BooleanEvent Triangle (EventLoop *loop) const
 Constructs an event instance around the triangle button's digital signal. More...
 
bool GetL1Button () const
 Read the value of the L1 button on the controller. More...
 
bool GetL1ButtonPressed ()
 Whether the L1 button was pressed since the last check. More...
 
bool GetL1ButtonReleased ()
 Whether the L1 button was released since the last check. More...
 
BooleanEvent L1 (EventLoop *loop) const
 Constructs an event instance around the L1 button's digital signal. More...
 
bool GetR1Button () const
 Read the value of the R1 button on the controller. More...
 
bool GetR1ButtonPressed ()
 Whether the R1 button was pressed since the last check. More...
 
bool GetR1ButtonReleased ()
 Whether the R1 button was released since the last check. More...
 
BooleanEvent R1 (EventLoop *loop) const
 Constructs an event instance around the R1 button's digital signal. More...
 
bool GetL2Button () const
 Read the value of the L2 button on the controller. More...
 
bool GetL2ButtonPressed ()
 Whether the L2 button was pressed since the last check. More...
 
bool GetL2ButtonReleased ()
 Whether the L2 button was released since the last check. More...
 
BooleanEvent L2 (EventLoop *loop) const
 Constructs an event instance around the L2 button's digital signal. More...
 
bool GetR2Button () const
 Read the value of the R2 button on the controller. More...
 
bool GetR2ButtonPressed ()
 Whether the R2 button was pressed since the last check. More...
 
bool GetR2ButtonReleased ()
 Whether the R2 button was released since the last check. More...
 
BooleanEvent R2 (EventLoop *loop) const
 Constructs an event instance around the R2 button's digital signal. More...
 
bool GetShareButton () const
 Read the value of the Share button on the controller. More...
 
bool GetShareButtonPressed ()
 Whether the Share button was pressed since the last check. More...
 
bool GetShareButtonReleased ()
 Whether the Share button was released since the last check. More...
 
BooleanEvent Share (EventLoop *loop) const
 Constructs an event instance around the share button's digital signal. More...
 
bool GetOptionsButton () const
 Read the value of the Options button on the controller. More...
 
bool GetOptionsButtonPressed ()
 Whether the Options button was pressed since the last check. More...
 
bool GetOptionsButtonReleased ()
 Whether the Options button was released since the last check. More...
 
BooleanEvent Options (EventLoop *loop) const
 Constructs an event instance around the options button's digital signal. More...
 
bool GetL3Button () const
 Read the value of the L3 button (pressing the left analog stick) on the controller. More...
 
bool GetL3ButtonPressed ()
 Whether the L3 (left stick) button was pressed since the last check. More...
 
bool GetL3ButtonReleased ()
 Whether the L3 (left stick) button was released since the last check. More...
 
BooleanEvent L3 (EventLoop *loop) const
 Constructs an event instance around the L3 button's digital signal. More...
 
bool GetR3Button () const
 Read the value of the R3 button (pressing the right analog stick) on the controller. More...
 
bool GetR3ButtonPressed ()
 Whether the R3 (right stick) button was pressed since the last check. More...
 
bool GetR3ButtonReleased ()
 Whether the R3 (right stick) button was released since the last check. More...
 
BooleanEvent R3 (EventLoop *loop) const
 Constructs an event instance around the R3 button's digital signal. More...
 
bool GetPSButton () const
 Read the value of the PS button on the controller. More...
 
bool GetPSButtonPressed ()
 Whether the PS button was pressed since the last check. More...
 
bool GetPSButtonReleased ()
 Whether the PS button was released since the last check. More...
 
BooleanEvent PS (EventLoop *loop) const
 Constructs an event instance around the PS button's digital signal. More...
 
bool GetTouchpad () const
 Read the value of the touchpad button on the controller. More...
 
bool GetTouchpadPressed ()
 Whether the touchpad was pressed since the last check. More...
 
bool GetTouchpadReleased ()
 Whether the touchpad was released since the last check. More...
 
BooleanEvent Touchpad (EventLoop *loop) const
 Constructs an event instance around the touchpad's digital signal. More...
 
- Public Member Functions inherited from frc::GenericHID
 GenericHID (int port)
 
virtual ~GenericHID ()=default
 
 GenericHID (GenericHID &&)=default
 
GenericHIDoperator= (GenericHID &&)=default
 
bool GetRawButton (int button) const
 Get the button value (starting at button 1). More...
 
bool GetRawButtonPressed (int button)
 Whether the button was pressed since the last check. More...
 
bool GetRawButtonReleased (int button)
 Whether the button was released since the last check. More...
 
BooleanEvent Button (int button, EventLoop *loop) const
 Constructs an event instance around this button's digital signal. More...
 
double GetRawAxis (int axis) const
 Get the value of the axis. More...
 
int GetPOV (int pov=0) const
 Get the angle in degrees of a POV on the HID. More...
 
BooleanEvent POV (int angle, EventLoop *loop) const
 Constructs a BooleanEvent instance based around this angle of a POV on the HID. More...
 
BooleanEvent POV (int pov, int angle, EventLoop *loop) const
 Constructs a BooleanEvent instance based around this angle of a POV on the HID. More...
 
BooleanEvent POVUp (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 0 degree angle (up) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVUpRight (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 45 degree angle (right up) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVRight (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 90 degree angle (right) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVDownRight (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 135 degree angle (right down) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVDown (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 180 degree angle (down) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVDownLeft (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 225 degree angle (down left) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVLeft (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 270 degree angle (left) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVUpLeft (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 315 degree angle (left up) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVCenter (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the center (not pressed) of the default (index 0) POV on the HID. More...
 
BooleanEvent AxisLessThan (int axis, double threshold, EventLoop *loop) const
 Constructs an event instance that is true when the axis value is less than threshold. More...
 
BooleanEvent AxisGreaterThan (int axis, double threshold, EventLoop *loop) const
 Constructs an event instance that is true when the axis value is greater than threshold. More...
 
int GetAxisCount () const
 Get the number of axes for the HID. More...
 
int GetPOVCount () const
 Get the number of POVs for the HID. More...
 
int GetButtonCount () const
 Get the number of buttons for the HID. More...
 
bool IsConnected () const
 Get if the HID is connected. More...
 
GenericHID::HIDType GetType () const
 Get the type of the HID. More...
 
std::string GetName () const
 Get the name of the HID. More...
 
int GetAxisType (int axis) const
 Get the axis type of a joystick axis. More...
 
int GetPort () const
 Get the port number of the HID. More...
 
void SetOutput (int outputNumber, bool value)
 Set a single HID output value for the HID. More...
 
void SetOutputs (int value)
 Set all output values for the HID. More...
 
void SetRumble (RumbleType type, double value)
 Set the rumble output for the HID. More...
 

Additional Inherited Members

- Public Types inherited from frc::GenericHID
enum  RumbleType { kLeftRumble , kRightRumble , kBothRumble }
 Represents a rumble output on the Joystick. More...
 
enum  HIDType {
  kUnknown = -1 , kXInputUnknown = 0 , kXInputGamepad = 1 , kXInputWheel = 2 ,
  kXInputArcadeStick = 3 , kXInputFlightStick = 4 , kXInputDancePad = 5 , kXInputGuitar = 6 ,
  kXInputGuitar2 = 7 , kXInputDrumKit = 8 , kXInputGuitar3 = 11 , kXInputArcadePad = 19 ,
  kHIDJoystick = 20 , kHIDGamepad = 21 , kHIDDriving = 22 , kHIDFlight = 23 ,
  kHID1stPerson = 24
}
 USB HID interface type. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ PS4Controller() [1/2]

frc::PS4Controller::PS4Controller ( int  port)
explicit

Construct an instance of an PS4 controller.

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

Parameters
portThe port on the Driver Station that the controller is plugged into (0-5).

◆ ~PS4Controller()

frc::PS4Controller::~PS4Controller ( )
overridedefault

◆ PS4Controller() [2/2]

frc::PS4Controller::PS4Controller ( PS4Controller &&  )
default

Member Function Documentation

◆ Circle()

BooleanEvent frc::PS4Controller::Circle ( EventLoop loop) const

Constructs an event instance around the circle button's digital signal.

Parameters
loopthe 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()

BooleanEvent frc::PS4Controller::Cross ( EventLoop loop) const

Constructs an event instance around the cross button's digital signal.

Parameters
loopthe 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 frc::PS4Controller::GetCircleButton ( ) const

Read the value of the Circle button on the controller.

Returns
The state of the button.

◆ GetCircleButtonPressed()

bool frc::PS4Controller::GetCircleButtonPressed ( )

Whether the Circle button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetCircleButtonReleased()

bool frc::PS4Controller::GetCircleButtonReleased ( )

Whether the Circle button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetCrossButton()

bool frc::PS4Controller::GetCrossButton ( ) const

Read the value of the Cross button on the controller.

Returns
The state of the button.

◆ GetCrossButtonPressed()

bool frc::PS4Controller::GetCrossButtonPressed ( )

Whether the Cross button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetCrossButtonReleased()

bool frc::PS4Controller::GetCrossButtonReleased ( )

Whether the Cross button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetL1Button()

bool frc::PS4Controller::GetL1Button ( ) const

Read the value of the L1 button on the controller.

Returns
The state of the button.

◆ GetL1ButtonPressed()

bool frc::PS4Controller::GetL1ButtonPressed ( )

Whether the L1 button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetL1ButtonReleased()

bool frc::PS4Controller::GetL1ButtonReleased ( )

Whether the L1 button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetL2Axis()

double frc::PS4Controller::GetL2Axis ( ) const

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.

◆ GetL2Button()

bool frc::PS4Controller::GetL2Button ( ) const

Read the value of the L2 button on the controller.

Returns
The state of the button.

◆ GetL2ButtonPressed()

bool frc::PS4Controller::GetL2ButtonPressed ( )

Whether the L2 button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetL2ButtonReleased()

bool frc::PS4Controller::GetL2ButtonReleased ( )

Whether the L2 button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetL3Button()

bool frc::PS4Controller::GetL3Button ( ) const

Read the value of the L3 button (pressing the left analog stick) on the controller.

Returns
The state of the button.

◆ GetL3ButtonPressed()

bool frc::PS4Controller::GetL3ButtonPressed ( )

Whether the L3 (left stick) button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetL3ButtonReleased()

bool frc::PS4Controller::GetL3ButtonReleased ( )

Whether the L3 (left stick) button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetLeftX()

double frc::PS4Controller::GetLeftX ( ) const

Get the X axis value of left side of the controller.

Returns
the axis value.

◆ GetLeftY()

double frc::PS4Controller::GetLeftY ( ) const

Get the Y axis value of left side of the controller.

Returns
the axis value.

◆ GetOptionsButton()

bool frc::PS4Controller::GetOptionsButton ( ) const

Read the value of the Options button on the controller.

Returns
The state of the button.

◆ GetOptionsButtonPressed()

bool frc::PS4Controller::GetOptionsButtonPressed ( )

Whether the Options button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetOptionsButtonReleased()

bool frc::PS4Controller::GetOptionsButtonReleased ( )

Whether the Options button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetPSButton()

bool frc::PS4Controller::GetPSButton ( ) const

Read the value of the PS button on the controller.

Returns
The state of the button.

◆ GetPSButtonPressed()

bool frc::PS4Controller::GetPSButtonPressed ( )

Whether the PS button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetPSButtonReleased()

bool frc::PS4Controller::GetPSButtonReleased ( )

Whether the PS button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetR1Button()

bool frc::PS4Controller::GetR1Button ( ) const

Read the value of the R1 button on the controller.

Returns
The state of the button.

◆ GetR1ButtonPressed()

bool frc::PS4Controller::GetR1ButtonPressed ( )

Whether the R1 button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetR1ButtonReleased()

bool frc::PS4Controller::GetR1ButtonReleased ( )

Whether the R1 button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetR2Axis()

double frc::PS4Controller::GetR2Axis ( ) const

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.

◆ GetR2Button()

bool frc::PS4Controller::GetR2Button ( ) const

Read the value of the R2 button on the controller.

Returns
The state of the button.

◆ GetR2ButtonPressed()

bool frc::PS4Controller::GetR2ButtonPressed ( )

Whether the R2 button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetR2ButtonReleased()

bool frc::PS4Controller::GetR2ButtonReleased ( )

Whether the R2 button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetR3Button()

bool frc::PS4Controller::GetR3Button ( ) const

Read the value of the R3 button (pressing the right analog stick) on the controller.

Returns
The state of the button.

◆ GetR3ButtonPressed()

bool frc::PS4Controller::GetR3ButtonPressed ( )

Whether the R3 (right stick) button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetR3ButtonReleased()

bool frc::PS4Controller::GetR3ButtonReleased ( )

Whether the R3 (right stick) button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetRightX()

double frc::PS4Controller::GetRightX ( ) const

Get the X axis value of right side of the controller.

Returns
the axis value.

◆ GetRightY()

double frc::PS4Controller::GetRightY ( ) const

Get the Y axis value of right side of the controller.

Returns
the axis value.

◆ GetShareButton()

bool frc::PS4Controller::GetShareButton ( ) const

Read the value of the Share button on the controller.

Returns
The state of the button.

◆ GetShareButtonPressed()

bool frc::PS4Controller::GetShareButtonPressed ( )

Whether the Share button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetShareButtonReleased()

bool frc::PS4Controller::GetShareButtonReleased ( )

Whether the Share button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetSquareButton()

bool frc::PS4Controller::GetSquareButton ( ) const

Read the value of the Square button on the controller.

Returns
The state of the button.

◆ GetSquareButtonPressed()

bool frc::PS4Controller::GetSquareButtonPressed ( )

Whether the Square button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetSquareButtonReleased()

bool frc::PS4Controller::GetSquareButtonReleased ( )

Whether the Square button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetTouchpad()

bool frc::PS4Controller::GetTouchpad ( ) const

Read the value of the touchpad button on the controller.

Returns
The state of the button.

◆ GetTouchpadPressed()

bool frc::PS4Controller::GetTouchpadPressed ( )

Whether the touchpad was pressed since the last check.

Returns
Whether the touchpad was pressed since the last check.

◆ GetTouchpadReleased()

bool frc::PS4Controller::GetTouchpadReleased ( )

Whether the touchpad was released since the last check.

Returns
Whether the touchpad was released since the last check.

◆ GetTriangleButton()

bool frc::PS4Controller::GetTriangleButton ( ) const

Read the value of the Triangle button on the controller.

Returns
The state of the button.

◆ GetTriangleButtonPressed()

bool frc::PS4Controller::GetTriangleButtonPressed ( )

Whether the Triangle button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetTriangleButtonReleased()

bool frc::PS4Controller::GetTriangleButtonReleased ( )

Whether the Triangle button was released since the last check.

Returns
Whether the button was released since the last check.

◆ L1()

BooleanEvent frc::PS4Controller::L1 ( EventLoop loop) const

Constructs an event instance around the L1 button's digital signal.

Parameters
loopthe event loop instance to attach the event to.
Returns
an event instance representing the L1 button's digital signal attached to the given loop.

◆ L2()

BooleanEvent frc::PS4Controller::L2 ( EventLoop loop) const

Constructs an event instance around the L2 button's digital signal.

Parameters
loopthe event loop instance to attach the event to.
Returns
an event instance representing the L2 button's digital signal attached to the given loop.

◆ L3()

BooleanEvent frc::PS4Controller::L3 ( EventLoop loop) const

Constructs an event instance around the L3 button's digital signal.

Parameters
loopthe event loop instance to attach the event to.
Returns
an event instance representing the L3 button's digital signal attached to the given loop.

◆ operator=()

PS4Controller & frc::PS4Controller::operator= ( PS4Controller &&  )
default

◆ Options()

BooleanEvent frc::PS4Controller::Options ( EventLoop loop) const

Constructs an event instance around the options button's digital signal.

Parameters
loopthe 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()

BooleanEvent frc::PS4Controller::PS ( EventLoop loop) const

Constructs an event instance around the PS button's digital signal.

Parameters
loopthe 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()

BooleanEvent frc::PS4Controller::R1 ( EventLoop loop) const

Constructs an event instance around the R1 button's digital signal.

Parameters
loopthe event loop instance to attach the event to.
Returns
an event instance representing the R1 button's digital signal attached to the given loop.

◆ R2()

BooleanEvent frc::PS4Controller::R2 ( EventLoop loop) const

Constructs an event instance around the R2 button's digital signal.

Parameters
loopthe event loop instance to attach the event to.
Returns
an event instance representing the R2 button's digital signal attached to the given loop.

◆ R3()

BooleanEvent frc::PS4Controller::R3 ( EventLoop loop) const

Constructs an event instance around the R3 button's digital signal.

Parameters
loopthe event loop instance to attach the event to.
Returns
an event instance representing the R3 button's digital signal attached to the given loop.

◆ Share()

BooleanEvent frc::PS4Controller::Share ( EventLoop loop) const

Constructs an event instance around the share button's digital signal.

Parameters
loopthe 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()

BooleanEvent frc::PS4Controller::Square ( EventLoop loop) const

Constructs an event instance around the square button's digital signal.

Parameters
loopthe 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()

BooleanEvent frc::PS4Controller::Touchpad ( EventLoop loop) const

Constructs an event instance around the touchpad's digital signal.

Parameters
loopthe event loop instance to attach the event to.
Returns
an event instance representing the touchpad's digital signal attached to the given loop.

◆ Triangle()

BooleanEvent frc::PS4Controller::Triangle ( EventLoop loop) const

Constructs an event instance around the triangle button's digital signal.

Parameters
loopthe event loop instance to attach the event to.
Returns
an event instance representing the triangle button's digital signal attached to the given loop.

The documentation for this class was generated from the following file: