Joystick
- class wpilib.Joystick(*args, **kwargs)
Bases:
HIDDeviceHandle input from standard Joysticks connected to the Driver Station.
This class handles standard 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 joystick and the mapping of ports to hardware buttons depends on the code in the Driver Station.
Overloaded function.
__init__(self: wpilib._wpilib.Joystick, port: typing.SupportsInt | typing.SupportsIndex) -> None
Construct an instance of a joystick.
The joystick index is the USB port on the Driver Station.
- Parameters:
port – The port on the Driver Station that the joystick is plugged into (0-5).
__init__(self: wpilib._wpilib.Joystick, hid: wpilib._wpilib.GenericHID) -> None
Construct an instance of a joystick with a GenericHID object.
- Parameters:
hid – The GenericHID object to use for this joystick.
- class AxisType(value: SupportsInt | SupportsIndex)
Bases:
pybind11_objectRepresents an analog axis on a joystick.
Members:
X_AXIS : X axis.
Y_AXIS : Y axis.
Z_AXIS : Z axis.
TWIST_AXIS : Twist axis.
THROTTLE_AXIS : Throttle axis.
- THROTTLE_AXIS = <AxisType.THROTTLE_AXIS: 4>
- TWIST_AXIS = <AxisType.TWIST_AXIS: 3>
- X_AXIS = <AxisType.X_AXIS: 0>
- Y_AXIS = <AxisType.Y_AXIS: 1>
- Z_AXIS = <AxisType.Z_AXIS: 2>
- Joystick.AxisType.name -> str
- property value
- class ButtonType(value: SupportsInt | SupportsIndex)
Bases:
pybind11_objectRepresents a digital button on a joystick.
Members:
TRIGGER_BUTTON : kTrigger.
TOP_BUTTON : kTop.
- TOP_BUTTON = <ButtonType.TOP_BUTTON: 1>
- TRIGGER_BUTTON = <ButtonType.TRIGGER_BUTTON: 0>
- Joystick.ButtonType.name -> str
- property value
- DEFAULT_THROTTLE_CHANNEL = 3
- DEFAULT_TWIST_CHANNEL = 2
- DEFAULT_X_CHANNEL = 0
- DEFAULT_Y_CHANNEL = 1
- DEFAULT_Z_CHANNEL = 2
- get_direction_degrees() wpimath.units.degrees
- get_direction_radians() wpimath.units.radians
Get the direction of the vector formed by the joystick and its origin. 0 is forward and clockwise is positive. (Straight right is π/2 radians or 90 degrees.)
- Returns:
The direction of the vector.
- get_hid() wpilib._wpilib.GenericHID
Get the underlying GenericHID object.
- Returns:
the wrapped GenericHID object
- get_magnitude() float
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_pov(pov: SupportsInt | SupportsIndex = 0) wpilib._wpilib.POVDirection
Get the angle in degrees of a POV on the HID.
The POV angles start at 0 in the up direction, and increase clockwise (e.g. right is 90, upper-left is 315).
- Parameters:
pov – The index of the POV to read, starting at 0.
- Returns:
the angle of the POV
- get_raw_axis(axis: SupportsInt | SupportsIndex) float
Get the value of the axis.
- Parameters:
axis – The axis to read, starting at 0.
- Returns:
The value of the axis.
- get_raw_button(button: SupportsInt | SupportsIndex) bool
Get the button value (starting at button 1).
The buttons are returned in a single 16 bit value with one bit representing the state of each button. The appropriate button is returned as a boolean value.
- Parameters:
button – The button number to be read (starting at 1)
- Returns:
The state of the button
- get_raw_button_pressed(button: SupportsInt | SupportsIndex) bool
Whether the button was pressed since the last check. Button indexes begin at 1.
- Parameters:
button – The button index, beginning at 1.
- Returns:
Whether the button was pressed since the last check.
- get_raw_button_released(button: SupportsInt | SupportsIndex) bool
Whether the button was released since the last check. Button indexes begin at 1.
- Parameters:
button – The button index, beginning at 1.
- Returns:
Whether the button was released since the last check.
- get_throttle() float
Get the throttle value of the current joystick.
This depends on the mapping of the joystick connected to the current port.
- get_throttle_channel() int
Get the channel currently associated with the throttle axis.
- Returns:
The channel for the axis.
- get_top() bool
Read the state of the top button on the joystick.
Look up which button has been assigned to the top and read its state.
- Returns:
The state of the top button.
- get_top_pressed() bool
Whether the top button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- get_top_released() bool
Whether the top button was released since the last check.
- Returns:
Whether the button was released since the last check.
- get_trigger() bool
Read the state of the trigger on the joystick.
Look up which button has been assigned to the trigger and read its state.
- Returns:
The state of the trigger.
- get_trigger_pressed() bool
Whether the trigger was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- get_trigger_released() bool
Whether the trigger was released since the last check.
- Returns:
Whether the button was released since the last check.
- get_twist() float
Get the twist value of the current joystick.
This depends on the mapping of the joystick connected to the current port.
- get_twist_channel() int
Get the channel currently associated with the twist axis.
- Returns:
The channel for the axis.
- get_x() float
Get the X value of the current joystick.
This depends on the mapping of the joystick connected to the current port. On most joysticks, positive is to the right.
- get_x_channel() int
Get the channel currently associated with the X axis.
- Returns:
The channel for the axis.
- get_y() float
Get the Y value of the current joystick.
This depends on the mapping of the joystick connected to the current port. On most joysticks, positive is to the back.
- get_y_channel() int
Get the channel currently associated with the Y axis.
- Returns:
The channel for the axis.
- get_z() float
Get the Z value of the current joystick.
This depends on the mapping of the joystick connected to the current port.
- get_z_channel() int
Get the channel currently associated with the Z axis.
- Returns:
The channel for the axis.
- set_throttle_channel(channel: SupportsInt | SupportsIndex) None
Set the channel associated with the throttle axis.
- Parameters:
channel – The channel to set the axis to.
- set_twist_channel(channel: SupportsInt | SupportsIndex) None
Set the channel associated with the twist axis.
- Parameters:
channel – The channel to set the axis to.
- set_x_channel(channel: SupportsInt | SupportsIndex) None
Set the channel associated with the X axis.
- Parameters:
channel – The channel to set the axis to.
- set_y_channel(channel: SupportsInt | SupportsIndex) None
Set the channel associated with the Y axis.
- Parameters:
channel – The channel to set the axis to.
- set_z_channel(channel: SupportsInt | SupportsIndex) None
Set the channel associated with the Z axis.
- Parameters:
channel – The channel to set the axis to.
- top(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent
Constructs an event instance around the top button’s digital signal.
- Parameters:
loop – the event loop instance to attach the event to.
- Returns:
an event instance representing the top button’s digital signal attached to the given loop.
- trigger(loop: wpilib._wpilib.EventLoop) wpilib._wpilib.BooleanEvent
Constructs an event instance around the trigger button’s digital signal.
- Parameters:
loop – the event loop instance to attach the event to.
- Returns:
an event instance representing the trigger button’s digital signal attached to the given loop.