Package trclib.sensor
Class TrcTriggerThresholdZones
java.lang.Object
trclib.sensor.TrcTriggerThresholdZones
- All Implemented Interfaces:
TrcTrigger
This class implements a Threshold Zones Trigger. It monitors the value source against an array of threshold
values. If the sensor reading crosses any of the thresholds in the array, it signals an event or notifies the
callback handler so that an action could be performed.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis class encapsulates all the info for the the trigger event callback.private static classThis class encapsulates the trigger state.Nested classes/interfaces inherited from interface trclib.sensor.TrcTrigger
TrcTrigger.TriggerMode -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final TrcTriggerThresholdZones.CallbackContextprivate Threadprivate final Stringprivate double[]private final TrcDbgTraceprivate TrcEvent.Callbackprivate TrcEventprivate TrcTrigger.TriggerModeprivate final TrcTriggerThresholdZones.TriggerStateprivate final TrcTaskMgr.TaskObjectprivate final TrcValueSource<Double> -
Constructor Summary
ConstructorsConstructorDescriptionTrcTriggerThresholdZones(String instanceName, TrcValueSource<Double> valueSource, double[] dataPoints, boolean dataIsTrigger) Constructor: Create an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionvoidThis method disarms the trigger.voidenableTrigger(TrcTrigger.TriggerMode triggerMode, TrcEvent event) This method arms the trigger.voidenableTrigger(TrcTrigger.TriggerMode triggerMode, TrcEvent.Callback callback) This method arms the trigger.intThis method returns the current zone it is in.intThis method returns the previous zone it was in.booleanThis method reads the current digital sensor state (not supported).doubleThis method reads the current sensor value.private intgetValueZone(double value) This method determines the sensor zone with the given sensor value.booleanThis method checks if the trigger task is enabled.private voidsetEnabled(boolean enabled, TrcEvent event) This method arms/disarms the trigger.voidsetThresholds(double[] thresholds) This method stores the threshold array.voidsetTriggerPoints(double[] triggerPoints) This method creates and threshold array and calculates all the threshold values.toString()This method returns the instance name and its state.private voidtriggerTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to check the current sensor value against the threshold array to see it crosses any thresholds and the triggerHandler will be notified.
-
Field Details
-
tracer
-
instanceName
-
valueSource
-
triggerState
-
callbackContext
-
triggerTaskObj
-
thresholds
private double[] thresholds -
triggerMode
-
triggerEvent
-
triggerCallback
-
callbackThread
-
-
Constructor Details
-
TrcTriggerThresholdZones
public TrcTriggerThresholdZones(String instanceName, TrcValueSource<Double> valueSource, double[] dataPoints, boolean dataIsTrigger) Constructor: Create an instance of the object.- Parameters:
instanceName- specifies the instance name.valueSource- specifies the interface that implements the value source.dataPoints- specifies an array of trigger points or an array of thresholds if dataIsTrigger is true.dataIsTrigger- specifies true if dataPoints specifies an array of trigger points, false if it is an array of thresholds. Trigger points will be converted to threshold points.
-
-
Method Details
-
toString
This method returns the instance name and its state. -
setEnabled
This method arms/disarms the trigger. It enables/disables the task that monitors the sensor value.- Parameters:
enabled- specifies true to enable, false to disable.event- specifies the event to signal when the trigger state changed, ignored if enabled is false.
-
enableTrigger
This method arms the trigger. It enables the task that monitors the sensor value.- Specified by:
enableTriggerin interfaceTrcTrigger- Parameters:
triggerMode- specifies the trigger direction that will signal the event. TriggerMode.OnActive will trigger only when crossing a lower zone to a higher zone. TriggerMode.OnInactive will trigger only when crossing from a higher zone to a lower zone. TriggerMode.OnBoth will trigger on both directions.event- specifies the event to signal when the trigger state changed.
-
enableTrigger
This method arms the trigger. It enables the task that monitors the sensor value.- Specified by:
enableTriggerin interfaceTrcTrigger- Parameters:
triggerMode- specifies the trigger direction that will trigger a callback. TriggerMode.OnActive will trigger only when crossing a lower zone to a higher zone. TriggerMode.OnInactive will trigger only when crossing from a higher zone to a lower zone. TriggerMode.OnBoth will trigger on both directions.callback- specifies the callback handler to notify when the trigger state changed.
-
disableTrigger
public void disableTrigger()This method disarms the trigger. It disables the task that monitors the sensor value.- Specified by:
disableTriggerin interfaceTrcTrigger
-
isEnabled
public boolean isEnabled()This method checks if the trigger task is enabled.- Specified by:
isEnabledin interfaceTrcTrigger- Returns:
- true if enabled, false otherwise.
-
getSensorValue
public double getSensorValue()This method reads the current sensor value. It may return null if it failed to read the sensor.- Specified by:
getSensorValuein interfaceTrcTrigger- Returns:
- current sensor value.
-
getSensorState
public boolean getSensorState()This method reads the current digital sensor state (not supported).- Specified by:
getSensorStatein interfaceTrcTrigger- Returns:
- current sensor state.
-
getCurrentZone
public int getCurrentZone()This method returns the current zone it is in.- Returns:
- current zone index.
-
getPreviousZone
public int getPreviousZone()This method returns the previous zone it was in.- Returns:
- previous zone index.
-
getValueZone
private int getValueZone(double value) This method determines the sensor zone with the given sensor value.- Parameters:
value- specifies the sensor value.- Returns:
- sensor zone the value is in.
-
setTriggerPoints
public void setTriggerPoints(double[] triggerPoints) This method creates and threshold array and calculates all the threshold values. A threshold value is the average of two adjacent trigger points.- Parameters:
triggerPoints- specifies the array of trigger points.
-
setThresholds
public void setThresholds(double[] thresholds) This method stores the threshold array.- Parameters:
thresholds- specifies the array of thresholds.
-
triggerTask
private void triggerTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to check the current sensor value against the threshold array to see it crosses any thresholds and the triggerHandler will be notified.- Parameters:
taskType- specifies the type of task being run.runMode- specifies the competition mode that is running. (e.g. Autonomous, TeleOp, Test).slowPeriodicLoop- specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.
-