Ask Your Question
0

Time delay between the cycles

asked 2018-07-03 06:55:12 -0500

kk2105 gravatar image

updated 2018-08-16 09:29:51 -0500

Hi Guys,

I have below snippet of the code.

 ros::Rate rate(50);
 while (ros::ok())
 {
       ros_time = ros::Time::now();
       //Do some operations
       //Publish messages
       rate.sleep();
       ros.SpinOnce();
  }

I want to know the time gap/delay between each publish of messages. Could you please let me know if there a way to fetch the time delay ?

Thank you, KK

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-07-03 08:59:18 -0500

Two things, firstly yes you can measure durations using the ros::Time module very easily. Secondly the delay between each iteration of this loop should be 0.02 seconds assuming that the code within the loop doesn't take longer than that to execute. That's what the ros::Rate::sleep method does, it waits until the requested time has elapsed since the last time it was called.

Are you trying to measure the time between subsequent calls to ros::Time::now() at the top of the loop? If so you'll need two ros::Time members one to store the previous time and one to store the current time, the duration is then simple one minus the other. This calculation cannot be done on the first iteration of the loop because there was no previous time so you'll need to detect and avoid this.

Hope this helps.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-07-03 06:55:12 -0500

Seen: 296 times

Last updated: Jul 03 '18