Skip to content

Commit d04d71e

Browse files
committed
Calculate path lanelets faster and do not ignore following lanelets
Signed-off-by: Maxime CLEMENT <maxime.clement@tier4.jp>
1 parent d192149 commit d04d71e

File tree

3 files changed

+28
-34
lines changed

3 files changed

+28
-34
lines changed

planning/behavior_velocity_out_of_lane_module/src/lanelets_selection.cpp

+8-17
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,18 @@
2525
namespace behavior_velocity_planner::out_of_lane
2626
{
2727
lanelet::ConstLanelets calculate_path_lanelets(
28-
const EgoData & ego_data, const route_handler::RouteHandler & route_handler,
29-
const lanelet::BasicPolygon2d & ego_footprint)
28+
const EgoData & ego_data, const route_handler::RouteHandler & route_handler)
3029
{
3130
const auto lanelet_map_ptr = route_handler.getLaneletMapPtr();
3231
lanelet::ConstLanelets path_lanelets =
3332
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);
33+
lanelet::BasicLineString2d path_ls;
34+
for (const auto & p : ego_data.path.points)
35+
path_ls.emplace_back(p.point.pose.position.x, p.point.pose.position.y);
36+
for (const auto & dist_lanelet :
37+
lanelet::geometry::findWithin2d(lanelet_map_ptr->laneletLayer, path_ls)) {
38+
if (!contains_lanelet(path_lanelets, dist_lanelet.second.id()))
39+
path_lanelets.push_back(dist_lanelet.second);
4540
}
4641
return path_lanelets;
4742
}
@@ -51,10 +46,6 @@ lanelet::ConstLanelets calculate_ignored_lanelets(
5146
const route_handler::RouteHandler & route_handler, const PlannerParam & params)
5247
{
5348
lanelet::ConstLanelets ignored_lanelets;
54-
// ignore lanelets that follows path lanelets
55-
for (const auto & path_lanelet : path_lanelets)
56-
for (const auto & following : route_handler.getRoutingGraphPtr()->following(path_lanelet))
57-
if (!contains_lanelet(path_lanelets, following.id())) ignored_lanelets.push_back(following);
5849
// ignore lanelets directly behind ego
5950
const auto behind =
6051
planning_utils::calculateOffsetPoint2d(ego_data.pose, params.rear_offset, 0.0);

planning/behavior_velocity_out_of_lane_module/src/lanelets_selection.hpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,12 @@ inline bool contains_lanelet(const lanelet::ConstLanelets & lanelets, const lane
3535
};
3636

3737
/// @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
38+
/// @details calculated from the ids of the path msg, the lanelets containing path points
4039
/// @param [in] ego_data data about the ego vehicle
4140
/// @param [in] route_handler route handler
42-
/// @param [in] ego_footprint footprint of ego at its current pose
4341
/// @return lanelets crossed by the ego vehicle
4442
lanelet::ConstLanelets calculate_path_lanelets(
45-
const EgoData & ego_data, const route_handler::RouteHandler & route_handler,
46-
const lanelet::BasicPolygon2d & ego_footprint);
43+
const EgoData & ego_data, const route_handler::RouteHandler & route_handler);
4744
/// @brief calculate lanelets that should be ignored
4845
/// @param [in] ego_data data about the ego vehicle
4946
/// @param [in] path_lanelets lanelets driven by the ego vehicle

planning/behavior_velocity_out_of_lane_module/src/scene_out_of_lane.cpp

+18-12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ OutOfLaneModule::OutOfLaneModule(
5656
velocity_factor_.init(PlanningBehavior::UNKNOWN);
5757
}
5858

59+
size_t calculate_index_ahead(
60+
const std::vector<PathPointWithLaneId> & points, const size_t start, const double dist_ahead)
61+
{
62+
auto last_idx = start;
63+
auto length = 0.0;
64+
while (length < dist_ahead && last_idx + 1 < points.size()) {
65+
length +=
66+
tier4_autoware_utils::calcDistance2d(points[last_idx].point, points[last_idx + 1].point);
67+
++last_idx;
68+
}
69+
return last_idx;
70+
}
71+
5972
bool OutOfLaneModule::modifyPathVelocity(PathWithLaneId * path, StopReason * stop_reason)
6073
{
6174
debug_data_.reset_data();
@@ -68,15 +81,9 @@ bool OutOfLaneModule::modifyPathVelocity(PathWithLaneId * path, StopReason * sto
6881
ego_data.path.points = path->points;
6982
ego_data.first_path_idx =
7083
motion_utils::findNearestSegmentIndex(path->points, ego_data.pose.position);
71-
auto last_idx = ego_data.first_path_idx;
72-
auto length = 0.0;
73-
while (length < std::max(params_.slow_dist_threshold, params_.stop_dist_threshold) &&
74-
last_idx + 1 < path->points.size()) {
75-
length += tier4_autoware_utils::calcDistance2d(
76-
path->points[last_idx].point, path->points[last_idx + 1].point);
77-
++last_idx;
78-
}
79-
ego_data.path.points.resize(last_idx + 1);
84+
ego_data.path.points.resize(calculate_index_ahead(
85+
path->points, ego_data.first_path_idx,
86+
std::max(params_.slow_dist_threshold, params_.stop_dist_threshold)));
8087
motion_utils::removeOverlapPoints(ego_data.path.points);
8188
ego_data.velocity = planner_data_->current_velocity->twist.linear.x;
8289
ego_data.max_decel = -planner_data_->max_stop_acceleration_threshold;
@@ -86,8 +93,7 @@ bool OutOfLaneModule::modifyPathVelocity(PathWithLaneId * path, StopReason * sto
8693
const auto calculate_path_footprints_us = stopwatch.toc("calculate_path_footprints");
8794
// Calculate lanelets to ignore and consider
8895
stopwatch.tic("calculate_lanelets");
89-
const auto path_lanelets =
90-
calculate_path_lanelets(ego_data, *planner_data_->route_handler_, current_ego_footprint);
96+
const auto path_lanelets = calculate_path_lanelets(ego_data, *planner_data_->route_handler_);
9197
const auto ignored_lanelets =
9298
calculate_ignored_lanelets(ego_data, path_lanelets, *planner_data_->route_handler_, params_);
9399
const auto other_lanelets = calculate_other_lanelets(
@@ -191,7 +197,7 @@ bool OutOfLaneModule::modifyPathVelocity(PathWithLaneId * path, StopReason * sto
191197
debug_data_.ranges = inputs.ranges;
192198

193199
const auto total_time_us = stopwatch.toc();
194-
RCLCPP_DEBUG(
200+
RCLCPP_WARN(
195201
logger_,
196202
"Total time = %2.2fus\n"
197203
"\tcalculate_lanelets = %2.0fus\n"

0 commit comments

Comments
 (0)