Ask Your Question
2

How to load a nodelet into a manager from CPP

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

markpitchless gravatar image

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

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
0

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

Miguel Riem de Oliveira gravatar image

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

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;
srv.request.name = "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
//srv.request.remap_source_args.push_back("name");
//srv.request.remap_target_args.push_back("new_name");                                                                                                  
//srv.request.my_argv.push_back("point_cloud_in:=/camera/depth_registered/points");


if (client.call(srv))
{   
    ROS_INFO("Service response ok");
}   
else
{   
    ROS_ERROR("Failed to call service");
}

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

Regards

Miguel

edit flag offensive delete link more

Comments

1

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 http://answers.ros.org/question/66017/load-nodelet-service-as-an-library/

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

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

Seen: 1,381 times

Last updated: Oct 03 '17