Package trclib.driverio
Class TrcGameController
java.lang.Object
trclib.driverio.TrcGameController
- Direct Known Subclasses:
FrcButtonPanel
,FrcDualJoystick
,FrcJoystick
,FrcXboxController
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 enum
This enum specifies different drive modes. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTrcGameController
(String instanceName, double deadbandThreshold) Constructor: Create an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.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
init()
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.toString()
This method returns the instance name.
-
Field Details
-
tracer
-
instanceName
-
-
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.
-
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.
-