unload a nodelet from within its own code
Looks like there is no official and clean way to shut down (unload) a nodelet from within its nodelet code without killing the manager.
Something like
#include <nodelet/NodeletUnload.h>
nodelet::NodeletUnload unload_service;
unload_service.request.name = getName();
ros::service::call(ros::this_node::getName() + "/unload_nodelet", unload_service);
might work, though I experienced problems when loading and unloading the samle nodelet more than once (however this might have been problems related to that particular nodelet's cleanup). In addition, as far as I can see, the service is not available in case the nodelet is started standalone. In the standalone case, a ros::shutdown(); or ros::requestShutdown(); might be OK? Is there any way to figure out if a nodelet is started standalone from within the nodelet code? st checking the aforementioned service call a safe way to do it or can it fail for other reasons? E.g., is
#include <nodelet/NodeletUnload.h>
nodelet::NodeletUnload unload_service;
unload_service.request.name = getName();
if(false == ros::service::call(ros::this_node::getName() + "/unload_nodelet", unload_service)) {
ros::shutdown();
}
a good way to go?
It would be nice to have a consistent and obvious way (i.e. one function call that works no matter how the nodelet is started) to unload a nodelet from within its own code.
The request is not really new, see also http://ros-users.122217.n3.nabble.com/nodelet-shutdown-unload-itself-requestShutdown-td3151148.html In addtion, there seems to have been a trac ticket https://code.ros.org/trac/ros-pkg/ticket/4431, which I neither can access nor locate on github - has it ever been migrated?
Anything new and worth mentioning about this? Is there an official way by now?