[openrtm-commit:02710] r861 - in branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist: . examples/StaticFsm
openrtm @ openrtm.org
openrtm @ openrtm.org
2017年 7月 26日 (水) 16:04:25 JST
Author: miyamoto
Date: 2017-07-26 16:04:25 +0900 (Wed, 26 Jul 2017)
New Revision: 861
Added:
branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort_pyfsm.py
branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/StaticFSM_pyfsm.py
branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/MicrowaveFsm_pyfsm.py
branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/Microwave_pyfsm.py
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
Log:
[incompat,2.0,FSM4RTC] support pyfsm.
Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort.py 2017-07-24 04:28:53 UTC (rev 860)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort.py 2017-07-26 07:04:25 UTC (rev 861)
@@ -26,7 +26,7 @@
pass
def __call__(self, info, data):
if info.properties.getProperty("fsm_event_name") == self._eventName or info.name == self._eventName:
- self._fsm.dispatch(OpenRTM_aist.Macho.Event0(self._handler))
+ self._fsm.dispatch(OpenRTM_aist.Macho.Event(self._handler))
return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
@@ -44,7 +44,7 @@
data_ = OpenRTM_aist.ConnectorDataListenerT.__call__(self, info, data, self._data_type)
if info.properties.getProperty("fsm_event_name") == self._eventName or info.name == self._eventName:
- self._fsm.dispatch(OpenRTM_aist.Macho.Event1(self._handler, data_))
+ self._fsm.dispatch(OpenRTM_aist.Macho.Event(self._handler, data_))
return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
Added: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort_pyfsm.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort_pyfsm.py (rev 0)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/EventPort_pyfsm.py 2017-07-26 07:04:25 UTC (rev 861)
@@ -0,0 +1,211 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file EventPort_pyfsm.py
+# @brief EventInPort template class
+# @date $Date: $
+# @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+#
+# Copyright (C) 2017
+# Intelligent Systems Research Institute,
+# National Institute of
+# Advanced Industrial Science and Technology (AIST), Japan
+# All rights reserved.
+
+import OpenRTM_aist
+import OpenRTM_aist.StaticFSM_pyfsm
+import pyfsm
+
+
+class EventBinder0(OpenRTM_aist.ConnectorDataListener):
+ def __init__(self, fsm, event_name, handler):
+ self._fsm = fsm
+ self._eventName = event_name
+ self._handler = handler
+ def __del__(self):
+ pass
+ def __call__(self, info, data):
+ if info.properties.getProperty("fsm_event_name") == self._eventName or info.name == self._eventName:
+ self._fsm.dispatch(pyfsm.Event(self._handler))
+ return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
+ return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
+
+
+
+class EventBinder1(OpenRTM_aist.ConnectorDataListenerT):
+ def __init__(self, fsm, event_name, handler, data_type):
+ self._fsm = fsm
+ self._eventName = event_name
+ self._handler = handler
+ self._data_type = data_type
+ def __del__(self):
+ pass
+ def __call__(self, info, data):
+ data_ = OpenRTM_aist.ConnectorDataListenerT.__call__(self, info, data, self._data_type)
+
+ if info.properties.getProperty("fsm_event_name") == self._eventName or info.name == self._eventName:
+ self._fsm.dispatch(pyfsm.Event(self._handler, data_))
+ return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
+ return OpenRTM_aist.ConnectorListenerStatus.NO_CHANGE
+
+
+
+
+
+
+##
+# @if jp
+#
+# @class EventInPort
+#
+# @brief EventInPort ¥Æ¥ó¥×¥ì¡¼¥È¥¯¥é¥¹
+#
+# EventInPort ¤Î¼ÂÁõ¤Ç¤¢¤ë EventInPort<T> ¤Î¥Æ¥ó¥×¥ì¡¼¥È¥¯¥é¥¹¡£
+# <T> ¤ÏBasicDataType.idl ¤Ë¤ÆÄêµÁ¤µ¤ì¤Æ¤¤¤ë·¿¤Ç¡¢¥á¥ó¥Ð¤È¤·¤Æ
+# Time ·¿¤Î tm , ¤ª¤è¤Ó T·¿¤Î data ¤ò»ý¤Ä¹½Â¤ÂΤǤʤ¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
+# EventInPort ¤ÏÆâÉô¤Ë¥ê¥ó¥°¥Ð¥Ã¥Õ¥¡¤ò»ý¤Á¡¢³°Éô¤«¤éÁ÷¿®¤µ¤ì¤¿¥Ç¡¼¥¿¤ò½ç¼¡
+# ¤³¤Î¥ê¥ó¥°¥Ð¥Ã¥Õ¥¡¤Ë³ÊǼ¤¹¤ë¡£¥ê¥ó¥°¥Ð¥Ã¥Õ¥¡¤Î¥µ¥¤¥º¤Ï¥Ç¥Õ¥©¥ë¥È¤Ç64¤È
+# ¤Ê¤Ã¤Æ¤¤¤ë¤¬¡¢¥³¥ó¥¹¥È¥é¥¯¥¿°ú¿ô¤Ë¤è¤ê¥µ¥¤¥º¤ò»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤¤ë¡£
+# ¥Ç¡¼¥¿¤Ï¥Õ¥é¥°¤Ë¤è¤Ã¤Æ̤ÆÉ¡¢´ûÆɾõÂÖ¤¬´ÉÍý¤µ¤ì¡¢isNew(), write(), read(),
+# isFull(), isEmpty() Åù¤Î¥á¥½¥Ã¥É¤Ë¤è¤ê¥Ï¥ó¥É¥ê¥ó¥°¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
+#
+# OnRead·Ï¥³¡¼¥ë¥Ð¥Ã¥¯ (Æɤ߽Ф·¤Ëµ¯°ø¤¹¤ë¥¤¥Ù¥ó¥È¤Ë¤è¤ê¥³¡¼¥ë¤µ¤ì¤ë)
+#
+# - void OnRead::operator():
+# EventInPort::read() ¤ò¸Æ¤Ó½Ð¤·Æɤ߽Ф·¤ò¹Ô¤¦ºÝ¤Ë¥³¡¼¥ë¤µ¤ì¤ë¡£
+#
+# - DataType OnReadConvert::operator(DataType):
+# EventInPort::read() ¤ò¸Æ¤Ó½Ð¤·¡¢¥Ç¡¼¥¿¤ò¥Ð¥Ã¥Õ¥¡¤«¤éÆɤߤÀ¤¹ºÝ¤Ë¸Æ¤Ð¤ì
+# ¥Ç¡¼¥¿¤ÎÊÑ´¹¤ò¹Ô¤¦¡£°ú¿ô¤Ë¤Ï¥Ð¥Ã¥Õ¥¡¤«¤éÆɤ߽Фµ¤ì¤¿Ãͤ¬Í¿¤¨¤é¤ì¡¢
+# ÊÑ´¹¸å¤Î¥Ç¡¼¥¿¤òÌá¤êÃͤȤ·¤ÆÊÖ¤¹¡£¤³¤ÎÃͤ¬read()¤ÎÊÖ¤¹ÃͤȤʤ롣
+#
+# @since 0.2.0
+#
+# @else
+#
+# @class EventInPort
+#
+# @brief EventInPort template class
+#
+# This is a template class that implements EventInPort. <T> is the type
+# defined in BasicDataType.idl and must be the structure which has
+# both Time type tm and type-T data as a member. EventInPort has a ring
+# buffer internally, and stores the received data externally in
+# this buffer one by one. The size of ring buffer can be specified
+# according to the argument of constructor, though the default size
+# is 64. Unread data and data which is already read are managed
+# with the flag, and the data can be handled by the isNew(),
+# write(), read(), isFull() and isEmpty() method etc.
+#
+# @since 0.2.0
+#
+# @endif
+#
+class EventInPort(OpenRTM_aist.InPortBase):
+ ##
+ # @if jp
+ #
+ # @brief ¥³¥ó¥¹¥È¥é¥¯¥¿
+ #
+ # ¥³¥ó¥¹¥È¥é¥¯¥¿¡£
+ # ¥Ñ¥é¥á¡¼¥¿¤È¤·¤ÆÍ¿¤¨¤é¤ì¤ë T ·¿¤ÎÊÑ¿ô¤Ë¥Ð¥¤¥ó¥É¤µ¤ì¤ë¡£
+ #
+ # @param name EventInPort ̾¡£EventInPortBase:name() ¤Ë¤è¤ê»²¾È¤µ¤ì¤ë¡£
+ # @param value ¤³¤Î EventInPort ¤Ë¥Ð¥¤¥ó¥É¤µ¤ì¤ë T ·¿¤ÎÊÑ¿ô
+ # @param bufsize EventInPort ÆâÉô¤Î¥ê¥ó¥°¥Ð¥Ã¥Õ¥¡¤Î¥Ð¥Ã¥Õ¥¡Ä¹(¥Ç¥Õ¥©¥ë¥ÈÃÍ:64)
+ # @param read_block Æɹþ¥Ö¥í¥Ã¥¯¥Õ¥é¥°¡£
+ # ¥Ç¡¼¥¿Æɹþ»þ¤Ë̤Æɥǡ¼¥¿¤¬¤Ê¤¤¾ì¹ç¡¢¼¡¤Î¥Ç¡¼¥¿¼õ¿®¤Þ¤Ç¥Ö¥í¥Ã¥¯¤¹¤ë
+ # ¤«¤É¤¦¤«¤òÀßÄê(¥Ç¥Õ¥©¥ë¥ÈÃÍ:false)
+ # @param write_block ½ñ¹þ¥Ö¥í¥Ã¥¯¥Õ¥é¥°¡£
+ # ¥Ç¡¼¥¿½ñ¹þ»þ¤Ë¥Ð¥Ã¥Õ¥¡¤¬¥Õ¥ë¤Ç¤¢¤Ã¤¿¾ì¹ç¡¢¥Ð¥Ã¥Õ¥¡¤Ë¶õ¤¤¬¤Ç¤¤ë
+ # ¤Þ¤Ç¥Ö¥í¥Ã¥¯¤¹¤ë¤«¤É¤¦¤«¤òÀßÄê(¥Ç¥Õ¥©¥ë¥ÈÃÍ:false)
+ # @param read_timeout Æɹþ¥Ö¥í¥Ã¥¯¤ò»ØÄꤷ¤Æ¤¤¤Ê¤¤¾ì¹ç¤Î¡¢¥Ç¡¼¥¿Æɼ西¥¤¥à
+ # ¥¢¥¦¥È»þ´Ö(¥ß¥êÉÃ)(¥Ç¥Õ¥©¥ë¥ÈÃÍ:0)
+ # @param write_timeout ½ñ¹þ¥Ö¥í¥Ã¥¯¤ò»ØÄꤷ¤Æ¤¤¤Ê¤¤¾ì¹ç¤Î¡¢¥Ç¡¼¥¿½ñ¹þ¥¿¥¤¥à
+ # ¥¢¥¦¥È»þ´Ö(¥ß¥êÉÃ)(¥Ç¥Õ¥©¥ë¥ÈÃÍ:0)
+ #
+ # @else
+ #
+ # @brief A constructor.
+ #
+ # constructor.
+ # This is bound to type-T variable given as a parameter.
+ #
+ # @param name A name of the EventInPort. This name is referred by
+ # EventInPortBase::name().
+ # @param value type-T variable that is bound to this EventInPort.
+ # @param bufsize Buffer length of internal ring buffer of EventInPort
+ # (The default value:64)
+ # @param read_block Flag of reading block.
+ # When there are not unread data at reading data,
+ # set whether to block data until receiving the next
+ # data. (The default value:false)
+ # @param write_block Flag of writing block.
+ # If the buffer was full at writing data, set whether
+ # to block data until the buffer has space.
+ # (The default value:false)
+ # @param read_timeout Data reading timeout time (millisecond)
+ # when not specifying read blocking.
+ # (The default value:0)
+ # @param write_timeout Data writing timeout time (millisecond)
+ # when not specifying writing block.
+ # (The default value:0)
+ #
+ # @endif
+ #
+ def __init__(self, name, fsm, bufsize=64, read_block=False, write_block=False, read_timeout=0, write_timeout=0):
+ super(EventInPort, self).__init__(name, "any")
+ self._name = name
+ self._fsm = fsm
+ ##
+ # @if jp
+ #
+ # @brief ¥Ç¥¹¥È¥é¥¯¥¿
+ #
+ # ¥Ç¥¹¥È¥é¥¯¥¿¡£
+ #
+ # @else
+ #
+ # @brief Destructor
+ #
+ # Destructor
+ #
+ # @endif
+ #
+ def __del__(self):
+ pass
+ ##
+ # @if jp
+ #
+ # @brief ¥Ý¡¼¥È̾¾Î¤ò¼èÆÀ¤¹¤ë¡£
+ #
+ # ¥Ý¡¼¥È̾¾Î¤ò¼èÆÀ¤¹¤ë¡£
+ #
+ # @return ¥Ý¡¼¥È̾¾Î
+ #
+ # @else
+ #
+ # @brief Get port name
+ #
+ # Get port name.
+ #
+ # @return The port name
+ #
+ # @endif
+ #
+ def name(self):
+ return self._name
+
+ def bindEvent0(self, name, handler):
+ self.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED,
+ EventBinder0(self._fsm, name, handler))
+
+ def bindEvent1(self, name, handler, data_type):
+ self.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED,
+ EventBinder1(self._fsm, name, handler, data_type))
+
+
+
+
+
Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/Macho.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/Macho.py 2017-07-24 04:28:53 UTC (rev 860)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/Macho.py 2017-07-26 07:04:25 UTC (rev 861)
@@ -123,7 +123,7 @@
#global _theDefaultInitializer
self._myStateInstance.machine().setPendingState(current, _Initializer())
def _shutdown(self):
- self._myStateInstance.machine().shutdown()
+ self._myStateInstance.machine()._shutdown()
def _setHistorySuper(self, instance, deep):
pass
@@ -785,7 +785,7 @@
def startAlias(self, state):
self.myCurrentState = _StateSpecification._getInstance(self)
self.setStateAlias(state)
- def shutdown(self):
+ def _shutdown(self):
#global _theDefaultInitializer
self.setState(_StateSpecification._getInstance(self), _Initializer())
self.myCurrentState = None
@@ -926,10 +926,11 @@
self.init(box=None, initial_state=initial_state, args=args)
def __del__(self):
pass
- def exit(self):
+ def shutdown(self):
self.myCurrentState.shutdown()
self.free(Machine.theStateCount)
Machine.theStateCount = 1
+
def init(self, box=None,initial_state=None, args=()):
self.allocate(Machine.theStateCount)
top = self.TOP._getInstance(self, self.TopBase, self.TOP)
Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/StaticFSM.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/StaticFSM.py 2017-07-24 04:28:53 UTC (rev 860)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/StaticFSM.py 2017-07-26 07:04:25 UTC (rev 861)
@@ -83,7 +83,7 @@
-class Link(OpenRTM_aist.Macho.Link):
+class Link(OpenRTM_aist.Macho.StateDef):
def __init__(self, instance):
super(Link,self).__init__(instance)
self._rtComponent = None
@@ -128,4 +128,9 @@
def onInit(self):
return RTC.RTC_OK
def onExit(self):
- return RTC.RTC_OK
\ No newline at end of file
+ return RTC.RTC_OK
+
+
+State = OpenRTM_aist.Macho.State
+deephistory = OpenRTM_aist.Macho.deephistory
+Event = OpenRTM_aist.Macho.Event
\ No newline at end of file
Added: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/StaticFSM_pyfsm.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/StaticFSM_pyfsm.py (rev 0)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/StaticFSM_pyfsm.py 2017-07-26 07:04:25 UTC (rev 861)
@@ -0,0 +1,130 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file StaticFSM_pyfsm.py
+# @brief Static FSM framework based on pyfsm
+# @date $Date: $
+# @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+#
+# Copyright (C) 2017
+# Intelligent Systems Research Institute,
+# National Institute of
+# Advanced Industrial Science and Technology (AIST), Japan
+# All rights reserved.
+
+import OpenRTM_aist
+import pyfsm
+import RTC
+
+
+def fsm_topstate(TOP):
+ ret = pyfsm.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 = pyfsm.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
+
+
+
+
+
+
+class Machine(pyfsm.Machine):
+ def __init__(self, TOP, comp):
+ self._rtComponent = comp
+ super(Machine,self).__init__(TOP)
+
+
+
+ def __del__(self):
+ pass
+ def init_other(self, other):
+ pass
+ def equal(self, snapshot):
+ pass
+ def getComp(self):
+ return self._rtComponent
+
+
+
+class Link(pyfsm.StateDef):
+ def __init__(self):
+ super(Link,self).__init__()
+ self._rtComponent = None
+ def __del__(self):
+ pass
+ def setrtc(self):
+ if self._rtComponent:
+ return
+ machine = self._myStateInstance.machine()
+ if machine:
+ self._rtComponent = machine.getComp()
+
+ def call_entry(self):
+ self.setrtc()
+ if not self._rtComponent:
+ self.onEntry()
+ else:
+ self._rtComponent.postOnFsmStateChange(self._state_name(), RTC.RTC_OK)
+ self._rtComponent.preOnFsmEntry(self._state_name())
+ self._rtComponent.postOnFsmEntry(self._state_name(), self.onEntry())
+
+ def call_init(self):
+ self.setrtc()
+ if not self._rtComponent:
+ self.onInit()
+ else:
+ self._rtComponent.preOnFsmInit(self._state_name())
+ self._rtComponent.postOnFsmInit(self._state_name(), self.onInit())
+
+
+ def call_exit(self):
+ self.setrtc()
+ if not self._rtComponent:
+ self.onExit()
+ else:
+ self._rtComponent.preOnFsmExit(self._state_name())
+ self._rtComponent.postOnFsmExit(self._state_name(), self.onExit())
+ self._rtComponent.preOnFsmStateChange(self._state_name())
+
+ def onEntry(self):
+ return RTC.RTC_OK
+ def onInit(self):
+ return RTC.RTC_OK
+ def onExit(self):
+ return RTC.RTC_OK
+
+
+State = pyfsm.State
+deephistory = pyfsm.deephistory
+Event = pyfsm.Event
\ No newline at end of file
Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/Microwave.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/Microwave.py 2017-07-24 04:28:53 UTC (rev 860)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/Microwave.py 2017-07-26 07:04:25 UTC (rev 861)
@@ -17,6 +17,8 @@
import RTC
import OpenRTM_aist
+import OpenRTM_aist.StaticFSM as StaticFSM
+import OpenRTM_aist.EventPort as EventPort
import MicrowaveFsm
@@ -44,13 +46,13 @@
return
def onFinalize(self):
- self._fsm.exit()
+ self._fsm.shutdown()
return RTC.RTC_OK
def onInitialize(self):
- self._fsm = OpenRTM_aist.Machine(MicrowaveFsm.TOP, self)
+ self._fsm = StaticFSM.Machine(MicrowaveFsm.TOP, self)
#self._fsm.init()
- self._eventIn = OpenRTM_aist.EventInPort("event", self._fsm)
+ self._eventIn = EventPort.EventInPort("event", self._fsm)
self.addInPort("event", self._eventIn)
self._eventIn.bindEvent0("open", MicrowaveFsm.TOP.open)
Modified: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/MicrowaveFsm.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/MicrowaveFsm.py 2017-07-24 04:28:53 UTC (rev 860)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/MicrowaveFsm.py 2017-07-26 07:04:25 UTC (rev 861)
@@ -17,12 +17,13 @@
import RTC
import OpenRTM_aist
-import OpenRTM_aist.Macho
+import OpenRTM_aist.StaticFSM as StaticFSM
+import OpenRTM_aist.EventPort as EventPort
- at OpenRTM_aist.fsm_topstate
-class TOP(OpenRTM_aist.Link):
+ at StaticFSM.fsm_topstate
+class TOP(StaticFSM.Link):
def on_init(self):
- self.set_state(OpenRTM_aist.Macho.State(Operational))
+ self.set_state(StaticFSM.State(Operational))
def open(self):
@@ -55,8 +56,8 @@
- at OpenRTM_aist.fsm_substate(TOP)
-class Disabled(OpenRTM_aist.Link):
+ at StaticFSM.fsm_substate(TOP)
+class Disabled(StaticFSM.Link):
def on_entry(self):
print(" Microwave opened")
def on_exit(self):
@@ -63,18 +64,18 @@
print(" Microwave closed")
def close(self):
#self.setStateHistory(OpenRTM_aist.Macho.State(Operational))
- self.set_state(OpenRTM_aist.Macho.State(Operational))
+ self.set_state(StaticFSM.State(Operational))
- at OpenRTM_aist.Macho.deephistory
- at OpenRTM_aist.fsm_substate(TOP)
-class Operational(OpenRTM_aist.Link):
+ at StaticFSM.deephistory
+ at StaticFSM.fsm_substate(TOP)
+class Operational(StaticFSM.Link):
def open(self):
- self.set_state(OpenRTM_aist.Macho.State(Disabled))
+ self.set_state(StaticFSM.State(Disabled))
def stop(self):
- self.set_state(OpenRTM_aist.Macho.State(Idle))
+ self.set_state(StaticFSM.State(Idle))
def on_init(self):
- self.set_state(OpenRTM_aist.Macho.State(Idle))
+ self.set_state(StaticFSM.State(Idle))
@@ -84,11 +85,11 @@
- at OpenRTM_aist.fsm_substate(Operational)
-class Idle(OpenRTM_aist.Link):
+ at StaticFSM.fsm_substate(Operational)
+class Idle(StaticFSM.Link):
def minute(self, time_):
- self.set_state(OpenRTM_aist.Macho.State(Programmed))
- self.dispatch(OpenRTM_aist.Macho.Event(TOP.minute,time_))
+ self.set_state(StaticFSM.State(Programmed))
+ self.dispatch(StaticFSM.Event(TOP.minute,time_))
def on_entry(self):
self.data(TOP).resetTimer()
@@ -98,21 +99,21 @@
- at OpenRTM_aist.fsm_substate(Operational)
-class Programmed(OpenRTM_aist.Link):
+ at StaticFSM.fsm_substate(Operational)
+class Programmed(StaticFSM.Link):
def minute(self, time_):
for t in range(time_.data):
self.data(TOP).incrementTimer()
self.data(TOP).printTimer()
def start(self):
- self.setState(Cooking)
+ self.set_state(StaticFSM.State(Cooking))
- at OpenRTM_aist.fsm_substate(Programmed)
-class Cooking(OpenRTM_aist.Link):
+ at StaticFSM.fsm_substate(Programmed)
+class Cooking(StaticFSM.Link):
def tick(self):
print(" Clock tick")
tb = self.data(TOP)
@@ -119,7 +120,7 @@
tb.decrementTimer()
if tb.getRemainingTime() == 0:
print(" Finished")
- self.setState(Idle)
+ self.set_state(StaticFSM.State(Idle))
else:
tb.printTimer()
Added: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/MicrowaveFsm_pyfsm.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/MicrowaveFsm_pyfsm.py (rev 0)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/MicrowaveFsm_pyfsm.py 2017-07-26 07:04:25 UTC (rev 861)
@@ -0,0 +1,132 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file Microwave.py
+# @brief example StaticFSM
+# @date $Date: $
+# @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+#
+# Copyright (C) 2017
+# Intelligent Systems Research Institute,
+# National Institute of
+# Advanced Industrial Science and Technology (AIST), Japan
+# All rights reserved.
+
+import sys
+
+import RTC
+import OpenRTM_aist
+import OpenRTM_aist.StaticFSM_pyfsm as StaticFSM
+import OpenRTM_aist.EventPort_pyfsm as EventPort
+
+ at StaticFSM.fsm_topstate
+class TOP(StaticFSM.Link):
+ def on_init(self):
+ self.set_state(StaticFSM.State(Operational))
+
+
+ def open(self):
+ pass
+ def close(self):
+ pass
+ def minute(self, time_):
+ pass
+ def start(self):
+ pass
+ def stop(self):
+ pass
+ def tick(self):
+ pass
+
+ class Data:
+ def __init__(self):
+ self.myCookingTime = 0
+ def printTimer(self):
+ print " Timer set to ", self.myCookingTime, " minutes"
+ def incrementTimer(self):
+ self.myCookingTime+=1
+ def decrementTimer(self):
+ self.myCookingTime-=1
+ def resetTimer(self):
+ self.myCookingTime = 0
+ def getRemainingTime(self):
+ return self.myCookingTime
+
+
+
+
+ at StaticFSM.fsm_substate(TOP)
+class Disabled(StaticFSM.Link):
+ def on_entry(self):
+ print(" Microwave opened")
+ def on_exit(self):
+ print(" Microwave closed")
+ def close(self):
+ #self.setStateHistory(OpenRTM_aist.Macho.State(Operational))
+ self.set_state(StaticFSM.State(Operational))
+
+
+ at StaticFSM.deephistory
+ at StaticFSM.fsm_substate(TOP)
+class Operational(StaticFSM.Link):
+ def open(self):
+ self.set_state(StaticFSM.State(Disabled))
+ def stop(self):
+ self.set_state(StaticFSM.State(Idle))
+ def on_init(self):
+ self.set_state(StaticFSM.State(Idle))
+
+
+
+
+
+
+
+
+
+ at StaticFSM.fsm_substate(Operational)
+class Idle(StaticFSM.Link):
+ def minute(self, time_):
+ self.set_state(StaticFSM.State(Programmed))
+ self.dispatch(StaticFSM.Event(TOP.minute,time_))
+
+ def on_entry(self):
+ self.data(TOP).resetTimer()
+ print(" Microwave ready")
+
+
+
+
+
+ at StaticFSM.fsm_substate(Operational)
+class Programmed(StaticFSM.Link):
+ def minute(self, time_):
+ for t in range(time_.data):
+ self.data(TOP).incrementTimer()
+ self.data(TOP).printTimer()
+ def start(self):
+ self.set_state(StaticFSM.State(Cooking))
+
+
+
+
+
+ at StaticFSM.fsm_substate(Programmed)
+class Cooking(StaticFSM.Link):
+ def tick(self):
+ print(" Clock tick")
+ tb = self.data(TOP)
+ tb.decrementTimer()
+ if tb.getRemainingTime() == 0:
+ print(" Finished")
+ self.set_state(StaticFSM.State(Idle))
+ else:
+ tb.printTimer()
+
+ def on_entry(self):
+ print(" Heating on")
+ def on_exit(self):
+ print(" Heating off")
+
+
Added: branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/Microwave_pyfsm.py
===================================================================
--- branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/Microwave_pyfsm.py (rev 0)
+++ branches/FSM4RTC/OpenRTM-aist-Python/OpenRTM_aist/examples/StaticFsm/Microwave_pyfsm.py 2017-07-26 07:04:25 UTC (rev 861)
@@ -0,0 +1,108 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file Microwave.py
+# @brief example StaticFSM
+# @date $Date: $
+# @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+#
+# Copyright (C) 2017
+# Intelligent Systems Research Institute,
+# National Institute of
+# Advanced Industrial Science and Technology (AIST), Japan
+# All rights reserved.
+
+import sys
+
+import RTC
+import OpenRTM_aist
+import OpenRTM_aist.StaticFSM_pyfsm as StaticFSM
+import OpenRTM_aist.EventPort_pyfsm as EventPort
+
+
+import MicrowaveFsm_pyfsm
+
+microwave_spec = ["implementation_id", "Microwave",
+ "type_name", "Microwave",
+ "description", "Console input component",
+ "version", "1.0",
+ "vendor", "Nobuhiko Miyamoto",
+ "category", "example",
+ "activity_type", "DataFlowComponent",
+ "max_instance", "10",
+ "language", "Python",
+ "lang_type", "script",
+ ""]
+
+
+
+
+
+class Microwave(OpenRTM_aist.DataFlowComponentBase):
+ def __init__(self, manager):
+ OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
+
+ return
+
+ def onFinalize(self):
+ self._fsm.exit()
+ return RTC.RTC_OK
+
+ def onInitialize(self):
+ self._fsm = StaticFSM.Machine(MicrowaveFsm.TOP, self)
+ #self._fsm.init()
+ self._eventIn = EventPort.EventInPort("event", self._fsm)
+
+ self.addInPort("event", self._eventIn)
+ self._eventIn.bindEvent0("open", MicrowaveFsm.TOP.open)
+ self._eventIn.bindEvent0("close", MicrowaveFsm.TOP.close)
+ self._eventIn.bindEvent1("minute", MicrowaveFsm.TOP.minute, RTC.TimedLong(RTC.Time(0,0),0))
+ self._eventIn.bindEvent0("start", MicrowaveFsm.TOP.start)
+ self._eventIn.bindEvent0("stop", MicrowaveFsm.TOP.stop)
+ self._eventIn.bindEvent0("tick", MicrowaveFsm.TOP.tick)
+
+
+
+ return RTC.RTC_OK
+
+
+ def onExecute(self, ec_id):
+
+
+ return RTC.RTC_OK
+
+
+def MicrowaveInit(manager):
+ profile = OpenRTM_aist.Properties(defaults_str=microwave_spec)
+ manager.registerFactory(profile,
+ Microwave,
+ OpenRTM_aist.Delete)
+
+
+def MyModuleInit(manager):
+ MicrowaveInit(manager)
+
+ # Create a component
+ comp = manager.createComponent("Microwave")
+
+def main():
+ # Initialize manager
+ mgr = OpenRTM_aist.Manager.init(sys.argv)
+
+ # Set module initialization proceduer
+ # This procedure will be invoked in activateManager() function.
+ mgr.setModuleInitProc(MyModuleInit)
+
+ # Activate manager and register to naming service
+ mgr.activateManager()
+
+ # run the manager in blocking mode
+ # runManager(False) is the default
+ mgr.runManager()
+
+ # If you want to run the manager in non-blocking mode, do like this
+ # mgr.runManager(True)
+
+if __name__ == "__main__":
+ main()
More information about the openrtm-commit
mailing list