ros 程式碼中執行node

weixin_34236869發表於2018-01-19

在程式中啟動node:

運用python的subprocess

import subprocess

...

cmd = ["rosrun", "xx_package",  "xx_node", "param:=value"]
node = subprocess.Popen(cmd)

殺死node:
呼叫subprocess的函式

node.terminate()
node.wait()

另外一種方式:
呼叫ROS提供的API

cmd = ["rosnode", "kill", "xx_node"]
terminate_node = subprocess.Popen(cmd)
terminate_node.wait()

相關文章