Engee documentation

Hierarchy of the state machine

Use a state machine (MS) with nested states to create a hierarchy in the model.:

  • A parent state is a state that contains one or more substates called child states. When the parent state is activated, the default transition for the child states occurs. Further, the child states work according to the usual procedure. logic until the parent state is no longer active;

  • Child state is the state that is inside the parent state.

embedded state 1 1 en

States can be nested within each other, but they should not overlap. When overlapping, an error (exclamation mark) is issued stating that the states cannot be superimposed on each other.:

chart error 1 en

All nested states are subject to the following rules:

  • There may be a default transition at each nesting level, but this is not a prerequisite. If the state is the only one, then there may be no default transition. This is true for both top-level and nested states.

  • States have no restrictions on the depth of nesting. When entering the Engee state, it automatically detects the presence of nesting:

    • There are nested states — the default transition to child states is performed. Next, the logic of the state machine is applied to the child states as long as the parent state is active.

    • There are no nested states — the logic of the state machine is applied.

Parallel states

Parallel states are a set of states stateflow state state machines that, without being linked by a parent-child relationship, can be synchronously activated, remain active, or deactivate during one clock cycle of the machine.

However, in order to understand how such states can work in parallel (without a parent-child relationship), but within the framework of a single automaton, it is important to consider the concept of decomposition. The decomposition of a state allows you to specify a strategy for activating, executing, and deactivating its child states.:

  • Exclusive (OR) is used by default and is indicated by a solid line of state boundaries. In this mode, only one child state can be active at one time (clock cycle). For example:

    parallel state 2

    Here, after activating the state A, its child state B automatically becomes active. At the same time, the C state remains inactive. If the machine switches from B to C, then B is deactivated, and C becomes active. This mechanism is convenient for modeling mutually exclusive operating modes, for example, "On" / "Off" or "Heating" / "Cooling".


  • Parallel (AND) — is indicated by the dotted border of the child states and allows you to activate all nested states during one clock cycle of the machine. In this case, the states perform their actions sequentially, in the order of their numbering. For example:

    parallel state 3

    When the state A is activated, its child states B and C also become active during one clock cycle of the machine, performing their actions sequentially, in the order of their numbering (B first, C second). They work independently of each other, which is convenient for simulating parallel processes, for example, when one part of the system controls temperature and the other controls pressure. This approach does not require a default transition to the child state, as the system activates parallel states in the order of their numbering.


When should I use parallel states? They are useful if:

  • The finite state machine model must run several independent processes simultaneously.;

  • We need to simplify the structure of the model by breaking it down into separate logical parts.

To change the decomposition type, right-click on the state and select: Decomposition → Parallel/Exclusive:

parallel states 1 en

Decomposition levels

If both parallel and exclusive child states are used in the same state, then they form different levels of decomposition. Consider an example:

decomposition levels 1

  1. At startup, the state machine switches to the A state, which has a parallel decomposition. This means that both its child states B and C are also activated.

  2. However, the C state itself is the parent of the C1 and C2 states and forms a new level of decomposition. At this level, the C state already has an exclusive (OR) decomposition, so only one of its child states (C1 or C2) can be active at any given time.

  3. The child states C1 and C2, in turn, use parallel decomposition again, so their nested states are active or inactive at the same time (up to the clock cycle).

Such an alternation of levels can be repeated as many times as necessary, as long as it corresponds to the logic of the finite state machine.

All child states of the same level must correspond to the decomposition of the parent state. The decomposition level is determined by a single iteration of the Parent—Child relationship at the same hierarchical level.

Numbering of parallel states

Each parallel state in the state machine receives a priority number that determines the order of its execution. The smaller the number, the earlier the condition will be completed. The priority number is displayed in the upper right corner of each parallel status.:

parallel state num

If the model is created from scratch or there are no parallel states in it yet, the system automatically assigns priority numbers in the order they are added. The numbering starts from the first available number inside the parent state.

To change the execution order of the parallel state:

  1. Right-click on the parallel state.

  2. Click on "Order of execution" and select a new priority number.

parallel state num 1 en

Limitations

Although parallel states are very useful, they have several limitations.:

  • There are no incoming and outgoing transitions — you cannot directly create a transition from or into a parallel state;

  • No default transitions or super transitionsdefault transition is not used in parallel states. You can also not create super-transitions[1].

  • Memory nodes are prohibitedmemory node stateflow history junction (history junction) cannot be placed directly inside states with parallel decomposition (AND). This is because they work independently, and restoring them to their previous states requires a separate mechanism for each of them.


1. Super—transition is a transition that crosses the boundaries of the state blocks. For example, it can connect nested states of different parent states that are not related to each other.