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(map_based_prediction): filter by distance for opposite lanes as well #5195

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 @@ -176,8 +176,7 @@ class MapBasedPredictionNode : public rclcpp::Node

LaneletsData getCurrentLanelets(const TrackedObject & object);
bool checkCloseLaneletCondition(
const std::pair<double, lanelet::Lanelet> & lanelet, const TrackedObject & object,
const bool check_distance = true);
const std::pair<double, lanelet::Lanelet> & lanelet, const TrackedObject & object);
float calculateLocalLikelihood(
const lanelet::Lanelet & current_lanelet, const TrackedObject & object) const;
void updateObjectData(TrackedObject & object);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Tier IV, Inc.

Check notice on line 1 in perception/map_based_prediction/src/map_based_prediction_node.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 1478 to 1477, 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 perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 6.46 to 6.43, 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 @@ -1251,7 +1251,7 @@
for (const auto & lanelet : surrounding_opposite_lanelets) {
// Check if the close lanelets meet the necessary condition for start lanelets
// except for distance checking
if (!checkCloseLaneletCondition(lanelet, object, false)) {
if (!checkCloseLaneletCondition(lanelet, object)) {

Check warning on line 1254 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/src/map_based_prediction_node.cpp#L1254

Added line #L1254 was not covered by tests
continue;
}

Expand All @@ -1271,43 +1271,42 @@
}

bool MapBasedPredictionNode::checkCloseLaneletCondition(
const std::pair<double, lanelet::Lanelet> & lanelet, const TrackedObject & object,
const bool check_distance)
const std::pair<double, lanelet::Lanelet> & lanelet, const TrackedObject & object)
{
// Step1. If we only have one point in the centerline, we will ignore the lanelet
if (lanelet.second.centerline().size() <= 1) {
return false;
}

// If the object is in the objects history, we check if the target lanelet is
// inside the current lanelets id or following lanelets
const std::string object_id = tier4_autoware_utils::toHexString(object.object_id);
if (objects_history_.count(object_id) != 0) {
const std::vector<lanelet::ConstLanelet> & possible_lanelet =
objects_history_.at(object_id).back().future_possible_lanelets;

bool not_in_possible_lanelet =
std::find(possible_lanelet.begin(), possible_lanelet.end(), lanelet.second) ==
possible_lanelet.end();
if (!possible_lanelet.empty() && not_in_possible_lanelet) {
return false;
}
}

// Step2. Calculate the angle difference between the lane angle and obstacle angle
const double object_yaw = tf2::getYaw(object.kinematics.pose_with_covariance.pose.orientation);
const double lane_yaw = lanelet::utils::getLaneletAngle(
lanelet.second, object.kinematics.pose_with_covariance.pose.position);
const double delta_yaw = object_yaw - lane_yaw;
const double normalized_delta_yaw = tier4_autoware_utils::normalizeRadian(delta_yaw);
const double abs_norm_delta = std::fabs(normalized_delta_yaw);

// Step3. Check if the closest lanelet is valid, and add all
// of the lanelets that are below max_dist and max_delta_yaw
const double object_vel = object.kinematics.twist_with_covariance.twist.linear.x;
const bool is_yaw_reversed =
M_PI - delta_yaw_threshold_for_searching_lanelet_ < abs_norm_delta && object_vel < 0.0;
if (check_distance && dist_threshold_for_searching_lanelet_ < lanelet.first) {
if (dist_threshold_for_searching_lanelet_ < lanelet.first) {

Check notice on line 1309 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Complex Method

MapBasedPredictionNode::checkCloseLaneletCondition decreases in cyclomatic complexity from 10 to 9, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 1309 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/src/map_based_prediction_node.cpp#L1309

Added line #L1309 was not covered by tests
return false;
}
if (!is_yaw_reversed && delta_yaw_threshold_for_searching_lanelet_ < abs_norm_delta) {
Expand Down
Loading