Engee documentation

Temporal logic operators

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

condition action stateflow en

Where they are used

Example

On transitions, inside conditions, as well as inside actions specified in square brackets

condition action 1

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

Inside states together with a group of operators on or inside the Julia code

condition action 2

For example, using temporal logic operators and a group of operators on you can 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 the value is assigned 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 2.5 or more seconds, then y becomes equal 0.

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


The following temporal logic operators are available in Engee:

  • after — it is triggered after a set number of actions or time. For example, after(5, sec) activates the transition through 5 seconds after the start of the current state;

  • at — it is triggered at a specific step. For example, at(10, tick) it will be true in the step when the associated state has a group of operators during it will be performed for the tenth time (starting counting from one);

  • before — remains true until a certain point in time or the number of clock cycles of the state machine is reached. For example, before(3, sec) It works until it has passed 3 seconds from the moment of activation of the associated state;

  • count — counts the number of times the status block has been executed since the boolean expression in the parameter became true. For example, the command on at(10, tick): y = count(true) assigns a variable y meaning 10 if the state is active during 10 steps of the state machine.;

  • duration is an analog of the operator count, but instead of the number of steps, it returns the time during which the specified boolean expression remains true. For example, the command on after(10, sec): y = duration(true, sec) will assign to a variable y values that are getting bigger 10 if the state remains active after 10 seconds after activation;

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

  • every — is triggered after a set number of steps of the state machine, while the associated state remains active. For example, if the associated state is active 10 steps, then on every(3, tick): y += 1 increments the variable three times consecutively y per unit.

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

  • temporalCount is a counter that helps you keep track of how many steps the state machine has completed or how much time has passed while the state remained active. For example, the challenge temporalCount(tick) shows how many steps the state machine has been in this state. And the use of temporalCount(sec) returns how many seconds have passed since this state was activated.

after

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

Syntax Description Example

after(n,tick)
n — a positive integer or expression.
tick — the clock cycle of the finite state machine.

Returns true if the associated state remains active for at least n cycles from the moment of its activation. Otherwise, it returns false.

after(3,tick)[x>3]

Exit from 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 — a positive real number or the result of calculating an expression.
sec —One second.
msec — Millisecond.
usec — Microsecond.

Returns true, if at least one year has passed since the current state became active . n units of time. Otherwise, it returns false.

[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 the variable is x more 10 And it passed 4 seconds after the start of the transition, then the value of the variable y increases 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 — a positive integer or expression.
tick — the clock cycle of the finite state machine.

Returns true if the associated state remains active exactly n cycles from the moment of its activation. Otherwise, it returns false.

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 from the moment of activation of the associated state, the value of the variable x It turned out to be less 7, then the variable y the value will be assigned 8.

before

before is an operator that checks whether the action occurred before the specified 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 calculating an expression.
sec —One second.
msec — Millisecond.
usec — Microsecond.

Returns true If it has been less than n units of time since the moment when the current state became active. Otherwise, it returns false.

before(3, sec)[x < 5]

The transition occurs if less than 3 seconds have passed since the activation of the state, provided that x < 5.

before(n, tick)
n — a positive integer or expression.
tick — the clock cycle of the finite state machine.

Returns true if the associated state remains active for less than n cycles from the moment of its activation. Otherwise, it returns false.

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]

The transition occurs if less time has passed. 5 seconds from the moment of activation of the state and the value of the variable x greater than or equal to 8.

count

count is an operator that counts the number of executions of the associated status block from the moment when the passed boolean expression became true. The count operator has the following syntax:

Syntax Description Example

count(condition)
condition — a logical expression.

Returns the number of state machine clock cycles that have elapsed since the expression n it became true, while the associated state remained active.

[count(x > 2) = 3]

The transition occurs if the value of the variable x There were more than two left exactly 3 The clock cycle has been running since the activation of the associated state.

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 — a logical expression that is tracked over time.

Returns the number of units of time that have passed since the moment when condition it became true. If the condition is false, it returns 0.

duration(x > 5) > 3

The transition occurs if more than 3 seconds from the moment when x There are more 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 that have elapsed since the associated state became active.

elapsed(sec) >= 3

The transition occurs if 3 or more seconds have passed since the activation of the state.

every

every is an operator that helps you perform actions with a specified frequency. It has the following syntax:

Syntax Description Example

every(n, tick)
n — a positive integer or expression.
tick — the clock cycle of the finite state machine.

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

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 the variable a It turns out to be less 5, then a variable is assigned b values 10.

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 that has passed since the start of the simulation.

t >= 5

The 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 the time elapsed since the activation of the associated state. The temporalCount operator has the following syntax:

Syntax Description Example

temporalCount(tick)

Returns the number of state machine clock cycles that have elapsed since the associated state was activated.

temporalCount(tick)

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

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

temporalCount(msec)

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