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

How to load a nodelet into a manager from CPP

asked 2013-01-16 02:32:52 -0600

markpitchless gravatar image

updated 2017-10-03 09:46:17 -0600

130s gravatar image

I using a set of nodelets that until now have been started from a lauch file, loading into the standard nodelet manager (rosrun nodelet nodelet manager). Now I would like one of those nodelets (a CPP node) to be able to load and unload nodelets in it's manager but can't get it to work.

Loading from the command line using the nodelet tool or via a launch file (which is the same tool) works. But if I try calling the load_nodelet service on the manager the nodelet seems to load, maybe processes a callback or two but then disappears again!

Looking at the source for the nodelet tool ($(rospack find nodelet)/src/nodelet.cpp) it seems that after calling the service on the manager it spins it's own ros loop and does some funky things with signal handlers and bonds.

  • What is this process doing?
  • If the nodelet is running as a thread in the manager why do we need this other process to keep the nodelet running?

Edit: These are answered by reading about bonds here and here. However I still want to know:

  • How can I load a nodelet into the manager from a CPP node?

(I'm currently working around this with a fork and exec to rosrun nodelet, but that is not a good solution).

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-06-26 04:53:08 -0600

Miguel Riem de Oliveira gravatar image

updated 2013-06-26 04:55:59 -0600

Hi Jan.

I am also trying to do this. I can call the service in cpp code. The problem is I cannot add the parameters. Anyway, I can tell you how I did it.

ros::init(argc, argv, "tracker"); // Initialize ROS coms
ros::NodeHandle* n = (ros::NodeHandle*) new ros::NodeHandle("~"); //The node handle

ros::ServiceClient client = n->serviceClient<nodelet::NodeletLoad>("/nodelet_manager/load_nodelet"); //this is my service name

nodelet::NodeletLoad srv; = "name1";
srv.request.type = "race_3d_object_tracking/race_3d_object_tracking_nodelet"; //this is my nodelet

//This is the part that does not work. But the rest does. Meaning I can call the service and it runs, but I cannot change the parameters

if (
    ROS_INFO("Service response ok");
    ROS_ERROR("Failed to call service");

If you can find how to insert params please tell me.



edit flag offensive delete link more



Actually, I was reading around the ros answers forum and I found some other stuff. I asked a new question related to this one. Perhaps you can check it, is at

Miguel Riem de Oliveira gravatar image Miguel Riem de Oliveira  ( 2013-06-26 07:19:08 -0600 )edit

Question Tools



Asked: 2013-01-16 02:32:52 -0600

Seen: 1,582 times

Last updated: Oct 03 '17