Engee documentation

State machine hierarchy

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

  • A Parent state is a state that contains one or more sub-states called child states. When the parent state is activated, a default transition is made for the child states. The child states then operate according to the usual logic until the parent state is no longer active;

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

embedded state 1 1

States can be nested inside each other, but they must not overlap. If they overlap, an error (red exclamation mark) is generated stating that states cannot be overlapped:

chart error 1

All nested states obey the following rules:

  • There may be a default transition at each level of nesting, but it is not a mandatory condition. If the state is singular, there may be no transition by default. This is true for both top-level and nested states.

  • States do not have nesting depth restrictions. When entering a state, Engee automatically detects if it is nested:

    • There are nested states - a jump by default to child states is performed. Then the state machine logic is applied to the child states as long as the parent state is active.

    • No nested states - state machine logic is applied.

Parallel states

Parallel states is a set of states stateflow state of a finite automaton, which, not being connected by parent-sibling relation, can be synchronously activated, remain active or deactivated during one clock cycle of the automaton.

However, in order to understand how such states can operate in parallel (without a parent-sibling relationship) but within a single automaton, it is important to consider the concept of decomposition. Decomposition of a state allows us to specify a strategy for activation, execution and deactivation of its child states:

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

    parallel state 2

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


  • Parallel (AND) - indicated by a dotted border of child states and allows activating all nested states during one automaton cycle. In this case, the states perform their actions sequentially, in the order of their numbering. For example:

    parallel state 3

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


When should parallel states be used? They are useful if:

  • A finite automaton model needs to perform several independent processes simultaneously;

  • You need to simplify the model structure into separate logical parts.

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

parallel states 1

Levels of decomposition

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

decomposition levels 1

  1. At startup, a finite automaton enters state A, which has a parallel decomposition. This means that both its child states B and C are also activated.

  2. However, the state C is itself parent to the states C1 and C2 and forms a new level of decomposition. At this level, the state C 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 again use parallel decomposition, so their nested states are active or inactive at the same time (with the precision of an automaton clock).

This alternation of levels can be repeated as many times as desired, as long as it corresponds to the logic of the finite automaton.

All child states of the same level must correspond to the decomposition of the parent state. The decomposition level is defined by one iteration of the "Parent state - child state" connection at one hierarchical level.

Numbering of parallel states

Each parallel state in a finite automaton gets a priority number that determines the order of its execution. The lower the number, the earlier the state will be executed. The priority number is displayed in the upper right corner of each parallel state:

parallel state num

If the model is created from scratch or does not yet have parallel states, the system automatically assigns priority numbers in the order in which they are added. The numbering starts from the first available number within the parent state.

To change the order of execution of a parallel state:

  1. Right-click the parallel state.

  2. Click "Execution order" and select the new priority number.

parallel state num 1

Restrictions

Although parallel states are very useful, they have a few limitations:

  • No inbound or outbound transitions - you cannot directly create a transition from or to a parallel state;

  • No By default transitions or super transitions -. default transition is not used in parallel states. Also, you cannot create supertransitions[1].

  • Memory nodes are forbidden -. memory junction stateflow history junction (history junction) cannot be placed directly inside parallel decomposition (AND) states. This is because they operate independently, and restoring their previous states requires a separate mechanism for each.


1. Supertransition - a transition that crosses block-state boundaries. For example, it can connect nested states of different parent states that are not related to each other