Joystick¶
- class wpilib.Joystick(port: int)¶
Bases:
GenericHID
Handle 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: int)¶
Bases:
pybind11_object
Members:
kXAxis
kYAxis
kZAxis
kTwistAxis
kThrottleAxis
- kThrottleAxis = <AxisType.kThrottleAxis: 4>¶
- kTwistAxis = <AxisType.kTwistAxis: 3>¶
- kXAxis = <AxisType.kXAxis: 0>¶
- kYAxis = <AxisType.kYAxis: 1>¶
- kZAxis = <AxisType.kZAxis: 2>¶
- property name¶
- property value¶
- class ButtonType(value: int)¶
Bases:
pybind11_object
Members:
kTriggerButton
kTopButton
- kTopButton = <ButtonType.kTopButton: 1>¶
- kTriggerButton = <ButtonType.kTriggerButton: 0>¶
- property name¶
- property value¶
- getDirectionDegrees() float ¶
Get the direction of the vector formed by the joystick and its origin in degrees.
- Returns:
The direction of the vector in degrees
- getDirectionRadians() float ¶
Get the direction of the vector formed by the joystick and its origin in radians.
- Returns:
The direction of the vector in radians
- getMagnitude() float ¶
Get the magnitude of the direction 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.
- 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.
- 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: int) None ¶
Set the channel associated with the throttle axis.
- Parameters:
channel – The channel to set the axis to.
- setTwistChannel(channel: int) None ¶
Set the channel associated with the twist axis.
- Parameters:
channel – The channel to set the axis to.
- setXChannel(channel: int) None ¶
Set the channel associated with the X axis.
- Parameters:
channel – The channel to set the axis to.
- setYChannel(channel: int) None ¶
Set the channel associated with the Y axis.
- Parameters:
channel – The channel to set the axis to.
- setZChannel(channel: int) None ¶
Set the channel associated with the Z axis.
- Parameters:
channel – The channel to set the axis to.
- top(loop: wpilib.event._event.EventLoop) wpilib.event._event.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.event._event.EventLoop) wpilib.event._event.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.