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

Prevent tf message filter from preempting the oldest message while it is waiting for transforms. #544

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
38 changes: 28 additions & 10 deletions tf2_ros/include/tf2_ros/message_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,19 +404,37 @@ class MessageFilter : public MessageFilterBase, public message_filters::SimpleFi
// Keep a lock on the messages
std::unique_lock<std::mutex> unique_lock(messages_mutex_);

// If this message is about to push us past our queue size, erase the oldest message
// If this message is about to push us past our queue size, erase the 2nd oldest message.
// Note: The oldest message is not removed because that would preempt the waitForTransform check that is currently
// being conducted for it.
if (queue_size_ != 0 && messages_.size() + 1 > queue_size_) {
++dropped_message_count_;
const MessageInfo & front = messages_.front();
TF2_ROS_MESSAGEFILTER_DEBUG(
"Removed oldest message because buffer is full, count now %d (frame_id=%s, stamp=%f)",
messages_.size(),
(mt::FrameId<M>::value(*front.event.getMessage())).c_str(),
mt::TimeStamp<M>::value(*front.event.getMessage()).seconds());
if (messages_.size() > 1) {
// Drop 2nd oldest message
auto second_oldest = std::next(messages_.begin());

messageDropped(front.event, filter_failure_reasons::QueueFull);
++dropped_message_count_;
TF2_ROS_MESSAGEFILTER_DEBUG(
"Removed old message because buffer is full, count now %d (frame_id=%s, stamp=%f)",
messages_.size(),
(mt::FrameId<M>::value(*second_oldest->event.getMessage())).c_str(),
mt::TimeStamp<M>::value(*second_oldest->event.getMessage()).seconds());

messages_.pop_front();
messageDropped(second_oldest->event, filter_failure_reasons::QueueFull);

messages_.erase(second_oldest);
}
else {
// Drop this message because the queue size is only 1 and we don't want to preempt the message currently being
// waited on.

TF2_ROS_MESSAGEFILTER_DEBUG(
"Removed message because buffer is full, count now %d (frame_id=%s, stamp=%f)",
messages_.size(),
(mt::FrameId<M>::value(*evt.getMessage())).c_str(),
mt::TimeStamp<M>::value(*evt.getMessage()).seconds());

messageDropped(evt, filter_failure_reasons::QueueFull);
}
}

// Add the message to our list
Expand Down