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

feat(ndt_scan_matcher): warn if the lidar scan has gone out of the range of the loaded map #7612

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class MapUpdateModule
rclcpp::Node * node, std::mutex * ndt_ptr_mutex, NdtPtrType & ndt_ptr,
HyperParameters::DynamicMapLoading param);

bool out_of_map_range(const geometry_msgs::msg::Point & position);

private:
friend class NDTScanMatcher;

Expand All @@ -62,6 +64,7 @@ class MapUpdateModule
[[nodiscard]] bool should_update_map(
const geometry_msgs::msg::Point & position,
std::unique_ptr<DiagnosticsModule> & diagnostics_ptr);

void update_map(
const geometry_msgs::msg::Point & position,
std::unique_ptr<DiagnosticsModule> & diagnostics_ptr);
Expand Down
14 changes: 14 additions & 0 deletions localization/ndt_scan_matcher/src/map_update_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@
return distance > param_.update_distance;
}

bool MapUpdateModule::out_of_map_range(const geometry_msgs::msg::Point & position)

Check warning on line 110 in localization/ndt_scan_matcher/src/map_update_module.cpp

View check run for this annotation

Codecov / codecov/patch

localization/ndt_scan_matcher/src/map_update_module.cpp#L110

Added line #L110 was not covered by tests
KYabuuchi marked this conversation as resolved.
Show resolved Hide resolved
{
if (last_update_position_ == std::nullopt) {
return true;
}

const double dx = position.x - last_update_position_.value().x;
const double dy = position.y - last_update_position_.value().y;
KYabuuchi marked this conversation as resolved.
Show resolved Hide resolved
const double distance = std::hypot(dx, dy);

Check warning on line 118 in localization/ndt_scan_matcher/src/map_update_module.cpp

View check run for this annotation

Codecov / codecov/patch

localization/ndt_scan_matcher/src/map_update_module.cpp#L116-L118

Added lines #L116 - L118 were not covered by tests

// check distance_last_update_position_to_current_position
return (distance + param_.lidar_radius > param_.map_radius);

Check warning on line 121 in localization/ndt_scan_matcher/src/map_update_module.cpp

View check run for this annotation

Codecov / codecov/patch

localization/ndt_scan_matcher/src/map_update_module.cpp#L121

Added line #L121 was not covered by tests
}

void MapUpdateModule::update_map(
const geometry_msgs::msg::Point & position, std::unique_ptr<DiagnosticsModule> & diagnostics_ptr)
{
Expand Down
12 changes: 12 additions & 0 deletions localization/ndt_scan_matcher/src/ndt_scan_matcher_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,18 @@
add_regularization_pose(sensor_ros_time);
}

// Warn if the lidar has gone out of the map range
KYabuuchi marked this conversation as resolved.
Show resolved Hide resolved
if (map_update_module_->out_of_map_range(
interpolation_result.interpolated_pose.pose.pose.position)) {
std::stringstream msg;

msg << "Lidar has gone out of the map range";
diagnostics_scan_points_->update_level_and_message(
diagnostic_msgs::msg::DiagnosticStatus::WARN, msg.str());

Check warning on line 449 in localization/ndt_scan_matcher/src/ndt_scan_matcher_core.cpp

View check run for this annotation

Codecov / codecov/patch

localization/ndt_scan_matcher/src/ndt_scan_matcher_core.cpp#L449

Added line #L449 was not covered by tests

RCLCPP_WARN_STREAM_THROTTLE(this->get_logger(), *this->get_clock(), 1000, msg.str());

Check warning on line 451 in localization/ndt_scan_matcher/src/ndt_scan_matcher_core.cpp

View check run for this annotation

Codecov / codecov/patch

localization/ndt_scan_matcher/src/ndt_scan_matcher_core.cpp#L451

Added line #L451 was not covered by tests
}

Check warning on line 453 in localization/ndt_scan_matcher/src/ndt_scan_matcher_core.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

NDTScanMatcher::callback_sensor_points_main increases in cyclomatic complexity from 27 to 28, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
// check is_set_map_points
const bool is_set_map_points = (ndt_ptr_->getInputTarget() != nullptr);
diagnostics_scan_points_->add_key_value("is_set_map_points", is_set_map_points);
Expand Down
Loading