Memory Node
Page in progress. |
History Junction — this is an element the state machine Engee, which captures the state of the children states
inside the parent state, so that when reactivated, it returns to the last active state.
Read more about parent and child states in the article Hierarchy of the state machine. |
History Junction it can only be located inside states. Incorrect location will give an error.: |
History Junction records the activity of child states inside the parent state. When the parent state becomes active for the first time, the state machine uses default transition to determine which child state becomes active. However, if the parent state becomes inactive and is then reactivated, the memory node allows you to return to the last active child state, bypassing the default transition.
For example, there is an automatic door, which can have only two child states — open and Closed. The parent state will be the "Door_Activity" state, which is common to the child states. We obtain the following model of a finite automaton:
-
When the state machine first switches to the Door_Activity state, the Closed state is activated by default;
-
If the door opens, and then the system temporarily shuts down (switching to the "inactive" state, i.e. the parent state of Door_Activity will cease to be active), the memory node remembers the Open state.;
-
When the Door_Activity state is reactivated, the door automatically returns to the Open state, rather than Closed, as it would be without the memory node.
History Junction as an internal transition
History Junction It can be used as an internal passage.
An internal transition is a mechanism in the hierarchy of states of a finite automaton that allows you to move from the current state to one of its child states without going to a higher level. This transition is performed automatically when the parent state is activated and can be either unconditional or dependent on certain conditions.
An internal transition is created from the frame of the parent state to the child state, but in our case it will go to the memory node.:
This transition works as a self-loop for each child state. When the internal transition condition is met, the state machine temporarily exits the active child state, and then immediately returns to it. This allows you to reactivate the state by performing all related actions (for example, groups of operators during
and on
). Therefore, the memory node, as an internal transition, helps manage transitions while maintaining the current state of the system.
Let’s look at how the internal transition to the memory node works. To do this, let’s imagine the following model with the parent state A and two child states — A1 and A2. The model will not have a memory node and conditions on the internal transition:
The internal transition from state A to A1 is performed unconditionally, that is, every time the state A is activated. This makes the A2 state unreachable without using a memory node. Such a model of a finite state machine will work according to the following logic:
Logics of a finite state machine in a model without a memory node and conditions
-
Activating the Chart block, starting the operation of the model’s state machine:
-
1. Transition to the A state;
-
2. Activation of the A state;
-
3. Transition to the A1 state;
-
4. Activation of the A1 state;
-
5. Chart and the states A, A1 fall asleep.
-
-
Chart and the active state A are waking up:
-
1. The groups of operators
during
andon
are executed (if any);
-
2. Deactivating the A1 state;
-
3. Activation of the A1 state;
-
4. The Chart block and the states A, A1 fall asleep.
-
-
Return to step 2, repeat the cycle.
Now let’s add a condition (temporal logic operator every) on an internal transition:
After adding the condition, the transition from state A to A1 will be performed only every second time the state A is awakened. For odd awakenings, the transition A1 → A2 occurs, and for even ones, the transition A2 → A1 occurs. Therefore, the model will work according to the following logic:
Logics of a finite state machine in a model without a memory node with the condition
-
Activating the Chart block, starting the operation of the model’s state machine:
-
1. Transition to the A state;
-
2. Activation of the A state;
-
3. Transition to the A1 state;
-
4. Activation of the A1 state;
-
5. Chart and the states A, A1 fall asleep.
-
-
The Chart block and the active state A are waking up (waking up #1, 3, 5… states A):
-
1. Transition A1→A2 is in progress;
-
2. Deactivating the A1 state;
-
3. Activation of the A2 state;
-
4. The Chart block and the states A, A2 fall asleep.
-
-
The Chart block and the active state A are waking up (waking up #2, 4, 6… states A):
-
1. The
during
andon
operator groups are executed (if any);
-
2. The internal transition condition is triggered (the awakening is even), and it is fulfilled;
-
3. Deactivating the A2 state;
-
4. Activation of the A1 state;
-
5. Chart and the states A, A1 fall asleep.
-
-
Return to step 2, repeat the cycle.
Now let’s consider a model with a memory node on the inner junction. Additionally, we add a temporal logic operator. after and another external state, as shown in the figure:
Recall that the task of the memory node on the internal transition is to remember the last active child state and return to it when the conditions are met. Then the model will work according to the following logic:
Logic of a finite state machine in a model with a memory node and a condition_
-
Activating the Chart block, starting the operation of the model’s state machine:
-
1. Transition to the A state;
-
2. Activation of the A state;
-
3. Transition to the A1 state;
-
4. Activation of the A1 state;
-
5. Chart and the states A, A1 fall asleep.
-
-
Chart and the active state A wake up (the first awakening of the state A):
-
1. Transition A1→A2 is in progress;
-
2. Deactivating the A1 state;
-
3. Activation of the A2 state;
-
4. History Junction remembers the status of A2;
-
5. Chart and the states A, A2 fall asleep.
-
-
Chart and active state A wake up (second waking of state A):
-
1. The groups of operators
during
andon
are executed (if any);
-
2. The condition of internal transition to the memory node is triggered, and it is executed in the stored state A2;
-
3. Deactivating the A2 state;
-
4. Activation of the A2 status;
-
5. History Junction remembers the status of A2;
-
6. Chart and the states A, A2 fall asleep.
-
-
Chart wakes up (third awakening of state A):
-
1. The transition condition A→B is triggered, and it is executed;
-
2. Deactivating the A2 state;
-
3. Deactivating the A state;
-
4. Activation of the B state;
-
5. Chart and B state fall asleep.
-
-
Chart wakes up:
-
1. An unconditional transition is performed B→A;
-
2. Activation of the A state;
-
3. Activation of the stored state A2;
-
4. History Junction remembers the status of A2;
-
5. Chart and the states A, A2 fall asleep.
-
-
Chart, A and A2 wake up (first wake-up A):
-
1. History Junction remembers the status of A2;
-
2. Chart, A and A2 fall asleep.
-
-
Return to step 3, repeat the cycle.
Thus, an internal transition to a memory node allows you to temporarily exit the current child state and return to it if the transition condition is met. This happens immediately after executing the during
and on
groups of statements in the parent state. History Junction remembers the last active child state, helping in transition management.
The main differences between a memory node with an internal transition and without it are as follows:
|