Package trclib.sensor
Class TrcTriggerDigitalInput
java.lang.Object
trclib.sensor.TrcTriggerDigitalInput
- All Implemented Interfaces:
TrcTrigger
This class implements a trigger for a digital input device. A digital input trigger consists of a digital input
device. It monitors the device state and notifies the callback handler if the state changes.
-
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 final String
private final TrcDigitalInput
private final TrcDbgTrace
private TrcEvent.Callback
private TrcEvent
private TrcTrigger.TriggerMode
private final TrcTriggerDigitalInput.TriggerState
private final TrcTaskMgr.TaskObject
-
Constructor Summary
ConstructorsConstructorDescriptionTrcTriggerDigitalInput
(String instanceName, TrcDigitalInput sensor) 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.boolean
This method reads the current digital sensor state.double
This method reads the current analog sensor value (not supported).boolean
This method checks if the trigger task is enabled.private void
setEnabled
(boolean enabled, TrcEvent event) This method arms/disarms the trigger.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 state.
-
Field Details
-
tracer
-
instanceName
-
sensor
-
triggerState
-
callbackContext
-
triggerTaskObj
-
triggerMode
-
triggerEvent
-
triggerCallback
-
callbackThread
-
-
Constructor Details
-
TrcTriggerDigitalInput
Constructor: Create an instance of the object.- Parameters:
instanceName
- specifies the instance name.sensor
- specifies the digital input device.
-
-
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 (not supported).- Specified by:
getSensorValue
in interfaceTrcTrigger
- Returns:
- current sensor value.
-
getSensorState
public boolean getSensorState()This method reads the current digital sensor state.- Specified by:
getSensorState
in interfaceTrcTrigger
- Returns:
- current sensor state.
-
triggerTask
private void triggerTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to check the current sensor state. If it has changed from the previous state, the triggerCallback 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.
-