Skip to content

Commit 8acbf18

Browse files
committed
Add a function to calculate the lanelets crossed by the ego path points
Signed-off-by: Maxime CLEMENT <maxime.clement@tier4.jp>
1 parent be5663c commit 8acbf18

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

planning/behavior_velocity_out_of_lane_module/src/lanelets_selection.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,28 @@
2424

2525
namespace behavior_velocity_planner::out_of_lane
2626
{
27+
lanelet::ConstLanelets calculate_path_lanelets(
28+
const EgoData & ego_data, const route_handler::RouteHandler & route_handler,
29+
const lanelet::BasicPolygon2d & ego_footprint)
30+
{
31+
const auto lanelet_map_ptr = route_handler.getLaneletMapPtr();
32+
lanelet::ConstLanelets path_lanelets =
33+
planning_utils::getLaneletsOnPath(ego_data.path, lanelet_map_ptr, ego_data.pose);
34+
const auto add_unique_within = [&](const auto & geometry) {
35+
const auto dist_lanelet_pairs =
36+
lanelet::geometry::findWithin2d(lanelet_map_ptr->laneletLayer, geometry);
37+
for (const auto & dist_lanelet_pair : dist_lanelet_pairs)
38+
if (!contains_lanelet(path_lanelets, dist_lanelet_pair.second.id()))
39+
path_lanelets.push_back(dist_lanelet_pair.second);
40+
};
41+
add_unique_within(ego_footprint);
42+
for (const auto & p : ego_data.path.points) {
43+
const auto pt = lanelet::BasicPoint2d(p.point.pose.position.x, p.point.pose.position.y);
44+
add_unique_within(pt);
45+
}
46+
return path_lanelets;
47+
}
48+
2749
lanelet::ConstLanelets calculate_ignored_lanelets(
2850
const EgoData & ego_data, const lanelet::ConstLanelets & path_lanelets,
2951
const route_handler::RouteHandler & route_handler, const PlannerParam & params)

planning/behavior_velocity_out_of_lane_module/src/lanelets_selection.hpp

+11
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ inline bool contains_lanelet(const lanelet::ConstLanelets & lanelets, const lane
3333
return l.id() == id;
3434
}) != lanelets.end();
3535
};
36+
37+
/// @brief calculate lanelets crossed by the ego path
38+
/// @details calculated from the ids of the path msg, the lanelets containing path points, and the
39+
/// lanelets currently overlapped by the ego footprint
40+
/// @param [in] ego_data data about the ego vehicle
41+
/// @param [in] route_handler route handler
42+
/// @param [in] ego_footprint footprint of ego at its current pose
43+
/// @return lanelets crossed by the ego vehicle
44+
lanelet::ConstLanelets calculate_path_lanelets(
45+
const EgoData & ego_data, const route_handler::RouteHandler & route_handler,
46+
const lanelet::BasicPolygon2d & ego_footprint);
3647
/// @brief calculate lanelets that should be ignored
3748
/// @param [in] ego_data data about the ego vehicle
3849
/// @param [in] path_lanelets lanelets driven by the ego vehicle

planning/behavior_velocity_out_of_lane_module/src/scene_out_of_lane.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ bool OutOfLaneModule::modifyPathVelocity(PathWithLaneId * path, StopReason * sto
7575
const auto path_footprints = calculate_path_footprints(ego_data, params_);
7676
const auto calculate_path_footprints_us = stopwatch.toc("calculate_path_footprints");
7777
// Calculate lanelets to ignore and consider
78-
const auto path_lanelets = planning_utils::getLaneletsOnPath(
79-
ego_data.path, planner_data_->route_handler_->getLaneletMapPtr(),
80-
planner_data_->current_odometry->pose);
78+
const auto path_lanelets =
79+
calculate_path_lanelets(ego_data, *planner_data_->route_handler_, current_ego_footprint);
8180
const auto ignored_lanelets =
8281
calculate_ignored_lanelets(ego_data, path_lanelets, *planner_data_->route_handler_, params_);
8382
const auto other_lanelets = calculate_other_lanelets(

0 commit comments

Comments
 (0)