@@ -833,20 +833,27 @@ std::vector<PullOverPath> GoalPlannerModule::sortPullOverPathCandidatesByGoalPri
833
833
std::stringstream ss;
834
834
835
835
// 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
+ }
840
844
841
845
ss << " \n ---------------------- path priority ----------------------\n " ;
842
846
for (size_t i = 0 ; i < sorted_pull_over_path_candidates.size (); ++i) {
843
847
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
+
847
854
ss << " path_priority: " << i << " , path_type: " << magic_enum::enum_name (path.type )
848
855
<< " , 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 " )
850
857
<< " , margin: " << path_id_to_margin_map.at (path.id )
851
858
<< (isSoftMargin (path) ? " (soft)" : " (hard)" ) << " , curvature: " << path.max_curvature
852
859
<< (isHighCurvature (path) ? " (high)" : " (low)" );
@@ -938,38 +945,39 @@ std::vector<PullOverPath> GoalPlannerModule::sortPullOverPathCandidatesByGoalPri
938
945
return path.max_curvature >= parameters_->high_curvature_threshold ;
939
946
};
940
947
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
+
941
959
std::stable_sort (
942
960
sorted_pull_over_path_candidates.begin (), sorted_pull_over_path_candidates.end (),
943
961
[&](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 ;
945
969
});
946
970
947
971
// (4) Sort pull_over_path_candidates based on the order in efficient_path_order keeping the
948
972
// collision check margin and curvature priority.
949
973
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
-
961
974
std::stable_sort (
962
975
sorted_pull_over_path_candidates.begin (), sorted_pull_over_path_candidates.end (),
963
976
[&](const auto & a, const auto & b) {
964
977
// if any of following conditions are met, sort by path type priority
965
978
// - both are soft margin
966
979
// - 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)) {
973
981
return comparePathTypePriority (a, b);
974
982
}
975
983
// otherwise, keep the order.
0 commit comments