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(localization_util): fixed rejection criteria of SmartPoseBuffer::interpolate #5818

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
8 changes: 7 additions & 1 deletion localization/localization_util/src/smart_pose_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,22 @@

if (pose_buffer_.size() < 2) {
RCLCPP_INFO(logger_, "pose_buffer_.size() < 2");
return std::nullopt;

Check warning on line 36 in localization/localization_util/src/smart_pose_buffer.cpp

View check run for this annotation

Codecov / codecov/patch

localization/localization_util/src/smart_pose_buffer.cpp#L36

Added line #L36 was not covered by tests
}

const rclcpp::Time time_first = pose_buffer_.front()->header.stamp;
const rclcpp::Time time_last = pose_buffer_.back()->header.stamp;

if (target_ros_time < time_first || time_last < target_ros_time) {
if (target_ros_time < time_first) {
return std::nullopt;
}

// [time_last < target_ros_time] is acceptable here.
// It is possible that the target_ros_time (often sensor timestamp) is newer than the latest
// timestamp of buffered pose (often EKF).
// However, if the timestamp difference is too large,
// it will later be rejected by validate_time_stamp_difference.

Check notice on line 51 in localization/localization_util/src/smart_pose_buffer.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Complex Method

SmartPoseBuffer::interpolate is no longer above the threshold for cyclomatic complexity
// get the nearest poses
result.old_pose = *pose_buffer_.front();
for (const PoseWithCovarianceStamped::ConstSharedPtr & pose_cov_msg_ptr : pose_buffer_) {
Expand All @@ -68,7 +74,7 @@

// all validations must be true
if (!(is_old_pose_valid && is_new_pose_valid && is_pose_diff_valid)) {
return std::nullopt;

Check warning on line 77 in localization/localization_util/src/smart_pose_buffer.cpp

View check run for this annotation

Codecov / codecov/patch

localization/localization_util/src/smart_pose_buffer.cpp#L77

Added line #L77 was not covered by tests
}

// interpolate the pose
Expand All @@ -92,22 +98,22 @@
const rclcpp::Time msg_time = pose_msg_ptr->header.stamp;
if (msg_time < end_time) {
// Clear the buffer if timestamps are reversed to maintain chronological order
pose_buffer_.clear();

Check warning on line 101 in localization/localization_util/src/smart_pose_buffer.cpp

View check run for this annotation

Codecov / codecov/patch

localization/localization_util/src/smart_pose_buffer.cpp#L101

Added line #L101 was not covered by tests
}
}
pose_buffer_.push_back(pose_msg_ptr);
}

void SmartPoseBuffer::pop_old(const rclcpp::Time & target_ros_time)

Check warning on line 107 in localization/localization_util/src/smart_pose_buffer.cpp

View check run for this annotation

Codecov / codecov/patch

localization/localization_util/src/smart_pose_buffer.cpp#L107

Added line #L107 was not covered by tests
{
std::lock_guard<std::mutex> lock(mutex_);

Check warning on line 109 in localization/localization_util/src/smart_pose_buffer.cpp

View check run for this annotation

Codecov / codecov/patch

localization/localization_util/src/smart_pose_buffer.cpp#L109

Added line #L109 was not covered by tests
while (!pose_buffer_.empty()) {
if (rclcpp::Time(pose_buffer_.front()->header.stamp) >= target_ros_time) {
break;
}
pose_buffer_.pop_front();

Check warning on line 114 in localization/localization_util/src/smart_pose_buffer.cpp

View check run for this annotation

Codecov / codecov/patch

localization/localization_util/src/smart_pose_buffer.cpp#L114

Added line #L114 was not covered by tests
}
}

Check warning on line 116 in localization/localization_util/src/smart_pose_buffer.cpp

View check run for this annotation

Codecov / codecov/patch

localization/localization_util/src/smart_pose_buffer.cpp#L116

Added line #L116 was not covered by tests

void SmartPoseBuffer::clear()
{
Expand Down
Loading