Engee documentation

Operators of temporal logic

Temporal logic operators are mechanisms that specify the moment at which a finite automaton should execute certain operators of the Julia language and are set on transitions before/inside conditions and in states:

condition action stateflow

Where are used

Example

At transitions, within conditions, and within actions specified in square brackets

сondition action 1

[
  if at(10, tick)
    y = 10
  end
]

Inside states together with the operator group on or inside Julia’s code

сondition action 2

For example, you can use temporal logic operators and the on operator group to change the values of variables over time:

stateflow on after 1

Here:

  • en, du: y = x - when entering state A and while it is active, the variable y is assigned the value x. This action is performed immediately and repeated while the state is active.

  • on after(2.5, sec): y = 0 - if state A is active for 2.5 or more seconds, y becomes 0.

  • on after(5, sec): y = -1 - if state A is active 5 or more seconds, then y becomes 0. 5 or more seconds, then y becomes equal to -1.


The following temporal logic operators are available in Engee:

  • after - after(5, sec) triggers after a specified number of actions or times. For example, after(5, sec) activates a transition 5 seconds after the start of the current state;

  • at - triggers at a specific step. For example, at(10, tick) will be true at the step when the associated state has a group of during statements executed for the tenth time (starting the count at one);

  • before - remains true until a certain point in time or number of state machine clock cycles is reached. For example, before(3, sec) is triggered until 3 seconds have passed since the associated state was activated;

  • count. - counts how many times the state block has been executed since the logical expression in the parameters became true. For example, the command on at(10, tick): y = count(true) will assign the y variable the value 10 if the state has been active for 10 state machine steps…​;

  • duration - is the analogue of the count operator, but instead of the number of steps, it returns the time for which the specified logical expression remains true. For example, the command on after(10, sec): y = duration(true, sec) will assign values to the variable y that become greater than 10 if the state remains active 10 seconds after activation;

  • `elapsed, et - returns the time elapsed since the current state was entered. For example, et >= 2 will be true if the state has been active for two or more seconds;

  • every - triggers after the given number of state machine steps, as long as the associated state remains active. For example, if the associated state is active for 10 steps, on every(3, tick): y += 1 will increment the variable y by one three times consecutively.

  • t, getSimulationTime. - Returns the current simulation time. For example, t >= 10 will be true if the simulation time has reached 10 seconds;

  • temporalCount. - is a counter that helps keep track of how many steps the state machine has completed or how much time has passed while the state remained active. For example, calling temporalCount(tick) will show how many steps the state machine has been in this state. And usage of temporalCount(sec) will return how many seconds have passed since this state was activated.

after

after is an operator that implements temporal logic on transitions. It has two variants of call:

Syntax Description Example

after(n,tick).
n - positive integer or expression.
tick - the clock of the finite automaton.

Returns true if the associated state remains active for at least n clock cycles since its activation. Otherwise returns false.

[source,julia].

after(3,tick)[x>3]

Exits the current state when the block has been activated at least three times since the state became active, provided that x > 3.

after(n,sec) after(n,msec) after(n,usec).
n is a positive real number or the result of evaluating the expression.
sec is a second.
msec - millisecond.
usec - microsecond.

Returns true if at least n time units have elapsed since the current state became active. Otherwise returns false.

[source,julia].

[after(1,tick) || x > 5]

after(10,tick)[x > 5]

after(n, tick){y = 20;}

after(2, sec)[x < 3]{y = 0;}

For a better understanding of the examples given, consider:

after(4,sec)[x > 10]

If the value of variable x is greater than 10 and 4 seconds have elapsed since the start of the transition, the value of variable y is incremented by one.

at

at is an operator that checks whether an action has occurred at a certain point in time. It has the following syntax:

Syntax Description Example

at(n, tick).
n - positive integer or expression.
tick - the clock of the finite automaton.

Returns true if the associated state remains active for exactly n clock cycles since its activation. Otherwise it returns false.

[source,julia].

at(5, tick)[y < 3]

For a better understanding of the examples given, consider:

at(4, tick) [x < 7] {y = 8}

If during the execution of the 4th clock cycle since the associated state was activated, the value of the x variable is less than 7, then the y variable will be assigned the value 8.

before

before is an operator that checks whether an action has occurred before the specified point in time. It has the following syntax:

Syntax Description Example

before(n, sec) before(n, msec) before(n, usec).
n - a positive real number or the result of evaluating the expression.
sec - second.
msec - millisecond.
usec - microsecond.

Returns true if less than n units of time have elapsed since the current state became active. Otherwise returns false.

[source,julia].

before(3, sec)[x < 5]

Transition occurs if less than 3 seconds have elapsed since the state became active, provided x < 5.

before(n, tick).
n - positive integer or expression.
tick - the clock cycle of the finite automaton.

Returns true if the associated state remains active for less than n clock cycles since its activation. Otherwise returns false.

[source,julia].

before(4, tick)[y > 2]

before(n, sec){z = 0;}

before(1, msec)[x != 10]{y = 2;}

For a better understanding of the examples given, consider:

before(5, sec)[x >= 8]

A transition occurs if less than 5 seconds have elapsed since the state was activated and the value of the variable x is greater than or equal to 8.

count.

count is an operator that counts the number of times the associated state block has been executed since the passed boolean expression became true. The count operator has the following syntax:

Syntax Description Example

count(condition).
condition is a boolean expression.

Returns the number of state machine clock cycles since the expression n became true while the associated state remained active.

[source,julia].

[count(x > 2) = 3]

Transition occurs if the value of the variable x has remained greater than two exactly 3 clock cycles since the associated state was activated.

duration

duration is an operator that checks how long a certain condition remains true. The duration operator has the following syntax:

Syntax Description Example

duration(condition).
condition is a boolean expression that tracks over time.

Returns the number of units of time elapsed since condition became true. If condition is false, it returns 0.

[source,julia].

duration(x > 5) > 3

Transition occurs if more than 3 seconds have elapsed since x became greater than 5.

`elapsed, et

elapsed (et) is an operator that keeps track of how much time has passed since the state was activated. The elapsed operator has the following syntax:

Syntax Description Example

et(sec) et(msec) et(usec)

or

elapsed(sec) elapsed(msec) elapsed(usec).

Returns the number of time units elapsed since the associated state became active.

[source,julia].

elapsed(sec) >= 3

Transition occurs if 3 seconds or more have elapsed since the state became active.

every

every is an operator that helps to perform actions at a given frequency. It has the following syntax:

Syntax Description Example

every(n, tick).
n - positive integer or expression.
tick - the clock of the finite automaton.

Returns true if the number of clock cycles since the associated state was activated is a multiple of n.

[source,julia].

every(3, tick)

For a better understanding of the examples given, consider:

every(4, tick)[a < 5]{b = 10}

If every fourth clock cycle since the activation of the associated state the value of variable a is less than 5, the value of 10 is assigned to variable b.

t, getSimulationTime.

t (getSimulationTime) is an operator that keeps track of the current simulation time. It has the following syntax:

Syntax Description Example

t

or

getSimulationTime.

Returns the time in seconds elapsed since the start of the simulation.

[source,julia].

t >= 5

Transition occurs if the current simulation time has reached 5 seconds or more.

temporalCount.

temporalCount is an operator that counts the number of clock cycles or time elapsed since the associated state was activated. The temporalCount operator has the following syntax:

Syntax Syntax Description Example

temporalCount(tick).

Returns the number of state machine ticks since the associated state was activated.

[source,julia].

temporalCount(tick)

temporalCount(sec). temporalCount(msec) temporalCount(usec).

Returns the number of specified time units elapsed since the associated state was activated.

[source,julia].

temporalCount(msec)

Returns the time elapsed since the associated state was activated, in milliseconds.