Skip to content

Commit 7f02d6a

Browse files
authored
fix(start_planner): fix geometric parallel parking lane ids (#4603)
* fix(start_planner): fix geometric parallel parking lane ids Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> * fix stop path drivable lanes Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> --------- Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
1 parent c2b7b7d commit 7f02d6a

File tree

3 files changed

+64
-24
lines changed

3 files changed

+64
-24
lines changed

planning/behavior_path_planner/include/behavior_path_planner/scene_module/start_planner/start_planner_module.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class StartPlannerModule : public SceneModuleInterface
143143
const std::vector<Pose> & start_pose_candidates, const Pose & goal_pose,
144144
const std::string search_priority);
145145
PathWithLaneId generateStopPath() const;
146-
lanelet::ConstLanelets getPathLanes(const PathWithLaneId & path) const;
146+
lanelet::ConstLanelets getPathRoadLanes(const PathWithLaneId & path) const;
147147
std::vector<DrivableLanes> generateDrivableLanes(const PathWithLaneId & path) const;
148148
void updatePullOutStatus();
149149
static bool isOverlappedWithLane(

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

+31-7
Original file line numberDiff line numberDiff line change
@@ -534,19 +534,23 @@ PathWithLaneId StartPlannerModule::generateStopPath() const
534534
return path;
535535
}
536536

537-
lanelet::ConstLanelets StartPlannerModule::getPathLanes(const PathWithLaneId & path) const
537+
lanelet::ConstLanelets StartPlannerModule::getPathRoadLanes(const PathWithLaneId & path) const
538538
{
539+
const auto & route_handler = planner_data_->route_handler;
540+
const auto & lanelet_layer = route_handler->getLaneletMapPtr()->laneletLayer;
541+
539542
std::vector<lanelet::Id> lane_ids;
540543
for (const auto & p : path.points) {
541544
for (const auto & id : p.lane_ids) {
545+
if (route_handler->isShoulderLanelet(lanelet_layer.get(id))) {
546+
continue;
547+
}
542548
if (std::find(lane_ids.begin(), lane_ids.end(), id) == lane_ids.end()) {
543549
lane_ids.push_back(id);
544550
}
545551
}
546552
}
547553

548-
const auto & lanelet_layer = planner_data_->route_handler->getLaneletMapPtr()->laneletLayer;
549-
550554
lanelet::ConstLanelets path_lanes;
551555
path_lanes.reserve(lane_ids.size());
552556
for (const auto & id : lane_ids) {
@@ -561,7 +565,22 @@ lanelet::ConstLanelets StartPlannerModule::getPathLanes(const PathWithLaneId & p
561565
std::vector<DrivableLanes> StartPlannerModule::generateDrivableLanes(
562566
const PathWithLaneId & path) const
563567
{
564-
return utils::generateDrivableLanesWithShoulderLanes(getPathLanes(path), status_.pull_out_lanes);
568+
const auto path_road_lanes = getPathRoadLanes(path);
569+
570+
if (!path_road_lanes.empty()) {
571+
return utils::generateDrivableLanesWithShoulderLanes(
572+
getPathRoadLanes(path), status_.pull_out_lanes);
573+
}
574+
575+
// if path_road_lanes is empty, use only pull_out_lanes as drivable lanes
576+
std::vector<DrivableLanes> drivable_lanes;
577+
for (const auto & lane : status_.pull_out_lanes) {
578+
DrivableLanes drivable_lane;
579+
drivable_lane.right_lane = lane;
580+
drivable_lane.left_lane = lane;
581+
drivable_lanes.push_back(drivable_lane);
582+
}
583+
return drivable_lanes;
565584
}
566585

567586
void StartPlannerModule::updatePullOutStatus()
@@ -702,10 +721,15 @@ bool StartPlannerModule::hasFinishedPullOut() const
702721
const auto current_pose = planner_data_->self_odometry->pose.pose;
703722

704723
// check that ego has passed pull out end point
705-
const auto path_lanes = getPathLanes(getFullPath());
706-
const auto arclength_current = lanelet::utils::getArcCoordinates(path_lanes, current_pose);
724+
const double backward_path_length =
725+
planner_data_->parameters.backward_path_length + parameters_->max_back_distance;
726+
const auto current_lanes = utils::getExtendedCurrentLanes(
727+
planner_data_, backward_path_length, std::numeric_limits<double>::max(),
728+
/*forward_only_in_route*/ true);
729+
730+
const auto arclength_current = lanelet::utils::getArcCoordinates(current_lanes, current_pose);
707731
const auto arclength_pull_out_end =
708-
lanelet::utils::getArcCoordinates(path_lanes, status_.pull_out_path.end_pose);
732+
lanelet::utils::getArcCoordinates(current_lanes, status_.pull_out_path.end_pose);
709733

710734
// offset to not finish the module before engage
711735
constexpr double offset = 0.1;

planning/behavior_path_planner/src/utils/geometric_parallel_parking/geometric_parallel_parking.cpp

+32-16
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ std::vector<PathWithLaneId> GeometricParallelParking::planOneTrial(
368368
{
369369
clearPaths();
370370

371-
const auto common_params = planner_data_->parameters;
371+
const auto & common_params = planner_data_->parameters;
372+
const auto & route_handler = planner_data_->route_handler;
372373

373374
const Pose arc_end_pose = calcOffsetPose(goal_pose, end_pose_offset, 0, 0);
374375
const double self_yaw = tf2::getYaw(start_pose.orientation);
@@ -435,34 +436,49 @@ std::vector<PathWithLaneId> GeometricParallelParking::planOneTrial(
435436
PathWithLaneId path_turn_left = generateArcPath(
436437
Cl, R_E_l, -M_PI_2, normalizeRadian(-M_PI_2 + theta_l), arc_path_interval, is_forward,
437438
is_forward);
438-
path_turn_left.header = planner_data_->route_handler->getRouteHeader();
439+
path_turn_left.header = route_handler->getRouteHeader();
439440

440441
PathWithLaneId path_turn_right = generateArcPath(
441442
Cr, R_E_r, normalizeRadian(psi + M_PI_2 + theta_l), M_PI_2, arc_path_interval, !is_forward,
442443
is_forward);
443-
path_turn_right.header = planner_data_->route_handler->getRouteHeader();
444+
path_turn_right.header = route_handler->getRouteHeader();
444445

445-
auto setLaneIds = [lanes](PathPointWithLaneId & p) {
446-
for (const auto & lane : lanes) {
447-
p.lane_ids.push_back(lane.id());
446+
// Need to add straight path to last right_turning for parking in parallel
447+
if (std::abs(end_pose_offset) > 0) {
448+
PathPointWithLaneId straight_point{};
449+
straight_point.point.pose = goal_pose;
450+
// setLaneIds(straight_point);
451+
path_turn_right.points.push_back(straight_point);
452+
}
453+
454+
// Populate lane ids for a given path.
455+
// It checks if each point in the path is within a lane
456+
// and if its ID hasn't been added yet, it appends the ID to the container.
457+
std::vector<lanelet::Id> path_lane_ids;
458+
const auto populateLaneIds = [&](const auto & path) {
459+
for (const auto & p : path.points) {
460+
for (const auto & lane : lanes) {
461+
if (
462+
lanelet::utils::isInLanelet(p.point.pose, lane) &&
463+
std::find(path_lane_ids.begin(), path_lane_ids.end(), lane.id()) == path_lane_ids.end()) {
464+
path_lane_ids.push_back(lane.id());
465+
}
466+
}
448467
}
449468
};
450-
auto setLaneIdsToPath = [setLaneIds](PathWithLaneId & path) {
469+
populateLaneIds(path_turn_left);
470+
populateLaneIds(path_turn_right);
471+
472+
// Set lane ids to each point in a given path.
473+
// It assigns the accumulated lane ids from path_lane_ids to each point's lane_ids member.
474+
const auto setLaneIdsToPath = [&](PathWithLaneId & path) {
451475
for (auto & p : path.points) {
452-
setLaneIds(p);
476+
p.lane_ids = path_lane_ids;
453477
}
454478
};
455479
setLaneIdsToPath(path_turn_left);
456480
setLaneIdsToPath(path_turn_right);
457481

458-
// Need to add straight path to last right_turning for parking in parallel
459-
if (std::abs(end_pose_offset) > 0) {
460-
PathPointWithLaneId straight_point{};
461-
straight_point.point.pose = goal_pose;
462-
setLaneIds(straight_point);
463-
path_turn_right.points.push_back(straight_point);
464-
}
465-
466482
// generate arc path vector
467483
paths_.push_back(path_turn_left);
468484
paths_.push_back(path_turn_right);

0 commit comments

Comments
 (0)