python - Multiple concurrent fsm Fysom -


i writing code in python operations , these operations has concurrent reason why draw fsm 2 concurrent fsms. while using fysom in python thought of having definition of 2 fsms. @ point thinking how transition happen; confused little bit here , that's why asking support. if 1 can please , grateful .. way defined fsms please tell me if makes no sense in fysom or no

fsm1 = fysom({ 'initial':'idle', 'events':[     {'name':'sc','src':'idle','dst':'percent30'},     {'name':'sc','src':'percent30','dst':'percent60'},     {'name':'sc','src':'percent60','dst':'percent90'},     {'name':'sc','src':'percent90','dst':'idle'}     ], 'callbacks':{     'onidle':onidle,     'onread':onpercent30,     'onturnon':onpercent60,     'ondisplay':onpercent90     }     })          fsm2 = fysom({     'initial':'sr',     'events':[         {'name':'right','src':'sr','dst':'sl'},         {'name':'left','src':'sl','dst':'sr'}         ],     'callbacks':{         'onidle':onsr,         'onread':onsl         } })   

the transition take me out of fsm1 fsm2 not added, part confused , wanted ask if thinking of maybe not possible , have merge both in one.

it works if use threading

            fysom import fysom             import threading             termcolor import colored             import time               def onidle(e):                 print 'fan off'             def ons30(e):                 print 'fan running @ 30% speed'             def ons60(e):                 print 'fan running @ 60% speed'             def ons90(e):                 print 'fan running @ 90% speed'             def onswingingright(e):                 if fsm1.current != "idle":                     print 'fan swinging right'             def onswingingleft(e):                 if fsm1.current != "idle":                     print 'fan swinging left'             def onnoswinging(e):                 if fsm1.current != "idle":                     print 'fan not swinging'             def onswinging(e):                 if fsm1.current != "idle":                     print 'fan swinging'             def onmeasure(e):                     print colored('                                 measuring temperature', 'red')             def onmedian(e):                     print colored('                                 finding median', 'red')             def onlcd(e):                     print colored('                                 updating lcd', 'red')               fsm1 = fysom(                 {'initial': 'idle','events':                     [                         {'name': 'sc', 'src': 'idle', 'dst': 's30'},                         {'name': 'sc', 'src': 's30', 'dst': 's60'},                         {'name': 'sc', 'src': 's60', 'dst': 's90'},                         {'name': 'sc', 'src': 's90', 'dst': 'idle'}                     ],                  'callbacks': {                              'onidle': onidle,                              'ons30': ons30,                              'ons60': ons60,                              'ons90': ons90}                 })              fsm2 = fysom(                 {'initial': 'swingingright','events':                     [                         {'name': 'right', 'src': 'swingingright', 'dst': 'swingingleft'},                         {'name': 'left', 'src': 'swingingleft', 'dst': 'swingingright'}                     ],                   'callbacks': {                              'onswingingright': onswingingright,                              'onswingingleft': onswingingleft                              }                 })              fsm3 = fysom(                 {'initial': 'noswinging','events':                     [                         {'name': 'swing', 'src': 'noswinging', 'dst': 'swinging'},                         {'name': 'swing', 'src': 'swinging', 'dst': 'noswinging'}                     ],                   'callbacks': {                              'onnoswinging': onnoswinging,                              'onswinging': onswinging                              }                 })              fsm4 = fysom(                 {'initial': 'measure','events':                     [                         {'name': 'timeup', 'src': 'measure', 'dst': 'median'},                         {'name': 'l', 'src': 'median', 'dst': 'lcd'},                         {'name': 'l', 'src': 'lcd', 'dst': 'measure'}                     ],                   'callbacks': {                              'onmeasure': onmeasure,                              'onmedian': onmedian,                              'onlcd':onlcd                              }                 })              def controlthreadloop():                 while true:                     input = raw_input(">>>>>  \n")                     if input == 'sc':                         fsm1.sc()                     elif input == 'swing':                         fsm3.swing()                     elif input == 'left':                         fsm2.left()                     elif input =='right':                         fsm2.right()              def monitoringthreadloop():                 while true:                     time.sleep(5.0)                     fsm4.timeup()                     fsm4.l()                     fsm4.l()               controlthread = threading.thread(target=controlthreadloop)             monitoringthread = threading.thread(target=monitoringthreadloop)             controlthread.start();             monitoringthread.start(); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -