ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

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() ?

Example:

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

    ros::Duration(2).sleep();
    ros::spinOnce();
  }
}
edit retag flag offensive close merge delete

Comments

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
0

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

Question Tools

1 follower

Stats

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

Seen: 656 times

Last updated: Feb 03 '17