Menu

Classes

ENGITEX

Condition

Condition base abstract class is extended by several condition classes. What each condition type means can be checked, for example, here:
https://introcs.cs.princeton.edu/java/71boolean/

Conditions:

  • AND
  • OR
  • NOT
  • XOR
  • MULTIAND
  • MULTIOR

Constructors of these classes take references to Trigger objects as arguments, ex.:

ConditionNOT(trigger1)
ConditionAND(trigger1, trigger2)

The object of Control class governs time advancement and acts as a "driver" checking which conditions are 'true' at the current time point.

Task

This class contains the action (what to do) upon the proper trigger 'on' signal. Every task must at least contain references to 2 Runnables, one Runnable (named onStart) is run when the task is started, the other one (named onStop) is run after onStart has finished.
There can also be continuous tasks that are not supposed to go through onStart-->onStop once, but have to do something until the control is stopped globally or the proper 'off' trigger becomes 'true'.
Such tasks must have one more Runnable, named loop. The flow will be the following: onStart-->while(conditions)-->loop-->onStop.
Thus, at least onStart and onStop Runnables are mandatory to construct Task object. Runnable loop is only needed for continuous tasks.

Another important parameter (int) sent to Task constructor is the number of allowed starts of the this task allowedMultiStarts. Setting this to -1 means no limit on task's restarts. A restart is not the same as rerunning Runnable loop!
A restart only takes place when the task is no longer running because it has completed onStop.
For simulations set allowedMultiStarts to -1 because technically at each simulated time slice a task will be restarted.

Available task constructors are:

  • for a continuous task - Task(Runnable onStart, Runnable loop, Runnable onStop, boolean allowMultipleStarts, String taskName)
  • for a one-time task - Task(Runnable onStart, Runnable onStop, boolean allowMultipleStarts, String taskName)

Trigger

Trigger class aggregates both Task and Condition(s):

A trigger might be viewed as 2 ('on' and 'off') logical (digital) input pins and 1 logical output pin.

Class Trigger is for automatic triggers that are set 'on' and 'off' by condition(s).
Class ManualTrigger extends Trigger and gives user extra public methods setOn() and setOff()
Of course in real-time or during a simulation, a manual trigger can be set automatically by some event.
In the temperature control example this will be (simulated) temperature raising above a certain point.

If an automatic trigger has no 'off' condition then it will run its assigned task (if any) continuously until the control is stopped globally. Of course, this will be possible only if the task is continuous itself, i.e. has loop. This point is explained in [Task types].

A trigger can be "void", that is can have no task assigned to it. It will still store a logical state that is checked and updated during the control.
The state is checked by calling Trigger.isTrue()
The following are the available Trigger constructors for triggers with and without assigned tasks:

Trigger(Condition on, Condition off, Task task, double delaySec, boolean checkDelayInterval, Control c, String tgName)
Trigger(Condition on, Condition off, double delaySec, boolean checkDelayInterval, Control c, String tgName)
Trigger(Condition on, Task task, double delaySec, boolean checkDelayInterval, Control c, String tgName)
Trigger(Condition on, double delaySec, boolean checkDelayInterval, Control c, String tgName)

Manual trigger has a different constructor:

TriggerManual(Task task, double delaySec, boolean checkDelayInterval, Control c, String triggerName)

Apparently, a manual trigger should not have any 'on' and 'off' conditions.

Paramer checkDelayInterval has the following meaning:

In case checkDelayIntervalis set to 'true' and delaySecis set to 2s, the shown behaviour of 'on' condition will prevent the task from starting.
The trigger itself in this case will also have 'false' status returned by Trigger.isTrue().
In case checkDelayIntervalis set to 'false' and delaySecis set to 2s, the task will be started at t0+2s time point.

Control

This is the "upper-level" class that

  • monitors and stops (if needed) triggers' threads
  • keeps track of the current time (either real or model time)
  • logs data to text output

All tasks and triggers are stopped when a control is stopped with
Control.stop()


Related

Wiki: Home
Wiki: Task types

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.