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.Nested classes/interfaces inherited from interface trclib.sensor.TrcTrigger
TrcTrigger.TriggerMode
-
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.boolean
This method checks if the trigger task is enabled.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.
-
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. -
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.
-
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.
-