CommandXboxController

class commands2.button.CommandXboxController(hid: int | XboxController)[source]

Bases: object

A version of wpilib.XboxController with Trigger factories for command-based.

Construct an instance of a controller.

Parameters:

hid – The port index on the Driver Station that the controller is plugged into, or the XboxController object to use for this controller.

a(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the A button’s digital signal.

Parameters:

loop – the event loop instance to attach the Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance representing the A button’s digital signal attached to the given loop.

axis_greater_than(axis: Axis, threshold: float, loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance that is true when the axis value is greater than threshold, attached to the given loop.

Parameters:
  • axis – the wpilib.XboxController.Axis to read

  • threshold – the value above which this Trigger should return true.

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

Returns:

a Trigger instance that is true when the axis value is greater than the provided threshold.

axis_less_than(axis: Axis, threshold: float, loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance that is true when the axis value is less than threshold, attached to the given loop.

Parameters:
  • axis – the wpilib.XboxController.Axis to read

  • threshold – the value below which this Trigger should return true.

  • loop – the event loop instance to attach the Trigger to

Returns:

a Trigger instance that is true when the axis value is less than the provided threshold.

axis_magnitude_greater_than(axis: Axis, threshold: float, loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance that is true when the axis magnitude is greater than threshold, attached to the given loop.

Parameters:
  • axis – the wpilib.XboxController.Axis to read

  • threshold – the value above which this Trigger should return true.

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

Returns:

a Trigger instance that is true when the axis magnitude is greater than the provided threshold.

b(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the B button’s digital signal.

Parameters:

loop – the event loop instance to attach the Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance representing the B button’s digital signal attached to the given loop.

button(button: Button, loop: EventLoop | None = None) Trigger[source]

Constructs an event instance around this button’s digital signal.

Parameters:
dpad_down(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the Dpad Down button’s digital signal.

Parameters:

loop – the event loop instance to attach the Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance representing the Dpad Down button’s digital signal attached to the given loop.

dpad_left(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the Dpad Left button’s digital signal.

Parameters:

loop – the event loop instance to attach the Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance representing the Dpad Left button’s digital signal attached to the given loop.

dpad_right(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the Dpad Right button’s digital signal.

Parameters:

loop – the event loop instance to attach the Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance representing the Dpad Right button’s digital signal attached to the given loop.

dpad_up(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the Dpad Up button’s digital signal.

Parameters:

loop – the event loop instance to attach the Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance representing the Dpad Up button’s digital signal attached to the given loop.

get_axis(axis: Axis) float[source]

Get the value of the axis.

Parameters:

axis – the wpilib.XboxController.Axis to read

get_controller() XboxController[source]

Get the wrapped controller object.

Returns:

the wrapped controller object

get_hid() CommandGenericHID[source]

Get the underlying CommandGenericHID object.

Returns:

the wrapped CommandGenericHID object

get_left_trigger() float[source]

Get the Left Trigger value of the controller.

Returns:

the axis value.

get_left_x() float[source]

Get the Left X value of the controller.

Returns:

the axis value.

get_left_y() float[source]

Get the Left Y value of the controller.

Returns:

the axis value.

get_right_trigger() float[source]

Get the Right Trigger value of the controller.

Returns:

the axis value.

get_right_x() float[source]

Get the Right X value of the controller.

Returns:

the axis value.

get_right_y() float[source]

Get the Right Y value of the controller.

Returns:

the axis value.

left_bumper(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the Left Bumper button’s digital signal.

Parameters:

loop – the event loop instance to attach the Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance representing the Left Bumper button’s digital signal attached to the given loop.

left_stick(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the Left Stick button’s digital signal.

Parameters:

loop – the event loop instance to attach the Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance representing the Left Stick button’s digital signal attached to the given loop.

left_trigger(threshold: float = 0.5, loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the Left Trigger axis value. The returned Trigger will be true when the axis value is greater than threshold.

Parameters:
  • threshold – the minimum axis value for the returned Trigger 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 Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance that is true when the Left Trigger axis exceeds the provided threshold, attached to the given event loop.

menu(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the Menu button’s digital signal.

Parameters:

loop – the event loop instance to attach the Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance representing the Menu button’s digital signal attached to the given loop.

right_bumper(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the Right Bumper button’s digital signal.

Parameters:

loop – the event loop instance to attach the Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance representing the Right Bumper button’s digital signal attached to the given loop.

right_stick(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the Right Stick button’s digital signal.

Parameters:

loop – the event loop instance to attach the Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance representing the Right Stick button’s digital signal attached to the given loop.

right_trigger(threshold: float = 0.5, loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the Right Trigger axis value. The returned Trigger will be true when the axis value is greater than threshold.

Parameters:
  • threshold – the minimum axis value for the returned Trigger 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 Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance that is true when the Right Trigger axis exceeds the provided threshold, attached to the given event loop.

view(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the View button’s digital signal.

Parameters:

loop – the event loop instance to attach the Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance representing the View button’s digital signal attached to the given loop.

x(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the X button’s digital signal.

Parameters:

loop – the event loop instance to attach the Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance representing the X button’s digital signal attached to the given loop.

xbox(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the Xbox button’s digital signal.

Parameters:

loop – the event loop instance to attach the Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance representing the Xbox button’s digital signal attached to the given loop.

y(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the Y button’s digital signal.

Parameters:

loop – the event loop instance to attach the Trigger to, defaults to commands2.CommandScheduler.get_default_button_loop()

Returns:

a Trigger instance representing the Y button’s digital signal attached to the given loop.