Skip to content

Commit 8575f4f

Browse files
committed
fix
Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
1 parent 6ebdeba commit 8575f4f

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/goal_planner_module.cpp

+34-26
Original file line numberDiff line numberDiff line change
@@ -833,20 +833,27 @@ std::vector<PullOverPath> GoalPlannerModule::sortPullOverPathCandidatesByGoalPri
833833
std::stringstream ss;
834834

835835
// unsafe goal and it's priority are not visible as debug marker in rviz,
836-
// so subtract of unsafe goal from goal_priority(index)
837-
const size_t num_of_unsafe_goals = std::count_if(
838-
goal_candidates.begin(), goal_candidates.end(),
839-
[](const auto & goal_candidate) { return !goal_candidate.is_safe; });
836+
// so exclude unsafe goal from goal_priority
837+
std::map<size_t, int> goal_id_and_priority;
838+
{
839+
int priority = 0;
840+
for (const auto & goal_candidate : goal_candidates) {
841+
goal_id_and_priority[goal_candidate.id] = goal_candidate.is_safe ? priority++ : -1;
842+
}
843+
}
840844

841845
ss << "\n---------------------- path priority ----------------------\n";
842846
for (size_t i = 0; i < sorted_pull_over_path_candidates.size(); ++i) {
843847
const auto & path = sorted_pull_over_path_candidates[i];
844-
const int goal_priority =
845-
(static_cast<int>(goal_id_to_index.at(path.goal_id)) -
846-
static_cast<int>(num_of_unsafe_goals));
848+
849+
// goal_index is same to goal priority including unsafe goal
850+
const int goal_index = static_cast<int>(goal_id_to_index.at(path.goal_id));
851+
const bool is_safe_goal = goal_candidates[goal_index].is_safe;
852+
const int goal_priority = goal_id_and_priority[path.goal_id];
853+
847854
ss << "path_priority: " << i << ", path_type: " << magic_enum::enum_name(path.type)
848855
<< ", path_id: " << path.id << ", goal_id: " << path.goal_id
849-
<< ", goal_priority:" << goal_priority
856+
<< ", goal_priority: " << (is_safe_goal ? std::to_string(goal_priority) : "unsafe")
850857
<< ", margin: " << path_id_to_margin_map.at(path.id)
851858
<< (isSoftMargin(path) ? " (soft)" : " (hard)") << ", curvature: " << path.max_curvature
852859
<< (isHighCurvature(path) ? " (high)" : " (low)");
@@ -938,38 +945,39 @@ std::vector<PullOverPath> GoalPlannerModule::sortPullOverPathCandidatesByGoalPri
938945
return path.max_curvature >= parameters_->high_curvature_threshold;
939946
};
940947

948+
const auto isSoftMargin = [&](const PullOverPath & path) -> bool {
949+
const double margin = path_id_to_margin_map[path.id];
950+
return std::any_of(
951+
soft_margins.begin(), soft_margins.end(),
952+
[margin](const double soft_margin) { return std::abs(margin - soft_margin) < 0.01; });
953+
};
954+
const auto isSameHardMargin = [&](const PullOverPath & a, const PullOverPath & b) -> bool {
955+
return !isSoftMargin(a) && !isSoftMargin(b) &&
956+
std::abs(path_id_to_margin_map[a.id] - path_id_to_margin_map[b.id]) < 0.01;
957+
};
958+
941959
std::stable_sort(
942960
sorted_pull_over_path_candidates.begin(), sorted_pull_over_path_candidates.end(),
943961
[&](const PullOverPath & a, const PullOverPath & b) {
944-
return !isHighCurvature(a) && isHighCurvature(b);
962+
// if both are soft margin or both are same hard margin, prioritize the path with lower
963+
// curvature.
964+
if ((isSoftMargin(a) && isSoftMargin(b)) || isSameHardMargin(a, b)) {
965+
return !isHighCurvature(a) && isHighCurvature(b);
966+
}
967+
// otherwise, keep the order based on the margin.
968+
return false;
945969
});
946970

947971
// (4) Sort pull_over_path_candidates based on the order in efficient_path_order keeping the
948972
// collision check margin and curvature priority.
949973
if (parameters_->path_priority == "efficient_path") {
950-
const auto isSoftMargin = [&](const PullOverPath & path) -> bool {
951-
const double margin = path_id_to_margin_map[path.id];
952-
return std::any_of(
953-
soft_margins.begin(), soft_margins.end(),
954-
[margin](const double soft_margin) { return std::abs(margin - soft_margin) < 0.01; });
955-
};
956-
const auto isSameHardMargin = [&](const PullOverPath & a, const PullOverPath & b) -> bool {
957-
return !isSoftMargin(a) && !isSoftMargin(b) &&
958-
std::abs(path_id_to_margin_map[a.id] - path_id_to_margin_map[b.id]) < 0.01;
959-
};
960-
961974
std::stable_sort(
962975
sorted_pull_over_path_candidates.begin(), sorted_pull_over_path_candidates.end(),
963976
[&](const auto & a, const auto & b) {
964977
// if any of following conditions are met, sort by path type priority
965978
// - both are soft margin
966979
// - both are same hard margin
967-
// - both are high curvature
968-
// - both are low curvature
969-
if (
970-
(isSoftMargin(a) && isSoftMargin(b)) || isSameHardMargin(a, b) ||
971-
(isHighCurvature(a) && isHighCurvature(b)) ||
972-
(!isHighCurvature(a) && !isHighCurvature(b))) {
980+
if ((isSoftMargin(a) && isSoftMargin(b)) || isSameHardMargin(a, b)) {
973981
return comparePathTypePriority(a, b);
974982
}
975983
// otherwise, keep the order.

0 commit comments

Comments
 (0)