Joystick
- class wpilib.Joystick(port: SupportsInt | SupportsIndex)
Bases:
GenericHIDHandle 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.
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).
- class AxisType(value: SupportsInt | SupportsIndex)
Bases:
pybind11_objectRepresents an analog axis on a joystick.
Members:
kXAxis : X axis.
kYAxis : Y axis.
kZAxis : Z axis.
kTwistAxis : Twist axis.
kThrottleAxis : Throttle axis.
- kThrottleAxis = <AxisType.kThrottleAxis: 4>
- kTwistAxis = <AxisType.kTwistAxis: 3>
- kXAxis = <AxisType.kXAxis: 0>
- kYAxis = <AxisType.kYAxis: 1>
- kZAxis = <AxisType.kZAxis: 2>
- Joystick.AxisType.name -> str
- property value
- class ButtonType(value: SupportsInt | SupportsIndex)
Bases:
pybind11_objectRepresents a digital button on a joystick.
Members:
kTriggerButton : kTrigger.
kTopButton : kTop.
- kTopButton = <ButtonType.kTopButton: 1>
- kTriggerButton = <ButtonType.kTriggerButton: 0>
- Joystick.ButtonType.name -> str
- property value
- getDirectionDegrees() wpimath.units.degrees
- getDirectionRadians() 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.
- getMagnitude() 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
- getThrottle() float
Get the throttle value of the current joystick.
This depends on the mapping of the joystick connected to the current port.
- getThrottleChannel() int
Get the channel currently associated with the throttle axis.
- Returns:
The channel for the axis.
- getTop() 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.
- getTopPressed() bool
Whether the top button was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- getTopReleased() bool
Whether the top button was released since the last check.
- Returns:
Whether the button was released since the last check.
- getTrigger() 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.
- getTriggerPressed() bool
Whether the trigger was pressed since the last check.
- Returns:
Whether the button was pressed since the last check.
- getTriggerReleased() bool
Whether the trigger was released since the last check.
- Returns:
Whether the button was released since the last check.
- getTwist() float
Get the twist value of the current joystick.
This depends on the mapping of the joystick connected to the current port.
- getTwistChannel() int
Get the channel currently associated with the twist axis.
- Returns:
The channel for the axis.
- getX() 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.
- getXChannel() int
Get the channel currently associated with the X axis.
- Returns:
The channel for the axis.
- getY() 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.
- getYChannel() int
Get the channel currently associated with the Y axis.
- Returns:
The channel for the axis.
- getZ() float
Get the Z value of the current joystick.
This depends on the mapping of the joystick connected to the current port.
- getZChannel() int
Get the channel currently associated with the Z axis.
- Returns:
The channel for the axis.
- kDefaultThrottleChannel = 3
- kDefaultTwistChannel = 2
- kDefaultXChannel = 0
- kDefaultYChannel = 1
- kDefaultZChannel = 2
- setThrottleChannel(channel: SupportsInt | SupportsIndex) None
Set the channel associated with the throttle axis.
- Parameters:
channel – The channel to set the axis to.
- setTwistChannel(channel: SupportsInt | SupportsIndex) None
Set the channel associated with the twist axis.
- Parameters:
channel – The channel to set the axis to.
- setXChannel(channel: SupportsInt | SupportsIndex) None
Set the channel associated with the X axis.
- Parameters:
channel – The channel to set the axis to.
- setYChannel(channel: SupportsInt | SupportsIndex) None
Set the channel associated with the Y axis.
- Parameters:
channel – The channel to set the axis to.
- setZChannel(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.