
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.)
Table for vending machine:
//
+---------------------+-----------------------+----------------------+---------------------+-------
Row < waiting, key_press, selection, none, is_start>, /// If start button
pressed, go to selection state
Row < waiting, key_press, waiting, none, is_cancel>, // If cancel pressed
stay in the waiting state
Row < selection, key_press, Payment, none, is_number>, //If a product
number pressed go to payment
Row < selection, key_press, waiting, none, is_cancel>, // If cancel
pressed go to
Row < Payment, key_press, waiting, none, is_cancel>,
Row < Payment, last_state, waiting, dispatch_item, none> //the last_state
event is generated in the
//
"payment_done" state of the Payment submachine
//
+---------+-------------+---------+---------------------+----------------------+
Table for Payment machine:
//
+---------------------+-----------------------+----------------------+---------------------+-------
Row < Payment_init, none, Paying, none, none >, // Just make an auto
transition after displaying a msg
Row < Paying, coin_insert, check_payment, none, none>,
Row < check_payment, none, Paying, none, is_not_paid>, //If enough
money received
Row < check_payment, none, payment_done, none, is_paid>
//
+---------+-------------+---------+---------------------+----------------------+
The code for payment_done state is:
struct payment_done: public msm::front::state
{
template