cycleTime returning very incorrect times
I am trying to look at the timing actually performed by ros::Rate::sleep.
ros::Rate loop_rate{1};
while(ros::ok()) {
//publish to a topic
ros::spinOnce();
loop_rate.sleep();
ROS_INFO("time: %f \n", loop_rate.cycleTime().toSec());
}
I am doing this on the turtlebot platform running ros indigo.
What I am seeing is that the expected cylce time of 1 second holds true in output, however I see outputs of the actual cycle time of 0.0005 seconds on average. However, through
rostopic hz <my topic>
I see a very accurate frequency of 1hz for publishing.
Any ideas on how to fix this/where I am going wrong?