Package trclib.dataprocessor
Class TrcWrapValueConverter
java.lang.Object
trclib.dataprocessor.TrcWrapValueConverter
- Direct Known Subclasses:
TrcAbsoluteEncoder
This class is typically used to monitor a sensor value that wraps around and convert it to a continuous value.
For example, absolute encoder usually returns a value range between 0.0 and 1.0. When the value crosses over the
zero crossing, it jumps to the other extreme end. This doesn't work well for controllers such as PID control.
This class will monitors the crossovers and will increment or decrement the crossover count depending on which
direction the value is crossing over. It provides a getContinuousValue method to return a continuous value
incorporating the crossover count as part of the value. For example, instead of returning a value between 0.0 and
1.0, it will return a value such as 3.56 where 3 is the number of crossovers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final TrcTaskMgr.TaskObject
private boolean
protected final String
private int
private double
private final double
private final double
protected final DoubleSupplier
-
Constructor Summary
ConstructorsConstructorDescriptionTrcWrapValueConverter
(String instanceName, DoubleSupplier valueSupplier, double rangeLow, double rangeHigh) 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.double
This method returns the current continuous value.boolean
This method returns the state of the converter task.void
This method resets the converter state.void
setTaskEnabled
(boolean enabled) This method enables/disables the converter task.toString()
This method returns the instance name.
-
Field Details
-
instanceName
-
valueSupplier
-
rangeLow
private final double rangeLow -
rangeHigh
private final double rangeHigh -
converterTaskObj
-
enabled
private boolean enabled -
prevValue
private double prevValue -
numCrossovers
private int numCrossovers
-
-
Constructor Details
-
TrcWrapValueConverter
public TrcWrapValueConverter(String instanceName, DoubleSupplier valueSupplier, double rangeLow, double rangeHigh) Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the instance name.valueSupplier
- specifies the method to call to get the value.rangeLow
- specifies the low range of the value.rangeHigh
- specifies the high range of the value.
-
-
Method Details
-
toString
This method returns the instance name. -
isTaskEnabled
public boolean isTaskEnabled()This method returns the state of the converter task.- Returns:
- true if converter task is enabled, false otherwise.
-
setTaskEnabled
public void setTaskEnabled(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.
-
resetConverter
public void resetConverter()This method resets the converter state. -
getContinuousValue
public double getContinuousValue()This method returns the current continuous value.- Returns:
- current continuous value.
-
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.
-