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

Cleaning up after shutdown request

asked 2017-02-02 19:26:20 -0500

errolflynn gravatar image

updated 2017-02-03 10:05:28 -0500

In my node looping portion, I check for shutdown using ros::isShuttingDown(). After the looping portion, I wish to perform a couple of actions before shutdown. The reason for this is that I am attempting to programatically start and stop nodes. The node is being stopped either with CTRL-C or rosnode kill

However, this doesn't seem to function as I hope.

Here is a sample of my code:

 while(!ros::isShuttingDown()){
 //while(ros::ok()) { // Does not work either.

      ros::spinOnce();
      rate.sleep();
  }

  //EDIT:
  ROS_INFO("will not print");
  fflush(stdout);

  //FIXME Cleanup section not running
  // Cleanup

  localizer.nh.setParam(
    strcat(strcat(strcpy(localizer_node_param, "/"),
    LOCALIZER_NODE),"_running"), false);

  return SUCCESS;

In this instance, the parameter is not re-set at the end of life of this node. Can someone reproduce this behavior? Simple loop and ROS_INFO() statement is sufficient.

EDIT: ROS log statements also do not print to stdout when placed as shown (with or without fflush(stdout);)

edit retag flag offensive close merge delete

Comments

I am not fully aware of how the shutdown is implemented. But it could be in the process of shutting down, the parameter cannot be written to the parameter server, due to the shutdown itself...

mgruhler gravatar image mgruhler  ( 2017-02-03 01:19:47 -0500 )edit

See edit. ROS log statements don't print out either. I get the sense that the code after the looping portion does not run.

errolflynn gravatar image errolflynn  ( 2017-02-03 10:02:58 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-02-07 01:29:47 -0500

mgruhler gravatar image

When ROS is shutting down, it drops all connections to the master and afaik thus looses all "ROS"-Functionality. I.e. you cannot

  • publish or subscribe to a topic
  • call a service or action
  • read to or write from the Parameter server
  • and apparently all ROS logging does not work either.

If you replace the ROS_INFO with a std::cout, you see that this is actually handled. However, all code with ROS functionality is, in the end, a noop, due to the missing connections.

edit flag offensive delete link more

Comments

This seems to be correct. Where is this documented?

errolflynn gravatar image errolflynn  ( 2017-02-07 10:52:46 -0500 )edit
1

I don't know. There is http://wiki.ros.org/roscpp/Overview/I...

At any time you may call the ros::shutdown() function to shutdown your node. This will kill all open subscriptions, publications, service calls, and service servers.

But this does not explicitely talk ...

mgruhler gravatar image mgruhler  ( 2017-02-08 01:23:00 -0500 )edit
1

about Parameters. It is, however, talking about the use of ros::isShuttingDown.

mgruhler gravatar image mgruhler  ( 2017-02-08 01:23:41 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-02-02 19:26:20 -0500

Seen: 1,983 times

Last updated: Feb 07 '17