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

Revision history [back]

click to hide/show revision 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.