Package trclib.sensor
Class TrcTriggerThresholdRange
java.lang.Object
trclib.sensor.TrcTriggerThresholdRange
- All Implemented Interfaces:
TrcTrigger
This class implements a Threshold Range Trigger. It monitors the value source against the lower and upper
threshold values. If the value stays within the lower and upper thresholds for at least the given settling
period, the the trigger state is set to active and the trigger callback is called or an event is signaled.
If the value exits the threshold range, the trigger state is set to inactive and the trigger callback is
also called or an event signaled.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate 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 AtomicBoolean
private Thread
private static final int
private final String
private final TrcDbgTrace
private TrcEvent.Callback
private TrcEvent
private TrcTrigger.TriggerMode
private final TrcTriggerThresholdRange.TriggerState
private final TrcTaskMgr.TaskObject
private final TrcValueSource<Double>
-
Constructor Summary
ConstructorsConstructorDescriptionTrcTriggerThresholdRange
(String instanceName, TrcValueSource<Double> valueSource) 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.This method calculates the average sensor value recorded in the cache.This method returns the maximum sensor value recorded in the cache.This method returns the minimum sensor value recorded in the cache.boolean
This method reads the current digital sensor state (not supported).double
This method reads the current analog sensor value.Double[]
This method returns an array of the data recorded during the trigger settling period.boolean
This method checks if the trigger task is enabled.private void
setEnabled
(boolean enabled, TrcEvent event) This method arms/disarms the trigger.void
setTrigger
(double lowerThreshold, double upperThreshold, double settlingPeriod) This method sets the lower/upper threshold values within which the sensor reading must stay for at least the settling period for it to trigger the notification.void
setTrigger
(double lowerThreshold, double upperThreshold, double settlingPeriod, int maxCachedSize) This method sets the lower/upper threshold values within which the sensor reading must stay for at least the settling period for it to trigger the notification.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 if the sensor value is within the lower and upper threshold range.
-
Field Details
-
DEF_CACHE_SIZE
private static final int DEF_CACHE_SIZE- See Also:
-
tracer
-
instanceName
-
valueSource
-
triggerState
-
callbackContext
-
triggerTaskObj
-
triggerMode
-
triggerEvent
-
triggerCallback
-
callbackThread
-
-
Constructor Details
-
TrcTriggerThresholdRange
Constructor: Create an instance of the object.- Parameters:
instanceName
- specifies the instance name.valueSource
- specifies the interface that implements the value source.
-
-
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 mode that will signal the event.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 mode that will trigger a callback.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 analog 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.
-
setTrigger
public void setTrigger(double lowerThreshold, double upperThreshold, double settlingPeriod, int maxCachedSize) This method sets the lower/upper threshold values within which the sensor reading must stay for at least the settling period for it to trigger the notification.- Parameters:
lowerThreshold
- specifies the lower threshold value for the trigger.upperThreshold
- specifies the upper threshold value for the trigger.settlingPeriod
- specifies the period in seconds the sensor value must stay within threshold range for it to trigger.maxCachedSize
- specifies the max number of of cached values.
-
setTrigger
public void setTrigger(double lowerThreshold, double upperThreshold, double settlingPeriod) This method sets the lower/upper threshold values within which the sensor reading must stay for at least the settling period for it to trigger the notification.- Parameters:
lowerThreshold
- specifies the lower threshold value for the trigger.upperThreshold
- specifies the upper threshold value for the trigger.settlingPeriod
- specifies the period in seconds the sensor value must stay within threshold range for it to trigger.
-
getTriggerSettlingData
This method returns an array of the data recorded during the trigger settling period.- Returns:
- array of trigger settling data, null if no data recorded.
-
getMinimumValue
This method returns the minimum sensor value recorded in the cache. Cache only records values within thresholds.- Returns:
- minimum value in the cache, null if cache was empty.
-
getMaximumValue
This method returns the maximum sensor value recorded in the cache. Cache only records values within thresholds.- Returns:
- maximum value in the cache, null if cache was empty.
-
getAverageValue
This method calculates the average sensor value recorded in the cache.- Returns:
- average value calculated.
-
triggerTask
private void triggerTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to check if the sensor value is within the lower and upper threshold range.- 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.
-