XboxController

class wpilib.XboxController(port: int)

Bases: GenericHID, Sendable

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.

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).

A(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent

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

Parameters:

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

Returns:

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

class Axis

Bases: pybind11_object

Represents an axis on an XboxController.

kLeftTrigger = 2
kLeftX = 0
kLeftY = 1
kRightTrigger = 3
kRightX = 4
kRightY = 5
B(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent

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

Parameters:

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

Returns:

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

class Button

Bases: pybind11_object

Represents a digital button on an XboxController.

kA = 1
kB = 2
kBack = 7
kLeftBumper = 5
kLeftStick = 9
kRightBumper = 6
kRightStick = 10
kStart = 8
kX = 3
kY = 4
X(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent

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

Parameters:

loop – the 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(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent

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

Parameters:

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

Returns:

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

back(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent

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

Parameters:

loop – the 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

Read the value of the A button on the controller.

Returns:

The state of the button.

getAButtonPressed() bool

Whether the A button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

getAButtonReleased() bool

Whether the A button was released since the last check.

Returns:

Whether the button was released since the last check.

getBButton() bool

Read the value of the B button on the controller.

Returns:

The state of the button.

getBButtonPressed() bool

Whether the B button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

getBButtonReleased() bool

Whether the B button was released since the last check.

Returns:

Whether the button was released since the last check.

getBackButton() bool

Read the value of the back button on the controller.

Returns:

The state of the button.

getBackButtonPressed() bool

Whether the back button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

getBackButtonReleased() bool

Whether the back button was released since the last check.

Returns:

Whether the button was released since the last check.

getLeftBumper() bool

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

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:

the state of the button

getLeftBumperButton() bool

Read the value of the left bumper button on the controller.

Returns:

The state of the button.

getLeftBumperButtonPressed() bool

Whether the left bumper button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

getLeftBumperButtonReleased() bool

Whether the left bumper button was released since the last check.

Returns:

Whether the button was released since the last check.

getLeftBumperPressed() bool

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

Deprecated:

Use GetLeftBumperButtonPressed instead. This function is deprecated for removal to make function names consistent to allow the HID classes to be automatically generated.

Returns:

Whether the button was pressed since the last check

getLeftBumperReleased() bool

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

Deprecated:

Use GetLeftBumperButtonReleased instead. This function is deprecated for removal to make function names consistent to allow the HID classes to be automatically generated.

Returns:

Whether the button was released since the last check.

getLeftStickButton() bool

Read the value of the left stick button on the controller.

Returns:

The state of the button.

getLeftStickButtonPressed() bool

Whether the left stick button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

getLeftStickButtonReleased() bool

Whether the left stick button was released since the last check.

Returns:

Whether the button was released since the last check.

getLeftTriggerAxis() float

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].

Returns:

the axis value.

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.

getRightBumper() bool

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

Deprecated:

Use GetRightBumperButton 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

getRightBumperButton() bool

Read the value of the right bumper button on the controller.

Returns:

The state of the button.

getRightBumperButtonPressed() bool

Whether the right bumper button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

getRightBumperButtonReleased() bool

Whether the right bumper button was released since the last check.

Returns:

Whether the button was released since the last check.

getRightBumperPressed() bool

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

Deprecated:

Use GetRightBumperButtonPressed instead. This function is deprecated for removal to make function names consistent to allow the HID classes to be automatically generated.

Returns:

Whether the button was pressed since the last check

getRightBumperReleased() bool

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

Deprecated:

Use GetRightBumperButtonReleased instead. This function is deprecated for removal to make function names consistent to allow the HID classes to be automatically generated.

Returns:

Whether the button was released since the last check.

getRightStickButton() bool

Read the value of the right stick button on the controller.

Returns:

The state of the button.

getRightStickButtonPressed() bool

Whether the right stick button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

getRightStickButtonReleased() bool

Whether the right stick button was released since the last check.

Returns:

Whether the button was released since the last check.

getRightTriggerAxis() float

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].

Returns:

the axis value.

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.

getStartButton() bool

Read the value of the start button on the controller.

Returns:

The state of the button.

getStartButtonPressed() bool

Whether the start button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

getStartButtonReleased() bool

Whether the start button was released since the last check.

Returns:

Whether the button was released since the last check.

getXButton() bool

Read the value of the X button on the controller.

Returns:

The state of the button.

getXButtonPressed() bool

Whether the X button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

getXButtonReleased() bool

Whether the X button was released since the last check.

Returns:

Whether the button was released since the last check.

getYButton() bool

Read the value of the Y button on the controller.

Returns:

The state of the button.

getYButtonPressed() bool

Whether the Y button was pressed since the last check.

Returns:

Whether the button was pressed since the last check.

getYButtonReleased() bool

Whether the Y button was released since the last check.

Returns:

Whether the button was released since the last check.

initSendable(builder: wpiutil._wpiutil.SendableBuilder) None
leftBumper(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent

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

Parameters:

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

Returns:

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

leftStick(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent

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

Parameters:

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

Returns:

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

leftTrigger(*args, **kwargs)

Overloaded function.

  1. leftTrigger(self: wpilib._wpilib.XboxController, threshold: float, loop: wpilib.event._event.EventLoop) -> wpilib.event._event.BooleanEvent

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:
  • 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.

Returns:

an event instance that is true when the left trigger’s axis exceeds the provided threshold, attached to the given event loop

  1. leftTrigger(self: wpilib._wpilib.XboxController, loop: wpilib.event._event.EventLoop) -> wpilib.event._event.BooleanEvent

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:

loop – the 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

rightBumper(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent

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

Parameters:

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

Returns:

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

rightStick(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent

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

Parameters:

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

Returns:

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

rightTrigger(*args, **kwargs)

Overloaded function.

  1. rightTrigger(self: wpilib._wpilib.XboxController, threshold: float, loop: wpilib.event._event.EventLoop) -> wpilib.event._event.BooleanEvent

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:
  • 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.

Returns:

an event instance that is true when the right trigger’s axis exceeds the provided threshold, attached to the given event loop

  1. rightTrigger(self: wpilib._wpilib.XboxController, loop: wpilib.event._event.EventLoop) -> wpilib.event._event.BooleanEvent

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:

loop – the 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(loop: wpilib.event._event.EventLoop) wpilib.event._event.BooleanEvent

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

Parameters:

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

Returns:

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