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 latest time policy when cont. pivot switching due to decreasing rates #147

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Open
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
25 changes: 22 additions & 3 deletions include/message_filters/sync_policies/latest_time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,22 @@ struct LatestTime : public PolicyBase<M...>

std::get<i>(events_) = evt;
rclcpp::Time now = ros_clock_->now();
rclcpp::Time event_time_received_prev = rates_[i].prev;
bool valid_rate = rates_[i].compute_hz(now);
if (valid_rate && (i == find_pivot(now)) && is_full()) {
publish();
int pivot = find_pivot(now);
if (valid_rate && is_full()) {
if (i == pivot) {
publish(now);
} else if (i == pivot_prev_) {
rclcpp::Duration period_event_received = now - event_time_received_prev;
if (last_time_published_ + period_event_received * SLACK_DURATION_FACTOR_EXAMPLE <
event_time_received_prev)
{
publish(now);
}
}
}
pivot_prev_ = pivot;
}

private:
Expand Down Expand Up @@ -199,9 +211,10 @@ struct LatestTime : public PolicyBase<M...>
}

// assumed data_mutex_ is locked
void publish()
void publish(const rclcpp::Time & now)
{
std::apply([this](auto &&... args) {this->parent_->signal(args ...);}, events_);
last_time_published_ = now;
}

struct Rate
Expand Down Expand Up @@ -378,6 +391,12 @@ struct LatestTime : public PolicyBase<M...>
const int NO_PIVOT{Super::N_MESSAGES};

rclcpp::Clock::SharedPtr ros_clock_{nullptr};

int pivot_prev_ = NO_PIVOT;

rclcpp::Time last_time_published_ = rclcpp::Time(0, 0);

static constexpr double SLACK_DURATION_FACTOR_EXAMPLE{1.1};
};

} // namespace sync_policies
Expand Down