Joystick

class wpilib.Joystick(self: wpilib.Joystick, port: int) → None

Bases: wpilib.interfaces.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(self: wpilib._wpilib.Joystick.AxisType, value: int) → None

Bases: pybind11_builtins.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
class ButtonType(self: wpilib._wpilib.Joystick.ButtonType, value: int) → None

Bases: pybind11_builtins.pybind11_object

Members:

kTriggerButton

kTopButton

kTopButton = <ButtonType.kTopButton: 1>
kTriggerButton = <ButtonType.kTriggerButton: 0>
property name
getDirectionDegrees(self: wpilib.Joystick) → 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(self: wpilib.Joystick) → 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(self: wpilib.Joystick) → 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(self: wpilib.Joystick) → float

Get the throttle value of the current joystick.

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

getThrottleChannel(self: wpilib.Joystick) → int

Get the channel currently associated with the throttle axis.

Returns

The channel for the axis.

getTop(self: wpilib.Joystick) → 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(self: wpilib.Joystick) → bool

Whether the top button was pressed since the last check.

Returns

Whether the button was pressed since the last check.

getTopReleased(self: wpilib.Joystick) → bool

Whether the top button was released since the last check.

Returns

Whether the button was released since the last check.

getTrigger(self: wpilib.Joystick) → 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(self: wpilib.Joystick) → bool

Whether the trigger was pressed since the last check.

Returns

Whether the button was pressed since the last check.

getTriggerReleased(self: wpilib.Joystick) → bool

Whether the trigger was released since the last check.

Returns

Whether the button was released since the last check.

getTwist(self: wpilib.Joystick) → float

Get the twist value of the current joystick.

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

getTwistChannel(self: wpilib.Joystick) → int

Get the channel currently associated with the twist axis.

Returns

The channel for the axis.

getX(hand: wpilib.interfaces._interfaces.GenericHID.Hand = <Hand.kRightHand: 1>) → float

Get the X value of the joystick.

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

Parameters

hand – This parameter is ignored for the Joystick class and is only here to complete the GenericHID interface.

getXChannel(self: wpilib.Joystick) → int

Get the channel currently associated with the X axis.

Returns

The channel for the axis.

getY(hand: wpilib.interfaces._interfaces.GenericHID.Hand = <Hand.kRightHand: 1>) → float

Get the Y value of the joystick.

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

Parameters

hand – This parameter is ignored for the Joystick class and is only here to complete the GenericHID interface.

getYChannel(self: wpilib.Joystick) → int

Get the channel currently associated with the Y axis.

Returns

The channel for the axis.

getZ(self: wpilib.Joystick) → float

Get the Z value of the current joystick.

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

getZChannel(self: wpilib.Joystick) → 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(self: wpilib.Joystick, channel: int) → None

Set the channel associated with the throttle axis.

Parameters
  • axis – The axis to set the channel for.

  • channel – The channel to set the axis to.

setTwistChannel(self: wpilib.Joystick, channel: int) → None

Set the channel associated with the twist axis.

Parameters
  • axis – The axis to set the channel for.

  • channel – The channel to set the axis to.

setXChannel(self: wpilib.Joystick, channel: int) → None

Set the channel associated with the X axis.

Parameters

channel – The channel to set the axis to.

setYChannel(self: wpilib.Joystick, channel: int) → None

Set the channel associated with the Y axis.

Parameters
  • axis – The axis to set the channel for.

  • channel – The channel to set the axis to.

setZChannel(self: wpilib.Joystick, channel: int) → None

Set the channel associated with the Z axis.

Parameters
  • axis – The axis to set the channel for.

  • channel – The channel to set the axis to.