Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost MSM: Can not get out of the submachine
From: Christophe Henry (christophe.j.henry_at_[hidden])
Date: 2011-06-03 11:41:35


> Hi,
>
> I have been playing around with the boost MSM libraries, to know more
> about
> them. I am creating a vending machine simulation with a sub-machine for
> accepting payment from the user. The vending machine has 3 states: waiting
> (where the machine just waits for the user to start processing), selection
> (where user selects a product. The machine makes a transition to this
> state
> from "waiting" state if the event "key_press" occurs and if the key
> pressed
> is the start button (checked by a guard condition).). After a product is
> selected the machine goes in payment state, which is a submachine that
> accepts payment in quarters. After the payment is received (it is fixed $1
> for all products, just to make it simple) the machine again goes in the
> waiting state dispensing the product (action: dispatch_item).
>
> The submachine Payment has 4 states: Payment_init which just displays a
> message and then makes an immediate automatic transition to the next state
> "Paying". In this state the machine just waits for the "coin_insert" event
> to occur (which represents inserting a quarter). Once the "coin_insert"
> event occurs it makes a transition to "check_payment" state which checks
> if
> sufficient amount was paid. If not it again makes an automatic transition
> to
> "Paying" state, else it moves to the "Payment_done" state which is the
> last
> state in the submachine. This state generates an event "last_state" which
> is
> an indicator that the payment has been made and should cause a transition
> from the submachine "Payment" to waiting state (which I am not observing).
> The transition tables for both the machines are:
> (btw I am using the functors as the front end.)

<snip>

> The code for payment_done state is:
> struct payment_done: public msm::front::state
> {
> template<class Event, class FSM>
> void on_entry(Event const &, FSM &fsm)
> {
> cout << "---------------" << endl;
> cout << "Payment_done" << endl;
> fsm.process_event(last_state());
> }
> };

The FSM template argument, for a given state, is the state machine
immediately containing the state, in your case, Payment, which cannot
process this event. Later, I plan to provide you with more (although I have
mixed feelings to this feature), at best the list of all state machines in
the path to your state.
There are several ways to solve this, but the UML "standard" way is to make
payment_done an exit pseudo state (msm::front::exit_pseudo_state).

> As you can see the event "last_state" is occurring in the payment_done
> state
> but the transition is not taking place. I can post the entire code is
> someone is interested but I am just playing around with the libraries so
> the
> code (and some logic too) is not sophisticated at all. Still I can post it
> if someone wants to take a look at it.

Including a minimum working code is always helpful and would help me try
your example out, so in general, yes, it is a good idea.

Regards,
Christophe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net