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

ros::spinOnce() gets all messages(executes callbacks) and actions if there is a server once and returns. ros::spin() means do that all the time until a shutdown of the node is requested and then return. I suggest to define the publisher and subscriber outside the for loop, define a rate(ros::Rate loopRate(100) runs at 100Hz) for the execution of the thread and use ros::SpinOnce() and then loopRate.sleep() inside the for loop.