Ask Your Question

ros.spinOnce() during delay

asked 2017-02-03 10:49:43 -0500

roborag gravatar image

updated 2017-02-03 12:30:10 -0500

gvdhoorn gravatar image

Say I have a ros rate of 10 Hz. Does ros.spinOnce() occur during ros::Duration(2).sleep() ?


void main(void){
  ros::rate r(10);
    do something;

edit retag flag offensive close merge delete


ros::rate r(10); as it is used, is doing nothing. If you want the loop to run at 10Hz you should call r.sleep() at the end of your while loop.

Currently the loop would run at a rate of 1/(2 + call backs processing time).

afakih gravatar image afakih  ( 2017-02-08 08:10:22 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-02-03 12:31:36 -0500

gvdhoorn gravatar image

updated 2017-02-03 12:36:51 -0500

This has been asked before. See #q203760.

And we could also look at the source: ros::Duration::sleep() eventually calls ros_wallsleep(..), which basically does:

timespec req = { sec, nsec };
timespec rem = {0, 0};
while (nanosleep(&req, &rem) && !g_stopped)
  req = rem;

and nothing more.

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

1 follower


Asked: 2017-02-03 10:49:43 -0500

Seen: 389 times

Last updated: Feb 03 '17