WPILibC++ 2025.2.1
|
Handle input from Xbox controllers connected to the Driver Station. More...
#include <frc/XboxController.h>
Classes | |
struct | Axis |
Represents an axis on an XboxController. More... | |
struct | Button |
Represents a digital button on an XboxController. More... | |
Public Member Functions | |
XboxController (int port) | |
Construct an instance of a controller. | |
~XboxController () override=default | |
XboxController (XboxController &&)=default | |
XboxController & | operator= (XboxController &&)=default |
double | GetLeftX () const |
Get the X axis value of left side of the controller. | |
double | GetRightX () const |
Get the X axis value of right side of the controller. | |
double | GetLeftY () const |
Get the Y axis value of left side of the controller. | |
double | GetRightY () const |
Get the Y axis value of right side of the controller. | |
double | GetLeftTriggerAxis () const |
Get the left trigger axis value of the controller. | |
BooleanEvent | LeftTrigger (double threshold, EventLoop *loop) const |
Constructs an event instance around the axis value of the left trigger. | |
BooleanEvent | LeftTrigger (EventLoop *loop) const |
Constructs an event instance around the axis value of the left trigger. | |
double | GetRightTriggerAxis () const |
Get the right trigger axis value of the controller. | |
BooleanEvent | RightTrigger (double threshold, EventLoop *loop) const |
Constructs an event instance around the axis value of the right trigger. | |
BooleanEvent | RightTrigger (EventLoop *loop) const |
Constructs an event instance around the axis value of the right trigger. | |
bool | GetAButton () const |
Read the value of the A button on the controller. | |
bool | GetAButtonPressed () |
Whether the A button was pressed since the last check. | |
bool | GetAButtonReleased () |
Whether the A button was released since the last check. | |
BooleanEvent | A (EventLoop *loop) const |
Constructs an event instance around the A button's digital signal. | |
bool | GetBButton () const |
Read the value of the B button on the controller. | |
bool | GetBButtonPressed () |
Whether the B button was pressed since the last check. | |
bool | GetBButtonReleased () |
Whether the B button was released since the last check. | |
BooleanEvent | B (EventLoop *loop) const |
Constructs an event instance around the B button's digital signal. | |
bool | GetXButton () const |
Read the value of the X button on the controller. | |
bool | GetXButtonPressed () |
Whether the X button was pressed since the last check. | |
bool | GetXButtonReleased () |
Whether the X button was released since the last check. | |
BooleanEvent | X (EventLoop *loop) const |
Constructs an event instance around the X button's digital signal. | |
bool | GetYButton () const |
Read the value of the Y button on the controller. | |
bool | GetYButtonPressed () |
Whether the Y button was pressed since the last check. | |
bool | GetYButtonReleased () |
Whether the Y button was released since the last check. | |
BooleanEvent | Y (EventLoop *loop) const |
Constructs an event instance around the Y button's digital signal. | |
bool | GetLeftBumperButton () const |
Read the value of the left bumper button on the controller. | |
bool | GetLeftBumperButtonPressed () |
Whether the left bumper button was pressed since the last check. | |
bool | GetLeftBumperButtonReleased () |
Whether the left bumper button was released since the last check. | |
BooleanEvent | LeftBumper (EventLoop *loop) const |
Constructs an event instance around the left bumper button's digital signal. | |
bool | GetRightBumperButton () const |
Read the value of the right bumper button on the controller. | |
bool | GetRightBumperButtonPressed () |
Whether the right bumper button was pressed since the last check. | |
bool | GetRightBumperButtonReleased () |
Whether the right bumper button was released since the last check. | |
BooleanEvent | RightBumper (EventLoop *loop) const |
Constructs an event instance around the right bumper button's digital signal. | |
bool | GetBackButton () const |
Read the value of the back button on the controller. | |
bool | GetBackButtonPressed () |
Whether the back button was pressed since the last check. | |
bool | GetBackButtonReleased () |
Whether the back button was released since the last check. | |
BooleanEvent | Back (EventLoop *loop) const |
Constructs an event instance around the back button's digital signal. | |
bool | GetStartButton () const |
Read the value of the start button on the controller. | |
bool | GetStartButtonPressed () |
Whether the start button was pressed since the last check. | |
bool | GetStartButtonReleased () |
Whether the start button was released since the last check. | |
BooleanEvent | Start (EventLoop *loop) const |
Constructs an event instance around the start button's digital signal. | |
bool | GetLeftStickButton () const |
Read the value of the left stick button on the controller. | |
bool | GetLeftStickButtonPressed () |
Whether the left stick button was pressed since the last check. | |
bool | GetLeftStickButtonReleased () |
Whether the left stick button was released since the last check. | |
BooleanEvent | LeftStick (EventLoop *loop) const |
Constructs an event instance around the left stick button's digital signal. | |
bool | GetRightStickButton () const |
Read the value of the right stick button on the controller. | |
bool | GetRightStickButtonPressed () |
Whether the right stick button was pressed since the last check. | |
bool | GetRightStickButtonReleased () |
Whether the right stick button was released since the last check. | |
BooleanEvent | RightStick (EventLoop *loop) const |
Constructs an event instance around the right stick button's digital signal. | |
bool | GetLeftBumper () const |
Read the value of the left bumper (LB) button on the controller. | |
bool | GetRightBumper () const |
Read the value of the right bumper (RB) button on the controller. | |
bool | GetLeftBumperPressed () |
Whether the left bumper (LB) was pressed since the last check. | |
bool | GetRightBumperPressed () |
Whether the right bumper (RB) was pressed since the last check. | |
bool | GetLeftBumperReleased () |
Whether the left bumper (LB) was released since the last check. | |
bool | GetRightBumperReleased () |
Whether the right bumper (RB) was released since the last check. | |
void | InitSendable (wpi::SendableBuilder &builder) override |
Initializes this Sendable object. | |
Public Member Functions inherited from frc::GenericHID | |
GenericHID (int port) | |
virtual | ~GenericHID ()=default |
GenericHID (GenericHID &&)=default | |
GenericHID & | operator= (GenericHID &&)=default |
bool | GetRawButton (int button) const |
Get the button value (starting at button 1). | |
bool | GetRawButtonPressed (int button) |
Whether the button was pressed since the last check. | |
bool | GetRawButtonReleased (int button) |
Whether the button was released since the last check. | |
BooleanEvent | Button (int button, EventLoop *loop) const |
Constructs an event instance around this button's digital signal. | |
double | GetRawAxis (int axis) const |
Get the value of the axis. | |
int | GetPOV (int pov=0) const |
Get the angle in degrees of a POV on the HID. | |
BooleanEvent | POV (int angle, EventLoop *loop) const |
Constructs a BooleanEvent instance based around this angle of a POV on the HID. | |
BooleanEvent | POV (int pov, int angle, EventLoop *loop) const |
Constructs a BooleanEvent instance based around this angle of a POV on the HID. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
BooleanEvent | POVCenter (EventLoop *loop) const |
Constructs a BooleanEvent instance based around the center (not pressed) of the default (index 0) POV on the HID. | |
BooleanEvent | AxisLessThan (int axis, double threshold, EventLoop *loop) const |
Constructs an event instance that is true when the axis value is less than threshold. | |
BooleanEvent | AxisGreaterThan (int axis, double threshold, EventLoop *loop) const |
Constructs an event instance that is true when the axis value is greater than threshold. | |
int | GetAxisCount () const |
Get the number of axes for the HID. | |
int | GetPOVCount () const |
Get the number of POVs for the HID. | |
int | GetButtonCount () const |
Get the number of buttons for the HID. | |
bool | IsConnected () const |
Get if the HID is connected. | |
GenericHID::HIDType | GetType () const |
Get the type of the HID. | |
std::string | GetName () const |
Get the name of the HID. | |
int | GetAxisType (int axis) const |
Get the axis type of a joystick axis. | |
int | GetPort () const |
Get the port number of the HID. | |
void | SetOutput (int outputNumber, bool value) |
Set a single HID output value for the HID. | |
void | SetOutputs (int value) |
Set all output values for the HID. | |
void | SetRumble (RumbleType type, double value) |
Set the rumble output for the HID. | |
Public Member Functions inherited from wpi::Sendable | |
virtual constexpr | ~Sendable ()=default |
Public Member Functions inherited from wpi::SendableHelper< XboxController > | |
constexpr | SendableHelper (const SendableHelper &rhs)=default |
constexpr | SendableHelper (SendableHelper &&rhs) |
constexpr SendableHelper & | operator= (const SendableHelper &rhs)=default |
constexpr SendableHelper & | operator= (SendableHelper &&rhs) |
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... | |
Protected Member Functions inherited from wpi::SendableHelper< XboxController > | |
constexpr | SendableHelper ()=default |
constexpr | ~SendableHelper () |
Handle input from Xbox 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.
Only first party controllers from Microsoft 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.
|
explicit |
Construct an instance of a controller.
The controller index is the USB port on the Driver Station.
port | The port on the Driver Station that the controller is plugged into (0-5). |
|
overridedefault |
|
default |
BooleanEvent frc::XboxController::A | ( | EventLoop * | loop | ) | const |
Constructs an event instance around the A button's digital signal.
loop | the event loop instance to attach the event to. |
BooleanEvent frc::XboxController::B | ( | EventLoop * | loop | ) | const |
Constructs an event instance around the B button's digital signal.
loop | the event loop instance to attach the event to. |
BooleanEvent frc::XboxController::Back | ( | EventLoop * | loop | ) | const |
Constructs an event instance around the back button's digital signal.
loop | the event loop instance to attach the event to. |
bool frc::XboxController::GetAButton | ( | ) | const |
Read the value of the A button on the controller.
bool frc::XboxController::GetAButtonPressed | ( | ) |
Whether the A button was pressed since the last check.
bool frc::XboxController::GetAButtonReleased | ( | ) |
Whether the A button was released since the last check.
bool frc::XboxController::GetBackButton | ( | ) | const |
Read the value of the back button on the controller.
bool frc::XboxController::GetBackButtonPressed | ( | ) |
Whether the back button was pressed since the last check.
bool frc::XboxController::GetBackButtonReleased | ( | ) |
Whether the back button was released since the last check.
bool frc::XboxController::GetBButton | ( | ) | const |
Read the value of the B button on the controller.
bool frc::XboxController::GetBButtonPressed | ( | ) |
Whether the B button was pressed since the last check.
bool frc::XboxController::GetBButtonReleased | ( | ) |
Whether the B button was released since the last check.
bool frc::XboxController::GetLeftBumper | ( | ) | const |
Read the value of the left bumper (LB) button on the controller.
bool frc::XboxController::GetLeftBumperButton | ( | ) | const |
Read the value of the left bumper button on the controller.
bool frc::XboxController::GetLeftBumperButtonPressed | ( | ) |
Whether the left bumper button was pressed since the last check.
bool frc::XboxController::GetLeftBumperButtonReleased | ( | ) |
Whether the left bumper button was released since the last check.
bool frc::XboxController::GetLeftBumperPressed | ( | ) |
Whether the left bumper (LB) was pressed since the last check.
bool frc::XboxController::GetLeftBumperReleased | ( | ) |
Whether the left bumper (LB) was released since the last check.
bool frc::XboxController::GetLeftStickButton | ( | ) | const |
Read the value of the left stick button on the controller.
bool frc::XboxController::GetLeftStickButtonPressed | ( | ) |
Whether the left stick button was pressed since the last check.
bool frc::XboxController::GetLeftStickButtonReleased | ( | ) |
Whether the left stick button was released since the last check.
double frc::XboxController::GetLeftTriggerAxis | ( | ) | const |
Get the left trigger axis value of the controller.
Note that this axis is bound to the range of [0, 1] as opposed to the usual [-1, 1].
double frc::XboxController::GetLeftX | ( | ) | const |
Get the X axis value of left side of the controller.
double frc::XboxController::GetLeftY | ( | ) | const |
Get the Y axis value of left side of the controller.
bool frc::XboxController::GetRightBumper | ( | ) | const |
Read the value of the right bumper (RB) button on the controller.
bool frc::XboxController::GetRightBumperButton | ( | ) | const |
Read the value of the right bumper button on the controller.
bool frc::XboxController::GetRightBumperButtonPressed | ( | ) |
Whether the right bumper button was pressed since the last check.
bool frc::XboxController::GetRightBumperButtonReleased | ( | ) |
Whether the right bumper button was released since the last check.
bool frc::XboxController::GetRightBumperPressed | ( | ) |
Whether the right bumper (RB) was pressed since the last check.
bool frc::XboxController::GetRightBumperReleased | ( | ) |
Whether the right bumper (RB) was released since the last check.
bool frc::XboxController::GetRightStickButton | ( | ) | const |
Read the value of the right stick button on the controller.
bool frc::XboxController::GetRightStickButtonPressed | ( | ) |
Whether the right stick button was pressed since the last check.
bool frc::XboxController::GetRightStickButtonReleased | ( | ) |
Whether the right stick button was released since the last check.
double frc::XboxController::GetRightTriggerAxis | ( | ) | const |
Get the right trigger axis value of the controller.
Note that this axis is bound to the range of [0, 1] as opposed to the usual [-1, 1].
double frc::XboxController::GetRightX | ( | ) | const |
Get the X axis value of right side of the controller.
double frc::XboxController::GetRightY | ( | ) | const |
Get the Y axis value of right side of the controller.
bool frc::XboxController::GetStartButton | ( | ) | const |
Read the value of the start button on the controller.
bool frc::XboxController::GetStartButtonPressed | ( | ) |
Whether the start button was pressed since the last check.
bool frc::XboxController::GetStartButtonReleased | ( | ) |
Whether the start button was released since the last check.
bool frc::XboxController::GetXButton | ( | ) | const |
Read the value of the X button on the controller.
bool frc::XboxController::GetXButtonPressed | ( | ) |
Whether the X button was pressed since the last check.
bool frc::XboxController::GetXButtonReleased | ( | ) |
Whether the X button was released since the last check.
bool frc::XboxController::GetYButton | ( | ) | const |
Read the value of the Y button on the controller.
bool frc::XboxController::GetYButtonPressed | ( | ) |
Whether the Y button was pressed since the last check.
bool frc::XboxController::GetYButtonReleased | ( | ) |
Whether the Y button was released since the last check.
|
overridevirtual |
BooleanEvent frc::XboxController::LeftBumper | ( | EventLoop * | loop | ) | const |
Constructs an event instance around the left bumper button's digital signal.
loop | the event loop instance to attach the event to. |
BooleanEvent frc::XboxController::LeftStick | ( | EventLoop * | loop | ) | const |
Constructs an event instance around the left stick button's digital signal.
loop | the event loop instance to attach the event to. |
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
.
threshold | the 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. |
loop | the event loop instance to attach the event to. |
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.
loop | the event loop instance to attach the event to. |
|
default |
BooleanEvent frc::XboxController::RightBumper | ( | EventLoop * | loop | ) | const |
Constructs an event instance around the right bumper button's digital signal.
loop | the event loop instance to attach the event to. |
BooleanEvent frc::XboxController::RightStick | ( | EventLoop * | loop | ) | const |
Constructs an event instance around the right stick button's digital signal.
loop | the event loop instance to attach the event to. |
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
.
threshold | the 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. |
loop | the event loop instance to attach the event to. |
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.
loop | the event loop instance to attach the event to. |
BooleanEvent frc::XboxController::Start | ( | EventLoop * | loop | ) | const |
Constructs an event instance around the start button's digital signal.
loop | the event loop instance to attach the event to. |
BooleanEvent frc::XboxController::X | ( | EventLoop * | loop | ) | const |
Constructs an event instance around the X button's digital signal.
loop | the event loop instance to attach the event to. |
BooleanEvent frc::XboxController::Y | ( | EventLoop * | loop | ) | const |
Constructs an event instance around the Y button's digital signal.
loop | the event loop instance to attach the event to. |