Engee documentation

Groups of state machine operators

Groups of operators are the conditions that trigger the model’s actions inside states.

sf state 1 new en

Operator groups are used when it is necessary to configure more complex model behavior. For more information about the logic of operator groups, see The logic of finite automata operation.

Operator groups only support operations in the Julia language and can contain several parts that alternate in any order. For example:

during: du1
entry: en1
during: du2

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

You can use short names for groups of operators — du for during, en for entry and ex for exit, respectively (and combine them). The names of the operator groups during, entry and `exit' can be separated by commas.:

sf x 1

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

en, during, entry: foobar

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

during:
    if x > 10
        y = 1
    else
        y = 2
    end
exit: y = 3
The code in the 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 typical for the entry and during sections, but does not include logic related to deactivating the state (as the exit section does).

The entry group

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

The band during

'during` — is used to determine the actions that are performed at each stage of the model calculation step (except the first one) if the state is active. The actions specified in during are performed while the state is active.

Exit group

exit' is used to determine the actions that are performed when exiting the state. These actions are performed once when the state becomes inactive, and occur after all the actions of the transitions that initiated the exit from this state are completed. After exiting the state, the `during statements are no longer executed because the state is no longer active. For example, there is the following finite state machine:

exit order

Here, the state machine activates state "A" in the first step, and in the second it performs the actions in the following order:

y2 = 2
y1 = 1
y3 = 3

The on group

on — is performed when the specified action occurs in the active state. The on operator group allows you to use temporal logic within states. For example:

stateflow on after 2

Here:

  • on after(5, sec) determines that execution will start from the fifth second (and run after 6, 7, etc. seconds).

  • 'y = 0` determines that the variable y should be set to `0'.

The logic of operator groups

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

Types of logic for executing groups of operators

entry

during

exit

on

The order of execution

entry is performed when the state is activated, that is, at the moment when the state machine transitions to a new state. This stage occurs before any other groups of statements are executed. during will not be executed at this step.

during is performed at each step of the state machine operation, as long as the state remains active. However, if an exit occurs in the current step, then `during' is not executed.

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

on is activated when the specified condition is met (for example, temporal logic), if the current state is active.

Activation Features

entry can be used to initialize variables, configure 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 the values of variables or to complete calculations before exiting the state.

on They allow you to integrate elements of temporal logic, so that you can determine when actions should be performed inside the state.

Interaction with traffic

entry is activated only upon successful transition to a new state. If the transition to the state does not occur, then the group of entry statements is not executed.;

Before executing the during section, the state machine can check the conditions for switching to another state. If the transition conditions are met, then the actions in during do not start to be performed at all, instead the state machine proceeds to execute the exit of the current state.;

exit is activated only upon successful completion of the transition condition and preparation for the transition to a new state. If the transition is not completed, then the 'exit` statement is not executed.

on only works inside the current active state. If the condition for switching to a new state is met, then the transition occurs before the start of the on execution. After switching to on, it will no longer be executed. However, unlike during, which are performed at every step (except the first), on actions will be performed only at the step where the condition (the temporal logic operator) is true.