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(avoidance): prevent sudden steering at avoidance maneuver #5572

Merged
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 @@ -190,7 +190,8 @@
max_deviation_from_lane: 0.5 # [m]
# avoidance distance parameters
longitudinal:
prepare_time: 2.0 # [s]
min_prepare_time: 1.0 # [s]
max_prepare_time: 2.0 # [s]
min_prepare_distance: 1.0 # [m]
min_slow_down_speed: 1.38 # [m/s]
buf_slow_down_speed: 0.56 # [m/s]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ struct AvoidanceParameters
double stop_buffer{0.0};

// start avoidance after this time to avoid sudden path change
double prepare_time{0.0};
double min_prepare_time{0.0};
double max_prepare_time{0.0};

// Even if the vehicle speed is zero, avoidance will start after a distance of this much.
double min_prepare_distance{0.0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,16 @@ class AvoidanceHelper
return std::max(getEgoSpeed(), values.at(idx));
}

double getMinimumPrepareDistance() const
{
const auto & p = parameters_;
return std::max(getEgoSpeed() * p->min_prepare_time, p->min_prepare_distance);
}

double getNominalPrepareDistance() const
{
const auto & p = parameters_;
return std::max(getEgoSpeed() * p->prepare_time, p->min_prepare_distance);
return std::max(getEgoSpeed() * p->max_prepare_time, p->min_prepare_distance);
}

double getNominalAvoidanceDistance(const double shift_length) const
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 planning/behavior_path_planner/src/scene_module/avoidance/avoidance_module.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Lines of Code in a Single File

The lines of code increases from 2214 to 2232, 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/src/scene_module/avoidance/avoidance_module.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 6.19 to 6.25, 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 @@ -224,7 +224,7 @@

// If the vehicle is on the shift line, keep RUNNING.
{
const size_t idx = planner_data_->findEgoIndex(path_shifter_.getReferencePath().points);

Check warning on line 227 in planning/behavior_path_planner/src/scene_module/avoidance/avoidance_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/scene_module/avoidance/avoidance_module.cpp#L227

Added line #L227 was not covered by tests
const auto within = [](const auto & line, const size_t idx) {
return line.start_idx < idx && idx < line.end_idx;
};
Expand Down Expand Up @@ -437,10 +437,27 @@
{
// transit yield maneuver only when the avoidance maneuver is not initiated.
if (helper_.isShifted()) {
RCLCPP_DEBUG(getLogger(), "avoidance maneuver already initiated.");
return false;
}

// prevent sudden steering.
const auto registered_lines = path_shifter_.getShiftLines();
if (!registered_lines.empty()) {
const size_t idx = planner_data_->findEgoIndex(path_shifter_.getReferencePath().points);
const auto to_shift_start_point = calcSignedArcLength(
path_shifter_.getReferencePath().points, idx, registered_lines.front().start_idx);
if (to_shift_start_point < helper_.getMinimumPrepareDistance()) {
rej55 marked this conversation as resolved.
Show resolved Hide resolved
RCLCPP_DEBUG(
getLogger(),
"Distance to shift start point is less than minimum prepare distance. The distance is not "
"enough.");
return false;

Check warning on line 455 in planning/behavior_path_planner/src/scene_module/avoidance/avoidance_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/scene_module/avoidance/avoidance_module.cpp#L455

Added line #L455 was not covered by tests
}
}

if (!data.stop_target_object) {
RCLCPP_DEBUG(getLogger(), "can pass by the object safely without avoidance maneuver.");
return true;
}

Expand Down Expand Up @@ -1652,6 +1669,10 @@
continue;
}

if (s.start_longitudinal < helper_.getMinimumPrepareDistance()) {
continue;

Check warning on line 1673 in planning/behavior_path_planner/src/scene_module/avoidance/avoidance_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/scene_module/avoidance/avoidance_module.cpp#L1673

Added line #L1673 was not covered by tests
}

shift_lines.push_back(s);
}
}
Expand Down Expand Up @@ -2405,9 +2426,8 @@
for (size_t i = 0; i < shift_lines.size(); ++i) {
const auto & candidate = shift_lines.at(i);

// new shift points must exist in front of Ego
// this value should be larger than -eps consider path shifter calculation error.
if (candidate.start_idx < avoid_data_.ego_closest_path_index) {
// prevent sudden steering.
if (candidate.start_longitudinal < helper_.getMinimumPrepareDistance()) {
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@
// avoidance maneuver (longitudinal)
{
std::string ns = "avoidance.avoidance.longitudinal.";
p.prepare_time = getOrDeclareParameter<double>(*node, ns + "prepare_time");
p.min_prepare_time = getOrDeclareParameter<double>(*node, ns + "min_prepare_time");
p.max_prepare_time = getOrDeclareParameter<double>(*node, ns + "max_prepare_time");

Check warning on line 225 in planning/behavior_path_planner/src/scene_module/avoidance/manager.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

AvoidanceModuleManager::AvoidanceModuleManager already has high cyclomatic complexity, and now it increases in Lines of Code from 256 to 257. 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.
p.min_prepare_distance = getOrDeclareParameter<double>(*node, ns + "min_prepare_distance");
p.min_slow_down_speed = getOrDeclareParameter<double>(*node, ns + "min_slow_down_speed");
p.buf_slow_down_speed = getOrDeclareParameter<double>(*node, ns + "buf_slow_down_speed");
Expand Down Expand Up @@ -390,7 +391,8 @@

{
const std::string ns = "avoidance.avoidance.longitudinal.";
updateParam<double>(parameters, ns + "prepare_time", p->prepare_time);
updateParam<double>(parameters, ns + "min_prepare_time", p->min_prepare_time);
updateParam<double>(parameters, ns + "max_prepare_time", p->max_prepare_time);

Check warning on line 395 in planning/behavior_path_planner/src/scene_module/avoidance/manager.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

AvoidanceModuleManager::updateModuleParams already has high cyclomatic complexity, and now it increases in Lines of Code from 106 to 107. 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.
updateParam<double>(parameters, ns + "min_slow_down_speed", p->min_slow_down_speed);
updateParam<double>(parameters, ns + "buf_slow_down_speed", p->buf_slow_down_speed);
}
Expand Down
Loading