Tidy FSM state initialisation #622
-
Hello! Looking at the FSM example found here, I'm looking for a recommendation on how to wrap up the state initialisation in a bit more tidier way. The example uses in its main: `Fsm fsm; State1 state1; // The list of states. ... // Set up the FSM As I understand; the state objects cannot be a part of the Fsm class, as the state classes needs to know about the Fsm. Somewhat of a circular dependency. What I basically want is to hide away the above code from the user. Perhaps write a new class and inherit the Fsm class and do the setup in the new class? Suggestions are welcomed :) Edit: As well, is there an equivalent to the on_event function but that is not dependent on a message i.e. something that can be executed whenever the Fsm is poked from a timer or alike (but without the need to send a message)? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I've just tried modifying the example and it is entirely possible to have the states as internal classes to the user's FSM.
|
Beta Was this translation helpful? Give feedback.
-
As well, is there an equivalent to the on_event function but that is not dependent on a message i.e. something that can be executed whenever the Fsm is poked from a timer or alike (but without the need to send a message)? An event message can be defined as a simple empty class. Passing this to the FSM would be very low cost. |
Beta Was this translation helpful? Give feedback.
-
I'm curious, what would happen during this poke? Are there actions you want to take during this poke, like maybe checking conditions to see if you need to change state or what did you have in mind? |
Beta Was this translation helpful? Give feedback.
I've just tried modifying the example and it is entirely possible to have the states as internal classes to the user's FSM.