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(goal_planner): sort goal candidates by weighted distance #5110

Merged
merged 4 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

# goal search
goal_search:
search_priority: "efficient_path" # "efficient_path" or "close_goal"
goal_priority: "minimum_weighted_distance" # "minimum_weighted_distance" or "minimum_longitudinal_distance"
minimum_weighted_distance:
lateral_weight: 40.0
path_priority: "efficient_path" # "efficient_path" or "close_goal"
parking_policy: "left_side" # "left_side" or "right_side"
forward_goal_search_length: 20.0
backward_goal_search_length: 20.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,19 @@ searched for in certain range of the shoulder lane.

### Parameters for goal search

| Name | Unit | Type | Description | Default value |
| :------------------------------ | :--- | :----- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------- |
| search_priority | [-] | string | In case `efficient_path` use a goal that can generate an efficient path( priority is `shift_parking` -> `arc_forward_parking` -> `arc_backward_parking`). In case `close_goal` use the closest goal to the original one. | efficient_path |
| forward_goal_search_length | [m] | double | length of forward range to be explored from the original goal | 20.0 |
| backward_goal_search_length | [m] | double | length of backward range to be explored from the original goal | 20.0 |
| goal_search_interval | [m] | double | distance interval for goal search | 2.0 |
| longitudinal_margin | [m] | double | margin between ego-vehicle at the goal position and obstacles | 3.0 |
| max_lateral_offset | [m] | double | maximum offset of goal search in the lateral direction | 0.5 |
| lateral_offset_interval | [m] | double | distance interval of goal search in the lateral direction | 0.25 |
| ignore_distance_from_lane_start | [m] | double | distance from start of pull over lanes for ignoring goal candidates | 0.0 |
| ignore_distance_from_lane_start | [m] | double | distance from start of pull over lanes for ignoring goal candidates | 0.0 |
| margin_from_boundary | [m] | double | distance margin from edge of the shoulder lane | 0.5 |
| Name | Unit | Type | Description | Default value |
| :------------------------------ | :--- | :----- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------- |
| goal_priority | [-] | string | In case `minimum_weighted_distance`, sort with smaller longitudinal distances taking precedence over smaller lateral distances. In case `minimum_longitudinal_distance`, sort with weighted lateral distance against longitudinal distance. | `minimum_weighted_distance` |
| path_priority | [-] | string | In case `efficient_path` use a goal that can generate an efficient path( priority is `shift_parking` -> `arc_forward_parking` -> `arc_backward_parking`). In case `close_goal` use the closest goal to the original one. | efficient_path |
| forward_goal_search_length | [m] | double | length of forward range to be explored from the original goal | 20.0 |
| backward_goal_search_length | [m] | double | length of backward range to be explored from the original goal | 20.0 |
| goal_search_interval | [m] | double | distance interval for goal search | 2.0 |
| longitudinal_margin | [m] | double | margin between ego-vehicle at the goal position and obstacles | 3.0 |
| max_lateral_offset | [m] | double | maximum offset of goal search in the lateral direction | 0.5 |
| lateral_offset_interval | [m] | double | distance interval of goal search in the lateral direction | 0.25 |
| ignore_distance_from_lane_start | [m] | double | distance from start of pull over lanes for ignoring goal candidates | 0.0 |
| ignore_distance_from_lane_start | [m] | double | distance from start of pull over lanes for ignoring goal candidates | 0.0 |
| margin_from_boundary | [m] | double | distance margin from edge of the shoulder lane | 0.5 |

## **Pull Over**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ struct GoalPlannerParameters
double center_line_path_interval{0.0};

// goal search
std::string search_priority; // "efficient_path" or "close_goal"
std::string goal_priority; // "minimum_weighted_distance" or "minimum_longitudinal_distance"
double minimum_weighted_distance_lateral_weight{0.0};
std::string path_priority; // "efficient_path" or "close_goal"
ParkingPolicy parking_policy; // "left_side" or "right_side"

double forward_goal_search_length{0.0};
double backward_goal_search_length{0.0};
double goal_search_interval{0.0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ struct GoalCandidate
double lateral_offset{0.0};
size_t id{0};
bool is_safe{true};

bool operator<(const GoalCandidate & other) const noexcept
{
const double diff = distance_from_original_goal - other.distance_from_original_goal;
constexpr double eps = 0.01;
if (std::abs(diff) < eps) {
return lateral_offset < other.lateral_offset;
}

return distance_from_original_goal < other.distance_from_original_goal;
}
};
using GoalCandidates = std::vector<GoalCandidate>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,23 @@ void GoalPlannerModule::onTimer()
};

// plan candidate paths and set them to the member variable
if (parameters_->search_priority == "efficient_path") {
if (parameters_->path_priority == "efficient_path") {
for (const auto & planner : pull_over_planners_) {
for (const auto & goal_candidate : goal_candidates) {
planCandidatePaths(planner, goal_candidate);
}
}
} else if (parameters_->search_priority == "close_goal") {
} else if (parameters_->path_priority == "close_goal") {
for (const auto & goal_candidate : goal_candidates) {
for (const auto & planner : pull_over_planners_) {
planCandidatePaths(planner, goal_candidate);
}
}
} else {
RCLCPP_ERROR(
getLogger(), "search_priority should be efficient_path or close_goal, but %s is given.",
parameters_->search_priority.c_str());
throw std::domain_error("[pull_over] invalid search_priority");
getLogger(), "path_priority should be efficient_path or close_goal, but %s is given.",
parameters_->path_priority.c_str());
throw std::domain_error("[pull_over] invalid path_priority");
}

// set member variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
// goal search
{
const std::string ns = base_ns + "goal_search.";
p.search_priority = node->declare_parameter<std::string>(ns + "search_priority");
p.goal_priority = node->declare_parameter<std::string>(ns + "goal_priority");
p.minimum_weighted_distance_lateral_weight =
node->declare_parameter<double>(ns + "minimum_weighted_distance.lateral_weight");
p.path_priority = node->declare_parameter<std::string>(ns + "path_priority");

Check warning on line 51 in planning/behavior_path_planner/src/scene_module/goal_planner/manager.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Large Method

GoalPlannerModuleManager::GoalPlannerModuleManager increases from 301 to 304 lines of code, threshold = 70. Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function.
p.forward_goal_search_length =
node->declare_parameter<double>(ns + "forward_goal_search_length");
p.backward_goal_search_length =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 TIER IV, Inc.

Check notice on line 1 in planning/behavior_path_planner/src/utils/goal_planner/goal_searcher.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 6.13 to 5.00, 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.
Expand Down Expand Up @@ -38,6 +38,35 @@
using tier4_autoware_utils::calcOffsetPose;
using tier4_autoware_utils::inverseTransformPose;

// Sort with smaller longitudinal distances taking precedence over smaller lateral distances.
struct SortByLongitudinalDistance
{
bool operator()(const GoalCandidate & a, const GoalCandidate & b) const noexcept
{
const double diff = a.distance_from_original_goal - b.distance_from_original_goal;
constexpr double eps = 0.01;
// If the longitudinal distances are approximately equal, sort based on lateral offset.
if (std::abs(diff) < eps) {
kosuke55 marked this conversation as resolved.
Show resolved Hide resolved
return a.lateral_offset < b.lateral_offset;

Check warning on line 50 in planning/behavior_path_planner/src/utils/goal_planner/goal_searcher.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/goal_planner/goal_searcher.cpp#L50

Added line #L50 was not covered by tests
}
return a.distance_from_original_goal < b.distance_from_original_goal;

Check warning on line 52 in planning/behavior_path_planner/src/utils/goal_planner/goal_searcher.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/goal_planner/goal_searcher.cpp#L52

Added line #L52 was not covered by tests
}
};

// Sort with the weighted sum of the longitudinal distance and the lateral distance weighted by
// lateral_cost.
struct SortByWeightedDistance
{
double lateral_cost{0.0};
explicit SortByWeightedDistance(double cost) : lateral_cost(cost) {}

bool operator()(const GoalCandidate & a, const GoalCandidate & b) const noexcept
{
return a.distance_from_original_goal + lateral_cost * a.lateral_offset <

Check warning on line 65 in planning/behavior_path_planner/src/utils/goal_planner/goal_searcher.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/goal_planner/goal_searcher.cpp#L65

Added line #L65 was not covered by tests
b.distance_from_original_goal + lateral_cost * b.lateral_offset;
}
};

GoalSearcher::GoalSearcher(
const GoalPlannerParameters & parameters, const LinearRing2d & vehicle_footprint,
const std::shared_ptr<OccupancyGridBasedCollisionDetector> & occupancy_grid_map)
Expand Down Expand Up @@ -141,8 +170,13 @@
}
createAreaPolygons(original_search_poses);

// Sort with distance from original goal
std::sort(goal_candidates.begin(), goal_candidates.end());
if (parameters_.goal_priority == "minimum_weighted_distance") {
std::sort(

Check warning on line 174 in planning/behavior_path_planner/src/utils/goal_planner/goal_searcher.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/goal_planner/goal_searcher.cpp#L174

Added line #L174 was not covered by tests
goal_candidates.begin(), goal_candidates.end(),
SortByWeightedDistance(parameters_.minimum_weighted_distance_lateral_weight));
} else if (parameters_.goal_priority == "minimum_longitudinal_distance") {
std::sort(goal_candidates.begin(), goal_candidates.end(), SortByLongitudinalDistance());

Check warning on line 178 in planning/behavior_path_planner/src/utils/goal_planner/goal_searcher.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/goal_planner/goal_searcher.cpp#L178

Added line #L178 was not covered by tests
}

Check warning on line 179 in planning/behavior_path_planner/src/utils/goal_planner/goal_searcher.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

GoalSearcher::search increases in cyclomatic complexity from 14 to 16, 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.

return goal_candidates;
}
Expand Down
Loading