... | ... | @@ -2,11 +2,11 @@ In **hierarchical state machines** states are organized in a hierarchy. |
|
|
This means that states can be themselves other state machines.
|
|
|
|
|
|
## Implementation
|
|
|
In *skyward-boardcore* implementation, the **HSM** class extends the [EventHandler](EventHandler) class, as for FSMs.
|
|
|
HSM is also a template class, such as FSM.
|
|
|
|
|
|
The main difference is that we can specify also super-states and perform transitions to them.
|
|
|
|
|
|
In _skyward-boardcore_ implementation, the **HSM** class extends the [EventHandler](EventHandler) class, as for FSMs.
|
|
|
HSM is also a template class, such as FSM.
|
|
|
|
|
|
The main difference is that we can specify also super-states and perform transitions to them.
|
|
|
|
|
|
Moreover, state methods should return a value of type `State`:
|
|
|
```cpp
|
|
|
enum State
|
... | ... | @@ -46,8 +46,8 @@ Available public methods are: |
|
|
- **bool testState(State (T::\*test_state)(const Event&))**: test is the state machines is in a specific state (that is passed as a parameter).
|
|
|
|
|
|
#### Standard Events
|
|
|
As for FSMs, `EV_ENTRY` and `EV_EXIT` are automatically posted when entering or exiting a state. Moreover, by handling `EV_INIT` in a super-state we can perform the transition to its initial sub-state.
|
|
|
|
|
|
As for FSMs, `EV_ENTRY` and `EV_EXIT` are automatically posted when entering or exiting a state. Moreover, by handling `EV_INIT` in a super-state we can perform the transition to its initial sub-state.
|
|
|
|
|
|
You can find the complete implementation of the HSM class in `src/shared/events/HSM.h`.
|
|
|
|
|
|
## Example
|
... | ... | @@ -56,8 +56,8 @@ This example implements the following very simple hierarchical state machine beh |
|
|

|
|
|
|
|
|
Whenever the state machine moves to state `S2` (super-state), it will automatically transition to its first sub-state, that is `S3` (`S2` is a state machine itself and `S3` is its initial state).
|
|
|
We can notice that state `S3` only has a self-loop trasition that is triggered by event `EV_2`. However, if the HSM receives an event `EV_1` while being in state `S3`, the event is handled by state `S2`, which is a super-state of `S3`.
|
|
|
|
|
|
We can notice that state `S3` only has a self-loop trasition that is triggered by event `EV_2`. However, if the HSM receives an event `EV_1` while being in state `S3`, the event is handled by state `S2`, which is a super-state of `S3`.
|
|
|
|
|
|
No action is specified for the involved events (`EV_ENTRY`, `EV_EXIT`, `EV_1`, `EV_2`). They simply trigger the transitions.
|
|
|
|
|
|
#### MyHSM.h
|
... | ... | |