Engee documentation

Groups of state machine operators

Operator groups are conditions that initiate model actions within states.

sf state 1 new

Operator groups are used when more complex model behaviour needs to be configured. For more information on the logic behind operator groups, see Logic of finite automata.

Operator groups support only Julia language operations and can contain multiple parts that are interleaved in any order. For example:

during: du1
entry: en1
during: du2

In this case, the code entry: en1 will be executed when the state is activated. Thereafter, at each subsequent step while the state remains active, the combined code of the during operator group, represented as du1; du2, will be executed. This means that du1 and du2 are combined and executed sequentially as if they were joined together within a single during.

You can use short names for operator groups — du for during, en for entry, and ex for exit, respectively (and combine them). The operator group names during, entry and exit can be listed comma-separated:

sf x 1

When enumerating, it is important that the same word is not repeated. An example of an incorrect enumeration:

en, during, entry: foobar

Julia code in status blocks can be multi-line and continue until the entry, during, exit or on keyword is encountered at the beginning of the line. For example:

during:
    if x > 10
        y = 1
    else
        y = 2
    end
exit: y = 3
Code in a state without operator groups is executed both when the state is activated and at each step while the state remains active. Thus, it combines the actions characteristic of the entry and during sections, but does not include the logic associated with deactivating the state (as the exit section does).

Entry group

entry is used to define the actions that are performed when a state is entered. The actions specified in entry are performed each time the state becomes active.

The during

during - used to define the actions that are performed at each step of the model calculation step (except the first step) if the state is active. The actions specified in during are performed while the state is active.

Group exit

exit - used to define the actions that are performed when a state is exited. These actions are performed once when the state becomes inactive, and occur after all the actions of the transitions that initiated the exit from that state have completed. After exiting a state, the during operators are no longer executed because the state is no longer active. For example, there is the following finite automaton:

exit order

Here, the finite automaton will activate the state "A" in the first step and perform the actions in the following order in the second step:

y2 = 2
y1 = 1
y3 = 3

Group on

on - executed when the specified action occurs in an active state. The on operator group allows to use temporal logic inside states. For example:

stateflow on after 2

Here:

  • on after(5, sec) specifies that execution will start at the fifth second (it will also be executed after 6, 7, etc. seconds).

  • y = 0 specifies that the variable y should be set to 0.

Logic of operation of operator groups

In a state machine, the order of operation of transitions and the entry, during, exit, and on operator groups is as follows:

Types of operator group execution logic

entry

during

exit

on

Execution order

entry is executed at state activation, i.e. at the moment when the finite automaton moves to a new state. This step occurs before any other groups of operators are executed. during is not executed at this step.

during is executed at each step of the finite automaton as long as the state remains active. However, if a state exit occurs in the current step, during is not executed.

exit is executed before exiting the current state, ending its activity. After exit is executed, a new state is activated, for which entry is immediately executed.

on is activated when a given condition is met (e.g. temporal logic), if the current state is active.

Activation features

entry can be used to initialise variables, set parameters, or perform any other actions necessary to prepare for operations in the current state.

during can be used to perform periodic checks, update variable values, or perform repetitive calculations.

exit can be used to reset variable values or complete calculations before exiting the state.

on allow the integration of temporal logic elements, so that it is possible to determine when actions should be performed within a state.

Interaction with transitions

entry is only activated when a transition to a new state is successful. If no state transition occurs, the entry statement group is not executed;

Prior to executing the during section, the state machine may check the conditions for a state transition. If the transition conditions are met, the actions in during do not start executing at all; instead, the state machine proceeds to execute exit of the current state;

exit is activated only if the transition condition is successfully fulfilled and prepares to transition to a new state. If no transition is made, the exit statement is not executed.

on operates only inside the currently active state. If the condition for transitioning to a new state is met, the transition occurs before on starts executing. After the transition, on will no longer be executed. However, unlike during, which is executed at every step (except the first), on actions will only be executed at the step where the condition (a temporal logic operator) is true.