CommandJoystick

class commands2.button.CommandJoystick(port: int)[source]

Bases: object

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

Construct an instance of a controller.

Parameters:

port – The port index on the Driver Station that the controller is plugged into.

get_direction_degrees() float[source]

Get the direction of the vector formed by the joystick and its origin in degrees. 0 is forward and clockwise is positive. (Straight right is 90.)

Returns:

The direction of the vector in degrees

get_direction_radians() float[source]

Get the direction of the vector formed by the joystick and its origin in radians. 0 is forward and clockwise is positive. (Straight right is π/2.)

Returns:

The direction of the vector in radians

get_hid() CommandGenericHID[source]

Get the underlying CommandGenericHID object.

Returns:

the wrapped CommandGenericHID object

get_joystick() Joystick[source]

Get the underlying Joystick object.

Returns:

the wrapped Joystick object

get_magnitude() float[source]

Get the magnitude of the vector formed by the joystick’s current position relative to its origin.

Returns:

The magnitude of the direction vector

get_throttle() float[source]

Get the throttle value of the current joystick. This depends on the mapping of the joystick connected to the current port.

Returns:

The Throttle value of the joystick.

get_throttle_channel() int[source]

Get the channel currently associated with the throttle axis.

Returns:

The channel for the axis.

get_twist() float[source]

Get the twist value of the current joystick. This depends on the mapping of the joystick connected to the current port.

Returns:

The Twist value of the joystick.

get_twist_channel() int[source]

Get the channel currently associated with the twist axis.

Returns:

The channel for the axis.

get_x() float[source]

Get the x position of the HID.

This depends on the mapping of the joystick connected to the current port. On most joysticks, positive is to the right.

Returns:

the x position

get_x_channel() int[source]

Get the channel currently associated with the X axis.

Returns:

The channel for the axis.

get_y() float[source]

Get the y position of the HID.

This depends on the mapping of the joystick connected to the current port. On most joysticks, positive is to the back.

Returns:

the y position

get_y_channel() int[source]

Get the channel currently associated with the Y axis.

Returns:

The channel for the axis.

get_z() float[source]

Get the z position of the HID.

Returns:

the z position

get_z_channel() int[source]

Get the channel currently associated with the Z axis.

Returns:

The channel for the axis.

set_throttle_channel(channel: int)[source]

Set the channel associated with the throttle axis.

Parameters:

channel – The channel to set the axis to.

set_twist_channel(channel: int)[source]

Set the channel associated with the twist axis.

Parameters:

channel – The channel to set the axis to.

set_x_channel(channel: int)[source]

Set the channel associated with the X axis.

Parameters:

channel – The channel to set the axis to.

set_y_channel(channel: int)[source]

Set the channel associated with the Y axis.

Parameters:

channel – The channel to set the axis to.

set_z_channel(channel: int)[source]

Set the channel associated with the Z axis.

Parameters:

channel – The channel to set the axis to.

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

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

Parameters:

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

Returns:

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

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

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

Parameters:

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

Returns:

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