Class TrcGameController

java.lang.Object
trclib.driverio.TrcGameController
Direct Known Subclasses:
FtcGamepad

public abstract class TrcGameController extends Object
This class implements the platform independent game controller and is extended by a platform dependent game controller class providing methods to read various game controls. It also provides monitoring of the controller 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 enum 
    This enum specifies different drive modes.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
     
    private final TrcTaskMgr.TaskObject
     
    private final double
     
    private static final double
     
    private int
     
    protected final String
     
    private double
     
    private int
     
    private double
     
     
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    protected double
    adjustAnalogControl(double value, boolean doExp)
    This method adjusts the analog control value by raising it exponentially and adjusting the sign if appropriate.
    protected double
    adjustAnalogControl(double value, double cubicCoefficient)
    This method adjusts the analog control curve by using the cubic polynomial: coeff*value^3 + (1 - coeff)*value.
    private void
    buttonEventTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop)
    This method runs periodically and checks for changes in the button states.
    private double
    expValue(double value, boolean doExp)
    This method returns the exponentially raised of the given value.
    abstract int
    This method returns the buttons state of the game controller.
    double
    getDirectionDegrees(double xValue, double yValue)
    This method returns the stick direction in degrees combining the x and y axes.
    double
    getDirectionRadians(double xValue, double yValue)
    This method returns the stick direction in radians combining the x and y axes.
    double
    getMagnitude(double x, double y)
    This method returns the magnitude value combining the x and y values.
    protected void
    This method is called after the constructor is done because getButton may not be available before then.
    protected abstract void
    notifyButtonEvent(int buttonValue, boolean pressed)
    This method is called when a button event is detected.
    protected void
    setButtonEventEnabled(boolean enabled)
    This method enables/disables button event notification.
    void
    setExponent(int exponent)
    This method sets the exponential value for raising analog control values.
    void
    setSamplingPeriod(double period)
    This method sets the joystick button sampling period.
    This method returns the instance name.

    Methods inherited from class java.lang.Object

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

    • DEF_SAMPLING_PERIOD

      private static final double DEF_SAMPLING_PERIOD
      See Also:
    • tracer

      public final TrcDbgTrace tracer
    • instanceName

      protected final String instanceName
    • deadbandThreshold

      private final double deadbandThreshold
    • buttonEventTaskObj

      private final TrcTaskMgr.TaskObject buttonEventTaskObj
    • prevButtons

      private int prevButtons
    • samplingPeriod

      private double samplingPeriod
    • nextPeriod

      private double nextPeriod
    • exponent

      private int exponent
    • buttonEventEnabled

      private boolean buttonEventEnabled
  • Constructor Details

    • TrcGameController

      public TrcGameController(String instanceName, double deadbandThreshold)
      Constructor: Create an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      deadbandThreshold - specifies the deadband of the game controller analog sticks.
  • Method Details

    • getButtons

      public abstract int getButtons()
      This method returns the buttons state of the game controller.
      Returns:
      buttons state of the game controller.
    • notifyButtonEvent

      protected abstract void notifyButtonEvent(int buttonValue, boolean pressed)
      This method is called when a button event is detected.
      Parameters:
      buttonValue - specifies the value of the button that generated the event.
      pressed - specifies true if the button was pressed, false if released.
    • toString

      public String toString()
      This method returns the instance name.
      Overrides:
      toString in class Object
      Returns:
      instance name.
    • init

      protected void init()
      This method is called after the constructor is done because getButton may not be available before then.
    • setSamplingPeriod

      public void setSamplingPeriod(double period)
      This method sets the joystick button sampling period. By default, it is sampling at 50Hz. One could change the sampling period by calling this method.
      Parameters:
      period - specifies the new sampling period in seconds.
    • setExponent

      public void setExponent(int exponent)
      This method sets the exponential value for raising analog control values.
      Parameters:
      exponent - sepecifies the exponent value used to raise analog control values.
    • setButtonEventEnabled

      protected void setButtonEventEnabled(boolean enabled)
      This method enables/disables button event notification.
      Parameters:
      enabled - specifies true to enable button event notification, false to disable.
    • expValue

      private double expValue(double value, boolean doExp)
      This method returns the exponentially raised of the given value.
      Parameters:
      value - specifies the value to be raised exponentially.
      doExp - specifies true if the value will be exponentially raised, false otherwise.
      Returns:
      exponentially raised value.
    • adjustAnalogControl

      protected double adjustAnalogControl(double value, double cubicCoefficient)
      This method adjusts the analog control curve by using the cubic polynomial: coeff*value^3 + (1 - coeff)*value.
      Parameters:
      value - specifies the analog control value.
      cubicCoefficient - specifies the cubic coefficient.
    • adjustAnalogControl

      protected double adjustAnalogControl(double value, boolean doExp)
      This method adjusts the analog control value by raising it exponentially and adjusting the sign if appropriate.
      Parameters:
      value - specifies the analog control value.
      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:
      adjusted analog control value.
    • getMagnitude

      public double getMagnitude(double x, double y)
      This method returns the magnitude value combining the x and y values. The magnitude is calculated by squaring both x and y, sum them and take the square root.
      Parameters:
      x - specifies the x value.
      y - specifies the y value.
      Returns:
      returns the magnitude value.
    • getDirectionRadians

      public double getDirectionRadians(double xValue, double yValue)
      This method returns the stick direction in radians combining the x and y axes.
      Parameters:
      xValue - specifies the x-axis value.
      yValue - specifies the y-axis value.
      Returns:
      stick direction in radians.
    • getDirectionDegrees

      public double getDirectionDegrees(double xValue, double yValue)
      This method returns the stick direction in degrees combining the x and y axes.
      Parameters:
      xValue - specifies the x-axis value.
      yValue - specifies the y-axis value.
      Returns:
      stick direction in degrees.
    • buttonEventTask

      private void buttonEventTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop)
      This method runs periodically and checks for changes in the button states. If any button changed state, the button handler is called if one exists.
      Parameters:
      taskType - specifies the type of task being run.
      runMode - specifies the current robot run mode.
      slowPeriodicLoop - specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.