[openrtm-users 02845] コンポーネントの中からコンポーネントを終了する

Kei Okada k-okada @ jsk.t.u-tokyo.ac.jp
2013年 7月 22日 (月) 18:33:15 JST


岡田です.

コンポーネントの中からコンポーネントを終了させる,というようなことはできるのでしょうか?
具体的には,例えばonExecuteで10回データをもらったら,exitしたい,と思っています.

# rtm modules
import sys, time, signal
import RTC
import OpenRTM_aist

global mgr

class TestComp(OpenRTM_aist.DataFlowComponentBase):
    def __init__ (self, manager):
        OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
        return

    def onInitialize(self):
        port = "Short"
        self.inport = OpenRTM_aist.InPort(port, RTC.TimedShort)
        self.registerInPort(port, self.inport)
        self.data_received = 0

        return RTC.RTC_OK

    def onExecute(self, ec_id):
        if self.inport.isNew():
            data = self.inport.read()
            print data
            self.data_received += 1
            if ( self.data_received > 10 ) :
                mgr.shutdown()

        return RTC.RTC_OK

module_spec = ["implementation_id", "test_seqio",
               "type_name",         "test_seqio",
               "description",       "Dataport ROS bridge component",
               "version",           "1.0",
               "vendor",            "Kei Okada",
               "category",          "example",
               "activity_type",     "DataFlowComponent",
               "max_instance",      "10",
               "language",          "Python",
               "lang_type",         "script",
               ""]

def TestInit(manager):
    profile = OpenRTM_aist.Properties(defaults_str=module_spec)
    print  profile
    manager.registerFactory(profile,
                            TestComp,
                            OpenRTM_aist.Delete)
    comp = manager.createComponent("test_seqio")

def test_seqio():
    mgr = OpenRTM_aist.Manager.init(sys.argv)
    mgr.setModuleInitProc(TestInit)
    mgr.activateManager()
    mgr.runManager()


More information about the openrtm-users mailing list