
newbi question pleasee bare with me as Im struggling with this. I want to use boost msm state machine but i am having a hard time imagining how it works. Let say we only have 2 states (s1, s2) and to go from s1 to s2 you need event e1 to be fired and to bo back you need another one e2. e1 and e2 can only be fired from within s1 and s2 respectively. Now in main() I start by starting the statemachine (start()) then ill have a while loop that every 1 min will go back to the state machine but have to pick up from where it left.i.e. main() { MSM.start(); //start state machine while (a_condition) { ProcessInputsfromIO(); Go_backtoStatemachine(); //how can i do this? delay(1min) } MSM.stop(); } So basically when a state finishes executing, the statemachine will exit, then ill have a delay of 1 minutes, then the while loop will need to take me back to the state I was before I exit, or I think that's how we should implement a state machine. Is what I am asking for out of the ordinary? If yes then how do people implement a non-blocking state machine? if no, then how can I implement Go_backtoStatemachine()? -- View this message in context: http://boost.2283326.n4.nabble.com/Boost-msm-tp4444830p4444830.html Sent from the Boost - Users mailing list archive at Nabble.com.

Hi, I am not quite sure, if I have understood your question correctly. But you want to do some stuff in Go_backtoStatemachine() dependent on your active state? My solution for this is to generate another event (EventExecute) which does not trigger a state transition but an action. The statemachine itself handles only transitions if events happen for you, it is not a task-switching scheduler like an operating system is. Regards, Sven On 03/05/2012 02:22 AM, keithzz wrote:
newbi question pleasee bare with me as Im struggling with this.
I want to use boost msm state machine but i am having a hard time imagining how it works. Let say we only have 2 states (s1, s2) and to go from s1 to s2 you need event e1 to be fired and to bo back you need another one e2. e1 and e2 can only be fired from within s1 and s2 respectively.
Now in main() I start by starting the statemachine (start()) then ill have a while loop that every 1 min will go back to the state machine but have to pick up from where it left.i.e.
main() { MSM.start(); //start state machine
while (a_condition) { ProcessInputsfromIO(); Go_backtoStatemachine(); //how can i do this? delay(1min) } MSM.stop(); } So basically when a state finishes executing, the statemachine will exit, then ill have a delay of 1 minutes, then the while loop will need to take me back to the state I was before I exit, or I think that's how we should implement a state machine.
Is what I am asking for out of the ordinary? If yes then how do people implement a non-blocking state machine? if no, then how can I implement Go_backtoStatemachine()?
-- View this message in context: http://boost.2283326.n4.nabble.com/Boost-msm-tp4444830p4444830.html Sent from the Boost - Users mailing list archive at Nabble.com. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Yes Precisely, Basically my question is how can I tell what was my active state? and how can I go back to it directly without having to go through the initial state? Thank yoyu -- View this message in context: http://boost.2283326.n4.nabble.com/Boost-msm-tp4444830p4446698.html Sent from the Boost - Users mailing list archive at Nabble.com.

On Mon, Mar 5, 2012 at 17:57, keithzz
Yes Precisely, Basically my question is how can I tell what was my active state? and how can I go back to it directly without having to go through the initial state? Thank yoyu
My understanding of MSM is that if you don't re-start the state-machine and you don't send it any event, it will not change state. So if you don't do anything, it will still be in the state you've left it when you last manipulated it. (I might be wrong.) Joël Lamotte

Yes Precisely, Basically my question is how can I tell what was my active state? and how can I go back to it directly without having to go through the initial state? Thank yoyu
You don't need to go back to it, your state machine does not change state until you use it (send it an event). This is called "run-to-completion" in UML terminology. Often, people get confused because some libraries are actually actively doing something constantly. MSM does not do anything until you process an event. Then it moves to a next state, possibly executing some entry/exit/transition actions and stays there until a new event is sent. This happens entirely inside process_event. At the end of a process_event call, MSM does nothing at all. HTH, Christophe
participants (4)
-
Christophe Henry
-
keithzz
-
Klaim - Joël Lamotte
-
Sven Steckmann