Package trclib.archive
Class TrcCardinalConverter<D>
java.lang.Object
trclib.archive.TrcCardinalConverter<D>
This class converts cardinal data to cartesian data for sensors such as gyro or compass. It can handle sensors
that have one or more axes. Some value sensors such as the Modern Robotics gyro returns cardinal heading values
between 0.0 and 360.0. When the gyro crosses the value range boundary, it wraps around. For example, if the
current heading is 0.0 and the gyro turns 1 degree to the left, instead of giving you a value of -1.0, it wraps
to the value of 359.0. Similarly, if the current heading is 359.0 and the gyro turns 1, 2, ... degrees to the
right, instead of giving you a value of 360.0, 361.0, ... etc, it gives you 0.0, 1.0, ... This is undesirable
especially when the heading value is used in PID controlled driving. For example, if the robot wants to go
straight and maintain the heading of zero and the robot turned left slightly with a heading of 358.0, instead
of turning right 2 degrees to get back to zero heading, the robot will turn left all the way around to get back
to zero. This class implements a periodic task that monitor the sensor data. If it crosses the value range
boundary, it will keep track of the number of crossovers and will adjust the value so it doesn't wrap in effect
converting cardinal heading back to cartesian heading.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final double[]
private final double[]
private final TrcTaskMgr.TaskObject
private final D
private boolean
private final String
private final int
private final int[]
private final ArrayList<TrcSensor.SensorData<Double>>
-
Constructor Summary
ConstructorsConstructorDescriptionTrcCardinalConverter
(String instanceName, TrcSensor<D> sensor, D dataType) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
converterTask
(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to check for range crossovers.getCartesianData
(int index) This method returns the converted indexed cartesian data.boolean
This method returns the state of the cardinal converter task.void
reset()
This method resets the converter of all axes.void
reset
(int index) This method resets the indexed converter.void
setCardinalRange
(int index, double rangeLow, double rangeHigh) This method sets the value range of the indexed converter.void
setEnabled
(boolean enabled) This method enables/disables the converter task.toString()
This method returns the instance name.
-
Field Details
-
instanceName
-
sensor
-
dataType
-
numAxes
private final int numAxes -
converterTaskObj
-
cardinalRangeLows
private final double[] cardinalRangeLows -
cardinalRangeHighs
private final double[] cardinalRangeHighs -
prevData
-
numCrossovers
private final int[] numCrossovers -
enabled
private boolean enabled
-
-
Constructor Details
-
TrcCardinalConverter
Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the instance name.sensor
- specifies the sensor object that needs data unwrapping.dataType
- specifies the data type to be unwrapped.
-
-
Method Details
-
toString
This method returns the instance name. -
isEnabled
public boolean isEnabled()This method returns the state of the cardinal converter task.- Returns:
- true if converter task is enabled, false otherwise.
-
setEnabled
public void setEnabled(boolean enabled) This method enables/disables the converter task. It is not automatically enabled when created. You must explicitly call this method to enable the converter.- Parameters:
enabled
- specifies true for enabling the converter, disabling it otherwise.
-
reset
public void reset(int index) This method resets the indexed converter.- Parameters:
index
- specifies the axis index.
-
reset
public void reset()This method resets the converter of all axes. -
setCardinalRange
public void setCardinalRange(int index, double rangeLow, double rangeHigh) This method sets the value range of the indexed converter.- Parameters:
index
- specifies the axis index.rangeLow
- specifies the low value of the range.rangeHigh
- specifies the high value of the range.
-
getCartesianData
This method returns the converted indexed cartesian data.- Parameters:
index
- specifies the axis index.- Returns:
- converted cartesian data.
-
converterTask
private void converterTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to check for range crossovers.- Parameters:
taskType
- specifies the type of task being run.runMode
- specifies the competition mode that is running.slowPeriodicLoop
- specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.
-