|
|
In **hierarchical state machines** states are organized in a hierarchy. This means that states can be other state machines.
|
|
|
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 super-state and perform transiotions to them.
|
|
|
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
|
... | ... | @@ -44,7 +46,7 @@ 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 suprt-state we can perform the transition to the 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`.
|
|
|
|
... | ... | @@ -85,7 +87,8 @@ class MyHSM : public HSM<MyHSM> |
|
|
{
|
|
|
public:
|
|
|
MyHSM()
|
|
|
: HSM(&MyHSM::state_initialization), // set HSM initial state to state_S1
|
|
|
// set HSM initial state to state_initialization
|
|
|
: HSM(&MyHSM::state_initialization),
|
|
|
last_event(0)
|
|
|
{
|
|
|
// make this object to subscribe to TOPIC_1
|
... | ... | |