ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Crlt+C will be handled by the ros node logic internal and causes ros::ok() to no longer return true but false . After ros:ok() is not true any more there is no need to call ros::shutdown()
I think your code may look like this
int main()
{
bool running(false);
//running is set to true by a condition statement somewhere here
// exit the main loop
// if running flag is set false,
// or if ros::ok() is not ok anymore (likely we received Crlt+C),
// or if the view was stopped
for(; running && ros::ok() && !viewer->wasStopped() ;)
{
// ... ... ... ...
//do something
}
if ( ros::ok() )
{
// we exited the main loop because of false running value or the viewer was stopped,
// no Crlt+C received, i. e. we have to ros::shutdown() explizitly
ros::shutdown();
}
else
{
// nothing to be done here, ros::ok() no longer true, ros::shutdown not needed anymore
}
return 0;
}