How to load a nodelet into a manager from CPP
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).