Here we will make our first working project using FSME. There's (at least in Russia) a classic joke-problem, which sounds like following dialog:

The very beginning

First of all, we should create a refrigerator. From the previous page you know how to run FSME and how to create entities in it. So, we should now create a simple refrigerator.

This refrigerator will have two states: "the door is opened" and "the door is closed". Also, there will be 2 events: "Open" and "Close"

Two states and Two events
Final FSM

Now it is time to make source from this automata. In this tutorial we use Python, but C++ way will be nearly the same. As our FSM does not interact anyhow yet, we would include automatic trace information to see that it works.

Introducing light

All good refrigerators turn light on opening, and turn it off on closing. Our frige is not an exception. Let's extend it a bit.

A FSM with outputs

The Problem itself

Let's solve our problem at last! Draw FSM implementing the logic by yourself :). or take ready FSM from here
A sample FSM look

This FSM will have the following
  • PutGiraffe
  • PutHippopotamus
  • Empty
  • Giraffe
  • Hippopotamus
  • openFrige
  • closeFrige
  • getGiraffe
  • getHippopotamus
  • putGiraffe
  • putHippopotamus

Implement your logic:

 from frige         import *
 from frige_logic1  import *

class LightFrige( FrigeFSM ):
    def turnLightOn(self):
        print "Turning on the light"
    def turnLightOff(self):
        print "Turning off the light"

class FrigeLogic( FrigeLogicFSM ):
    def __init__(self, frige):
        super(FrigeLogic, self).__init__()
        self.frige = frige
    def putHippopotamus( self ):
        print "Putting Hippopotamus to the frige"

    def getGiraffe( self ):
        print "Getting Giraffe from the frige"

    def putGiraffe( self ):
        print "Putting Giraffe to the frige"

    def openFrige( self ):
        print "Opening frige"
        self.frige.A( FrigeFSM.Open )
        print "Frige opened"

    def closeFrige( self ):
        print "Closing frige"
        self.frige.A( FrigeFSM.Close )
        print "Frige closed"

    def getHippopotamus( self ):
        print "Getting Hippopotamus from the frige"

if __name__=="__main__":
    f = LightFrige()
    l = FrigeLogic( f )
    print "\n*** Putting Giraffe to Frige"
    l.A( FrigeLogicFSM.PutGiraffe )
    print "\n*** Putting Hippopotamus to Frige"
    l.A( FrigeLogicFSM.PutHippopotamus )
    print "\n*** Freeing Frige"
    l.A( FrigeLogicFSM.FreeFrige )


Working code for this tutorial and a sample C++ program can be downloaded here.