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

Ando Noriaki n-ando @ aist.go.jp
2013年 7月 23日 (火) 11:12:26 JST


岡田先生

安藤です

添付のコードを実行するとどうなりますか?

            if ( self.data_received > 10 ) :
                mgr.shutdown()

だと、プロセスごと終了になります。
コンポーネントだけを終了させたかったら
    self.exit()
でいけそうな気もするのですが、onExecute() の中で呼べたかどうかは
確信がありません。




2013/7/22 Kei Okada <k-okada @ jsk.t.u-tokyo.ac.jp>:
> 岡田です.
>
> コンポーネントの中からコンポーネントを終了させる,というようなことはできるのでしょうか?
> 具体的には,例えば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()
> _______________________________________________
> openrtm-users mailing list
> openrtm-users @ openrtm.org
> http://www.openrtm.org/mailman/listinfo/openrtm-users


More information about the openrtm-users mailing list