Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lane_change): remove overlapping preceding lanes #9526

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,22 @@ bool filter_target_lane_objects(
const bool before_terminal, TargetLaneLeadingObjects & leading_objects,
ExtendedPredictedObjects & trailing_objects);

/**
* @brief Retrieves the preceding lanes for the target lanes while removing overlapping and
* disconnected lanes.
*
* This function identifies all lanes that precede the target lanes based on the ego vehicle's
* current position and a specified backward search length. The resulting preceding lanes are
* filtered to remove lanes that overlap with the current lanes or are not connected to the route.
*
* @param common_data_ptr Shared pointer to commonly used data in lane change module, which contains
* route handler information, lane details, ego vehicle pose, and behavior parameters.
*
* @return A vector of preceding lanelet groups, with each group containing only the connected and
* non-overlapping preceding lanes.
*/
std::vector<lanelet::ConstLanelets> get_preceding_lanes(const CommonDataPtr & common_data_ptr);

/**
* @brief Determines if the object's predicted path overlaps with the given lane polygon.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 TIER IV, Inc.

Check notice on line 1 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Lines of Code in a Single File

The lines of code decreases from 1611 to 1610, improve code health by reducing it to 1000. The number of Lines of Code in a single file. More Lines of Code lowers the code health.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -112,9 +112,8 @@
common_data_ptr_->lanes_ptr->target_lane_in_goal_section =
route_handler_ptr->isInGoalRouteSection(target_lanes.back());

common_data_ptr_->lanes_ptr->preceding_target = utils::getPrecedingLanelets(
*route_handler_ptr, get_target_lanes(), common_data_ptr_->get_ego_pose(),
common_data_ptr_->lc_param_ptr->backward_lane_length);
common_data_ptr_->lanes_ptr->preceding_target =
utils::lane_change::get_preceding_lanes(common_data_ptr_);

lane_change_debug_.current_lanes = common_data_ptr_->lanes_ptr->current;
lane_change_debug_.target_lanes = common_data_ptr_->lanes_ptr->target;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Tier IV, Inc.

Check warning on line 1 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/utils/utils.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Lines of Code in a Single File

This module has 1001 lines of code, improve code health by reducing it to 1000. The number of Lines of Code in a single file. More Lines of Code lowers the code health.

Check notice on line 1 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/utils/utils.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Overall Code Complexity

The mean cyclomatic complexity increases from 4.88 to 4.89, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,9 +34,12 @@
#include <autoware_lanelet2_extension/utility/query.hpp>
#include <autoware_lanelet2_extension/utility/utilities.hpp>
#include <autoware_vehicle_info_utils/vehicle_info.hpp>
#include <range/v3/action/insert.hpp>
#include <range/v3/algorithm/any_of.hpp>
#include <range/v3/algorithm/find_if.hpp>
#include <range/v3/algorithm/for_each.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/transform.hpp>
#include <range/v3/view.hpp>
#include <rclcpp/rclcpp.hpp>

#include <geometry_msgs/msg/detail/pose__struct.hpp>
Expand All @@ -56,6 +59,7 @@
#include <memory>
#include <optional>
#include <string>
#include <unordered_set>
#include <vector>

namespace autoware::behavior_path_planner::utils::lane_change
Expand Down Expand Up @@ -1246,6 +1250,43 @@
return false;
}

std::vector<lanelet::ConstLanelets> get_preceding_lanes(const CommonDataPtr & common_data_ptr)
{
const auto & route_handler_ptr = common_data_ptr->route_handler_ptr;
const auto & target_lanes = common_data_ptr->lanes_ptr->target;
const auto & ego_pose = common_data_ptr->get_ego_pose();
const auto backward_lane_length = common_data_ptr->lc_param_ptr->backward_lane_length;

const auto preceding_lanes_list =
utils::getPrecedingLanelets(*route_handler_ptr, target_lanes, ego_pose, backward_lane_length);

const auto & current_lanes = common_data_ptr->lanes_ptr->current;
std::unordered_set<lanelet::Id> current_lanes_id;
for (const auto & lane : current_lanes) {
current_lanes_id.insert(lane.id());
}
const auto is_overlapping = [&](const lanelet::ConstLanelet & lane) {
return current_lanes_id.find(lane.id()) != current_lanes_id.end();
};

std::vector<lanelet::ConstLanelets> non_overlapping_lanes_vec;
for (const auto & lanes : preceding_lanes_list) {
auto lanes_reversed = lanes | ranges::views::reverse;
auto overlapped_itr = ranges::find_if(lanes_reversed, is_overlapping);

if (overlapped_itr == lanes_reversed.begin()) {
continue;

Check warning on line 1278 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/utils/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/utils/utils.cpp#L1278

Added line #L1278 was not covered by tests
}

// Lanes are not reversed by default. Avoid returning reversed lanes to prevent undefined
// behavior.
lanelet::ConstLanelets non_overlapping_lanes(overlapped_itr.base(), lanes.end());
non_overlapping_lanes_vec.push_back(non_overlapping_lanes);
}

return non_overlapping_lanes_vec;
}

bool object_path_overlaps_lanes(
const ExtendedPredictedObject & object, const lanelet::BasicPolygon2d & lanes_polygon)
{
Expand Down
Loading