On 05.04.2012 11:57, Santiago Romero wrote:
Hi Well did you take a look at the examples [1]? Especially at the mousefollower [2] example (look at the ### comments). But I'm willing to write a tutorial so every one can use it. I'll try a little introduction here: A state machine has certain input it has to process. Depending on the current state and the kind of input, the state machine can might perform some actions whether it changes state or not. There are three types of actions: entry, exit and transition action. The entry and exit actions are bound to a state and are executed whenever that state is entered of left (also when an external self transition is done). So to use sympleHFSM you will have to define the input and the actions it can perform. The input are just symbols that are passed to the 'event_handle' method of the state machine instance. This method will handle the input and perform the corresponding actions. Therefore you need to pass in an instance of the actions class you want to use at creation time of the state machine instance (this way you can use different 'backends', especially for testing). The second thing the state machine instance needs to know is the structure. By structure I mean the number of states that exists and their relationship between them. This is the parent-child relationship and of course the transitions between them. So lets go through the mousefollower example [2]: The mousefollower example has a pretty simple state machine: just three states: idle, following and a parent state Best way to visualize and plan a state machine is on paper, here is the drawing for the example: +--------------------------------------------------------------------+
| parent |
init --->| update/following_update |
| +------------------+ |
| | | |
| +-----------------+ in_range/ +------------------+ | |
| *-->| idle |---------------->| following |<-+ |
| | /idle_entry | | /following_entry | |
| | | | | |
| | | out_of_range/ | | |
| | |<----------------| | |
exit <---| +-----------------+ +------------------+ |
| |
+--------------------------------------------------------------------+
Now I will describe the different sections of the example:
I hope that helps. ~DR0ID [1] https://bitbucket.org/dr0id/symplehfsm/src/d9229897f4e6/trunk/symplehfsm/examples [2] https://bitbucket.org/dr0id/symplehfsm/src/d9229897f4e6/trunk/symplehfsm/examples/mousefollower/mousefollower.py [3] its a convenient way to call dynamically a method by its name on an object, see http://docs.python.org/library/operator.html?highlight=methodcaller#operator.methodcaller [4] https://bitbucket.org/dr0id/symplehfsm/src/d9229897f4e6/trunk/symplehfsm/examples/TestHFSM/symplehfsm_demo.py |