How can I react to node/nodelet shutdown?
I would like to have my node save some data before it is shut down, i.e, when I terminate it with Ctrl-C (started via roslaunch
). I have main code like this:
int main(int argc, char **argv)
{
ros::init(argc, argv, "pylon_camera_node");
pylon_camera::PylonCameraNode pylon_camera_node;
ros::Rate r(pylon_camera_node.frameRate());
ROS_INFO_STREAM("Start image grabbing if node connects to topic with "
<< "a frame_rate of: " << pylon_camera_node.frameRate() << " Hz");
// Main thread and brightness-service thread
/* boost::thread th(boost::bind(&ros::spin)); */
while ( ros::ok() )
{
pylon_camera_node.spin();
ros::spinOnce();
r.sleep();
}
ROS_INFO("Terminate PylonCameraNode");
return EXIT_SUCCESS;
}
Unforntunately, the call to ROS_INFO
isn't ever made. I've tried asking for ros::isShuttiingDown
in pylon_camera_node::spin()
as well, to no avail. I can also run the node in a nodelet, but there I also don't see a way to have slightly longer running operations be performed before shutdown. I'm trying to save a vector of images and most of the time, only one is saved and then the process seems to abort.
What is the proper was to execute operations at node or nodelet shutdown?