Change publishing rate in source code
I'm subscribing to /camera/depth/image
topic, after some processing I want to publish it again but in different rate.
I'm already trying to do it using some code but I didn't succeed yet. (Publishing is working)
I found a very short answer that I'm trying to follow but not very clear enough. Here
EDIT - SOLUTION:
I found a solution in throttle
package, but I don't get really exactly the rate I input which is g_period=msgs_per_sec
in the package:
The rate I get is:
rostopic hz /depth_output
average rate: 15.018
min: 0.063s max: 0.069s std dev: 0.00187s window: 14
Here is it:
ros::Time g_last_time;
ros::Duration g_period;
g_period = ros::Duration(1.0/20); //msgs_per_sec
ros::Time now;
now = ros::Time::now();
if((now - g_last_time) > g_period)
{
depth_pub_.publish(depth_msg.toImageMsg());
g_last_time = now;
}