Skip to content

Commit

Permalink
fix(avoidance): output return shift path properly
Browse files Browse the repository at this point in the history
Signed-off-by: satoshi-ota <[email protected]>
  • Loading branch information
satoshi-ota committed Jan 5, 2024
1 parent 5de111f commit ea98a96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion planning/behavior_path_avoidance_module/src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,8 @@ void AvoidanceModule::insertReturnDeadLine(
shifted_path.path.points, getEgoPosition(), shifted_path.path.points.size() - 1);
const auto buffer = std::max(0.0, to_shifted_path_end - to_reference_path_end);

const auto min_return_distance = helper_->getMinAvoidanceDistance(shift_length);
const auto min_return_distance =
helper_->getMinAvoidanceDistance(shift_length) + helper_->getMinimumPrepareDistance();

Check warning on line 1392 in planning/behavior_path_avoidance_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_avoidance_module/src/scene.cpp#L1392

Added line #L1392 was not covered by tests
const auto to_stop_line = data.to_return_point - min_return_distance - buffer;

// If we don't need to consider deceleration constraints, insert a deceleration point
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1101,12 +1101,14 @@ AvoidLineArray ShiftLineGenerator::addReturnShiftLine(
const double variable_prepare_distance =
std::max(nominal_prepare_distance - last_sl_distance, 0.0);

double prepare_distance_scaled = std::max(nominal_prepare_distance, last_sl_distance);
double prepare_distance_scaled =
std::clamp(nominal_prepare_distance, helper_->getMinimumPrepareDistance(), last_sl_distance);
double avoid_distance_scaled = nominal_avoid_distance;
if (remaining_distance < prepare_distance_scaled + avoid_distance_scaled) {
const auto scale = (remaining_distance - last_sl_distance) /
std::max(nominal_avoid_distance + variable_prepare_distance, 0.1);
prepare_distance_scaled = last_sl_distance + scale * nominal_prepare_distance;
prepare_distance_scaled = std::max(

Check warning on line 1110 in planning/behavior_path_avoidance_module/src/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_avoidance_module/src/shift_line_generator.cpp#L1110

Added line #L1110 was not covered by tests
helper_->getMinimumPrepareDistance(), last_sl_distance + scale * nominal_prepare_distance);

Check warning on line 1111 in planning/behavior_path_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::addReturnShiftLine already has high cyclomatic complexity, and now it increases in Lines of Code from 119 to 121. 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.
avoid_distance_scaled *= scale;
}

Expand Down Expand Up @@ -1219,7 +1221,7 @@ AvoidLineArray ShiftLineGenerator::findNewShiftLine(
const auto & candidate = shift_lines.at(i);

// prevent sudden steering.
if (candidate.start_longitudinal < helper_->getMinimumPrepareDistance()) {
if (candidate.start_longitudinal + 1e-3 < helper_->getMinimumPrepareDistance()) {
break;
}

Expand Down

0 comments on commit ea98a96

Please sign in to comment.