ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Run one node in another node?

asked 2015-11-04 19:44:23 -0500

Winston gravatar image

updated 2015-11-10 06:47:15 -0500

The subject looks weird and difficult to understand so I am going to explain what I mean here. I want to know if it is possible to run a node inside another node. For example, when you have written a ROS node A and what you want A to do is to run other several ROS nodes B, C, D and etc. How to implement that? I don't want to use roslaunch to run several nodes in this case because after node A has run other nodes, it also has to do other stuff.

To go further, I want to write a ROS server and what it is supposed to do is waiting for "node request", that is , when a client calls this service, the server tries to run a node instantaneously. That is to say, how to run nodes in a service server? I think this case is essentially the same as the former one.

Any suggestions are appreciated very much.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-11-10 15:54:20 -0500

Dimitri Schachmann gravatar image

How about using nodelets? You can load multiple nodelets in a node at runtime and each nodelet runs in it's own thread.

edit flag offensive delete link more


Thank you. Could you provide with me some sample codes?

Winston gravatar image Winston  ( 2017-04-21 08:49:12 -0500 )edit

answered 2015-11-10 07:01:01 -0500

NEngelhard gravatar image

You could use system calls to execute rosrun commands. What are you trying to achieve?

edit flag offensive delete link more


Yes, system call is a solution but it may not be the best one. I heard that using system call in source code was not recommended. Any other work around?

Winston gravatar image Winston  ( 2015-11-10 07:17:20 -0500 )edit

Could be explain a bit more what you want to achieve? You could maybe just start all nodes with a launch file and only activate them via action or service. At startup, they'd just sleep until activation and then subscribe or advertise so that they don't use CPU or bandwidth.

NEngelhard gravatar image NEngelhard  ( 2015-11-10 07:20:56 -0500 )edit

Question Tools

1 follower


Asked: 2015-11-04 19:44:23 -0500

Seen: 2,041 times

Last updated: Nov 10 '15