CommandSwitch2GCController

class commands2.button.CommandSwitch2GCController(hid: int | Switch2GCController)[source]

Bases: object

A version of wpilib.Switch2GCController 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 Switch2GCController 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.Switch2GCController.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.Switch2GCController.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.Switch2GCController.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:
c(loop: EventLoop | None = None) Trigger[source]

Constructs a Trigger instance around the C 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 C button’s digital signal attached to the given loop.

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

Constructs a Trigger instance around the Capture 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 Capture button’s digital signal attached to the given loop.

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.Switch2GCController.Axis to read

get_c_stick_x() float[source]

Get the C Stick X value of the controller.

Returns:

the axis value.

get_c_stick_y() float[source]

Get the C Stick Y value of the controller.

Returns:

the axis value.

get_controller() Switch2GCController[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_l_trigger() float[source]

Get the L 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_r_trigger() float[source]

Get the R Trigger value of the controller.

Returns:

the axis value.

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

Constructs a Trigger instance around the Home 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 Home button’s digital signal attached to the given loop.

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

Constructs a Trigger instance around the L 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 L button’s digital signal attached to the given loop.

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

Constructs a Trigger instance around the L 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 L Trigger axis exceeds the provided threshold, attached to the given event loop.

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

Constructs a Trigger instance around the R 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 R button’s digital signal attached to the given loop.

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

Constructs a Trigger instance around the R 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 R Trigger axis exceeds the provided threshold, attached to the given event loop.

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

Constructs a Trigger instance around the Start 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 Start 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.

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.

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

Constructs a Trigger instance around the Z 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 Z button’s digital signal attached to the given loop.

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

Constructs a Trigger instance around the ZL 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 ZL button’s digital signal attached to the given loop.