0
$\begingroup$

Rosanswers logo

Is there a way to automatically run a node using/inside a C++/Python program? Say some event happened and I want to run this node, then another event happened and I want to close the node. Or perhaps a launch file?


Originally posted by Homer Manalo on ROS Answers with karma: 475 on 2011-04-03

Post score: 0

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

This similar question I asked a while back might help you out.

http://answers.ros.org/question/501/spawn-and-kill-nodes-from-nodessmach


Originally posted by Miguel Prada with karma: 1071 on 2011-04-03

This answer was ACCEPTED on the original site

Post score: 3

$\endgroup$
0
$\begingroup$

Rosanswers logo

A ROS node is just an executable, so you can run (and kill) it as you run any other executable from your program (for C++ see man system or man popen). The main problem might be, that ros stuff that is setup in your bashrc (e.g. the environment variables ROS_PACKAGE_PATH and ROS_MASTER_URI) are not available. In that case you might be successful running a bash to interpret your command. You may need to run it as interactive shell "-i" to make sure it executes .bashrc. So altogether something like system("bash -i -c roslaunch somepackage somefile.launch") should work. To kill a node you could use rosnode kill [node] started in the above way.


Originally posted by Felix Endres with karma: 6468 on 2011-04-03

This answer was NOT ACCEPTED on the original site

Post score: 4

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.