ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How can I react to node/nodelet shutdown?

asked 2017-07-12 11:19:45 -0500

themightyoarfish gravatar image

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-07-13 11:40:43 -0500

lucasw gravatar image

updated 2017-07-13 12:11:12 -0500

SIGINT handlers: 'What is the correct way to do stuff before a node is shutdown?' #q27655 - the answer is a little out of date but I left some comments there on updating it.

Also not the stuff you do before shutdown maybe shouldn't depend on ros being available (e.g. ROS_INFO_STREAM()) if the ros shutdown isn't just your node but all of them including roscore.

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2017-07-12 11:19:45 -0500

Seen: 670 times

Last updated: Jul 13 '17