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 class
This class encapsulates all the info for the the trigger event callback.private static class
This class encapsulates the trigger state.Nested classes/interfaces inherited from interface trclib.sensor.TrcTrigger
TrcTrigger.TriggerMode
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final TrcTriggerThresholdZones.CallbackContext
private Thread
private final String
private double[]
private final TrcDbgTrace
private TrcEvent.Callback
private TrcEvent
private TrcTrigger.TriggerMode
private final TrcTriggerThresholdZones.TriggerState
private final TrcTaskMgr.TaskObject
private 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 TypeMethodDescriptionvoid
This method disarms the trigger.void
enableTrigger
(TrcTrigger.TriggerMode triggerMode, TrcEvent event) This method arms the trigger.void
enableTrigger
(TrcTrigger.TriggerMode triggerMode, TrcEvent.Callback callback) This method arms the trigger.int
This method returns the current zone it is in.int
This method returns the previous zone it was in.boolean
This method reads the current digital sensor state (not supported).double
This method reads the current sensor value.private int
getValueZone
(double value) This method determines the sensor zone with the given sensor value.boolean
This method checks if the trigger task is enabled.private void
setEnabled
(boolean enabled, TrcEvent event) This method arms/disarms the trigger.void
setThresholds
(double[] thresholds) This method stores the threshold array.void
setTriggerPoints
(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 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.
-
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:
enableTrigger
in 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:
enableTrigger
in 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:
disableTrigger
in interfaceTrcTrigger
-
isEnabled
public boolean isEnabled()This method checks if the trigger task is enabled.- Specified by:
isEnabled
in 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:
getSensorValue
in interfaceTrcTrigger
- Returns:
- current sensor value.
-
getSensorState
public boolean getSensorState()This method reads the current digital sensor state (not supported).- Specified by:
getSensorState
in 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.
-