ros::Rate::sleep() equivalent in rosserial

asked 2020-02-21 08:18:49 -0500

broomstick gravatar image

I am building a rosserial application.

I would like to use a construct such as the following

ros::Rate loop_rate(30);

while (ros::ok())

rate.h does not appear to be included in rosserial. With ros, I can effectively achieve the same thing using ros::Duration, which also has a sleep function. While duration.h exists in rosserial, it does not appear to have a sleep function...

Is there an equivalent of ros::Rate or ros::Duration in rosserial which allows me to set a looping frequency in this way?

The best equivalent I can find is something like the following:

while (1)

This is not exactly equivalent, though, as it sleeps for a constant time, whereas ros::Rate::sleep and ros::Duration::sleep only sleep for the remaining time in the cycle.

edit retag flag offensive close merge delete


Did you find a solution for this?

fjp gravatar image fjp  ( 2021-06-02 16:23:03 -0500 )edit

Nope, sorry. While not ideal, the workaround was good enough for my purposes, and I've not needed to return to it since.

I think implementing a simple approximation of ros::Rate::sleep would be pretty straightforward, though. The function would take a timestamp at each call, establish the time elapsed from the previous call, and then sleep for desired_period - elapsed_time.

broomstick gravatar image broomstick  ( 2021-06-03 06:52:47 -0500 )edit