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

2 posts / 0 new
Last post
Kei Okada
Offline
Last seen: Never ago
Joined: 2011-05-17 20:20
[openrtm-users 02845] コンポーネントの中からコンポーネントを終了する

岡田です.

コンポーネントの中からコンポーネントを終了させる,というようなことはできるのでしょうか?
具体的には,例えば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

Undefined
Ando Noriaki
Offline
Last seen: 1 year 9 months ago
Joined: 2011-09-04 17:20
[openrtm-users 02846] コンポーネントの中からコンポーネントを終了する

岡田先生

安藤です

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

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

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

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

Kei Okada
Offline
Last seen: Never ago
Joined: 2011-05-17 20:20
[openrtm-users 02847] コンポーネントの中からコンポーネントを終了する

岡田です.

ありがとうございます.
ご教示いただいた内容を
追加して,こちらで試すと,10秒ぐらいプログラムが停止したあと,以下のようにエラーになります.私は1.1.0を使っています.

prev data = 356 , current data = 357
2 12712
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 504, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/k-okada/ros/fuerte/rtm-ros-robotics/rtmros_common/openrtm/src/openrtm/OpenRTM_aist/Task.py",
line 80, in svc_run
self.svc()
File "/home/k-okada/ros/fuerte/rtm-ros-robotics/rtmros_common/openrtm/src/openrtm/OpenRTM_aist/PeriodicExecutionContext.py",
line 450, in svc
comp._sm.worker()
File "/home/k-okada/ros/fuerte/rtm-ros-robotics/rtmros_common/openrtm/src/openrtm/OpenRTM_aist/PeriodicExecutionContext.py",
line 317, in worker
return self._sm.worker()
File "/home/k-okada/ros/fuerte/rtm-ros-robotics/rtmros_common/openrtm/src/openrtm/OpenRTM_aist/StateMachine.py",
line 469, in worker
self._do[states.curr](states)
File "/home/k-okada/ros/fuerte/rtm-ros-robotics/rtmros_common/openrtm/src/openrtm/OpenRTM_aist/PeriodicExecutionContext.py",
line 256, in on_execute
if self._obj.on_execute(self.ec_id) != RTC.RTC_OK:
File "/home/k-okada/ros/fuerte/rtm-ros-robotics/rtmros_common/openrtm/src/openrtm/OpenRTM_aist/RTM_IDL/RTC_idl.py",
line 401, in on_execute
return _omnipy.invoke(self, "on_execute",
_0_RTC.DataFlowComponentAction._d_on_execute, args)
BAD_INV_ORDER: CORBA.BAD_INV_ORDER(omniORB.BAD_INV_ORDER_WouldDeadLock,
CORBA.COMPLETED_NO)

Traceback (most recent call last):
File "/home/k-okada/ros/fuerte/rtm-ros-robotics/rtmros_common/openrtm/src/openrtm/OpenRTM_aist/CorbaNaming.py",
line 616, in unbind
self._rootContext.unbind(name_)
File "/usr/lib/python2.7/dist-packages/CosNaming_idl.py", line 234, in unbind
return _omnipy.invoke(self, "unbind",
_0_CosNaming.NamingContext._d_unbind, args)
NotFound: CosNaming.NamingContext.NotFound(why=missing_node,
rest_of_name=[CosNaming.NameComponent(id='test_seqio0', kind='rtc')])

2013/7/23 Ando Noriaki :
> 岡田先生
>
> 安藤です
>
> 添付のコードを実行するとどうなりますか?
>
> if ( self.data_received > 10 ) :
> mgr.shutdown()
>
> だと、プロセスごと終了になります。
> コンポーネントだけを終了させたかったら
> self.exit()
> でいけそうな気もするのですが、onExecute() の中で呼べたかどうかは
> 確信がありません。
>
>
>
>
> 2013/7/22 Kei Okada :
>> 岡田です.
>>
>> コンポーネントの中からコンポーネントを終了させる,というようなことはできるのでしょうか?
>> 具体的には,例えば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
> _______________________________________________
> openrtm-users mailing list
> openrtm-users@openrtm.org
> http://www.openrtm.org/mailman/listinfo/openrtm-users
_______________________________________________
openrtm-users mailing list
openrtm-users@openrtm.org
http://www.openrtm.org/mailman/listinfo/openrtm-users

shinji.k
Offline
Last seen: Never ago
Joined: 2013-04-30 01:00
[openrtm-users 02852] コンポーネントの中からコンポーネントを終了する

栗原と申します。

お世話になっております。

下記エラーに関しては、原因を追えてないのですが、
onExecute()内にて、 mgr.shutdown()ではなく、
self.exit()を呼んでみてはいかがでしょうか?

その際に、一か所だけOpenRTM-aist-Pythonのコードの
修正をお願い致します。

修正箇所:
 Task.pyの__del__(self)メソッド

修正前:
def __del__(self):
self._count = 0
if self._thread:
self._thread.join()
self._thread = None
return

修正後
def __del__(self):
if self._thread:
if self._count > 0:
self._thread.join()
self._count = 0
self._thread = None
return

join()の前にself._countのチェックが抜けておりましたので、
self._countをチェックするようにしています。

以上、
よろしくお願い致します。

2013/7/23 Kei Okada :
> 岡田です.
>
> ありがとうございます.
> ご教示いただいた内容を
> 追加して,こちらで試すと,10秒ぐらいプログラムが停止したあと,以下のようにエラーになります.私は1.1.0を使っています.
>
> prev data = 356 , current data = 357
> 2 12712
> Exception in thread Thread-2:
> Traceback (most recent call last):
> File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
> self.run()
> File "/usr/lib/python2.7/threading.py", line 504, in run
> self.__target(*self.__args, **self.__kwargs)
> File "/home/k-okada/ros/fuerte/rtm-ros-robotics/rtmros_common/openrtm/src/openrtm/OpenRTM_aist/Task.py",
> line 80, in svc_run
> self.svc()
> File "/home/k-okada/ros/fuerte/rtm-ros-robotics/rtmros_common/openrtm/src/openrtm/OpenRTM_aist/PeriodicExecutionContext.py",
> line 450, in svc
> comp._sm.worker()
> File "/home/k-okada/ros/fuerte/rtm-ros-robotics/rtmros_common/openrtm/src/openrtm/OpenRTM_aist/PeriodicExecutionContext.py",
> line 317, in worker
> return self._sm.worker()
> File "/home/k-okada/ros/fuerte/rtm-ros-robotics/rtmros_common/openrtm/src/openrtm/OpenRTM_aist/StateMachine.py",
> line 469, in worker
> self._do[states.curr](states)
> File "/home/k-okada/ros/fuerte/rtm-ros-robotics/rtmros_common/openrtm/src/openrtm/OpenRTM_aist/PeriodicExecutionContext.py",
> line 256, in on_execute
> if self._obj.on_execute(self.ec_id) != RTC.RTC_OK:
> File "/home/k-okada/ros/fuerte/rtm-ros-robotics/rtmros_common/openrtm/src/openrtm/OpenRTM_aist/RTM_IDL/RTC_idl.py",
> line 401, in on_execute
> return _omnipy.invoke(self, "on_execute",
> _0_RTC.DataFlowComponentAction._d_on_execute, args)
> BAD_INV_ORDER: CORBA.BAD_INV_ORDER(omniORB.BAD_INV_ORDER_WouldDeadLock,
> CORBA.COMPLETED_NO)
>
> Traceback (most recent call last):
> File "/home/k-okada/ros/fuerte/rtm-ros-robotics/rtmros_common/openrtm/src/openrtm/OpenRTM_aist/CorbaNaming.py",
> line 616, in unbind
> self._rootContext.unbind(name_)
> File "/usr/lib/python2.7/dist-packages/CosNaming_idl.py", line 234, in unbind
> return _omnipy.invoke(self, "unbind",
> _0_CosNaming.NamingContext._d_unbind, args)
> NotFound: CosNaming.NamingContext.NotFound(why=missing_node,
> rest_of_name=[CosNaming.NameComponent(id='test_seqio0', kind='rtc')])
>
>
> 2013/7/23 Ando Noriaki :
>> 岡田先生
>>
>> 安藤です
>>
>> 添付のコードを実行するとどうなりますか?
>>
>> if ( self.data_received > 10 ) :
>> mgr.shutdown()
>>
>> だと、プロセスごと終了になります。
>> コンポーネントだけを終了させたかったら
>> self.exit()
>> でいけそうな気もするのですが、onExecute() の中で呼べたかどうかは
>> 確信がありません。
>>
>>
>>
>>
>> 2013/7/22 Kei Okada :
>>> 岡田です.
>>>
>>> コンポーネントの中からコンポーネントを終了させる,というようなことはできるのでしょうか?
>>> 具体的には,例えば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
>> _______________________________________________
>> openrtm-users mailing list
>> openrtm-users@openrtm.org
>> http://www.openrtm.org/mailman/listinfo/openrtm-users
> _______________________________________________
> openrtm-users mailing list
> openrtm-users@openrtm.org
> http://www.openrtm.org/mailman/listinfo/openrtm-users
_______________________________________________
openrtm-users mailing list
openrtm-users@openrtm.org
http://www.openrtm.org/mailman/listinfo/openrtm-users

Log in or register to post comments

Download

latest Releases : 2.0.0-RELESE

2.0.0-RELESE Download page

Number of Projects

Choreonoid

Motion editor/Dynamics simulator

OpenHRP3

Dynamics simulator

OpenRTP

Integrated Development Platform

AIST RTC collection

RT-Components collection by AIST

TORK

Tokyo Opensource Robotics Association

DAQ-Middleware

Middleware for DAQ (Data Aquisition) by KEK