ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Just declare your publisher in the global scope. So, above your callback.
Then, in main, you can loop the way you mentioned, but use ros::spinOnce()
instead of ros::spin()
while (ros::ok()) {
ros::spinOnce();
}
2 | No.2 Revision |
Just declare your publisher in the global scope. So, above your callback.
Then, in main, you can loop the way you mentioned, but use ros::spinOnce()
instead of ros::spin()
while (ros::ok()) {
ros::spinOnce();
loop_rate.sleep(); // Don't forget this! *
}
* Thanks @gvdhoorn: Without this, your node would use 100% CPU, even if it has nothing to do.
EDIT: loop_rate.sleep()