ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Definitely the second one!
In the first one your doing an infinite loop inside a constructor, which is in my eyes really bad.
Also the
ros::ok()
is checked twice.
No it isn't. The ros::ok()
call in the main
method is being called exactly one time, namely when you hit Ctrl + C and your infinite loop in the constructor exits.
For the future have a look at the ros::spin()
method also.