WPILibC++ 2023.4.3
frc::XboxController Class Reference

Handle input from Xbox 360 or Xbox One controllers connected to the Driver Station. More...

#include <frc/XboxController.h>

Inheritance diagram for frc::XboxController:
frc::GenericHID frc2::CommandXboxController

Classes

struct  Axis
 
struct  Button
 

Public Member Functions

 XboxController (int port)
 Construct an instance of an Xbox controller. More...
 
 ~XboxController () override=default
 
 XboxController (XboxController &&)=default
 
XboxControlleroperator= (XboxController &&)=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 GetLeftTriggerAxis () const
 Get the left trigger (LT) axis value of the controller. More...
 
double GetRightTriggerAxis () const
 Get the right trigger (RT) axis value of the controller. More...
 
bool GetLeftBumper () const
 Read the value of the left bumper (LB) button on the controller. More...
 
bool GetRightBumper () const
 Read the value of the right bumper (RB) button on the controller. More...
 
bool GetLeftBumperPressed ()
 Whether the left bumper (LB) was pressed since the last check. More...
 
bool GetRightBumperPressed ()
 Whether the right bumper (RB) was pressed since the last check. More...
 
bool GetLeftBumperReleased ()
 Whether the left bumper (LB) was released since the last check. More...
 
bool GetRightBumperReleased ()
 Whether the right bumper (RB) was released since the last check. More...
 
BooleanEvent LeftBumper (EventLoop *loop) const
 Constructs an event instance around the left bumper's digital signal. More...
 
BooleanEvent RightBumper (EventLoop *loop) const
 Constructs an event instance around the right bumper's digital signal. More...
 
bool GetLeftStickButton () const
 Read the value of the left stick button (LSB) on the controller. More...
 
bool GetRightStickButton () const
 Read the value of the right stick button (RSB) on the controller. More...
 
bool GetLeftStickButtonPressed ()
 Whether the left stick button (LSB) was pressed since the last check. More...
 
bool GetRightStickButtonPressed ()
 Whether the right stick button (RSB) was pressed since the last check. More...
 
bool GetLeftStickButtonReleased ()
 Whether the left stick button (LSB) was released since the last check. More...
 
bool GetRightStickButtonReleased ()
 Whether the right stick button (RSB) was released since the last check. More...
 
BooleanEvent LeftStick (EventLoop *loop) const
 Constructs an event instance around the left stick's digital signal. More...
 
BooleanEvent RightStick (EventLoop *loop) const
 Constructs an event instance around the right stick's digital signal. More...
 
bool GetAButton () const
 Read the value of the A button on the controller. More...
 
bool GetAButtonPressed ()
 Whether the A button was pressed since the last check. More...
 
bool GetAButtonReleased ()
 Whether the A button was released since the last check. More...
 
BooleanEvent A (EventLoop *loop) const
 Constructs an event instance around the A button's digital signal. More...
 
bool GetBButton () const
 Read the value of the B button on the controller. More...
 
bool GetBButtonPressed ()
 Whether the B button was pressed since the last check. More...
 
bool GetBButtonReleased ()
 Whether the B button was released since the last check. More...
 
BooleanEvent B (EventLoop *loop) const
 Constructs an event instance around the B button's digital signal. More...
 
bool GetXButton () const
 Read the value of the X button on the controller. More...
 
bool GetXButtonPressed ()
 Whether the X button was pressed since the last check. More...
 
bool GetXButtonReleased ()
 Whether the X button was released since the last check. More...
 
BooleanEvent X (EventLoop *loop) const
 Constructs an event instance around the X button's digital signal. More...
 
bool GetYButton () const
 Read the value of the Y button on the controller. More...
 
bool GetYButtonPressed ()
 Whether the Y button was pressed since the last check. More...
 
bool GetYButtonReleased ()
 Whether the Y button was released since the last check. More...
 
BooleanEvent Y (EventLoop *loop) const
 Constructs an event instance around the Y button's digital signal. More...
 
bool GetBackButton () const
 Read the value of the back button on the controller. More...
 
bool GetBackButtonPressed ()
 Whether the back button was pressed since the last check. More...
 
bool GetBackButtonReleased ()
 Whether the back button was released since the last check. More...
 
BooleanEvent Back (EventLoop *loop) const
 Constructs an event instance around the back button's digital signal. More...
 
bool GetStartButton () const
 Read the value of the start button on the controller. More...
 
bool GetStartButtonPressed ()
 Whether the start button was pressed since the last check. More...
 
bool GetStartButtonReleased ()
 Whether the start button was released since the last check. More...
 
BooleanEvent Start (EventLoop *loop) const
 Constructs an event instance around the start button's digital signal. More...
 
BooleanEvent LeftTrigger (double threshold, EventLoop *loop) const
 Constructs an event instance around the axis value of the left trigger. More...
 
BooleanEvent LeftTrigger (EventLoop *loop) const
 Constructs an event instance around the axis value of the left trigger. More...
 
BooleanEvent RightTrigger (double threshold, EventLoop *loop) const
 Constructs an event instance around the axis value of the right trigger. More...
 
BooleanEvent RightTrigger (EventLoop *loop) const
 Constructs an event instance around the axis value of the right trigger. 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 }
 
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
}
 

Detailed Description

Handle input from Xbox 360 or Xbox One controllers connected to the Driver Station.

This class handles Xbox 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.

Constructor & Destructor Documentation

◆ XboxController() [1/2]

frc::XboxController::XboxController ( int  port)
explicit

Construct an instance of an Xbox 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).

◆ ~XboxController()

frc::XboxController::~XboxController ( )
overridedefault

◆ XboxController() [2/2]

frc::XboxController::XboxController ( XboxController &&  )
default

Member Function Documentation

◆ A()

BooleanEvent frc::XboxController::A ( EventLoop loop) const

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

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

◆ B()

BooleanEvent frc::XboxController::B ( EventLoop loop) const

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

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

◆ Back()

BooleanEvent frc::XboxController::Back ( EventLoop loop) const

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

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

◆ GetAButton()

bool frc::XboxController::GetAButton ( ) const

Read the value of the A button on the controller.

Returns
The state of the button.

◆ GetAButtonPressed()

bool frc::XboxController::GetAButtonPressed ( )

Whether the A button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetAButtonReleased()

bool frc::XboxController::GetAButtonReleased ( )

Whether the A button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetBackButton()

bool frc::XboxController::GetBackButton ( ) const

Read the value of the back button on the controller.

Returns
The state of the button.

◆ GetBackButtonPressed()

bool frc::XboxController::GetBackButtonPressed ( )

Whether the back button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetBackButtonReleased()

bool frc::XboxController::GetBackButtonReleased ( )

Whether the back button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetBButton()

bool frc::XboxController::GetBButton ( ) const

Read the value of the B button on the controller.

Returns
The state of the button.

◆ GetBButtonPressed()

bool frc::XboxController::GetBButtonPressed ( )

Whether the B button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetBButtonReleased()

bool frc::XboxController::GetBButtonReleased ( )

Whether the B button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetLeftBumper()

bool frc::XboxController::GetLeftBumper ( ) const

Read the value of the left bumper (LB) button on the controller.

◆ GetLeftBumperPressed()

bool frc::XboxController::GetLeftBumperPressed ( )

Whether the left bumper (LB) was pressed since the last check.

◆ GetLeftBumperReleased()

bool frc::XboxController::GetLeftBumperReleased ( )

Whether the left bumper (LB) was released since the last check.

◆ GetLeftStickButton()

bool frc::XboxController::GetLeftStickButton ( ) const

Read the value of the left stick button (LSB) on the controller.

◆ GetLeftStickButtonPressed()

bool frc::XboxController::GetLeftStickButtonPressed ( )

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

◆ GetLeftStickButtonReleased()

bool frc::XboxController::GetLeftStickButtonReleased ( )

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

◆ GetLeftTriggerAxis()

double frc::XboxController::GetLeftTriggerAxis ( ) const

Get the left trigger (LT) axis value of the controller.

Note that this axis is bound to the range of [0, 1] as opposed to the usual [-1, 1].

◆ GetLeftX()

double frc::XboxController::GetLeftX ( ) const

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

◆ GetLeftY()

double frc::XboxController::GetLeftY ( ) const

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

◆ GetRightBumper()

bool frc::XboxController::GetRightBumper ( ) const

Read the value of the right bumper (RB) button on the controller.

◆ GetRightBumperPressed()

bool frc::XboxController::GetRightBumperPressed ( )

Whether the right bumper (RB) was pressed since the last check.

◆ GetRightBumperReleased()

bool frc::XboxController::GetRightBumperReleased ( )

Whether the right bumper (RB) was released since the last check.

◆ GetRightStickButton()

bool frc::XboxController::GetRightStickButton ( ) const

Read the value of the right stick button (RSB) on the controller.

◆ GetRightStickButtonPressed()

bool frc::XboxController::GetRightStickButtonPressed ( )

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

◆ GetRightStickButtonReleased()

bool frc::XboxController::GetRightStickButtonReleased ( )

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

◆ GetRightTriggerAxis()

double frc::XboxController::GetRightTriggerAxis ( ) const

Get the right trigger (RT) axis value of the controller.

Note that this axis is bound to the range of [0, 1] as opposed to the usual [-1, 1].

◆ GetRightX()

double frc::XboxController::GetRightX ( ) const

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

◆ GetRightY()

double frc::XboxController::GetRightY ( ) const

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

◆ GetStartButton()

bool frc::XboxController::GetStartButton ( ) const

Read the value of the start button on the controller.

Returns
The state of the button.

◆ GetStartButtonPressed()

bool frc::XboxController::GetStartButtonPressed ( )

Whether the start button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetStartButtonReleased()

bool frc::XboxController::GetStartButtonReleased ( )

Whether the start button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetXButton()

bool frc::XboxController::GetXButton ( ) const

Read the value of the X button on the controller.

Returns
The state of the button.

◆ GetXButtonPressed()

bool frc::XboxController::GetXButtonPressed ( )

Whether the X button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetXButtonReleased()

bool frc::XboxController::GetXButtonReleased ( )

Whether the X button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetYButton()

bool frc::XboxController::GetYButton ( ) const

Read the value of the Y button on the controller.

Returns
The state of the button.

◆ GetYButtonPressed()

bool frc::XboxController::GetYButtonPressed ( )

Whether the Y button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetYButtonReleased()

bool frc::XboxController::GetYButtonReleased ( )

Whether the Y button was released since the last check.

Returns
Whether the button was released since the last check.

◆ LeftBumper()

BooleanEvent frc::XboxController::LeftBumper ( EventLoop loop) const

Constructs an event instance around the left bumper's digital signal.

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

◆ LeftStick()

BooleanEvent frc::XboxController::LeftStick ( EventLoop loop) const

Constructs an event instance around the left stick's digital signal.

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

◆ LeftTrigger() [1/2]

BooleanEvent frc::XboxController::LeftTrigger ( double  threshold,
EventLoop loop 
) const

Constructs an event instance around the axis value of the left trigger.

The returned trigger will be true when the axis value is greater than
threshold
.

Parameters
thresholdthe minimum axis value for the returned event to be true. This value should be in the range [0, 1] where 0 is the unpressed state of the axis.
loopthe event loop instance to attach the event to.
Returns
an event instance that is true when the left trigger's axis exceeds the provided threshold, attached to the given event loop

◆ LeftTrigger() [2/2]

BooleanEvent frc::XboxController::LeftTrigger ( EventLoop loop) const

Constructs an event instance around the axis value of the left trigger.

The returned trigger will be true when the axis value is greater than 0.5.

Parameters
loopthe event loop instance to attach the event to.
Returns
an event instance that is true when the left trigger's axis exceeds 0.5, attached to the given event loop

◆ operator=()

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

◆ RightBumper()

BooleanEvent frc::XboxController::RightBumper ( EventLoop loop) const

Constructs an event instance around the right bumper's digital signal.

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

◆ RightStick()

BooleanEvent frc::XboxController::RightStick ( EventLoop loop) const

Constructs an event instance around the right stick's digital signal.

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

◆ RightTrigger() [1/2]

BooleanEvent frc::XboxController::RightTrigger ( double  threshold,
EventLoop loop 
) const

Constructs an event instance around the axis value of the right trigger.

The returned trigger will be true when the axis value is greater than threshold.

Parameters
thresholdthe minimum axis value for the returned event to be true. This value should be in the range [0, 1] where 0 is the unpressed state of the axis.
loopthe event loop instance to attach the event to.
Returns
an event instance that is true when the right trigger's axis exceeds the provided threshold, attached to the given event loop

◆ RightTrigger() [2/2]

BooleanEvent frc::XboxController::RightTrigger ( EventLoop loop) const

Constructs an event instance around the axis value of the right trigger.

The returned trigger will be true when the axis value is greater than 0.5.

Parameters
loopthe event loop instance to attach the event to.
Returns
an event instance that is true when the right trigger's axis exceeds 0.5, attached to the given event loop

◆ Start()

BooleanEvent frc::XboxController::Start ( EventLoop loop) const

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

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

◆ X()

BooleanEvent frc::XboxController::X ( EventLoop loop) const

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

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

◆ Y()

BooleanEvent frc::XboxController::Y ( EventLoop loop) const

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

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

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