Skip to content

Commit 86e0a01

Browse files
authored
fix(start_planner): fix path generation for separated lanes and extended loop lanes (#4418)
* fix(start_planner): fix path generation for separated lanes and extended loop lanes Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> * Add until goal lanes option Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> * add commnets Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> --------- Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
1 parent 8a13959 commit 86e0a01

File tree

10 files changed

+69
-30
lines changed

10 files changed

+69
-30
lines changed

planning/behavior_path_planner/include/behavior_path_planner/utils/utils.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ lanelet::ConstLanelets getExtendedCurrentLanes(
383383

384384
lanelet::ConstLanelets getExtendedCurrentLanes(
385385
const std::shared_ptr<const PlannerData> & planner_data, const double backward_length,
386-
const double forward_length);
386+
const double forward_length, const bool until_goal_lane);
387387

388388
lanelet::ConstLanelets calcLaneAroundPose(
389389
const std::shared_ptr<RouteHandler> route_handler, const geometry_msgs::msg::Pose & pose,

planning/behavior_path_planner/src/scene_module/goal_planner/goal_planner_module.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ void GoalPlannerModule::onTimer()
153153
// generate valid pull over path candidates and calculate closest start pose
154154
const auto current_lanes = utils::getExtendedCurrentLanes(
155155
planner_data_, parameters_->backward_goal_search_length,
156-
parameters_->forward_goal_search_length);
156+
parameters_->forward_goal_search_length,
157+
/*until_goal_lane*/ false);
157158
std::vector<PullOverPath> path_candidates{};
158159
std::optional<Pose> closest_start_pose{};
159160
double min_start_arc_length = std::numeric_limits<double>::max();
@@ -590,7 +591,8 @@ void GoalPlannerModule::setLanes()
590591
{
591592
status_.current_lanes = utils::getExtendedCurrentLanes(
592593
planner_data_, parameters_->backward_goal_search_length,
593-
parameters_->forward_goal_search_length);
594+
parameters_->forward_goal_search_length,
595+
/*until_goal_lane*/ false);
594596
status_.pull_over_lanes =
595597
goal_planner_utils::getPullOverLanes(*(planner_data_->route_handler), left_side_parking_);
596598
status_.lanes =

planning/behavior_path_planner/src/scene_module/start_planner/start_planner_module.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ bool StartPlannerModule::isExecutionRequested() const
115115
const double backward_path_length =
116116
planner_data_->parameters.backward_path_length + parameters_->max_back_distance;
117117
const auto current_lanes = utils::getExtendedCurrentLanes(
118-
planner_data_, backward_path_length, std::numeric_limits<double>::max());
118+
planner_data_, backward_path_length, std::numeric_limits<double>::max(),
119+
/*until_goal_lane*/ true);
119120
const auto pull_out_lanes =
120121
start_planner_utils::getPullOutLanes(planner_data_, backward_path_length);
121122
auto lanes = current_lanes;
@@ -326,7 +327,8 @@ BehaviorModuleOutput StartPlannerModule::planWaitingApproval()
326327
const double backward_path_length =
327328
planner_data_->parameters.backward_path_length + parameters_->max_back_distance;
328329
const auto current_lanes = utils::getExtendedCurrentLanes(
329-
planner_data_, backward_path_length, std::numeric_limits<double>::max());
330+
planner_data_, backward_path_length, std::numeric_limits<double>::max(),
331+
/*until_goal_lane*/ true);
330332

331333
const auto pull_out_lanes =
332334
start_planner_utils::getPullOutLanes(planner_data_, backward_path_length);
@@ -562,7 +564,8 @@ void StartPlannerModule::updatePullOutStatus()
562564
const double backward_path_length =
563565
planner_data_->parameters.backward_path_length + parameters_->max_back_distance;
564566
status_.current_lanes = utils::getExtendedCurrentLanes(
565-
planner_data_, backward_path_length, std::numeric_limits<double>::max());
567+
planner_data_, backward_path_length, std::numeric_limits<double>::max(),
568+
/*until_goal_lane*/ true);
566569
status_.pull_out_lanes =
567570
start_planner_utils::getPullOutLanes(planner_data_, backward_path_length);
568571

planning/behavior_path_planner/src/utils/goal_planner/geometric_pull_over.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ boost::optional<PullOverPath> GeometricPullOver::plan(const Pose & goal_pose)
4545

4646
// prepare road nad shoulder lanes
4747
const auto road_lanes = utils::getExtendedCurrentLanes(
48-
planner_data_, parameters_.backward_goal_search_length, parameters_.forward_goal_search_length);
48+
planner_data_, parameters_.backward_goal_search_length, parameters_.forward_goal_search_length,
49+
/*until_goal_lane*/ false);
4950
const auto shoulder_lanes =
5051
goal_planner_utils::getPullOverLanes(*route_handler, left_side_parking_);
5152
if (road_lanes.empty() || shoulder_lanes.empty()) {

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ GoalCandidates GoalSearcher::search(const Pose & original_goal_pose)
5454

5555
const auto pull_over_lanes =
5656
goal_planner_utils::getPullOverLanes(*route_handler, left_side_parking_);
57-
auto lanes = utils::getExtendedCurrentLanes(planner_data_, backward_length, forward_length);
57+
auto lanes = utils::getExtendedCurrentLanes(
58+
planner_data_, backward_length, forward_length,
59+
/*until_goal_lane*/ false);
5860
lanes.insert(lanes.end(), pull_over_lanes.begin(), pull_over_lanes.end());
5961

6062
const auto goal_arc_coords =

planning/behavior_path_planner/src/utils/goal_planner/shift_pull_over.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ boost::optional<PullOverPath> ShiftPullOver::plan(const Pose & goal_pose)
4646
const double jerk_resolution = std::abs(max_jerk - min_jerk) / shift_sampling_num;
4747

4848
// get road and shoulder lanes
49-
const auto road_lanes =
50-
utils::getExtendedCurrentLanes(planner_data_, backward_search_length, forward_search_length);
49+
const auto road_lanes = utils::getExtendedCurrentLanes(
50+
planner_data_, backward_search_length, forward_search_length,
51+
/*until_goal_lane*/ false);
5152
const auto shoulder_lanes =
5253
goal_planner_utils::getPullOverLanes(*route_handler, left_side_parking_);
5354
if (road_lanes.empty() || shoulder_lanes.empty()) {

planning/behavior_path_planner/src/utils/start_planner/geometric_pull_out.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ boost::optional<PullOutPath> GeometricPullOut::plan(Pose start_pose, Pose goal_p
4343
const double backward_path_length =
4444
planner_data_->parameters.backward_path_length + parameters_.max_back_distance;
4545
const auto road_lanes = utils::getExtendedCurrentLanes(
46-
planner_data_, backward_path_length, std::numeric_limits<double>::max());
46+
planner_data_, backward_path_length, std::numeric_limits<double>::max(),
47+
/*until_goal_lane*/ true);
4748
const auto pull_out_lanes = getPullOutLanes(planner_data_, backward_path_length);
4849
auto lanes = road_lanes;
4950
for (const auto & pull_out_lane : pull_out_lanes) {

planning/behavior_path_planner/src/utils/start_planner/shift_pull_out.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ boost::optional<PullOutPath> ShiftPullOut::plan(Pose start_pose, Pose goal_pose)
5353
}
5454

5555
const auto road_lanes = utils::getExtendedCurrentLanes(
56-
planner_data_, backward_path_length, std::numeric_limits<double>::max());
57-
56+
planner_data_, backward_path_length, std::numeric_limits<double>::max(),
57+
/*until_goal_lane*/ true);
5858
// find candidate paths
5959
auto pull_out_paths = calcPullOutPaths(
6060
*route_handler, road_lanes, start_pose, goal_pose, common_parameters, parameters_);

planning/behavior_path_planner/src/utils/start_planner/util.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ lanelet::ConstLanelets getPullOutLanes(
114114

115115
// pull out from road lane
116116
return utils::getExtendedCurrentLanes(
117-
planner_data, backward_length, /*forward_length*/ std::numeric_limits<double>::max());
117+
planner_data, backward_length,
118+
/*forward_length*/ std::numeric_limits<double>::max(),
119+
/*until_goal_lane*/ true);
118120
}
119121
} // namespace behavior_path_planner::start_planner_utils

planning/behavior_path_planner/src/utils/utils.cpp

+43-16
Original file line numberDiff line numberDiff line change
@@ -2864,7 +2864,14 @@ lanelet::ConstLanelets extendNextLane(
28642864
// Add next lane
28652865
const auto next_lanes = route_handler->getNextLanelets(extended_lanes.back());
28662866
if (!next_lanes.empty()) {
2867-
extended_lanes.push_back(next_lanes.front());
2867+
// use the next lane in route if it exists
2868+
auto target_next_lane = next_lanes.front();
2869+
for (const auto & next_lane : next_lanes) {
2870+
if (route_handler->isRouteLanelet(next_lane)) {
2871+
target_next_lane = next_lane;
2872+
}
2873+
}
2874+
extended_lanes.push_back(target_next_lane);
28682875
}
28692876

28702877
return extended_lanes;
@@ -2878,9 +2885,15 @@ lanelet::ConstLanelets extendPrevLane(
28782885
// Add previous lane
28792886
const auto prev_lanes = route_handler->getPreviousLanelets(extended_lanes.front());
28802887
if (!prev_lanes.empty()) {
2881-
extended_lanes.insert(extended_lanes.begin(), prev_lanes.front());
2888+
// use the previous lane in route if it exists
2889+
auto target_prev_lane = prev_lanes.front();
2890+
for (const auto & prev_lane : prev_lanes) {
2891+
if (route_handler->isRouteLanelet(prev_lane)) {
2892+
target_prev_lane = prev_lane;
2893+
}
2894+
}
2895+
extended_lanes.insert(extended_lanes.begin(), target_prev_lane);
28822896
}
2883-
28842897
return extended_lanes;
28852898
}
28862899

@@ -2895,26 +2908,24 @@ lanelet::ConstLanelets extendLanes(
28952908

28962909
lanelet::ConstLanelets getExtendedCurrentLanes(
28972910
const std::shared_ptr<const PlannerData> & planner_data, const double backward_length,
2898-
const double forward_length)
2911+
const double forward_length, const bool until_goal_lane)
28992912
{
29002913
auto lanes = getCurrentLanes(planner_data);
29012914
if (lanes.empty()) return lanes;
2915+
const auto start_lane = lanes.front();
29022916

29032917
double forward_length_sum = 0.0;
29042918
double backward_length_sum = 0.0;
29052919

2906-
const auto is_loop = [&](const auto & target_lane) {
2907-
auto it = std::find_if(lanes.begin(), lanes.end(), [&](const lanelet::ConstLanelet & lane) {
2908-
return lane.id() == target_lane.id();
2909-
});
2910-
2911-
return it != lanes.end();
2912-
};
2913-
29142920
while (backward_length_sum < backward_length) {
29152921
auto extended_lanes = extendPrevLane(planner_data->route_handler, lanes);
2916-
2917-
if (extended_lanes.empty() || is_loop(extended_lanes.front())) {
2922+
if (extended_lanes.empty()) {
2923+
return lanes;
2924+
}
2925+
// loop check
2926+
// if current map lanes is looping and has a very large value for backward_length,
2927+
// the extending process will not finish.
2928+
if (extended_lanes.front().id() == start_lane.id()) {
29182929
return lanes;
29192930
}
29202931

@@ -2927,9 +2938,25 @@ lanelet::ConstLanelets getExtendedCurrentLanes(
29272938
}
29282939

29292940
while (forward_length_sum < forward_length) {
2930-
auto extended_lanes = extendNextLane(planner_data->route_handler, lanes);
2941+
// stop extending if the goal lane is included
2942+
// if forward_length is a very large value, set it to true,
2943+
// as it may continue to extend lanes outside the route ahead of goal forever.
2944+
if (until_goal_lane) {
2945+
lanelet::ConstLanelet goal_lane;
2946+
planner_data->route_handler->getGoalLanelet(&goal_lane);
2947+
if (lanes.back().id() == goal_lane.id()) {
2948+
return lanes;
2949+
}
2950+
}
29312951

2932-
if (extended_lanes.empty() || is_loop(extended_lanes.back())) {
2952+
auto extended_lanes = extendNextLane(planner_data->route_handler, lanes);
2953+
if (extended_lanes.empty()) {
2954+
return lanes;
2955+
}
2956+
// loop check
2957+
// if current map lanes is looping and has a very large value for forward_length,
2958+
// the extending process will not finish.
2959+
if (extended_lanes.back().id() == start_lane.id()) {
29332960
return lanes;
29342961
}
29352962

0 commit comments

Comments
 (0)