Class Joystick


  • public class Joystick
    extends 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.

    • Constructor Detail

      • Joystick

        public Joystick​(int port)
        Construct an instance of a joystick. The joystick index is the USB port on the drivers station.
        Parameters:
        port - The port on the Driver Station that the joystick is plugged into.
    • Method Detail

      • setXChannel

        public void setXChannel​(int channel)
        Set the channel associated with the X axis.
        Parameters:
        channel - The channel to set the axis to.
      • setYChannel

        public void setYChannel​(int channel)
        Set the channel associated with the Y axis.
        Parameters:
        channel - The channel to set the axis to.
      • setZChannel

        public void setZChannel​(int channel)
        Set the channel associated with the Z axis.
        Parameters:
        channel - The channel to set the axis to.
      • setThrottleChannel

        public void setThrottleChannel​(int channel)
        Set the channel associated with the throttle axis.
        Parameters:
        channel - The channel to set the axis to.
      • setTwistChannel

        public void setTwistChannel​(int channel)
        Set the channel associated with the twist axis.
        Parameters:
        channel - The channel to set the axis to.
      • setAxisChannel

        @Deprecated
        public void setAxisChannel​(Joystick.AxisType axis,
                                   int channel)
        Deprecated.
        Use the more specific axis channel setter functions.
        Set the channel associated with a specified axis.
        Parameters:
        axis - The axis to set the channel for.
        channel - The channel to set the axis to.
      • getXChannel

        public int getXChannel()
        Get the channel currently associated with the X axis.
        Returns:
        The channel for the axis.
      • getYChannel

        public int getYChannel()
        Get the channel currently associated with the Y axis.
        Returns:
        The channel for the axis.
      • getZChannel

        public int getZChannel()
        Get the channel currently associated with the Z axis.
        Returns:
        The channel for the axis.
      • getTwistChannel

        public int getTwistChannel()
        Get the channel currently associated with the twist axis.
        Returns:
        The channel for the axis.
      • getThrottleChannel

        public int getThrottleChannel()
        Get the channel currently associated with the throttle axis.
        Returns:
        The channel for the axis.
      • getAxisChannel

        @Deprecated
        public int getAxisChannel​(Joystick.AxisType axis)
        Deprecated.
        Use the more specific axis channel getter functions.
        Get the channel currently associated with the specified axis.
        Parameters:
        axis - The axis to look up the channel for.
        Returns:
        The channel for the axis.
      • getX

        public final double getX​(GenericHID.Hand hand)
        Get the X value of the joystick. This depends on the mapping of the joystick connected to the current port.
        Specified by:
        getX in class GenericHID
        Parameters:
        hand - Unused
        Returns:
        The X value of the joystick.
      • getY

        public final double getY​(GenericHID.Hand hand)
        Get the Y value of the joystick. This depends on the mapping of the joystick connected to the current port.
        Specified by:
        getY in class GenericHID
        Parameters:
        hand - Unused
        Returns:
        The Y value of the joystick.
      • getZ

        public double getZ()
        Get the z position of the HID.
        Returns:
        the z position
      • getTwist

        public double getTwist()
        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.
      • getThrottle

        public double getThrottle()
        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.
      • getAxis

        @Deprecated
        public double getAxis​(Joystick.AxisType axis)
        Deprecated.
        Use the more specific axis getter functions.
        For the current joystick, return the axis determined by the argument.

        This is for cases where the joystick axis is returned programmatically, otherwise one of the previous functions would be preferable (for example getX()).

        Parameters:
        axis - The axis to read.
        Returns:
        The value of the axis.
      • getTrigger

        public boolean getTrigger()
        Read the state of the trigger on the joystick.
        Returns:
        The state of the trigger.
      • getTriggerPressed

        public boolean getTriggerPressed()
        Whether the trigger was pressed since the last check.
        Returns:
        Whether the button was pressed since the last check.
      • getTriggerReleased

        public boolean getTriggerReleased()
        Whether the trigger was released since the last check.
        Returns:
        Whether the button was released since the last check.
      • getTop

        public boolean getTop()
        Read the state of the top button on the joystick.
        Returns:
        The state of the top button.
      • getTopPressed

        public boolean getTopPressed()
        Whether the top button was pressed since the last check.
        Returns:
        Whether the button was pressed since the last check.
      • getTopReleased

        public boolean getTopReleased()
        Whether the top button was released since the last check.
        Returns:
        Whether the button was released since the last check.
      • getButton

        @Deprecated
        public boolean getButton​(Joystick.ButtonType button)
        Deprecated.
        Use Button enum values instead of ButtonType.
        Get buttons based on an enumerated type.

        The button type will be looked up in the list of buttons and then read.

        Parameters:
        button - The type of button to read.
        Returns:
        The state of the button.
      • getMagnitude

        public double getMagnitude()
        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
      • getDirectionRadians

        public double getDirectionRadians()
        Get the direction of the vector formed by the joystick and its origin in radians.
        Returns:
        The direction of the vector in radians
      • getDirectionDegrees

        public double getDirectionDegrees()
        Get the direction of the vector formed by the joystick and its origin in degrees.
        Returns:
        The direction of the vector in degrees