Ask Your Question

load nodelet service as an library

asked 2013-06-26 06:37:21 -0500

Miguel Riem de Oliveira gravatar image

updated 2014-01-28 17:17:03 -0500

ngrennan gravatar image


I want to use the load_nodelet service from the nodelet manager.

But instead of using a terminal call like described in point 4, I want to call the nodelet manager service in runtime, so within come cpp code.

The reason is that I want some nodes( or nodelets) to launch some other nodelets after some conditions are met.

I looked into this

and this

In this last one, it is suggested to look at the nodelet/src/nodelet.cpp code for a hint on how to load nodelets from cpp.

I did.

The way its done is with a

class NodeletInterface, which has methods for loading and unloading the nodelets.

This code is used to compile the nodelet we use by doing for example

rosrun nodelet nodelet load nodelet_tutorial_math/Plus nodelet_manager __name:=nodelet1 nodelet1/in:=foo _value:=1.1

and it works great.

My question is why not compile this code also as a library so that it could be used as an API by other packages which could then load nodelets from cpp code.

Right now, the only way I see to load a nodelet from cpp code is by doing a system call or a fork and calling rosrun nodelet nodelet.

With the API I mentioned one could do something like

NodeletInterface nodeletinterface; nodeletinterface.loadNodelet(...)

This I think would be more interesting than doing system calls ...

And the effort would not be that much. I try to list the steps necessary here (all to be done in the nodelet package):

  1. Add a library called to CMakeLists.txt

    rosbuild_add_library(nodelet_interface src/nodelet.cpp) //would have to remove the main from nodelet.cpp perhaps

  2. Add the class declaration include to nodelet/include/nodelet/nodelet_interface.h, and make this include global in the manifest

Given that the extra functionality seems interesting and that it does not seem very difficult to implement, my question is if there is any reason it was not implemented?

Perhaps I am missing some important detail.

Best regards


edit retag flag offensive close merge delete


Hey Miguel, so finally how do you successfully load the nodelets? I tried to use nodelet::Loader, but I don't know how to parse the parameters to the nodelet. Is there any ways to parse parameters through the constructor of nodelet or via the onInit() method?

jixiang-zhu gravatar image jixiang-zhu  ( 2017-08-24 03:35:15 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-08-12 11:08:00 -0500

tfoote gravatar image

updated 2013-08-12 11:08:21 -0500

I think that you'll find what you want to do is already implemented. That's exactly what the nodelet manager does. The ability to instantiate nodelets is handled at a lower level by pluginlib and under that class_loader.

If you want to inject a nodelet into a nodelet manager at runtime it uses a service call based interface to do so. You can just use the same service calls as the nodelet launchers to inject nodelets at runtime into an existing nodelet manager.

edit flag offensive delete link more


ok, I am using the nodelet_manager and it works. Thanks. Miguel

Miguel Riem de Oliveira gravatar image Miguel Riem de Oliveira  ( 2013-09-20 05:05:10 -0500 )edit

HI Miguel, how do you pass parameters to nodelet within the code? I use nodelet::Loader to load the nodelet, but do not know how to initiate the nodelet with the constructor function. Any possible ways to do it?

jixiang-zhu gravatar image jixiang-zhu  ( 2017-08-28 03:23:02 -0500 )edit

Maybe information about the service name, service message name, and example code could be very helpful here...

Danfoa gravatar image Danfoa  ( 2019-03-26 09:18:47 -0500 )edit

@Danfoa The primary documentation is on the wiki at: it includes the service definitions and the above linked questions have examples of calling the services. It's also relatively trivial to run a nodelet manager and introspect it. You can even try it out. You'll find that the nodelet code to invoke it mostly just passes through the command line options.

tfoote gravatar image tfoote  ( 2019-03-26 10:55:05 -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



Asked: 2013-06-26 06:37:21 -0500

Seen: 945 times

Last updated: Aug 28 '17