XboxController

class wpilib.XboxController(port: int)

Bases: GenericHID

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.

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 an Xbox 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.

Returns:

the state of the button

getLeftBumperPressed() bool

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

Returns:

Whether the button was pressed since the last check

getLeftBumperReleased() bool

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

Returns:

Whether the button was released since the last check.

getLeftStickButton() bool

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

Returns:

the state of the button

getLeftStickButtonPressed() bool

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

Returns:

Whether the button was pressed since the last check.

getLeftStickButtonReleased() bool

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

Returns:

Whether the button was released since the last check.

getLeftTriggerAxis() float

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

Returns:

the axis value

getLeftX() float

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

Returns:

the axis value

getLeftY() float

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

Returns:

the axis value

getRightBumper() bool

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

Returns:

the state of the button

getRightBumperPressed() bool

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

Returns:

Whether the button was pressed since the last check

getRightBumperReleased() bool

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

Returns:

Whether the button was released since the last check.

getRightStickButton() bool

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

Returns:

the state of the button

getRightStickButtonPressed() bool

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

Returns:

Whether the button was pressed since the last check

getRightStickButtonReleased() bool

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

Returns:

Whether the button was released since the last check.

getRightTriggerAxis() float

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

Returns:

the axis value

getRightX() float

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

Returns:

the axis value

getRightY() float

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

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.

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

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

Parameters:

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

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

Parameters:

loop – the 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(*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 {@code 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’s digital signal.

Parameters:

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

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

Parameters:

loop – the 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(*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.