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(avoidance): fix bug in minimum overhang distance calculation #6372

Merged
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
41 changes: 29 additions & 12 deletions planning/behavior_path_avoidance_module/src/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 TIER IV, Inc.

Check notice on line 1 in planning/behavior_path_avoidance_module/src/utils.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Lines of Code in a Single File

The lines of code increases from 1787 to 1803, improve code health by reducing it to 1000. The number of Lines of Code in a single file. More Lines of Code lowers the code health.

Check notice on line 1 in planning/behavior_path_avoidance_module/src/utils.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Overall Code Complexity

The mean cyclomatic complexity increases from 5.21 to 5.22, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -885,41 +885,58 @@
return 0.0;
}

std::vector<std::pair<Point, Point>> intersects;
std::vector<std::tuple<double, Point, Point>> intersects;
for (const auto & p1 : object.overhang_points) {
const auto centerline_pose =
lanelet::utils::getClosestCenterPose(object.overhang_lanelet, object_pose.position);
const auto p_tmp =
geometry_msgs::build<Pose>().position(p1.second).orientation(centerline_pose.orientation);
const auto p2 = calcOffsetPose(p_tmp, 0.0, (isOnRight(object) ? 100.0 : -100.0), 0.0).position;

// TODO(Satoshi OTA): check if the basic point is on right or left of bound.
const auto bound = isOnRight(object) ? data.left_bound : data.right_bound;

for (size_t i = 1; i < bound.size(); i++) {
const auto opt_intersect =
tier4_autoware_utils::intersect(p1.second, p2, bound.at(i - 1), bound.at(i));

if (!opt_intersect) {
continue;
{
const auto p2 =
calcOffsetPose(p_tmp, 0.0, (isOnRight(object) ? 100.0 : -100.0), 0.0).position;
const auto opt_intersect =
tier4_autoware_utils::intersect(p1.second, p2, bound.at(i - 1), bound.at(i));

if (opt_intersect.has_value()) {
intersects.emplace_back(

Check warning on line 906 in planning/behavior_path_avoidance_module/src/utils.cpp

Codecov / codecov/patch

planning/behavior_path_avoidance_module/src/utils.cpp#L906

Added line #L906 was not covered by tests
calcDistance2d(p1.second, opt_intersect.value()), p1.second, opt_intersect.value());
break;

Check warning on line 908 in planning/behavior_path_avoidance_module/src/utils.cpp

Codecov / codecov/patch

planning/behavior_path_avoidance_module/src/utils.cpp#L908

Added line #L908 was not covered by tests
}
}

intersects.emplace_back(p1.second, opt_intersect.value());
{
const auto p2 =
calcOffsetPose(p_tmp, 0.0, (isOnRight(object) ? -100.0 : 100.0), 0.0).position;
const auto opt_intersect =
tier4_autoware_utils::intersect(p1.second, p2, bound.at(i - 1), bound.at(i));

if (opt_intersect.has_value()) {
intersects.emplace_back(

Check warning on line 919 in planning/behavior_path_avoidance_module/src/utils.cpp

Codecov / codecov/patch

planning/behavior_path_avoidance_module/src/utils.cpp#L919

Added line #L919 was not covered by tests
-1.0 * calcDistance2d(p1.second, opt_intersect.value()), p1.second,
opt_intersect.value());
break;

Check warning on line 922 in planning/behavior_path_avoidance_module/src/utils.cpp

Codecov / codecov/patch

planning/behavior_path_avoidance_module/src/utils.cpp#L922

Added line #L922 was not covered by tests
}
}
}
}

std::sort(intersects.begin(), intersects.end(), [](const auto & a, const auto & b) {
return calcDistance2d(a.first, a.second) < calcDistance2d(b.first, b.second);
return std::get<0>(a) < std::get<0>(b);
});

if (intersects.empty()) {
return 0.0;
}

object.narrowest_place = intersects.front();
object.narrowest_place =
std::make_pair(std::get<1>(intersects.front()), std::get<2>(intersects.front()));

Check warning on line 937 in planning/behavior_path_avoidance_module/src/utils.cpp

Codecov / codecov/patch

planning/behavior_path_avoidance_module/src/utils.cpp#L937

Added line #L937 was not covered by tests

return calcDistance2d(
object.narrowest_place.value().first, object.narrowest_place.value().second);
return std::get<0>(intersects.front());

Check warning on line 939 in planning/behavior_path_avoidance_module/src/utils.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

getRoadShoulderDistance increases in cyclomatic complexity from 9 to 10, 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 warning on line 939 in planning/behavior_path_avoidance_module/src/utils.cpp

Codecov / codecov/patch

planning/behavior_path_avoidance_module/src/utils.cpp#L939

Added line #L939 was not covered by tests
}
} // namespace filtering_utils