ros::Rate::sleep() equivalent in rosserial
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())
{
update();
ros::spinOnce();
loop_rate.sleep();
}
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)
{
update();
nh.spinOnce();
sleep(1./30.);
}
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.
Asked by broomstick on 2020-02-21 09:18:49 UTC
Comments
Did you find a solution for this?
Asked by fjp on 2021-06-02 16:23:03 UTC
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 fordesired_period - elapsed_time
.Asked by broomstick on 2021-06-03 06:52:47 UTC