Skip to content

Commit a9e530d

Browse files
maxime-clemkarishma1911
authored andcommitted
perf(mission_planner): remove queries on all road and shoulder lanelets (autowarefoundation#7079)
Signed-off-by: Maxime CLEMENT <maxime.clement@tier4.jp>
1 parent 38b929a commit a9e530d

File tree

4 files changed

+62
-67
lines changed

4 files changed

+62
-67
lines changed

planning/mission_planner/src/lanelet2_plugins/default_planner.cpp

+44-32
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 Autoware Foundation
1+
// Copyright 2019-2024 Autoware Foundation
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -98,7 +98,7 @@ bool is_in_parking_lot(
9898
}
9999

100100
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)
102102
{
103103
const lanelet::ConstLineString3d center_line =
104104
lanelet::utils::generateFineCenterline(lanelet_component);
@@ -182,12 +182,6 @@ bool DefaultPlanner::ready() const
182182
void DefaultPlanner::map_callback(const HADMapBin::ConstSharedPtr msg)
183183
{
184184
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);
191185
is_graph_ready_ = true;
192186
}
193187

@@ -199,7 +193,7 @@ PlannerPlugin::MarkerArray DefaultPlanner::visualize(const LaneletRoute & route)
199193

200194
for (const auto & route_section : route.segments) {
201195
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);
203197
route_lanelets.push_back(lanelet);
204198
if (route_section.preferred_primitive.id == lane_id.id) {
205199
goal_lanelets.push_back(lanelet);
@@ -274,15 +268,15 @@ bool DefaultPlanner::check_goal_footprint_inside_lanes(
274268
if (boost::geometry::within(goal_footprint, combined_prev_lanelet.polygon2d().basicPolygon())) {
275269
return true;
276270
}
277-
271+
const auto following = route_handler_.getNextLanelets(current_lanelet);
278272
// 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) {
280274
next_lane_length += lanelet::utils::getLaneletLength2d(next_lane);
281275
lanelet::ConstLanelets lanelets;
282276
lanelets.push_back(combined_prev_lanelet);
283277
lanelets.push_back(next_lane);
284278
lanelet::ConstLanelet combined_lanelets =
285-
combine_lanelets_with_shoulder(lanelets, shoulder_lanelets_);
279+
combine_lanelets_with_shoulder(lanelets, route_handler_);
286280

287281
// if next lanelet length is longer than vehicle longitudinal offset
288282
if (vehicle_info_.max_longitudinal_offset_m + search_margin < next_lane_length) {
@@ -317,23 +311,38 @@ bool DefaultPlanner::is_goal_valid(
317311

318312
// check if goal is in shoulder lanelet
319313
lanelet::Lanelet closest_shoulder_lanelet;
314+
const auto shoulder_lanelets = route_handler_.getShoulderLaneletsAtPose(goal);
320315
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;
331323
}
332324
}
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;
337346
}
338347

339348
const auto local_vehicle_footprint = vehicle_info_.createFootprint();
@@ -345,15 +354,15 @@ bool DefaultPlanner::is_goal_valid(
345354
double next_lane_length = 0.0;
346355
// combine calculated route lanelets
347356
const lanelet::ConstLanelet combined_prev_lanelet =
348-
combine_lanelets_with_shoulder(path_lanelets, shoulder_lanelets_);
357+
combine_lanelets_with_shoulder(path_lanelets, route_handler_);
349358

350359
// check if goal footprint exceeds lane when the goal isn't in parking_lot
351360
if (
352361
param_.check_footprint_inside_lanes &&
353362
!check_goal_footprint_inside_lanes(
354363
closest_lanelet, combined_prev_lanelet, polygon_footprint, next_lane_length) &&
355364
!is_in_parking_lot(
356-
lanelet::utils::query::getAllParkingLots(lanelet_map_ptr_),
365+
lanelet::utils::query::getAllParkingLots(route_handler_.getLaneletMapPtr()),
357366
lanelet::utils::conversion::toLaneletPoint(goal.position))) {
358367
RCLCPP_WARN(logger, "Goal's footprint exceeds lane!");
359368
return false;
@@ -371,13 +380,15 @@ bool DefaultPlanner::is_goal_valid(
371380
}
372381

373382
// 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());
375385
if (is_in_parking_space(parking_spaces, goal_lanelet_pt)) {
376386
return true;
377387
}
378388

379389
// 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());
381392
if (is_in_parking_lot(parking_lots, goal_lanelet_pt)) {
382393
return true;
383394
}
@@ -424,7 +435,8 @@ PlannerPlugin::LaneletRoute DefaultPlanner::plan(const RoutePoints & points)
424435
auto goal_pose = points.back();
425436
if (param_.enable_correct_goal_pose) {
426437
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_);
428440
}
429441

430442
if (!is_goal_valid(goal_pose, all_route_lanelets)) {
@@ -451,7 +463,7 @@ geometry_msgs::msg::Pose DefaultPlanner::refine_goal_height(
451463
const Pose & goal, const RouteSections & route_sections)
452464
{
453465
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);
455467
const auto goal_lanelet_pt = lanelet::utils::conversion::toLaneletPoint(goal.position);
456468
const auto goal_height = project_goal_to_map(goal_lanelet, goal_lanelet_pt);
457469

planning/mission_planner/src/lanelet2_plugins/default_planner.hpp

-5
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ class DefaultPlanner : public mission_planner::PlannerPlugin
5858
using RouteSections = std::vector<autoware_planning_msgs::msg::LaneletSegment>;
5959
using Pose = geometry_msgs::msg::Pose;
6060
bool is_graph_ready_;
61-
lanelet::LaneletMapPtr lanelet_map_ptr_;
62-
lanelet::routing::RoutingGraphPtr routing_graph_ptr_;
63-
lanelet::traffic_rules::TrafficRulesPtr traffic_rules_ptr_;
64-
lanelet::ConstLanelets road_lanelets_;
65-
lanelet::ConstLanelets shoulder_lanelets_;
6661
route_handler::RouteHandler route_handler_;
6762

6863
DefaultPlannerParameters param_;

planning/mission_planner/src/lanelet2_plugins/utility_functions.cpp

+14-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 Autoware Foundation
1+
// Copyright 2019-2024 Autoware Foundation
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ void insert_marker_array(
4242
}
4343

4444
lanelet::ConstLanelet combine_lanelets_with_shoulder(
45-
const lanelet::ConstLanelets & lanelets, const lanelet::ConstLanelets & shoulder_lanelets)
45+
const lanelet::ConstLanelets & lanelets, const route_handler::RouteHandler & route_handler)
4646
{
4747
lanelet::Points3d lefts;
4848
lanelet::Points3d rights;
@@ -57,30 +57,18 @@ lanelet::ConstLanelet combine_lanelets_with_shoulder(
5757
}
5858
}
5959

60+
// lambda to add bound to target_bound
61+
const auto add_bound = [](const auto & bound, auto & target_bound) {
62+
std::transform(
63+
bound.begin(), bound.end(), std::back_inserter(target_bound),
64+
[](const auto & pt) { return lanelet::Point3d(pt); });
65+
};
6066
for (const auto & llt : lanelets) {
61-
// lambda to check if shoulder lane which share left bound with lanelets exist
62-
const auto find_bound_shared_shoulder =
63-
[&shoulder_lanelets](const auto & lanelet_bound, const auto & get_shoulder_bound) {
64-
return std::find_if(
65-
shoulder_lanelets.begin(), shoulder_lanelets.end(),
66-
[&lanelet_bound, &get_shoulder_bound](const auto & shoulder_llt) {
67-
return lanelet_bound.id() == get_shoulder_bound(shoulder_llt).id();
68-
});
69-
};
70-
71-
// lambda to add bound to target_bound
72-
const auto add_bound = [](const auto & bound, auto & target_bound) {
73-
std::transform(
74-
bound.begin(), bound.end(), std::back_inserter(target_bound),
75-
[](const auto & pt) { return lanelet::Point3d(pt); });
76-
};
77-
7867
// check if shoulder lanelets which has RIGHT bound same to LEFT bound of lanelet exist
79-
const auto left_shared_shoulder_it = find_bound_shared_shoulder(
80-
llt.leftBound(), [](const auto & shoulder_llt) { return shoulder_llt.rightBound(); });
81-
if (left_shared_shoulder_it != shoulder_lanelets.end()) {
68+
const auto left_shared_shoulder = route_handler.getLeftShoulderLanelet(llt);
69+
if (left_shared_shoulder) {
8270
// if exist, add left bound of SHOULDER lanelet to lefts
83-
add_bound(left_shared_shoulder_it->leftBound(), lefts);
71+
add_bound(left_shared_shoulder->leftBound(), lefts);
8472
} else if (
8573
// if not exist, add left bound of lanelet to lefts
8674
// if the **left** of this lanelet does not match any of the **right** bounds of `lanelets`,
@@ -90,11 +78,10 @@ lanelet::ConstLanelet combine_lanelets_with_shoulder(
9078
}
9179

9280
// check if shoulder lanelets which has LEFT bound same to RIGHT bound of lanelet exist
93-
const auto right_shared_shoulder_it = find_bound_shared_shoulder(
94-
llt.rightBound(), [](const auto & shoulder_llt) { return shoulder_llt.leftBound(); });
95-
if (right_shared_shoulder_it != shoulder_lanelets.end()) {
81+
const auto right_shared_shoulder = route_handler.getRightShoulderLanelet(llt);
82+
if (right_shared_shoulder) {
9683
// if exist, add right bound of SHOULDER lanelet to rights
97-
add_bound(right_shared_shoulder_it->rightBound(), rights);
84+
add_bound(right_shared_shoulder->rightBound(), rights);
9885
} else if (
9986
// if not exist, add right bound of lanelet to rights
10087
// if the **right** of this lanelet does not match any of the **left** bounds of `lanelets`,

planning/mission_planner/src/lanelet2_plugins/utility_functions.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 Autoware Foundation
1+
// Copyright 2019-2024 Autoware Foundation
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616
#define LANELET2_PLUGINS__UTILITY_FUNCTIONS_HPP_
1717

1818
#include <rclcpp/rclcpp.hpp>
19+
#include <route_handler/route_handler.hpp>
1920
#include <tier4_autoware_utils/geometry/geometry.hpp>
2021
#include <vehicle_info_util/vehicle_info_util.hpp>
2122

@@ -50,10 +51,10 @@ void insert_marker_array(
5051
* @brief create a single merged lanelet whose left/right bounds consist of the leftmost/rightmost
5152
* bound of the original lanelets or the left/right bound of its adjacent road_shoulder respectively
5253
* @param lanelets topologically sorted sequence of lanelets
53-
* @param shoulder_lanelets list of possible road_shoulder lanelets to combine with lanelets
54+
* @param route_handler route handler to query the lanelet map
5455
*/
5556
lanelet::ConstLanelet combine_lanelets_with_shoulder(
56-
const lanelet::ConstLanelets & lanelets, const lanelet::ConstLanelets & shoulder_lanelets);
57+
const lanelet::ConstLanelets & lanelets, const route_handler::RouteHandler & route_handler);
5758

5859
std::vector<geometry_msgs::msg::Point> convertCenterlineToPoints(const lanelet::Lanelet & lanelet);
5960
geometry_msgs::msg::Pose convertBasicPoint3dToPose(

0 commit comments

Comments
 (0)