Class FrcJoystick

Direct Known Subclasses:
FrcSideWinderJoystick

public class FrcJoystick extends TrcGameController
This class implements the platform dependent joystick. It provides monitoring of the joystick buttons. If the caller of this class provides a button notification handler, it will call it when there are button events.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    This interface, if provided, will allow this class to do a notification callback when there are button activities.
    static enum 
     

    Nested classes/interfaces inherited from class trclib.driverio.TrcGameController

    TrcGameController.DriveMode
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final edu.wpi.first.wpilibj.Joystick
     

    Fields inherited from class trclib.driverio.TrcGameController

    instanceName, tracer
  • Constructor Summary

    Constructors
    Constructor
    Description
    FrcJoystick(String instanceName, int port)
    Constructor: Create an instance of the object.
    FrcJoystick(String instanceName, int port, double deadbandThreshold)
    Constructor: Create an instance of the object.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    This method returns the button states in an integer by combining all the button states.
    double[]
    getDriveInputs(TrcGameController.DriveMode driveMode, boolean doExp)
    This method reads various joystick/gamepad control values and returns the drive powers for all three degrees of robot movement.
    double[]
    getDriveInputs(TrcGameController.DriveMode driveMode, boolean doExp, double drivePowerScale, double turnPowerScale)
    This method reads various joystick/gamepad control values and returns the drive powers for all three degrees of robot movement.
    double
    This method returns the throttle value of the stick.
    double
    getThrottle(boolean doExp)
    This method returns the throttle value of the stick.
    double
    getThrottle(double cubicCoefficient)
    This method returns the throttle value of the stick using the cubic polynomial curve.
    double
    This method returns the twist-axis value of the stick.
    double
    getTwist(boolean doExp)
    This method returns the twist-axis value of the stick.
    double
    getTwist(double cubicCoefficient)
    This method returns the twist-axis value of the stick using the cubic polynomial curve.
    double
    This method returns the x-axis value of the stick.
    double
    getX(boolean doExp)
    This method returns the x-axis value of the stick.
    double
    getX(double cubicCoefficient)
    This method returns the x-axis value of the stick using the cubic polynomial curve.
    double
    This method returns the y-axis value of the stick.
    double
    getY(boolean doExp)
    This method returns the y-axis value of the stick.
    double
    getY(double cubicCoefficient)
    This method returns the y-axis value of the stick using the cubic polynomial curve.
    double
    This method returns the z-axis value of the stick.
    double
    getZ(boolean doExp)
    This method returns the z-axis value of the stick.
    double
    getZ(double cubicCoefficient)
    This method returns the z-axis value of the stick using the cubic polynomial curve.
    protected void
    notifyButtonEvent(int buttonValue, boolean pressed)
    This method is called when a button event is detected.
    void
    This method sets the button event handler.
    void
    setInverted(boolean xInverted, boolean yInverted)
    This method inverts the analog axes.
    void
    setInverted(boolean xInverted, boolean yInverted, boolean zInverted, boolean twistInverted)
    This method inverts the analog axes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • joystick

      public final edu.wpi.first.wpilibj.Joystick joystick
  • Constructor Details

    • FrcJoystick

      public FrcJoystick(String instanceName, int port, double deadbandThreshold)
      Constructor: Create an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      port - specifies the USB port the joystick is plugged into.
      deadbandThreshold - specifies the deadband of the analog joystick.
    • FrcJoystick

      public FrcJoystick(String instanceName, int port)
      Constructor: Create an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      port - specifies the USB port the joystick is plugged into.
  • Method Details

    • setButtonEventHandler

      public void setButtonEventHandler(FrcJoystick.ButtonEventHandler buttonEventHandler)
      This method sets the button event handler.
      Parameters:
      buttonEventHandler - specifies button event notification handler, null to disable event notification.
    • setInverted

      public void setInverted(boolean xInverted, boolean yInverted, boolean zInverted, boolean twistInverted)
      This method inverts the analog axes.
      Parameters:
      xInverted - specifies true if inverting the x-axis, false otherwise.
      yInverted - specifies true if inverting the y-axis, false otherwise.
      zInverted - specifies true if inverting the z-axis, false otherwise.
      twistInverted - specifies true if inverting the twist-axis, false otherwise.
    • setInverted

      public void setInverted(boolean xInverted, boolean yInverted)
      This method inverts the analog axes.
      Parameters:
      xInverted - specifies true if inverting the x-axis, false otherwise.
      yInverted - specifies true if inverting the y-axis, false otherwise.
    • getX

      public double getX(double cubicCoefficient)
      This method returns the x-axis value of the stick using the cubic polynomial curve.
      Parameters:
      cubicCoefficient - specifies the cubic coefficient.
      Returns:
      x-axis value of the stick.
    • getX

      public double getX(boolean doExp)
      This method returns the x-axis value of the stick.
      Parameters:
      doExp - specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.
      Returns:
      x-axis value of the stick.
    • getX

      public double getX()
      This method returns the x-axis value of the stick.
      Returns:
      x-axis value of the stick.
    • getY

      public double getY(double cubicCoefficient)
      This method returns the y-axis value of the stick using the cubic polynomial curve.
      Parameters:
      cubicCoefficient - specifies the cubic coefficient.
      Returns:
      y-axis value of the stick.
    • getY

      public double getY(boolean doExp)
      This method returns the y-axis value of the stick.
      Parameters:
      doExp - specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.
      Returns:
      y-axis value of the stick.
    • getY

      public double getY()
      This method returns the y-axis value of the stick.
      Returns:
      y-axis value of the stick.
    • getZ

      public double getZ(double cubicCoefficient)
      This method returns the z-axis value of the stick using the cubic polynomial curve.
      Parameters:
      cubicCoefficient - specifies the cubic coefficient.
      Returns:
      z-axis value of the stick.
    • getZ

      public double getZ(boolean doExp)
      This method returns the z-axis value of the stick.
      Parameters:
      doExp - specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.
      Returns:
      z-axis value of the stick.
    • getZ

      public double getZ()
      This method returns the z-axis value of the stick.
      Returns:
      z-axis value of the stick.
    • getTwist

      public double getTwist(double cubicCoefficient)
      This method returns the twist-axis value of the stick using the cubic polynomial curve.
      Parameters:
      cubicCoefficient - specifies the cubic coefficient.
      Returns:
      twist-axis value of the stick.
    • getTwist

      public double getTwist(boolean doExp)
      This method returns the twist-axis value of the stick.
      Parameters:
      doExp - specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.
      Returns:
      twist-axis value of the stick.
    • getTwist

      public double getTwist()
      This method returns the twist-axis value of the stick.
      Returns:
      twist-axis value of the stick.
    • getThrottle

      public double getThrottle(double cubicCoefficient)
      This method returns the throttle value of the stick using the cubic polynomial curve.
      Parameters:
      cubicCoefficient - specifies the cubic coefficient.
      Returns:
      throttle value of the stick.
    • getThrottle

      public double getThrottle(boolean doExp)
      This method returns the throttle value of the stick.
      Parameters:
      doExp - specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.
      Returns:
      throttle value of the stick.
    • getThrottle

      public double getThrottle()
      This method returns the throttle value of the stick.
      Returns:
      throttle value of the stick.
    • getDriveInputs

      public double[] getDriveInputs(TrcGameController.DriveMode driveMode, boolean doExp, double drivePowerScale, double turnPowerScale)
      This method reads various joystick/gamepad control values and returns the drive powers for all three degrees of robot movement.
      Parameters:
      driveMode - specifies the drive mode which determines the control mappings.
      doExp - specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.
      drivePowerScale - specifies the scaling factor for drive power.
      turnPowerScale - specifies the scaling factor for turn power.
      Returns:
      an array of 3 values for x, y and rotation power.
    • getDriveInputs

      public double[] getDriveInputs(TrcGameController.DriveMode driveMode, boolean doExp)
      This method reads various joystick/gamepad control values and returns the drive powers for all three degrees of robot movement.
      Parameters:
      driveMode - specifies the drive mode which determines the control mappings.
      doExp - specifies true if the value should be raised exponentially, false otherwise. If the value is raised exponentially, it gives you more precise control on the low end values.
      Returns:
      an array of 3 values for x, y and rotation power.
    • getButtons

      public int getButtons()
      This method returns the button states in an integer by combining all the button states.
      Specified by:
      getButtons in class TrcGameController
      Returns:
      button states.
    • notifyButtonEvent

      protected void notifyButtonEvent(int buttonValue, boolean pressed)
      This method is called when a button event is detected. It translates the button value into button type and calls the button event handler.
      Specified by:
      notifyButtonEvent in class TrcGameController
      Parameters:
      buttonValue - specifies the button value that generated the event.
      pressed - specifies true if the button is pressed, false if it is released.