@@ -368,7 +368,8 @@ std::vector<PathWithLaneId> GeometricParallelParking::planOneTrial(
368
368
{
369
369
clearPaths ();
370
370
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 ;
372
373
373
374
const Pose arc_end_pose = calcOffsetPose (goal_pose, end_pose_offset, 0 , 0 );
374
375
const double self_yaw = tf2::getYaw (start_pose.orientation );
@@ -435,34 +436,49 @@ std::vector<PathWithLaneId> GeometricParallelParking::planOneTrial(
435
436
PathWithLaneId path_turn_left = generateArcPath (
436
437
Cl, R_E_l, -M_PI_2, normalizeRadian (-M_PI_2 + theta_l), arc_path_interval, is_forward,
437
438
is_forward);
438
- path_turn_left.header = planner_data_-> route_handler ->getRouteHeader ();
439
+ path_turn_left.header = route_handler->getRouteHeader ();
439
440
440
441
PathWithLaneId path_turn_right = generateArcPath (
441
442
Cr, R_E_r, normalizeRadian (psi + M_PI_2 + theta_l), M_PI_2, arc_path_interval, !is_forward,
442
443
is_forward);
443
- path_turn_right.header = planner_data_-> route_handler ->getRouteHeader ();
444
+ path_turn_right.header = route_handler->getRouteHeader ();
444
445
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
+ }
448
467
}
449
468
};
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) {
451
475
for (auto & p : path.points ) {
452
- setLaneIds (p) ;
476
+ p. lane_ids = path_lane_ids ;
453
477
}
454
478
};
455
479
setLaneIdsToPath (path_turn_left);
456
480
setLaneIdsToPath (path_turn_right);
457
481
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
-
466
482
// generate arc path vector
467
483
paths_.push_back (path_turn_left);
468
484
paths_.push_back (path_turn_right);
0 commit comments