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(static_obstacle_avoidance): avoid object behind unavoidance object if unavoidable is not on the path #8066

Merged
Merged
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
@@ -1,4 +1,4 @@
// Copyright 2023 TIER IV, Inc.

Check notice on line 1 in planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/shift_line_generator.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 8.32 to 8.64, 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 @@ -239,50 +239,70 @@

const auto is_forward_object = [](const auto & object) { return object.longitudinal > 0.0; };

const auto is_on_path = [this](const auto & object) {
const auto [overhang, point] = object.overhang_points.front();
return std::abs(overhang) < 0.5 * data_->parameters.vehicle_width;
};

const auto is_valid_shift_line = [](const auto & s) {
return s.start_longitudinal > 0.0 && s.start_longitudinal < s.end_longitudinal;
};

ObjectDataArray unavoidable_objects;

// target objects are sorted by longitudinal distance.
AvoidOutlines outlines;
for (auto & o : data.target_objects) {
if (!o.avoid_margin.has_value()) {
if (!data.red_signal_lane.has_value()) {
o.info = ObjectInfo::INSUFFICIENT_DRIVABLE_SPACE;
} else if (data.red_signal_lane.value().id() == o.overhang_lanelet.id()) {
o.info = ObjectInfo::LIMIT_DRIVABLE_SPACE_TEMPORARY;
} else {
o.info = ObjectInfo::INSUFFICIENT_DRIVABLE_SPACE;
}
if (o.avoid_required && is_forward_object(o)) {
if (o.avoid_required && is_forward_object(o) && is_on_path(o)) {
break;
} else {
unavoidable_objects.push_back(o);
continue;
}
}

const auto is_object_on_right = utils::static_obstacle_avoidance::isOnRight(o);
const auto desire_shift_length =
helper_->getShiftLength(o, is_object_on_right, o.avoid_margin.value());
if (utils::static_obstacle_avoidance::isSameDirectionShift(
is_object_on_right, desire_shift_length)) {
helper_->getShiftLength(o, isOnRight(o), o.avoid_margin.value());
if (utils::static_obstacle_avoidance::isSameDirectionShift(isOnRight(o), desire_shift_length)) {
o.info = ObjectInfo::SAME_DIRECTION_SHIFT;
if (o.avoid_required && is_forward_object(o)) {
if (o.avoid_required && is_forward_object(o) && is_on_path(o)) {
break;
} else {
unavoidable_objects.push_back(o);
continue;
}
}

// calculate feasible shift length based on behavior policy
const auto feasible_shift_profile = get_shift_profile(o, desire_shift_length);
if (!feasible_shift_profile.has_value()) {
if (o.avoid_required && is_forward_object(o)) {
if (o.avoid_required && is_forward_object(o) && is_on_path(o)) {

Check warning on line 287 in planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/shift_line_generator.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Conditional

ShiftLineGenerator::generateAvoidOutline has 3 complex conditionals with 6 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
break;
} else {
unavoidable_objects.push_back(o);
continue;
}
}

// If there is an object that cannot be avoided, this module only avoids object on the same side
// as unavoidable object.
if (!unavoidable_objects.empty()) {
if (isOnRight(unavoidable_objects.front()) && !isOnRight(o)) {
break;
}
if (!isOnRight(unavoidable_objects.front()) && isOnRight(o)) {
break;
}
}

Check notice on line 305 in planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/shift_line_generator.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Complex Method

ShiftLineGenerator::generateAvoidOutline increases in cyclomatic complexity from 50 to 58, 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 305 in planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/shift_line_generator.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Bumpy Road Ahead

ShiftLineGenerator::generateAvoidOutline increases from 4 to 5 logical blocks with deeply nested code, threshold is one single block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.
// use absolute dist for return-to-center, relative dist from current for avoiding.
const auto feasible_return_distance =
helper_->getMaxAvoidanceDistance(feasible_shift_profile.value().first);
Expand Down
Loading