Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix throttle #190

Merged
merged 3 commits into from
May 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions fuse_models/include/fuse_models/common/throttled_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,21 @@ class ThrottledCallback
// (b) The throttle period is zero, so we should always keep the callbacks
// (c) The elpased time between now and the last called time is greater than the throttle period
const ros::Time now = use_wall_time_ ? ros::Time(ros::WallTime::now().toSec()) : ros::Time::now();
if (!last_called_time_.isValid() || throttle_period_.isZero() || now - last_called_time_ > throttle_period_)
if (last_called_time_.isZero() || throttle_period_.isZero() || now - last_called_time_ > throttle_period_)
{
if (keep_callback_)
{
keep_callback_(message);
}

last_called_time_ = now;
if (last_called_time_.isZero())
{
last_called_time_ = now;
}
else
{
last_called_time_ += throttle_period_;
}
}
else if (drop_callback_)
{
Expand Down