[openrtm-commit:02658] r854 - in branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist: . examples/StaticFsm python3_examples/StaticFsm

openrtm @ openrtm.org openrtm @ openrtm.org
2017年 7月 4日 (火) 18:03:20 JST


Author: miyamoto
Date: 2017-07-04 18:03:20 +0900 (Tue, 04 Jul 2017)
New Revision: 854

Modified:
   branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort.py
   branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/Macho.py
   branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/StaticFSM.py
   branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/Microwave.py
   branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/MicrowaveFsm.py
   branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/python3_examples/StaticFsm/Microwave.py
   branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/python3_examples/StaticFsm/MicrowaveFsm.py
Log:
[incompat,2.0,FSM4RTC] fixed Machine Objects class library. 

Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort.py	2017-06-27 13:55:54 UTC (rev 853)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort.py	2017-07-04 09:03:20 UTC (rev 854)
@@ -14,6 +14,7 @@
 #     All rights reserved.
 
 import OpenRTM_aist
+import OpenRTM_aist.Macho
 
 
 class EventBinder0(OpenRTM_aist.ConnectorDataListener):

Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/Macho.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/Macho.py	2017-06-27 13:55:54 UTC (rev 853)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/Macho.py	2017-07-04 09:03:20 UTC (rev 854)
@@ -15,8 +15,8 @@
 
 
 
+import types
 
-
 class _EmptyBox:
   def __init__(self):
     pass
@@ -41,11 +41,25 @@
     return False
   isChild = staticmethod(isChild)
 
-  def setState(self, S):
+
+  def set_state(self, S, *args):
+    return self.setState(S, *args)
+
+
+  def setState(self, S, *args):
     global _theDefaultInitializer
     m = self._myStateInstance.machine()
     instance = S._getInstance(m, S.SUPER, S)
+    m.setPendingState(instance, _Initializer(*args))
+
+  def setState0(self, S):
+    global _theDefaultInitializer
+    m = self._myStateInstance.machine()
+    instance = S._getInstance(m, S.SUPER, S)
     m.setPendingState(instance, _theDefaultInitializer)
+
+
+  
     
   def setState1(self,S,p1):
     m = self._myStateInstance.machine()
@@ -100,12 +114,7 @@
     self._myStateInstance.machine().shutdown()
   def _setHistorySuper(self, instance, deep):
     pass
-  def exit(self):
-    pass
-  def entry(self):
-    pass
-  def init(self):
-    pass
+
   def _getInstance(machine, S=None, C=None):
     instance = machine.getInstances()
     if not instance[0]:
@@ -118,6 +127,12 @@
     pass
 
 
+  def on_entry(self):
+    pass
+  def on_init(self):
+    pass
+  def on_exit(self):
+    pass
 
 
 
@@ -124,6 +139,8 @@
 
 
 
+
+
 class Link(_StateSpecification):
   def __init__(self, instance):
     super(Link,self).__init__(instance)
@@ -175,11 +192,12 @@
     else:
       return Link.key(self)
   history = staticmethod(history)
-  def entry(self):
+
+  def on_entry(self):
     pass
-  def init(self):
+  def on_init(self):
     pass
-  def exit(self):
+  def on_exit(self):
     pass
   def _box(self):
     
@@ -208,8 +226,15 @@
         return obj
       
     return None
+  def data(self, class_=None):
+    if class_:
+      return self[class_]._box()
+    else:
+      return self._box()
     
 
+  def dispatch(self, event):
+    self["TopBase_"].dispatch(event)
 
 class StateID:
   def __init__(self):
@@ -231,7 +256,7 @@
     if first or not previous.isChild(self):
       self.myParent.entry(previous,False)
       self.createBox()
-      self.mySpecification.entry()
+      self.mySpecification.on_entry()
   def exit(self,next):
     
     if not self.myParent:
@@ -238,7 +263,7 @@
       return
     
     if self is next or not next.isChild(self):
-      self.mySpecification.exit()
+      self.mySpecification.on_exit()
       if self.myBox is not _EmptyBox.theEmptyBox:
         self.mySpecification._deleteBox(self)
       self.myParent.exit(next)
@@ -249,7 +274,7 @@
     if history and self.myHistory:
       self.myMachine.setPendingState(self.myHistory, _theDefaultInitializer)
     else:
-      self.mySpecification.init()
+      self.mySpecification.on_init()
     self.myHistory = None
     
       
@@ -319,6 +344,8 @@
     return 0
   def key(self):
     return 0
+  def name(self):
+    return ""
   def createBox(self):
     pass
   def deleteBox(self):
@@ -343,6 +370,8 @@
     return self.SUPER.StateID
   def key(self):
     return self.SUPER.key(self)
+  def name(self):
+    return self.SUPER._state_name()
   def create(self, machine, parent):
     _SubstateInstance(machine, parent, self.SUPER)
   def createBox(self):
@@ -450,7 +479,17 @@
     getattr(behaviour,self.myHandler)()
 
 
+class _Event(IEvent):
+  def __init__(self, handler, *args):
+    self.myHandler = handler
+    self.myParams = args
+  def dispatch(self, instance):
+    behaviour = instance.specification()
+    
+    getattr(behaviour,self.myHandler)(*self.myParams)
 
+
+
 def Event6(R,p1,p2,p3,p4,p5,p6):
   return _Event6(R,p1,p2,p3,p4,p5,p6)
 
@@ -474,29 +513,37 @@
   return _Event0(R)
 
 
+
+def Event(R, *args):
+  return _Event(R, *args)
+
+def execute(instance, *args):
+  behaviour = instance.specification()
+  behaviour.on_init(*args)
+
 def execute1(instance, p1):
   behaviour = instance.specification()
-  behaviour.init(p1)
+  behaviour.on_init(p1)
 
 def execute2(instance, p1, p2):
   behaviour = instance.specification()
-  behaviour.init(p1, p2)
+  behaviour.on_init(p1, p2)
 
 def execute3(instance, p1, p2, p3):
   behaviour = instance.specification()
-  behaviour.init(p1, p2, p3)
+  behaviour.on_init(p1, p2, p3)
 
 def execute4(instance, p1, p2, p3, p4):
   behaviour = instance.specification()
-  behaviour.init(p1, p2, p3, p4)
+  behaviour.on_init(p1, p2, p3, p4)
 
 def execute5(instance, p1, p2, p3, p4, p5):
   behaviour = instance.specification()
-  behaviour.init(p1, p2, p3, p4, p5)
+  behaviour.on_init(p1, p2, p3, p4, p5)
 
 def execute6(instance, p1, p2, p3, p4, p5, p6):
   behaviour = instance.specification()
-  behaviour.init(p1, p2, p3, p4, p5, p6)
+  behaviour.on_init(p1, p2, p3, p4, p5, p6)
   
 
 class _Initializer:
@@ -555,6 +602,14 @@
       return key
 
 
+class _Initializer(_Initializer):
+  def __init__(self, *args):
+    self.myParams = args
+  def clone(self):
+    return _Initializer(*self.myParams)
+  def execute(self, instance):
+    execute(instance, *self.myParams)
+
 class _Initializer1(_Initializer):
   def __init__(self, p1):
     self.myParam1 = p1
@@ -652,6 +707,7 @@
   def setState(self, instance, init):
     self.setPendingState(instance, init)
     self.rattleOn()
+    
   def setStateAlias(self, state):
     state.setState(self)
     self.rattleOn()
@@ -685,10 +741,10 @@
     self.myPendingInit = None
   def getInstances(self):
     return self.myInstances
-  def start(self, instance):
+  def start(self, instance, *args):
     global _theDefaultInitializer
     self.myCurrentState = _StateSpecification._getInstance(self)
-    self.setState(instance, _theDefaultInitializer)
+    self.setState(instance, _Initializer(*args))
   def startAlias(self, state):
     self.myCurrentState = _StateSpecification._getInstance(self)
     self.setStateAlias(state)
@@ -757,7 +813,7 @@
   def isParent(self, k):
     return self.key().childPredicate(k)
   def name(self):
-    return self.key().name()
+    return self.key().name
   def id(self):
     return self.key().id
   def key(self):
@@ -764,8 +820,8 @@
     return self.myInitializer.adapt(self.myStateKey)
   def setState(self, machine):
     machine.setPendingState(self.key().instanceGenerator(machine), self.myInitializer.clone())
-
-
+  
+"""
 def State(S):
   return Alias(S.key())
 
@@ -794,6 +850,7 @@
 
 def StateHistory(S, machine):
   return Alias(S.key(), _AdaptingInitializer(machine))
+"""
 
 
 class Snapshot(_MachineBase):
@@ -819,13 +876,17 @@
     return ret
     
     #return self.myMachine.myCurrentState.specification()
+
+
     
 class Machine(_MachineBase):
   theStateCount = 1
-  def __init__(self, TOP, TopBase):
+  #def __init__(self, TOP, TopBase):
+  def __init__(self, TOP, initial_state=None, args=()):
     super(Machine,self).__init__()
     self.TOP = TOP
-    self.TopBase = TopBase
+    self.TopBase = TOP.SUPER(TOP._state_name)
+    self.init(box=None, initial_state=initial_state, args=args)
   def __del__(self):
     pass
   def exit(self):
@@ -832,12 +893,16 @@
     self.myCurrentState.shutdown()
     self.free(Machine.theStateCount)
     Machine.theStateCount = 1
-  def init(self, box=None):
+  def init(self, box=None,initial_state=None, args=()):
     self.allocate(Machine.theStateCount)
     top = self.TOP._getInstance(self, self.TopBase, self.TOP)
     if box:
       top.setBox(box)
-    self.start(top)
+    if initial_state:
+      instance = initial_state._getInstance(self, initial_state.SUPER, initial_state)
+      self.start(instance, *args)
+    else:
+      self.start(top, *args)
     
   def init_Alias(self, state, box=None):
     self.allocate(Machine.theStateCount)
@@ -867,10 +932,42 @@
 
   def box(self):
     self.myCurrentState.specification().box()
+  def data(self):
+    self.myCurrentState.specification().box()
 
+  def _current_state(self):
+    return self.myCurrentState
+
   
+  def getCurrent(self):
+    spec = self.myCurrentState.specification()
+    class EventDelegator(object):
+      def __init__(self):
+        pass
+    ed = EventDelegator()
+    for name in dir(spec):
+      if name.startswith('__'):
+        continue
+      if hasattr(StateDef, name):
+        continue
+      if not isinstance(getattr(spec, name), types.MethodType):
+        continue
+      class Spec_Func(object):
+        def __init__(self, spec, name, machine):
+          self._spec = spec
+          self._name = name
+          self._machine = machine
+        def __call__(self, *args):
+          ret = getattr(self._spec,self._name)(*args)
+          self._machine.rattleOn()
+          return ret
+        
+      setattr(ed, name, Spec_Func(spec, name, self))
+    return ed
+  def setCurrent(self, state):
+    self.myCurrentState = state
+  current = property(getCurrent, setCurrent)
 
-
   
     
 def _createBox(place, B=None):
@@ -899,9 +996,73 @@
     def machine(self):
       return self._myStateInstance.machine()
 
+  
+    
+
   return TopBase_
 
+def topstate(cls):
+  class TOP(cls):
+    def __init__(self, instance):
+      super(cls,self).__init__(instance)
+    def on_init(self, *args):
+        return cls.on_init(self, *args)
+    def on_entry(self, *args):
+        return cls.on_entry(self, *args)
+    def on_exit(self, *args):
+        return cls.on_exit(self, *args)
+
+      
+  TOP.SUPER = TopBase(TOP)
+  TOP.StateID = Machine.theStateCount
+  Machine.theStateCount += 1
+  TOP._state_name = staticmethod(lambda  : TOP.__name__)
   
+  TOP.box = lambda self: self._box()
+
+  if hasattr(TOP, 'Data'):
+    TOP.Box = TOP.Data
+    
+  
+  return TOP
+
+def substate(superstate):
+  def _substate(cls):
+    class STATE(cls, superstate):
+      def __init__(self, instance):
+        cls.__init__(self, instance)
+      def on_init(self, *args):
+        return cls.on_init(self, *args)
+      def on_entry(self, *args):
+        return cls.on_entry(self, *args)
+      def on_exit(self, *args):
+        return cls.on_exit(self, *args)
+
+    STATE.SUPER = superstate
+    STATE.StateID = Machine.theStateCount
+    Machine.theStateCount += 1
+    STATE._state_name = staticmethod(lambda : cls.__name__)
+    STATE.box = lambda self: self._box()
+    #STATE.data = lambda self: self._box()
+
+    if hasattr(STATE, 'Data'):
+      STATE.Box = STATE.Data
+
+    return STATE
+  return _substate
+    
+
+def deephistory(cls):
+  def _saveHistory(self,instance,shallow,deep):
+    instance.setHistory(deep)
+    self[self.SUPER]._setHistorySuper(instance,deep)
+    
+  cls._saveHistory = _saveHistory
+
+  cls._setHistorySuper = lambda self,instance,deep: instance.setHistorySuper(deep)
+  return cls
+
+  
 def TOPSTATE(TOP):
   TOP.SUPER = TopBase(TOP)
   TOP.StateID = Machine.theStateCount
@@ -936,4 +1097,9 @@
 
   STATE._setHistorySuper = lambda self,instance,deep: instance.setHistorySuper(deep)
 
-    
\ No newline at end of file
+
+StateDef = Link
+
+
+def State(S):
+  return S
\ No newline at end of file

Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/StaticFSM.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/StaticFSM.py	2017-06-27 13:55:54 UTC (rev 853)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/StaticFSM.py	2017-07-04 09:03:20 UTC (rev 854)
@@ -14,9 +14,47 @@
 #     All rights reserved.
 
 import OpenRTM_aist
+import OpenRTM_aist.Macho
 import RTC
 
 
+def fsm_topstate(TOP):
+  ret = OpenRTM_aist.Macho.topstate(TOP)
+  class STATE(ret):
+    def __init__(self, instance):
+      ret.__init__(self, instance)
+    def on_entry(self, *argv):
+      OpenRTM_aist.Link.call_entry(self)
+      ret.on_entry(self, *argv)
+    def on_exit(self, *argv):
+      OpenRTM_aist.Link.call_exit(self)
+      ret.on_exit(self, *argv)
+    def on_init(self, *argv):
+      OpenRTM_aist.Link.call_init(self)
+      ret.on_init(self, *argv)
+  return ret
+
+
+def fsm_substate(superstate):
+  def _fsm_substate(cls):
+    ret = OpenRTM_aist.Macho.substate(superstate)(cls)
+    class STATE(ret):
+      def __init__(self, instance):
+        ret.__init__(self, instance)
+      def on_entry(self, *argv):
+        OpenRTM_aist.Link.call_entry(self)
+        ret.on_entry(self, *argv)
+      def on_exit(self, *argv):
+        OpenRTM_aist.Link.call_exit(self)
+        ret.on_exit(self, *argv)
+      def on_init(self, *argv):
+        OpenRTM_aist.Link.call_init(self)
+        ret.on_init(self, *argv)
+
+    return ret
+  return _fsm_substate
+
+
 def FSM_TOPSTATE(TOP):
   OpenRTM_aist.Macho.TOPSTATE(TOP)
 
@@ -25,12 +63,15 @@
   OpenRTM_aist.Macho.SUBSTATE(STATE, SUPERSTATE)
 
 
+
 class Machine(OpenRTM_aist.Macho.Machine):
   def __init__(self, TOP, comp):
-    super(Machine,self).__init__(TOP, OpenRTM_aist.Macho.TopBase(TOP))
+    #super(Machine,self).__init__(TOP, OpenRTM_aist.Macho.TopBase(TOP))
     self._rtComponent = comp
+    super(Machine,self).__init__(TOP)
     
     
+    
   def __del__(self):
     pass
   def init_other(self, other):
@@ -55,7 +96,7 @@
     if machine:
       self._rtComponent = machine.getComp()
 
-  def entry(self):
+  def call_entry(self):
     self.setrtc()
     if not self._rtComponent:
       self.onEntry()
@@ -64,7 +105,7 @@
       self._rtComponent.preOnFsmEntry(self._state_name())
       self._rtComponent.postOnFsmEntry(self._state_name(), self.onEntry())
 
-  def init(self):
+  def call_init(self):
     self.setrtc()
     if not self._rtComponent:
       self.onInit()
@@ -73,7 +114,7 @@
       self._rtComponent.postOnFsmInit(self._state_name(), self.onInit())
 
 
-  def exit(self):
+  def call_exit(self):
     self.setrtc()
     if not self._rtComponent:
       self.onExit()

Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/Microwave.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/Microwave.py	2017-06-27 13:55:54 UTC (rev 853)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/Microwave.py	2017-07-04 09:03:20 UTC (rev 854)
@@ -49,7 +49,7 @@
 
   def onInitialize(self):
     self._fsm = OpenRTM_aist.Machine(MicrowaveFsm.TOP, self)
-    self._fsm.init()
+    #self._fsm.init()
     self._eventIn = OpenRTM_aist.EventInPort("event", self._fsm)
     
     self.addInPort("event", self._eventIn)

Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/MicrowaveFsm.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/MicrowaveFsm.py	2017-06-27 13:55:54 UTC (rev 853)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/MicrowaveFsm.py	2017-07-04 09:03:20 UTC (rev 854)
@@ -19,18 +19,12 @@
 import OpenRTM_aist
 import OpenRTM_aist.Macho
 
+ at OpenRTM_aist.fsm_topstate
 class TOP(OpenRTM_aist.Link):
-  def __init__(self, instance):
-    super(TOP,self).__init__(instance)
-  def entry(self):
-    OpenRTM_aist.Link.entry(self)
-  def exit(self):
-    OpenRTM_aist.Link.exit(self)
-  def init(self):
-    OpenRTM_aist.Link.init(self)
-    self.setState(Operational)
-    
+  def on_init(self):
+    self.set_state(OpenRTM_aist.Macho.State(Operational))
 
+
   def open(self):
     pass
   def close(self):
@@ -44,7 +38,7 @@
   def tick(self):
     pass
 
-  class Box:
+  class Data:
     def __init__(self):
       self.myCookingTime = 0
     def printTimer(self):
@@ -59,94 +53,68 @@
       return self.myCookingTime
   
     
-OpenRTM_aist.FSM_TOPSTATE(TOP)
+
     
-
-class Disabled(TOP):
-  def __init__(self, instance):
-    super(Disabled,self).__init__(instance)
-  def entry(self):
-    OpenRTM_aist.Link.entry(self)
+ at OpenRTM_aist.fsm_substate(TOP)
+class Disabled(OpenRTM_aist.Link):
+  def on_entry(self):
     print("  Microwave opened")
-  def exit(self):
-    OpenRTM_aist.Link.exit(self)
+  def on_exit(self):
     print("  Microwave closed")
   def close(self):
-    self.setStateHistory(Operational)
-  def init(self):
-    OpenRTM_aist.Link.init(self)
+    self.setStateHistory(OpenRTM_aist.Macho.State(Operational))
 
-OpenRTM_aist.FSM_SUBSTATE(Disabled,TOP)
 
-class Operational(TOP):
-  def __init__(self, instance):
-    super(Operational,self).__init__(instance)
+ at OpenRTM_aist.Macho.deephistory
+ at OpenRTM_aist.fsm_substate(TOP)
+class Operational(OpenRTM_aist.Link):
   def open(self):
-    self.setState(Disabled)
+    self.set_state(OpenRTM_aist.Macho.State(Disabled))
   def stop(self):
-    self.setState(Idle)
-  def init(self):
-    OpenRTM_aist.Link.init(self)
-    self.setState(Idle)
-  def entry(self):
-    OpenRTM_aist.Link.entry(self)
-  def exit(self):
-    OpenRTM_aist.Link.exit(self)
+    self.set_state(OpenRTM_aist.Macho.State(Idle))
+  def on_init(self):
+    self.set_state(OpenRTM_aist.Macho.State(Idle))
+
+
   
 
 
 
-OpenRTM_aist.FSM_SUBSTATE(Operational,TOP)
-OpenRTM_aist.Macho.DEEPHISTORY(Operational)
 
 
-class Idle(Operational):
-  def __init__(self, instance):
-    super(Idle,self).__init__(instance)
+
+ at OpenRTM_aist.fsm_substate(Operational)
+class Idle(OpenRTM_aist.Link):
   def minute(self, time_):
-    self.setState(Programmed)
-    self["TopBase_"].dispatch(OpenRTM_aist.Macho.Event1("minute",time_))
+    self.set_state(OpenRTM_aist.Macho.State(Programmed))
+    self.dispatch(OpenRTM_aist.Macho.Event("minute",time_))
     
-  def entry(self):
-    OpenRTM_aist.Link.entry(self)
-    self[TOP].box().resetTimer()
+  def on_entry(self):
+    self.data(TOP).resetTimer()
     print("  Microwave ready")
-  def init(self):
-    OpenRTM_aist.Link.init(self)
-  def exit(self):
-    OpenRTM_aist.Link.exit(self)
 
 
-OpenRTM_aist.FSM_SUBSTATE(Idle,Operational)
 
 
-class Programmed(Operational):
-  def __init__(self, instance):
-    super(Programmed,self).__init__(instance)
+
+ at OpenRTM_aist.fsm_substate(Operational)
+class Programmed(OpenRTM_aist.Link):
   def minute(self, time_):
     for t in range(time_.data):
-      self[TOP].box().incrementTimer()
-    self[TOP].box().printTimer()
+      self.data(TOP).incrementTimer()
+    self.data(TOP).printTimer()
   def start(self):
     self.setState(Cooking)
-  def entry(self):
-    OpenRTM_aist.Link.entry(self)
-  def exit(self):
-    OpenRTM_aist.Link.exit(self)
-  def init(self):
-    OpenRTM_aist.Link.init(self)
 
 
 
-OpenRTM_aist.FSM_SUBSTATE(Programmed,Operational)
 
 
-class Cooking(Programmed):
-  def __init__(self, instance):
-    super(Cooking,self).__init__(instance)
+ at OpenRTM_aist.fsm_substate(Programmed)
+class Cooking(OpenRTM_aist.Link):
   def tick(self):
     print("  Clock tick")
-    tb = self[TOP].box()
+    tb = self.data(TOP)
     tb.decrementTimer()
     if tb.getRemainingTime() == 0:
       print("  Finished")
@@ -154,14 +122,9 @@
     else:
       tb.printTimer()
     
-  def entry(self):
-    OpenRTM_aist.Link.entry(self)
+  def on_entry(self):
     print("  Heating on")
-  def exit(self):
-    OpenRTM_aist.Link.exit(self)
+  def on_exit(self):
     print("  Heating off")
-  def init(self):
-    OpenRTM_aist.Link.init(self)
 
 
-OpenRTM_aist.FSM_SUBSTATE(Cooking,Programmed)
\ No newline at end of file

Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/python3_examples/StaticFsm/Microwave.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/python3_examples/StaticFsm/Microwave.py	2017-06-27 13:55:54 UTC (rev 853)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/python3_examples/StaticFsm/Microwave.py	2017-07-04 09:03:20 UTC (rev 854)
@@ -49,7 +49,7 @@
 
   def onInitialize(self):
     self._fsm = OpenRTM_aist.Machine(MicrowaveFsm.TOP, self)
-    self._fsm.init()
+    #self._fsm.init()
     self._eventIn = OpenRTM_aist.EventInPort("event", self._fsm)
     
     self.addInPort("event", self._eventIn)

Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/python3_examples/StaticFsm/MicrowaveFsm.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/python3_examples/StaticFsm/MicrowaveFsm.py	2017-06-27 13:55:54 UTC (rev 853)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/python3_examples/StaticFsm/MicrowaveFsm.py	2017-07-04 09:03:20 UTC (rev 854)
@@ -19,18 +19,12 @@
 import OpenRTM_aist
 import OpenRTM_aist.Macho
 
+ at OpenRTM_aist.fsm_topstate
 class TOP(OpenRTM_aist.Link):
-  def __init__(self, instance):
-    super(TOP,self).__init__(instance)
-  def entry(self):
-    OpenRTM_aist.Link.entry(self)
-  def exit(self):
-    OpenRTM_aist.Link.exit(self)
-  def init(self):
-    OpenRTM_aist.Link.init(self)
-    self.setState(Operational)
-    
+  def on_init(self):
+    self.set_state(OpenRTM_aist.Macho.State(Operational))
 
+
   def open(self):
     pass
   def close(self):
@@ -44,11 +38,11 @@
   def tick(self):
     pass
 
-  class Box:
+  class Data:
     def __init__(self):
       self.myCookingTime = 0
     def printTimer(self):
-      print(" Timer set to ", self.myCookingTime, " minutes")
+      print " Timer set to ", self.myCookingTime, " minutes"
     def incrementTimer(self):
       self.myCookingTime+=1
     def decrementTimer(self):
@@ -59,94 +53,68 @@
       return self.myCookingTime
   
     
-OpenRTM_aist.FSM_TOPSTATE(TOP)
+
     
-
-class Disabled(TOP):
-  def __init__(self, instance):
-    super(Disabled,self).__init__(instance)
-  def entry(self):
-    OpenRTM_aist.Link.entry(self)
+ at OpenRTM_aist.fsm_substate(TOP)
+class Disabled(OpenRTM_aist.Link):
+  def on_entry(self):
     print("  Microwave opened")
-  def exit(self):
-    OpenRTM_aist.Link.exit(self)
+  def on_exit(self):
     print("  Microwave closed")
   def close(self):
-    self.setStateHistory(Operational)
-  def init(self):
-    OpenRTM_aist.Link.init(self)
+    self.setStateHistory(OpenRTM_aist.Macho.State(Operational))
 
-OpenRTM_aist.FSM_SUBSTATE(Disabled,TOP)
 
-class Operational(TOP):
-  def __init__(self, instance):
-    super(Operational,self).__init__(instance)
+ at OpenRTM_aist.Macho.deephistory
+ at OpenRTM_aist.fsm_substate(TOP)
+class Operational(OpenRTM_aist.Link):
   def open(self):
-    self.setState(Disabled)
+    self.set_state(OpenRTM_aist.Macho.State(Disabled))
   def stop(self):
-    self.setState(Idle)
-  def init(self):
-    OpenRTM_aist.Link.init(self)
-    self.setState(Idle)
-  def entry(self):
-    OpenRTM_aist.Link.entry(self)
-  def exit(self):
-    OpenRTM_aist.Link.exit(self)
+    self.set_state(OpenRTM_aist.Macho.State(Idle))
+  def on_init(self):
+    self.set_state(OpenRTM_aist.Macho.State(Idle))
+
+
   
 
 
 
-OpenRTM_aist.FSM_SUBSTATE(Operational,TOP)
-OpenRTM_aist.Macho.DEEPHISTORY(Operational)
 
 
-class Idle(Operational):
-  def __init__(self, instance):
-    super(Idle,self).__init__(instance)
+
+ at OpenRTM_aist.fsm_substate(Operational)
+class Idle(OpenRTM_aist.Link):
   def minute(self, time_):
-    self.setState(Programmed)
-    self["TopBase_"].dispatch(OpenRTM_aist.Macho.Event1("minute",time_))
+    self.set_state(OpenRTM_aist.Macho.State(Programmed))
+    self.dispatch(OpenRTM_aist.Macho.Event("minute",time_))
     
-  def entry(self):
-    OpenRTM_aist.Link.entry(self)
-    self[TOP].box().resetTimer()
+  def on_entry(self):
+    self.data(TOP).resetTimer()
     print("  Microwave ready")
-  def init(self):
-    OpenRTM_aist.Link.init(self)
-  def exit(self):
-    OpenRTM_aist.Link.exit(self)
 
 
-OpenRTM_aist.FSM_SUBSTATE(Idle,Operational)
 
 
-class Programmed(Operational):
-  def __init__(self, instance):
-    super(Programmed,self).__init__(instance)
+
+ at OpenRTM_aist.fsm_substate(Operational)
+class Programmed(OpenRTM_aist.Link):
   def minute(self, time_):
     for t in range(time_.data):
-      self[TOP].box().incrementTimer()
-    self[TOP].box().printTimer()
+      self.data(TOP).incrementTimer()
+    self.data(TOP).printTimer()
   def start(self):
     self.setState(Cooking)
-  def entry(self):
-    OpenRTM_aist.Link.entry(self)
-  def exit(self):
-    OpenRTM_aist.Link.exit(self)
-  def init(self):
-    OpenRTM_aist.Link.init(self)
 
 
 
-OpenRTM_aist.FSM_SUBSTATE(Programmed,Operational)
 
 
-class Cooking(Programmed):
-  def __init__(self, instance):
-    super(Cooking,self).__init__(instance)
+ at OpenRTM_aist.fsm_substate(Programmed)
+class Cooking(OpenRTM_aist.Link):
   def tick(self):
     print("  Clock tick")
-    tb = self[TOP].box()
+    tb = self.data(TOP)
     tb.decrementTimer()
     if tb.getRemainingTime() == 0:
       print("  Finished")
@@ -154,14 +122,9 @@
     else:
       tb.printTimer()
     
-  def entry(self):
-    OpenRTM_aist.Link.entry(self)
+  def on_entry(self):
     print("  Heating on")
-  def exit(self):
-    OpenRTM_aist.Link.exit(self)
+  def on_exit(self):
     print("  Heating off")
-  def init(self):
-    OpenRTM_aist.Link.init(self)
 
 
-OpenRTM_aist.FSM_SUBSTATE(Cooking,Programmed)
\ No newline at end of file



More information about the openrtm-commit mailing list