Skip to content

Commit 0ff2b18

Browse files
committed
refactor(goal_planner): remove use_object_recognition because it is default
Signed-off-by: Mamoru Sobue <mamoru.sobue@tier4.jp>
1 parent 46aaaee commit 0ff2b18

File tree

6 files changed

+127
-161
lines changed

6 files changed

+127
-161
lines changed

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/config/goal_planner.param.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
# object recognition
4141
object_recognition:
42-
use_object_recognition: true
4342
collision_check_soft_margins: [5.0, 4.5, 4.0, 3.5, 3.0, 2.5, 2.0, 1.5, 1.0] # the maximum margin when ego and objects are oriented.
4443
collision_check_hard_margins: [0.6] # this should be larger than `surround_check_distance` of surround_obstacle_checker
4544
object_recognition_collision_check_max_extra_stopping_margin: 1.0

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/include/autoware/behavior_path_goal_planner_module/goal_planner_parameters.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ struct GoalPlannerParameters
7777
int obstacle_threshold{0};
7878

7979
// object recognition
80-
bool use_object_recognition{false};
8180
std::vector<double> object_recognition_collision_check_soft_margins{};
8281
std::vector<double> object_recognition_collision_check_hard_margins{};
8382
double object_recognition_collision_check_max_extra_stopping_margin{0.0};

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

+7-10
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,13 @@ PathDecisionState PathDecisionStateController::get_next_state(
175175

176176
// if object recognition for path collision check is enabled, transition to DECIDING to check
177177
// collision for a certain period of time. Otherwise, transition to DECIDED directly.
178-
if (parameters.use_object_recognition) {
179-
RCLCPP_DEBUG(
180-
logger_,
181-
"[DecidingPathStatus]: NOT_DECIDED->DECIDING. start checking collision for certain "
182-
"period of time");
183-
next_state.state = PathDecisionState::DecisionKind::DECIDING;
184-
next_state.deciding_start_time = now;
185-
return next_state;
186-
}
187-
return {PathDecisionState::DecisionKind::DECIDED, std::nullopt};
178+
RCLCPP_DEBUG(
179+
logger_,
180+
"[DecidingPathStatus]: NOT_DECIDED->DECIDING. start checking collision for certain "
181+
"period of time");
182+
next_state.state = PathDecisionState::DecisionKind::DECIDING;
183+
next_state.deciding_start_time = now;
184+
return next_state;
188185
}
189186

190187
} // namespace autoware::behavior_path_planner

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/goal_planner_module.cpp

+116-141
Original file line numberDiff line numberDiff line change
@@ -971,14 +971,13 @@ bool GoalPlannerModule::canReturnToLaneParking(const PullOverContextData & conte
971971

972972
const auto & path = lane_parking_path.full_path();
973973
const auto & curvatures = lane_parking_path.full_path_curvatures();
974-
if (
975-
parameters_.use_object_recognition &&
976-
goal_planner_utils::checkObjectsCollision(
977-
path, curvatures, context_data.static_target_objects, context_data.dynamic_target_objects,
978-
planner_data_->parameters, parameters_.object_recognition_collision_check_hard_margins.back(),
979-
/*extract_static_objects=*/false, parameters_.maximum_deceleration,
980-
parameters_.object_recognition_collision_check_max_extra_stopping_margin,
981-
debug_data_.ego_polygons_expanded)) {
974+
if (goal_planner_utils::checkObjectsCollision(
975+
path, curvatures, context_data.static_target_objects, context_data.dynamic_target_objects,
976+
planner_data_->parameters,
977+
parameters_.object_recognition_collision_check_hard_margins.back(),
978+
/*extract_static_objects=*/false, parameters_.maximum_deceleration,
979+
parameters_.object_recognition_collision_check_max_extra_stopping_margin,
980+
debug_data_.ego_polygons_expanded)) {
982981
return false;
983982
}
984983

@@ -1082,136 +1081,116 @@ void sortPullOverPaths(
10821081
};
10831082

10841083
// if object recognition is enabled, sort by collision check margin
1085-
if (parameters.use_object_recognition) {
1086-
// STEP2-2: Sort by collision check margins
1087-
const auto [margins, margins_with_zero] =
1088-
std::invoke([&]() -> std::tuple<std::vector<double>, std::vector<double>> {
1089-
std::vector<double> margins = soft_margins;
1090-
margins.insert(margins.end(), hard_margins.begin(), hard_margins.end());
1091-
std::vector<double> margins_with_zero = margins;
1092-
margins_with_zero.push_back(0.0);
1093-
return std::make_tuple(margins, margins_with_zero);
1094-
});
1084+
// STEP2-2: Sort by collision check margins
1085+
const auto [margins, margins_with_zero] =
1086+
std::invoke([&]() -> std::tuple<std::vector<double>, std::vector<double>> {
1087+
std::vector<double> margins = soft_margins;
1088+
margins.insert(margins.end(), hard_margins.begin(), hard_margins.end());
1089+
std::vector<double> margins_with_zero = margins;
1090+
margins_with_zero.push_back(0.0);
1091+
return std::make_tuple(margins, margins_with_zero);
1092+
});
10951093

1096-
// Create a map of PullOverPath pointer to largest collision check margin
1097-
std::map<size_t, double> path_id_to_rough_margin_map;
1098-
const auto & target_objects = static_target_objects;
1099-
for (const size_t i : sorted_path_indices) {
1100-
const auto & path = pull_over_path_candidates[i];
1101-
const double distance = utils::path_safety_checker::calculateRoughDistanceToObjects(
1102-
path.parking_path(), target_objects, planner_data->parameters, false, "max");
1103-
auto it = std::lower_bound(
1104-
margins_with_zero.begin(), margins_with_zero.end(), distance, std::greater<double>());
1105-
if (it == margins_with_zero.end()) {
1106-
path_id_to_rough_margin_map[path.id()] = margins_with_zero.back();
1107-
} else {
1108-
path_id_to_rough_margin_map[path.id()] = *it;
1109-
}
1094+
// Create a map of PullOverPath pointer to largest collision check margin
1095+
std::map<size_t, double> path_id_to_rough_margin_map;
1096+
const auto & target_objects = static_target_objects;
1097+
for (const size_t i : sorted_path_indices) {
1098+
const auto & path = pull_over_path_candidates[i];
1099+
const double distance = utils::path_safety_checker::calculateRoughDistanceToObjects(
1100+
path.parking_path(), target_objects, planner_data->parameters, false, "max");
1101+
auto it = std::lower_bound(
1102+
margins_with_zero.begin(), margins_with_zero.end(), distance, std::greater<double>());
1103+
if (it == margins_with_zero.end()) {
1104+
path_id_to_rough_margin_map[path.id()] = margins_with_zero.back();
1105+
} else {
1106+
path_id_to_rough_margin_map[path.id()] = *it;
11101107
}
1108+
}
11111109

1112-
// sorts in descending order so the item with larger margin comes first
1113-
std::stable_sort(
1114-
std::execution::par, sorted_path_indices.begin(), sorted_path_indices.end(),
1115-
[&](const size_t a_i, const size_t b_i) {
1116-
const auto & a = pull_over_path_candidates[a_i];
1117-
const auto & b = pull_over_path_candidates[b_i];
1118-
if (!isSameNumObjectsToAvoid(a, b)) {
1119-
return false;
1120-
}
1121-
if (
1122-
std::abs(path_id_to_rough_margin_map[a.id()] - path_id_to_rough_margin_map[b.id()]) <
1123-
0.01) {
1124-
return false;
1125-
}
1126-
return path_id_to_rough_margin_map[a.id()] > path_id_to_rough_margin_map[b.id()];
1127-
});
1110+
// sorts in descending order so the item with larger margin comes first
1111+
std::stable_sort(
1112+
std::execution::par, sorted_path_indices.begin(), sorted_path_indices.end(),
1113+
[&](const size_t a_i, const size_t b_i) {
1114+
const auto & a = pull_over_path_candidates[a_i];
1115+
const auto & b = pull_over_path_candidates[b_i];
1116+
if (!isSameNumObjectsToAvoid(a, b)) {
1117+
return false;
1118+
}
1119+
if (
1120+
std::abs(path_id_to_rough_margin_map[a.id()] - path_id_to_rough_margin_map[b.id()]) <
1121+
0.01) {
1122+
return false;
1123+
}
1124+
return path_id_to_rough_margin_map[a.id()] > path_id_to_rough_margin_map[b.id()];
1125+
});
1126+
1127+
// STEP2-3: Sort by curvature
1128+
// If the curvature is less than the threshold, prioritize the path.
1129+
const auto isHighCurvature = [&](const PullOverPath & path) -> bool {
1130+
return path.parking_path_max_curvature() >= parameters.high_curvature_threshold;
1131+
};
1132+
1133+
const auto isSoftMargin = [&](const PullOverPath & path) -> bool {
1134+
const double margin = path_id_to_rough_margin_map[path.id()];
1135+
return std::any_of(
1136+
soft_margins.begin(), soft_margins.end(),
1137+
[margin](const double soft_margin) { return std::abs(margin - soft_margin) < 0.01; });
1138+
};
1139+
const auto isSameHardMargin = [&](const PullOverPath & a, const PullOverPath & b) -> bool {
1140+
return !isSoftMargin(a) && !isSoftMargin(b) &&
1141+
std::abs(path_id_to_rough_margin_map[a.id()] - path_id_to_rough_margin_map[b.id()]) <
1142+
0.01;
1143+
};
11281144

1129-
// STEP2-3: Sort by curvature
1130-
// If the curvature is less than the threshold, prioritize the path.
1131-
const auto isHighCurvature = [&](const PullOverPath & path) -> bool {
1132-
return path.parking_path_max_curvature() >= parameters.high_curvature_threshold;
1133-
};
1134-
1135-
const auto isSoftMargin = [&](const PullOverPath & path) -> bool {
1136-
const double margin = path_id_to_rough_margin_map[path.id()];
1137-
return std::any_of(
1138-
soft_margins.begin(), soft_margins.end(),
1139-
[margin](const double soft_margin) { return std::abs(margin - soft_margin) < 0.01; });
1140-
};
1141-
const auto isSameHardMargin = [&](const PullOverPath & a, const PullOverPath & b) -> bool {
1142-
return !isSoftMargin(a) && !isSoftMargin(b) &&
1143-
std::abs(path_id_to_rough_margin_map[a.id()] - path_id_to_rough_margin_map[b.id()]) <
1144-
0.01;
1145-
};
1146-
1147-
// NOTE: this is just partition sort based on curvature threshold within each sub partitions
1145+
// NOTE: this is just partition sort based on curvature threshold within each sub partitions
1146+
std::stable_sort(
1147+
std::execution::par, sorted_path_indices.begin(), sorted_path_indices.end(),
1148+
[&](const size_t a_i, const size_t b_i) {
1149+
const auto & a = pull_over_path_candidates[a_i];
1150+
const auto & b = pull_over_path_candidates[b_i];
1151+
if (!isSameNumObjectsToAvoid(a, b)) {
1152+
return false;
1153+
}
1154+
1155+
// if both are soft margin or both are same hard margin, prioritize the path with lower
1156+
// curvature.
1157+
if ((isSoftMargin(a) && isSoftMargin(b)) || isSameHardMargin(a, b)) {
1158+
return !isHighCurvature(a) && isHighCurvature(b);
1159+
}
1160+
// otherwise, keep the order based on the margin.
1161+
return false;
1162+
});
1163+
1164+
// STEP2-4: Sort pull_over_path_candidates based on the order in efficient_path_order keeping
1165+
// the collision check margin and curvature priority.
1166+
if (parameters.path_priority == "efficient_path") {
11481167
std::stable_sort(
11491168
std::execution::par, sorted_path_indices.begin(), sorted_path_indices.end(),
11501169
[&](const size_t a_i, const size_t b_i) {
1170+
// if any of following conditions are met, sort by path type priority
1171+
// - both are soft margin
1172+
// - both are same hard margin
11511173
const auto & a = pull_over_path_candidates[a_i];
11521174
const auto & b = pull_over_path_candidates[b_i];
11531175
if (!isSameNumObjectsToAvoid(a, b)) {
11541176
return false;
11551177
}
1156-
1157-
// if both are soft margin or both are same hard margin, prioritize the path with lower
1158-
// curvature.
11591178
if ((isSoftMargin(a) && isSoftMargin(b)) || isSameHardMargin(a, b)) {
1160-
return !isHighCurvature(a) && isHighCurvature(b);
1179+
return comparePathTypePriority(a, b);
11611180
}
1162-
// otherwise, keep the order based on the margin.
1181+
// otherwise, keep the order.
11631182
return false;
11641183
});
1165-
1166-
// STEP2-4: Sort pull_over_path_candidates based on the order in efficient_path_order keeping
1167-
// the collision check margin and curvature priority.
1168-
if (parameters.path_priority == "efficient_path") {
1169-
std::stable_sort(
1170-
std::execution::par, sorted_path_indices.begin(), sorted_path_indices.end(),
1171-
[&](const size_t a_i, const size_t b_i) {
1172-
// if any of following conditions are met, sort by path type priority
1173-
// - both are soft margin
1174-
// - both are same hard margin
1175-
const auto & a = pull_over_path_candidates[a_i];
1176-
const auto & b = pull_over_path_candidates[b_i];
1177-
if (!isSameNumObjectsToAvoid(a, b)) {
1178-
return false;
1179-
}
1180-
if ((isSoftMargin(a) && isSoftMargin(b)) || isSameHardMargin(a, b)) {
1181-
return comparePathTypePriority(a, b);
1182-
}
1183-
// otherwise, keep the order.
1184-
return false;
1185-
});
1186-
}
1187-
1188-
// debug print path priority sorted by
1189-
// - efficient_path_order
1190-
// - collision check margin
1191-
// - curvature
1192-
const std::string path_priority_info_str = goal_planner_utils::makePathPriorityDebugMessage(
1193-
sorted_path_indices, pull_over_path_candidates, goal_id_to_index, goal_candidates,
1194-
path_id_to_rough_margin_map, isSoftMargin, isHighCurvature);
1195-
RCLCPP_DEBUG_STREAM(logger, path_priority_info_str);
1196-
} else {
1197-
/**
1198-
* NOTE: use_object_recognition=false is not recommended. This option will be deprecated in the
1199-
* future. sort by curvature is not implemented yet.
1200-
* Sort pull_over_path_candidates based on the order in efficient_path_order
1201-
*/
1202-
if (parameters.path_priority == "efficient_path") {
1203-
std::stable_sort(
1204-
std::execution::par, sorted_path_indices.begin(), sorted_path_indices.end(),
1205-
[&](const size_t a_i, const size_t b_i) {
1206-
const auto & a = pull_over_path_candidates[a_i];
1207-
const auto & b = pull_over_path_candidates[b_i];
1208-
if (!isSameNumObjectsToAvoid(a, b)) {
1209-
return false;
1210-
}
1211-
return comparePathTypePriority(a, b);
1212-
});
1213-
}
12141184
}
1185+
1186+
// debug print path priority sorted by
1187+
// - efficient_path_order
1188+
// - collision check margin
1189+
// - curvature
1190+
const std::string path_priority_info_str = goal_planner_utils::makePathPriorityDebugMessage(
1191+
sorted_path_indices, pull_over_path_candidates, goal_id_to_index, goal_candidates,
1192+
path_id_to_rough_margin_map, isSoftMargin, isHighCurvature);
1193+
RCLCPP_DEBUG_STREAM(logger, path_priority_info_str);
12151194
}
12161195

12171196
std::optional<PullOverPath> GoalPlannerModule::selectPullOverPath(
@@ -1285,14 +1264,12 @@ std::optional<PullOverPath> GoalPlannerModule::selectPullOverPath(
12851264
const auto & path = pull_over_path_candidates[i];
12861265
const PathWithLaneId & parking_path = path.parking_path();
12871266
const auto & parking_path_curvatures = path.parking_path_curvatures();
1288-
if (
1289-
parameters_.use_object_recognition &&
1290-
goal_planner_utils::checkObjectsCollision(
1291-
parking_path, parking_path_curvatures, context_data.static_target_objects,
1292-
context_data.dynamic_target_objects, planner_data_->parameters, collision_check_margin,
1293-
true, parameters_.maximum_deceleration,
1294-
parameters_.object_recognition_collision_check_max_extra_stopping_margin,
1295-
debug_data_.ego_polygons_expanded, true)) {
1267+
if (goal_planner_utils::checkObjectsCollision(
1268+
parking_path, parking_path_curvatures, context_data.static_target_objects,
1269+
context_data.dynamic_target_objects, planner_data_->parameters, collision_check_margin,
1270+
true, parameters_.maximum_deceleration,
1271+
parameters_.object_recognition_collision_check_max_extra_stopping_margin,
1272+
debug_data_.ego_polygons_expanded, true)) {
12961273
continue;
12971274
}
12981275
if (
@@ -1859,18 +1836,16 @@ bool FreespaceParkingPlanner::isStuck(
18591836
return true;
18601837
}
18611838

1862-
if (parameters.use_object_recognition) {
1863-
const auto & path = req.get_pull_over_path().value().getCurrentPath();
1864-
const auto curvatures = autoware::motion_utils::calcCurvature(path.points);
1865-
std::vector<Polygon2d> ego_polygons_expanded;
1866-
if (goal_planner_utils::checkObjectsCollision(
1867-
path, curvatures, static_target_objects, dynamic_target_objects, planner_data->parameters,
1868-
parameters.object_recognition_collision_check_hard_margins.back(),
1869-
/*extract_static_objects=*/false, parameters.maximum_deceleration,
1870-
parameters.object_recognition_collision_check_max_extra_stopping_margin,
1871-
ego_polygons_expanded)) {
1872-
return true;
1873-
}
1839+
const auto & path = req.get_pull_over_path().value().getCurrentPath();
1840+
const auto curvatures = autoware::motion_utils::calcCurvature(path.points);
1841+
std::vector<Polygon2d> ego_polygons_expanded;
1842+
if (goal_planner_utils::checkObjectsCollision(
1843+
path, curvatures, static_target_objects, dynamic_target_objects, planner_data->parameters,
1844+
parameters.object_recognition_collision_check_hard_margins.back(),
1845+
/*extract_static_objects=*/false, parameters.maximum_deceleration,
1846+
parameters.object_recognition_collision_check_max_extra_stopping_margin,
1847+
ego_polygons_expanded)) {
1848+
return true;
18741849
}
18751850

18761851
if (

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/goal_searcher.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,10 @@ bool GoalSearcher::checkCollision(
444444
}
445445
}
446446

447-
if (parameters_.use_object_recognition) {
448-
if (utils::checkCollisionBetweenFootprintAndObjects(
449-
vehicle_footprint_, pose, objects,
450-
parameters_.object_recognition_collision_check_hard_margins.back())) {
451-
return true;
452-
}
447+
if (utils::checkCollisionBetweenFootprintAndObjects(
448+
vehicle_footprint_, pose, objects,
449+
parameters_.object_recognition_collision_check_hard_margins.back())) {
450+
return true;
453451
}
454452
return false;
455453
}

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/manager.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ GoalPlannerParameters GoalPlannerModuleManager::initGoalPlannerParameters(
106106
// object recognition
107107
{
108108
const std::string ns = base_ns + "object_recognition.";
109-
p.use_object_recognition = node->declare_parameter<bool>(ns + "use_object_recognition");
110109
p.object_recognition_collision_check_soft_margins =
111110
node->declare_parameter<std::vector<double>>(ns + "collision_check_soft_margins");
112111
p.object_recognition_collision_check_hard_margins =
@@ -513,7 +512,6 @@ void GoalPlannerModuleManager::updateModuleParams(
513512
{
514513
const std::string ns = base_ns + "object_recognition.";
515514

516-
updateParam<bool>(parameters, ns + "use_object_recognition", p->use_object_recognition);
517515
updateParam(
518516
parameters, ns + "object_recognition_collision_check_max_extra_stopping_margin",
519517
p->object_recognition_collision_check_max_extra_stopping_margin);

0 commit comments

Comments
 (0)