Package trclib.driverio
Class TrcGameController
java.lang.Object
trclib.driverio.TrcGameController
- Direct Known Subclasses:
FtcGamepad
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 ClassesModifier and TypeClassDescriptionstatic enumThis enum specifies different drive modes. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final TrcTaskMgr.TaskObjectprivate final doubleprivate static final doubleprivate intprotected final Stringprivate doubleprivate intprivate doublefinal TrcDbgTrace -
Constructor Summary
ConstructorsConstructorDescriptionTrcGameController(String instanceName, double deadbandThreshold) Constructor: Create an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionprotected doubleadjustAnalogControl(double value, boolean doExp) This method adjusts the analog control value by raising it exponentially and adjusting the sign if appropriate.protected doubleadjustAnalogControl(double value, double cubicCoefficient) This method adjusts the analog control curve by using the cubic polynomial: coeff*value^3 + (1 - coeff)*value.private voidbuttonEventTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method runs periodically and checks for changes in the button states.private doubleexpValue(double value, boolean doExp) This method returns the exponentially raised of the given value.abstract intThis method returns the buttons state of the game controller.doublegetDirectionDegrees(double xValue, double yValue) This method returns the stick direction in degrees combining the x and y axes.doublegetDirectionRadians(double xValue, double yValue) This method returns the stick direction in radians combining the x and y axes.doublegetMagnitude(double x, double y) This method returns the magnitude value combining the x and y values.protected voidinit()This method is called after the constructor is done because getButton may not be available before then.protected abstract voidnotifyButtonEvent(int buttonValue, boolean pressed) This method is called when a button event is detected.protected voidsetButtonEventEnabled(boolean enabled) This method enables/disables button event notification.voidsetExponent(int exponent) This method sets the exponential value for raising analog control values.voidsetSamplingPeriod(double period) This method sets the joystick button sampling period.toString()This method returns the instance name.
-
Field Details
-
DEF_SAMPLING_PERIOD
private static final double DEF_SAMPLING_PERIOD- See Also:
-
tracer
-
instanceName
-
deadbandThreshold
private final double deadbandThreshold -
buttonEventTaskObj
-
prevButtons
private int prevButtons -
samplingPeriod
private double samplingPeriod -
nextPeriod
private double nextPeriod -
exponent
private int exponent -
buttonEventEnabled
private boolean buttonEventEnabled
-
-
Constructor Details
-
TrcGameController
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
This method returns the 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.
-