1
- // Copyright 2019 Autoware Foundation
1
+ // Copyright 2019-2024 Autoware Foundation
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
@@ -98,7 +98,7 @@ bool is_in_parking_lot(
98
98
}
99
99
100
100
double project_goal_to_map (
101
- const lanelet::Lanelet & lanelet_component, const lanelet::ConstPoint3d & goal_point)
101
+ const lanelet::ConstLanelet & lanelet_component, const lanelet::ConstPoint3d & goal_point)
102
102
{
103
103
const lanelet::ConstLineString3d center_line =
104
104
lanelet::utils::generateFineCenterline (lanelet_component);
@@ -182,12 +182,6 @@ bool DefaultPlanner::ready() const
182
182
void DefaultPlanner::map_callback (const HADMapBin::ConstSharedPtr msg)
183
183
{
184
184
route_handler_.setMap (*msg);
185
- lanelet_map_ptr_ = std::make_shared<lanelet::LaneletMap>();
186
- lanelet::utils::conversion::fromBinMsg (
187
- *msg, lanelet_map_ptr_, &traffic_rules_ptr_, &routing_graph_ptr_);
188
- lanelet::ConstLanelets all_lanelets = lanelet::utils::query::laneletLayer (lanelet_map_ptr_);
189
- road_lanelets_ = lanelet::utils::query::roadLanelets (all_lanelets);
190
- shoulder_lanelets_ = lanelet::utils::query::shoulderLanelets (all_lanelets);
191
185
is_graph_ready_ = true ;
192
186
}
193
187
@@ -199,7 +193,7 @@ PlannerPlugin::MarkerArray DefaultPlanner::visualize(const LaneletRoute & route)
199
193
200
194
for (const auto & route_section : route.segments ) {
201
195
for (const auto & lane_id : route_section.primitives ) {
202
- auto lanelet = lanelet_map_ptr_-> laneletLayer . get (lane_id.id );
196
+ auto lanelet = route_handler_. getLaneletsFromId (lane_id.id );
203
197
route_lanelets.push_back (lanelet);
204
198
if (route_section.preferred_primitive .id == lane_id.id ) {
205
199
goal_lanelets.push_back (lanelet);
@@ -274,15 +268,15 @@ bool DefaultPlanner::check_goal_footprint_inside_lanes(
274
268
if (boost::geometry::within (goal_footprint, combined_prev_lanelet.polygon2d ().basicPolygon ())) {
275
269
return true ;
276
270
}
277
-
271
+ const auto following = route_handler_. getNextLanelets (current_lanelet);
278
272
// check if goal footprint is in between many lanelets in depth-first search manner
279
- for (const auto & next_lane : routing_graph_ptr_-> following (current_lanelet) ) {
273
+ for (const auto & next_lane : following) {
280
274
next_lane_length += lanelet::utils::getLaneletLength2d (next_lane);
281
275
lanelet::ConstLanelets lanelets;
282
276
lanelets.push_back (combined_prev_lanelet);
283
277
lanelets.push_back (next_lane);
284
278
lanelet::ConstLanelet combined_lanelets =
285
- combine_lanelets_with_shoulder (lanelets, shoulder_lanelets_ );
279
+ combine_lanelets_with_shoulder (lanelets, route_handler_ );
286
280
287
281
// if next lanelet length is longer than vehicle longitudinal offset
288
282
if (vehicle_info_.max_longitudinal_offset_m + search_margin < next_lane_length) {
@@ -317,23 +311,38 @@ bool DefaultPlanner::is_goal_valid(
317
311
318
312
// check if goal is in shoulder lanelet
319
313
lanelet::Lanelet closest_shoulder_lanelet;
314
+ const auto shoulder_lanelets = route_handler_.getShoulderLaneletsAtPose (goal);
320
315
if (lanelet::utils::query::getClosestLanelet (
321
- shoulder_lanelets_, goal, &closest_shoulder_lanelet)) {
322
- if (is_in_lane (closest_shoulder_lanelet, goal_lanelet_pt)) {
323
- const auto lane_yaw =
324
- lanelet::utils::getLaneletAngle (closest_shoulder_lanelet, goal.position );
325
- const auto goal_yaw = tf2::getYaw (goal.orientation );
326
- const auto angle_diff = tier4_autoware_utils::normalizeRadian (lane_yaw - goal_yaw);
327
- const double th_angle = tier4_autoware_utils::deg2rad (param_.goal_angle_threshold_deg );
328
- if (std::abs (angle_diff) < th_angle) {
329
- return true ;
330
- }
316
+ shoulder_lanelets, goal, &closest_shoulder_lanelet)) {
317
+ const auto lane_yaw = lanelet::utils::getLaneletAngle (closest_shoulder_lanelet, goal.position );
318
+ const auto goal_yaw = tf2::getYaw (goal.orientation );
319
+ const auto angle_diff = tier4_autoware_utils::normalizeRadian (lane_yaw - goal_yaw);
320
+ const double th_angle = tier4_autoware_utils::deg2rad (param_.goal_angle_threshold_deg );
321
+ if (std::abs (angle_diff) < th_angle) {
322
+ return true ;
331
323
}
332
324
}
333
-
334
- lanelet::Lanelet closest_lanelet;
335
- if (!lanelet::utils::query::getClosestLanelet (road_lanelets_, goal, &closest_lanelet)) {
336
- return false ;
325
+ lanelet::ConstLanelet closest_lanelet;
326
+ const auto road_lanelets_at_goal = route_handler_.getRoadLaneletsAtPose (goal);
327
+ if (!lanelet::utils::query::getClosestLanelet (road_lanelets_at_goal, goal, &closest_lanelet)) {
328
+ // if no road lanelets directly at the goal, find the closest one
329
+ const lanelet::BasicPoint2d goal_point{goal.position .x , goal.position .y };
330
+ auto closest_dist = std::numeric_limits<double >::max ();
331
+ const auto closest_road_lanelet_found =
332
+ route_handler_.getLaneletMapPtr ()->laneletLayer .nearestUntil (
333
+ goal_point, [&](const auto & bbox, const auto & ll) {
334
+ // this search is done by increasing distance between the bounding box and the goal
335
+ // we stop the search when the bounding box is further than the closest dist found
336
+ if (lanelet::geometry::distance2d (bbox, goal_point) > closest_dist)
337
+ return true ; // stop the search
338
+ const auto dist = lanelet::geometry::distance2d (goal_point, ll.polygon2d ());
339
+ if (route_handler_.isRoadLanelet (ll) && dist < closest_dist) {
340
+ closest_dist = dist;
341
+ closest_lanelet = ll;
342
+ }
343
+ return false ; // continue the search
344
+ });
345
+ if (!closest_road_lanelet_found) return false ;
337
346
}
338
347
339
348
const auto local_vehicle_footprint = vehicle_info_.createFootprint ();
@@ -345,15 +354,15 @@ bool DefaultPlanner::is_goal_valid(
345
354
double next_lane_length = 0.0 ;
346
355
// combine calculated route lanelets
347
356
const lanelet::ConstLanelet combined_prev_lanelet =
348
- combine_lanelets_with_shoulder (path_lanelets, shoulder_lanelets_ );
357
+ combine_lanelets_with_shoulder (path_lanelets, route_handler_ );
349
358
350
359
// check if goal footprint exceeds lane when the goal isn't in parking_lot
351
360
if (
352
361
param_.check_footprint_inside_lanes &&
353
362
!check_goal_footprint_inside_lanes (
354
363
closest_lanelet, combined_prev_lanelet, polygon_footprint, next_lane_length) &&
355
364
!is_in_parking_lot (
356
- lanelet::utils::query::getAllParkingLots (lanelet_map_ptr_ ),
365
+ lanelet::utils::query::getAllParkingLots (route_handler_. getLaneletMapPtr () ),
357
366
lanelet::utils::conversion::toLaneletPoint (goal.position ))) {
358
367
RCLCPP_WARN (logger, " Goal's footprint exceeds lane!" );
359
368
return false ;
@@ -371,13 +380,15 @@ bool DefaultPlanner::is_goal_valid(
371
380
}
372
381
373
382
// check if goal is in parking space
374
- const auto parking_spaces = lanelet::utils::query::getAllParkingSpaces (lanelet_map_ptr_);
383
+ const auto parking_spaces =
384
+ lanelet::utils::query::getAllParkingSpaces (route_handler_.getLaneletMapPtr ());
375
385
if (is_in_parking_space (parking_spaces, goal_lanelet_pt)) {
376
386
return true ;
377
387
}
378
388
379
389
// check if goal is in parking lot
380
- const auto parking_lots = lanelet::utils::query::getAllParkingLots (lanelet_map_ptr_);
390
+ const auto parking_lots =
391
+ lanelet::utils::query::getAllParkingLots (route_handler_.getLaneletMapPtr ());
381
392
if (is_in_parking_lot (parking_lots, goal_lanelet_pt)) {
382
393
return true ;
383
394
}
@@ -424,7 +435,8 @@ PlannerPlugin::LaneletRoute DefaultPlanner::plan(const RoutePoints & points)
424
435
auto goal_pose = points.back ();
425
436
if (param_.enable_correct_goal_pose ) {
426
437
goal_pose = get_closest_centerline_pose (
427
- lanelet::utils::query::laneletLayer (lanelet_map_ptr_), goal_pose, vehicle_info_);
438
+ lanelet::utils::query::laneletLayer (route_handler_.getLaneletMapPtr ()), goal_pose,
439
+ vehicle_info_);
428
440
}
429
441
430
442
if (!is_goal_valid (goal_pose, all_route_lanelets)) {
@@ -451,7 +463,7 @@ geometry_msgs::msg::Pose DefaultPlanner::refine_goal_height(
451
463
const Pose & goal, const RouteSections & route_sections)
452
464
{
453
465
const auto goal_lane_id = route_sections.back ().preferred_primitive .id ;
454
- lanelet::Lanelet goal_lanelet = lanelet_map_ptr_-> laneletLayer . get (goal_lane_id);
466
+ const auto goal_lanelet = route_handler_. getLaneletsFromId (goal_lane_id);
455
467
const auto goal_lanelet_pt = lanelet::utils::conversion::toLaneletPoint (goal.position );
456
468
const auto goal_height = project_goal_to_map (goal_lanelet, goal_lanelet_pt);
457
469
0 commit comments