ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
So I looked up the source code and there is a bug. The calculation of the publish_frequency:
// dynamic window resizing
if (stats.arrival_time_list.size() > static_cast<size_t>(max_elements) && pub_frequency_ * 2 <= max_window)
{
pub_frequency_ *= 2;
}
if (stats.arrival_time_list.size() < static_cast<size_t>(min_elements) && pub_frequency_ / 2 >= min_window)
{
pub_frequency_ /= 2;
}
So basically if there are more messages then max_elements increase the frequency or if there are less messages then min_elements decrease the frequency. This is fine.
And the decision if one should publish a new statistics message:
// should publish new statistics?
if (stats.last_publish + ros::Duration(pub_frequency_) < received_time)
{
...
}
I recognized that pub_frequency_ is a double value, which doesn't make sense. So a simple example:
stats.last_publish = 1
pub_frequency_ = 10
received_time = 2
Obviously in this case one should publish cause 1 second passed and our frequency is 10 Hz. But the if-statement evaluates to:
1 + 10 < 2 -> false
which means don't publish. So this line need to be changed to:
if (stats.last_publish + ros::Duration(1 / pub_frequency_) < received_time)