load nodelet service as an library
Hello
I want to use the load_nodelet service from the nodelet manager.
But instead of using a terminal call like described in http://www.ros.org/wiki/nodelet/Tutorials/Running%20a%20nodelet 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
http://answers.ros.org/question/52462/how-to-load-a-nodelet-into-a-manager-from-cpp/
and this
http://answers.ros.org/question/46687/calling-nodelet-manager-service-from-console/
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):
Add a library called libnodelet_interface.so to CMakeLists.txt
rosbuild_add_library(nodelet_interface src/nodelet.cpp) //would have to remove the main from nodelet.cpp perhaps
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
Miguel
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?