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 will be executed entry: en1. After that, at each subsequent step, while the state remains active, the combined code of the operator group will be executed. during, represented as "du1; du2". This means that du1 and du2 they 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 accordingly (and combine them). Names of operator groups during, entry and exit you can separate them 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 occurs at the beginning of the line. entry, during, exit or on. 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, he combines the actions specific to the sections. entry and during, but it does not include logic related to deactivating the state (as the section does exit).

The entry group

entry (input) — is used to determine the actions that are performed when entering the state. Actions specified in entry, are executed each time the state becomes active.

The band during

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. Actions specified in during, are executed while the state is active.

Exit group

exit (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 operators during are no longer running 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. Operator Group on 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 defines what needs to be assigned to a variable y meaning 0.

The logic of operator groups

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

Types of logic for executing groups of operators

entry

during

exit

on

The order of execution

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

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

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

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

Activation Features

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

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

exit It 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 it is activated only upon successful transition to a new state. If the transition to the state does not occur, then the operator group entry not performed;

Before completing the section during the state machine can check the conditions for the transition to another state. If the transition conditions are met, then the actions in during they don’t start executing at all, instead the state machine proceeds to execute exit the current state;

exit They are activated only when the transition condition is successfully fulfilled and the transition to a new state is being prepared. If the transition is not completed, then the operator exit are not executed.

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