"

2013 FRC Java API

"

edu.wpi.first.wpilibj
Class Joystick

java.lang.Object
  extended by edu.wpi.first.wpilibj.GenericHID
      extended by edu.wpi.first.wpilibj.Joystick
All Implemented Interfaces:
IDevice, IInputOutput

public class Joystick
extends GenericHID
implements IInputOutput

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.


Nested Class Summary
static class Joystick.AxisType
          Represents an analog axis on a joystick.
static class Joystick.ButtonType
          Represents a digital button on the JoyStick
 
Nested classes/interfaces inherited from class edu.wpi.first.wpilibj.GenericHID
GenericHID.Hand
 
Constructor Summary
  Joystick(int port)
          Construct an instance of a joystick.
protected Joystick(int port, int numAxisTypes, int numButtonTypes)
          Protected version of the constructor to be called by sub-classes.
 
Method Summary
 double getAxis(Joystick.AxisType axis)
          For the current joystick, return the axis determined by the argument.
 int getAxisChannel(Joystick.AxisType axis)
          Get the channel currently associated with the specified axis.
 boolean getBumper(GenericHID.Hand hand)
          This is not supported for the Joystick.
 boolean getButton(Joystick.ButtonType button)
          Get buttons based on an enumerated type.
 double getDirectionDegrees()
          Get the direction of the vector formed by the joystick and its origin in degrees uses acos(-1) to represent Pi due to absence of readily accessable Pi constant in C++
 double getDirectionRadians()
          Get the direction of the vector formed by the joystick and its origin in radians
 double getMagnitude()
          Get the magnitude of the direction vector formed by the joystick's current position relative to its origin
 double getRawAxis(int axis)
          Get the value of the axis.
 boolean getRawButton(int button)
          Get the button value for buttons 1 through 12.
 double getThrottle()
          Get the throttle value of the current joystick.
 boolean getTop(GenericHID.Hand hand)
          Read the state of the top button on the joystick.
 boolean getTrigger(GenericHID.Hand hand)
          Read the state of the trigger on the joystick.
 double getTwist()
          Get the twist value of the current joystick.
 double getX(GenericHID.Hand hand)
          Get the X value of the joystick.
 double getY(GenericHID.Hand hand)
          Get the Y value of the joystick.
 double getZ(GenericHID.Hand hand)
          Get the Z value of the joystick.
 void setAxisChannel(Joystick.AxisType axis, int channel)
          Set the channel associated with a specified axis.
 
Methods inherited from class edu.wpi.first.wpilibj.GenericHID
getBumper, getTop, getTrigger, getX, getY, getZ
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.

Joystick

protected Joystick(int port,
                   int numAxisTypes,
                   int numButtonTypes)
Protected version of the constructor to be called by sub-classes. This constructor allows the subclass to configure the number of constants for axes and buttons.

Parameters:
port - The port on the driver station that the joystick is plugged into.
numAxisTypes - The number of axis types in the enum.
numButtonTypes - The number of button types in the enum.
Method Detail

getX

public 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 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(GenericHID.Hand hand)
Get the Z value of the joystick. This depends on the mapping of the joystick connected to the current port.

Specified by:
getZ in class GenericHID
Parameters:
hand - Unused
Returns:
The Z value of the joystick.

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.

Specified by:
getTwist in class GenericHID
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.

Specified by:
getThrottle in class GenericHID
Returns:
The Throttle value of the joystick.

getRawAxis

public double getRawAxis(int axis)
Get the value of the axis.

Specified by:
getRawAxis in class GenericHID
Parameters:
axis - The axis to read [1-6].
Returns:
The value of the axis.

getAxis

public double getAxis(Joystick.AxisType axis)
For the current joystick, return the axis determined by the argument. This is for cases where the joystick axis is returned programatically, 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(GenericHID.Hand hand)
Read the state of the trigger on the joystick. Look up which button has been assigned to the trigger and read its state.

Specified by:
getTrigger in class GenericHID
Parameters:
hand - This parameter is ignored for the Joystick class and is only here to complete the GenericHID interface.
Returns:
The state of the trigger.

getTop

public boolean getTop(GenericHID.Hand hand)
Read the state of the top button on the joystick. Look up which button has been assigned to the top and read its state.

Specified by:
getTop in class GenericHID
Parameters:
hand - This parameter is ignored for the Joystick class and is only here to complete the GenericHID interface.
Returns:
The state of the top button.

getBumper

public boolean getBumper(GenericHID.Hand hand)
This is not supported for the Joystick. This method is only here to complete the GenericHID interface.

Specified by:
getBumper in class GenericHID
Parameters:
hand - This parameter is ignored for the Joystick class and is only here to complete the GenericHID interface.
Returns:
The state of the bumper (always false)

getRawButton

public boolean getRawButton(int button)
Get the button value for buttons 1 through 12. 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.

Specified by:
getRawButton in class GenericHID
Parameters:
button - The button number to be read.
Returns:
The state of the button.

getButton

public boolean getButton(Joystick.ButtonType button)
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 uses acos(-1) to represent Pi due to absence of readily accessable Pi constant in C++

Returns:
The direction of the vector in degrees

getAxisChannel

public int getAxisChannel(Joystick.AxisType axis)
Get the channel currently associated with the specified axis.

Parameters:
axis - The axis to look up the channel for.
Returns:
The channel fr the axis.

setAxisChannel

public void setAxisChannel(Joystick.AxisType axis,
                           int channel)
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.

"

2013 FRC Java API

"

"
For updated information see the Java FRC site
"