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

feat(avoidance): keep stopping until all shift lines are registered #5658

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 @@ -231,6 +231,10 @@
stop_buffer: 1.0 # [m]

policy:
# policy for rtc request. select "per_shift_line" or "per_avoidance_maneuver".
# "per_shift_line": request approval for each shift line.
# "per_avoidance_maneuver": request approval for avoidance maneuver (avoid + return).
make_approval_request: "per_shift_line"
# policy for vehicle slow down behavior. select "best_effort" or "reliable".
# "best_effort": slow down deceleration & jerk are limited by constraints.
# but there is a possibility that the vehicle can't stop in front of the vehicle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ struct AvoidanceParameters
// policy
bool use_shorten_margin_immediately{false};

// policy
std::string policy_approval{"per_shift_line"};

// policy
std::string policy_deceleration{"best_effort"};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
// policy
{
std::string ns = "avoidance.policy.";
p.policy_approval = getOrDeclareParameter<std::string>(*node, ns + "make_approval_request");

Check warning on line 295 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 288 to 289. 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.policy_deceleration = getOrDeclareParameter<std::string>(*node, ns + "deceleration");
p.policy_lateral_margin = getOrDeclareParameter<std::string>(*node, ns + "lateral_margin");
p.use_shorten_margin_immediately =
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/src/utils/avoidance/shift_line_generator.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 7.88 to 7.68, 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 @@ -35,41 +35,46 @@
return policy == "best_effort";
}

bool perManeuver(const std::string & policy)
{
return policy == "per_avoidance_maneuver";
}

AvoidLine merge(const AvoidLine & line1, const AvoidLine & line2, const UUID id)

Check warning on line 43 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L43

Added line #L43 was not covered by tests
{
AvoidLine ret{};

ret.start_idx = line1.start_idx;
ret.start_shift_length = line1.start_shift_length;
ret.start_longitudinal = line1.start_longitudinal;

Check warning on line 49 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L47-L49

Added lines #L47 - L49 were not covered by tests

ret.end_idx = line2.end_idx;
ret.end_shift_length = line2.end_shift_length;
ret.end_longitudinal = line2.end_longitudinal;

Check warning on line 53 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L51-L53

Added lines #L51 - L53 were not covered by tests

ret.id = id;

Check warning on line 55 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L55

Added line #L55 was not covered by tests
ret.object = line1.object;

return ret;
}

Check warning on line 59 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L58-L59

Added lines #L58 - L59 were not covered by tests

AvoidLine fill(const AvoidLine & line1, const AvoidLine & line2, const UUID id)

Check warning on line 61 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L61

Added line #L61 was not covered by tests
{
AvoidLine ret{};

ret.start_idx = line1.end_idx;
ret.start_shift_length = line1.end_shift_length;
ret.start_longitudinal = line1.end_longitudinal;

Check warning on line 67 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L65-L67

Added lines #L65 - L67 were not covered by tests

ret.end_idx = line2.start_idx;
ret.end_shift_length = line2.start_shift_length;
ret.end_longitudinal = line2.start_longitudinal;

Check warning on line 71 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L69-L71

Added lines #L69 - L71 were not covered by tests

ret.id = id;

Check warning on line 73 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L73

Added line #L73 was not covered by tests
ret.object = line1.object;

return ret;
}

Check warning on line 77 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L76-L77

Added lines #L76 - L77 were not covered by tests

AvoidLineArray toArray(const AvoidOutlines & outlines)
{
Expand All @@ -83,7 +88,7 @@
[&ret](const auto & line) { ret.push_back(line); });
}
return ret;
}

Check warning on line 91 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L91

Added line #L91 was not covered by tests
} // namespace

void ShiftLineGenerator::update(AvoidancePlanningData & data, DebugData & debug)
Expand Down Expand Up @@ -120,26 +125,26 @@

// Calculate feasible shift length
const auto get_shift_profile =
[&](

Check warning on line 128 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L128

Added line #L128 was not covered by tests
auto & object, const auto & desire_shift_length) -> std::optional<std::pair<double, double>> {
// use each object param
const auto object_type = utils::getHighestProbLabel(object.object.classification);

Check warning on line 131 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L131

Added line #L131 was not covered by tests
const auto object_parameter = parameters_->object_parameters.at(object_type);
const auto is_object_on_right = utils::avoidance::isOnRight(object);

Check warning on line 133 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L133

Added line #L133 was not covered by tests

// use absolute dist for return-to-center, relative dist from current for avoiding.
const auto avoiding_shift = desire_shift_length - current_ego_shift;
const auto nominal_avoid_distance = helper_->getMaxAvoidanceDistance(avoiding_shift);

Check warning on line 137 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L136-L137

Added lines #L136 - L137 were not covered by tests

// calculate remaining distance.
const auto prepare_distance = helper_->getNominalPrepareDistance();
const auto & additional_buffer_longitudinal =
object_parameter.use_conservative_buffer_longitudinal ? data_->parameters.base_link2front
: 0.0;
const auto constant = object_parameter.safety_buffer_longitudinal +

Check warning on line 144 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L144

Added line #L144 was not covered by tests
additional_buffer_longitudinal + prepare_distance;
const auto has_enough_distance = object.longitudinal > constant + nominal_avoid_distance;
const auto remaining_distance = object.longitudinal - constant;

Check warning on line 147 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L146-L147

Added lines #L146 - L147 were not covered by tests
const auto avoidance_distance =
has_enough_distance ? nominal_avoid_distance : remaining_distance;

Expand Down Expand Up @@ -170,7 +175,7 @@
}

// the avoidance path is already approved
const auto & object_pos = object.object.kinematics.initial_pose_with_covariance.pose.position;

Check warning on line 178 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L178

Added line #L178 was not covered by tests
const auto is_approved = (helper_->getShift(object_pos) > 0.0 && is_object_on_right) ||
(helper_->getShift(object_pos) < 0.0 && !is_object_on_right);
if (is_approved) {
Expand All @@ -179,12 +184,12 @@

// prepare distance is not enough. unavoidable.
if (remaining_distance < 1e-3) {
object.reason = AvoidanceDebugFactor::REMAINING_DISTANCE_LESS_THAN_ZERO;
return std::nullopt;

Check warning on line 188 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L187-L188

Added lines #L187 - L188 were not covered by tests
}

// calculate lateral jerk.
const auto required_jerk = PathShifter::calcJerkFromLatLonDistance(

Check warning on line 192 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L192

Added line #L192 was not covered by tests
avoiding_shift, remaining_distance, helper_->getAvoidanceEgoSpeed());

// relax lateral jerk limit. avoidable.
Expand All @@ -194,36 +199,36 @@

// avoidance distance is not enough. unavoidable.
if (!isBestEffort(parameters_->policy_deceleration)) {
object.reason = AvoidanceDebugFactor::TOO_LARGE_JERK;
return std::nullopt;

Check warning on line 203 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L202-L203

Added lines #L202 - L203 were not covered by tests
}

// output avoidance path under lateral jerk constraints.
const auto feasible_relative_shift_length = PathShifter::calcLateralDistFromJerk(

Check warning on line 207 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L207

Added line #L207 was not covered by tests
remaining_distance, helper_->getLateralMaxJerkLimit(), helper_->getAvoidanceEgoSpeed());

if (std::abs(feasible_relative_shift_length) < parameters_->lateral_execution_threshold) {
object.reason = "LessThanExecutionThreshold";
return std::nullopt;

Check warning on line 212 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L211-L212

Added lines #L211 - L212 were not covered by tests
}

const auto feasible_shift_length =
desire_shift_length > 0.0 ? feasible_relative_shift_length + current_ego_shift
: -1.0 * feasible_relative_shift_length + current_ego_shift;

Check warning on line 217 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L217

Added line #L217 was not covered by tests

const auto infeasible =
std::abs(feasible_shift_length - object.overhang_dist) <
0.5 * data_->parameters.vehicle_width + object_parameter.safety_buffer_lateral;

Check warning on line 221 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L221

Added line #L221 was not covered by tests
if (infeasible) {
RCLCPP_DEBUG(rclcpp::get_logger(""), "feasible shift length is not enough to avoid. ");
object.reason = AvoidanceDebugFactor::TOO_LARGE_JERK;
return std::nullopt;

Check warning on line 225 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L224-L225

Added lines #L224 - L225 were not covered by tests
}

return std::make_pair(feasible_shift_length, avoidance_distance);
};

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

Check warning on line 231 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L231

Added line #L231 was not covered by tests

const auto is_valid_shift_line = [](const auto & s) {
return s.start_longitudinal > 0.0 && s.start_longitudinal < s.end_longitudinal;
Expand All @@ -236,7 +241,7 @@
if (o.avoid_required && is_forward_object(o)) {
break;
} else {
continue;

Check warning on line 244 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L244

Added line #L244 was not covered by tests
}
}

Expand All @@ -248,20 +253,20 @@
if (o.avoid_required && is_forward_object(o)) {
break;
} else {
continue;

Check warning on line 256 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L256

Added line #L256 was not covered by tests
}
}

// use each object param
const auto object_type = utils::getHighestProbLabel(o.object.classification);
const auto object_parameter = parameters_->object_parameters.at(object_type);

Check warning on line 262 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L262

Added line #L262 was not covered by tests
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)) {
break;
} else {
continue;

Check warning on line 269 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L269

Added line #L269 was not covered by tests
}
}

Expand All @@ -274,13 +279,13 @@
const auto & additional_buffer_longitudinal =
object_parameter.use_conservative_buffer_longitudinal ? data_->parameters.base_link2front
: 0.0;
const auto offset =

Check warning on line 282 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L282

Added line #L282 was not covered by tests
object_parameter.safety_buffer_longitudinal + additional_buffer_longitudinal;
const auto to_shift_end = o.longitudinal - offset;

Check warning on line 284 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L284

Added line #L284 was not covered by tests
const auto path_front_to_ego = data.arclength_from_ego.at(data.ego_closest_path_index);

// start point (use previous linear shift length as start shift length.)
al_avoid.start_longitudinal = [&]() {

Check warning on line 288 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L288

Added line #L288 was not covered by tests
const auto nearest_avoid_distance =
std::max(to_shift_end - feasible_shift_profile.value().second, 1e-3);

Expand All @@ -288,8 +293,8 @@
return nearest_avoid_distance;
}

const auto minimum_avoid_distance = helper_->getMinAvoidanceDistance(
feasible_shift_profile.value().first - current_ego_shift);

Check warning on line 297 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L296-L297

Added lines #L296 - L297 were not covered by tests
const auto furthest_avoid_distance = std::max(to_shift_end - minimum_avoid_distance, 1e-3);

return std::clamp(data.to_start_point, nearest_avoid_distance, furthest_avoid_distance);
Expand All @@ -301,8 +306,8 @@
al_avoid.start_shift_length = helper_->getLinearShift(al_avoid.start.position);

// end point
al_avoid.end_shift_length = feasible_shift_profile.value().first;
al_avoid.end_longitudinal = to_shift_end;

Check warning on line 310 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L309-L310

Added lines #L309 - L310 were not covered by tests

// misc
al_avoid.id = generateUUID();
Expand All @@ -312,23 +317,23 @@

AvoidLine al_return;
{
const auto offset = object_parameter.safety_buffer_longitudinal + base_link2rear + o.length;

Check warning on line 320 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L320

Added line #L320 was not covered by tests
const auto to_shift_start = o.longitudinal + offset;

// start point
al_return.start_shift_length = feasible_shift_profile.value().first;
al_return.start_longitudinal = to_shift_start;

Check warning on line 325 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L324-L325

Added lines #L324 - L325 were not covered by tests

// end point
al_return.end_longitudinal = [&]() {

Check warning on line 328 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L328

Added line #L328 was not covered by tests
if (data.to_return_point > to_shift_start) {
return std::clamp(
data.to_return_point, to_shift_start, feasible_return_distance + to_shift_start);
}

return to_shift_start + feasible_return_distance;

Check warning on line 334 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L334

Added line #L334 was not covered by tests
}();
al_return.end_shift_length = 0.0;

Check warning on line 336 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L336

Added line #L336 was not covered by tests

// misc
al_return.id = generateUUID();
Expand All @@ -336,22 +341,22 @@
al_return.object_on_right = utils::avoidance::isOnRight(o);
}

if (is_valid_shift_line(al_avoid) && is_valid_shift_line(al_return)) {

Check warning on line 344 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L344

Added line #L344 was not covered by tests
outlines.emplace_back(al_avoid, al_return);
} else {
o.reason = "InvalidShiftLine";
continue;
}

o.is_avoidable = true;
}

Check warning on line 352 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L351-L352

Added lines #L351 - L352 were not covered by tests

utils::avoidance::fillAdditionalInfoFromLongitudinal(data, outlines);

debug.step1_current_shift_line = toArray(outlines);

return outlines;
}

Check warning on line 359 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L359

Added line #L359 was not covered by tests

AvoidLineArray ShiftLineGenerator::applyPreProcess(
const AvoidOutlines & outlines, const AvoidancePlanningData & data, DebugData & debug) const
Expand Down Expand Up @@ -449,22 +454,22 @@
const auto & al = avoid_lines.at(j);
for (size_t i = 0; i < N; ++i) {
// calc current interpolated shift
const auto i_shift = utils::avoidance::lerpShiftLengthOnArc(arcs.at(i), al);

Check warning on line 457 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L457

Added line #L457 was not covered by tests

// update maximum shift for positive direction
if (i_shift > sl.pos_shift_line.at(i)) {
sl.pos_shift_line.at(i) = i_shift;
sl.pos_shift_line_grad.at(i) = al.getGradient();

Check warning on line 462 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L462

Added line #L462 was not covered by tests
}

// update minumum shift for negative direction
if (i_shift < sl.neg_shift_line.at(i)) {
sl.neg_shift_line.at(i) = i_shift;
sl.neg_shift_line_grad.at(i) = al.getGradient();

Check warning on line 468 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L468

Added line #L468 was not covered by tests
}

// store for debug print
sl.shift_line_history.at(j).at(i) = i_shift;

Check warning on line 472 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L472

Added line #L472 was not covered by tests
}
}

Expand Down Expand Up @@ -504,15 +509,15 @@
return;
}

const auto grad_first_shift_line = (avoid_lines.front().start_shift_length - current_shift) /
avoid_lines.front().start_longitudinal;

Check warning on line 513 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L512-L513

Added lines #L512 - L513 were not covered by tests

for (size_t i = data.ego_closest_path_index; i <= avoid_lines.front().start_idx; ++i) {
sl.shift_line.at(i) = helper_->getLinearShift(getPoint(path.points.at(i)));
sl.shift_line_grad.at(i) = grad_first_shift_line;

Check warning on line 517 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L517

Added line #L517 was not covered by tests
}

sl.shift_line_history.push_back(sl.shift_line);

Check warning on line 520 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L520

Added line #L520 was not covered by tests
}

AvoidLineArray ShiftLineGenerator::extractShiftLinesFromLine(
Expand All @@ -533,7 +538,7 @@
}
const double ds = arcs.at(i) - arcs.at(i - 1);
if (ds < 1.0e-5) {
return sl.shift_line_grad.at(i);

Check warning on line 541 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L541

Added line #L541 was not covered by tests
} // use theoretical value when ds is too small.
return (sl.shift_line.at(i) - sl.shift_line.at(i - 1)) / ds;
};
Expand All @@ -544,7 +549,7 @@
}
const double ds = arcs.at(i + 1) - arcs.at(i);
if (ds < 1.0e-5) {
return sl.shift_line_grad.at(i);

Check warning on line 552 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L552

Added line #L552 was not covered by tests
} // use theoretical value when ds is too small.
return (sl.shift_line.at(i + 1) - sl.shift_line.at(i)) / ds;
};
Expand Down Expand Up @@ -618,7 +623,7 @@
};

const auto same_side_shift = [](const auto & line1, const auto & line2) {
return line1.object_on_right == line2.object_on_right;

Check warning on line 626 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L626

Added line #L626 was not covered by tests
};

const auto within = [](const auto & line, const size_t idx) {
Expand All @@ -631,42 +636,42 @@
auto & last_outline = ret.back();
auto & next_outline = outlines.at(i);

const auto & return_line = last_outline.return_line;

Check warning on line 639 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L639

Added line #L639 was not covered by tests
const auto & avoid_line = next_outline.avoid_line;

if (no_conflict(return_line, avoid_line)) {

Check warning on line 642 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L642

Added line #L642 was not covered by tests
ret.push_back(outlines.at(i));
continue;

Check warning on line 644 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L644

Added line #L644 was not covered by tests
}

const auto merged_shift_line = merge(return_line, avoid_line, generateUUID());

if (!helper_->isComfortable(AvoidLineArray{merged_shift_line})) {
ret.push_back(outlines.at(i));
continue;

Check warning on line 651 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L651

Added line #L651 was not covered by tests
}

if (same_side_shift(return_line, avoid_line)) {
last_outline.middle_lines.push_back(merged_shift_line);
last_outline.return_line = next_outline.return_line;
debug.step1_merged_shift_line.push_back(merged_shift_line);
continue;

Check warning on line 658 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L658

Added line #L658 was not covered by tests
}

if (within(return_line, avoid_line.end_idx) && within(avoid_line, return_line.start_idx)) {
last_outline.middle_lines.push_back(merged_shift_line);
last_outline.return_line = next_outline.return_line;
debug.step1_merged_shift_line.push_back(merged_shift_line);
continue;

Check warning on line 665 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L665

Added line #L665 was not covered by tests
}

if (within(return_line, avoid_line.start_idx) && within(avoid_line, return_line.end_idx)) {
last_outline.middle_lines.push_back(merged_shift_line);
last_outline.return_line = next_outline.return_line;
debug.step1_merged_shift_line.push_back(merged_shift_line);
continue;

Check warning on line 672 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L672

Added line #L672 was not covered by tests
}
}

Check warning on line 674 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L674

Added line #L674 was not covered by tests

utils::avoidance::fillAdditionalInfoFromLongitudinal(data, ret);
utils::avoidance::fillAdditionalInfoFromLongitudinal(data, debug.step1_merged_shift_line);
Expand All @@ -684,7 +689,7 @@
const auto new_line = fill(outline.avoid_line, outline.return_line, generateUUID());
outline.middle_lines.push_back(new_line);
debug.step1_filled_shift_line.push_back(new_line);
}

Check warning on line 692 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L692

Added line #L692 was not covered by tests

helper_->alignShiftLinesOrder(outline.middle_lines, false);

Expand All @@ -692,7 +697,7 @@
const auto new_line = fill(outline.avoid_line, outline.middle_lines.front(), generateUUID());
outline.middle_lines.push_back(new_line);
debug.step1_filled_shift_line.push_back(new_line);
}

Check warning on line 700 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L700

Added line #L700 was not covered by tests

helper_->alignShiftLinesOrder(outline.middle_lines, false);

Expand All @@ -700,7 +705,7 @@
const auto new_line = fill(outline.middle_lines.back(), outline.return_line, generateUUID());
outline.middle_lines.push_back(new_line);
debug.step1_filled_shift_line.push_back(new_line);
}

Check warning on line 708 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L708

Added line #L708 was not covered by tests

helper_->alignShiftLinesOrder(outline.middle_lines, false);
}
Expand All @@ -709,7 +714,7 @@
utils::avoidance::fillAdditionalInfoFromLongitudinal(data, debug.step1_filled_shift_line);

return ret;
}

Check warning on line 717 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L717

Added line #L717 was not covered by tests

AvoidLineArray ShiftLineGenerator::applyFillGapProcess(
const AvoidLineArray & shift_lines, const AvoidancePlanningData & data, DebugData & debug) const
Expand All @@ -734,20 +739,20 @@
const auto new_line = fill(ego_line, sorted.front(), generateUUID());
ret.push_back(new_line);
debug.step1_front_shift_line.push_back(new_line);
}

Check warning on line 742 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L742

Added line #L742 was not covered by tests

helper_->alignShiftLinesOrder(sorted, false);

// fill gap among shift lines.
for (size_t i = 0; i < sorted.size() - 1; ++i) {
if (sorted.at(i + 1).start_longitudinal < sorted.at(i).end_longitudinal) {
continue;

Check warning on line 749 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L749

Added line #L749 was not covered by tests
}

const auto new_line = fill(sorted.at(i), sorted.at(i + 1), generateUUID());
ret.push_back(new_line);
debug.step1_front_shift_line.push_back(new_line);
}

Check warning on line 755 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L755

Added line #L755 was not covered by tests

helper_->alignShiftLinesOrder(ret, false);

Expand Down Expand Up @@ -805,7 +810,7 @@
return shift_lines;
}

AvoidLineArray sl_array_trimmed = shift_lines;

Check warning on line 813 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L813

Added line #L813 was not covered by tests

// sort shift points from front to back.
helper_->alignShiftLinesOrder(sl_array_trimmed);
Expand All @@ -819,7 +824,7 @@
// - Combine avoid points that have almost same gradient.
// this is to remove the noise.
{
const auto THRESHOLD = parameters_->same_grad_filter_1_threshold;

Check warning on line 827 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L827

Added line #L827 was not covered by tests
applySimilarGradFilter(sl_array_trimmed, THRESHOLD);
debug.step3_grad_filtered_1st = sl_array_trimmed;
}
Expand All @@ -827,7 +832,7 @@
// - Quantize the shift length to reduce the shift point noise
// This is to remove the noise coming from detection accuracy, interpolation, resampling, etc.
{
const auto THRESHOLD = parameters_->quantize_filter_threshold;

Check warning on line 835 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L835

Added line #L835 was not covered by tests
applyQuantizeProcess(sl_array_trimmed, THRESHOLD);
debug.step3_quantize_filtered = sl_array_trimmed;
}
Expand All @@ -841,22 +846,22 @@

// - Combine avoid points that have almost same gradient (again)
{
const auto THRESHOLD = parameters_->same_grad_filter_2_threshold;

Check warning on line 849 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L849

Added line #L849 was not covered by tests
applySimilarGradFilter(sl_array_trimmed, THRESHOLD);
debug.step3_grad_filtered_2nd = sl_array_trimmed;
}

// - Combine avoid points that have almost same gradient (again)
{
const auto THRESHOLD = parameters_->same_grad_filter_3_threshold;

Check warning on line 856 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L856

Added line #L856 was not covered by tests
applySimilarGradFilter(sl_array_trimmed, THRESHOLD);
debug.step3_grad_filtered_3rd = sl_array_trimmed;
}

return sl_array_trimmed;
}

Check warning on line 862 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L862

Added line #L862 was not covered by tests

void ShiftLineGenerator::applyQuantizeProcess(

Check warning on line 864 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L864

Added line #L864 was not covered by tests
AvoidLineArray & shift_lines, const double threshold) const
{
if (threshold < 1.0e-5) {
Expand All @@ -864,43 +869,43 @@
}

for (auto & sl : shift_lines) {
sl.end_shift_length = std::round(sl.end_shift_length / threshold) * threshold;

Check warning on line 872 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L872

Added line #L872 was not covered by tests
}

helper_->alignShiftLinesOrder(shift_lines);

Check warning on line 875 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L875

Added line #L875 was not covered by tests
}

void ShiftLineGenerator::applySmallShiftFilter(

Check warning on line 878 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L878

Added line #L878 was not covered by tests
AvoidLineArray & shift_lines, const double threshold) const
{
if (shift_lines.empty()) {
return;

Check warning on line 882 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L882

Added line #L882 was not covered by tests
}

AvoidLineArray input = shift_lines;

Check warning on line 885 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L885

Added line #L885 was not covered by tests
shift_lines.clear();

for (const auto & s : input) {
if (s.getRelativeLongitudinal() < threshold) {
continue;

Check warning on line 890 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L890

Added line #L890 was not covered by tests
}

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

Check warning on line 894 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L894

Added line #L894 was not covered by tests
}

shift_lines.push_back(s);
}
}

Check warning on line 899 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L899

Added line #L899 was not covered by tests

void ShiftLineGenerator::applySimilarGradFilter(

Check warning on line 901 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L901

Added line #L901 was not covered by tests
AvoidLineArray & avoid_lines, const double threshold) const
{
if (avoid_lines.empty()) {
return;

Check warning on line 905 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L905

Added line #L905 was not covered by tests
}

AvoidLineArray input = avoid_lines;

Check warning on line 908 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L908

Added line #L908 was not covered by tests
avoid_lines.clear();
avoid_lines.push_back(input.front()); // Take the first one anyway (think later)

Expand All @@ -909,12 +914,12 @@
AvoidLineArray combine_buffer;
combine_buffer.push_back(input.front());

constexpr auto SHIFT_THR = 1e-3;

Check warning on line 917 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L917

Added line #L917 was not covered by tests
const auto is_negative_shift = [&](const auto & s) {
return s.getRelativeLength() < -1.0 * SHIFT_THR;
};

Check warning on line 920 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L920

Added line #L920 was not covered by tests

const auto is_positive_shift = [&](const auto & s) { return s.getRelativeLength() > SHIFT_THR; };

Check warning on line 922 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L922

Added line #L922 was not covered by tests

for (size_t i = 1; i < input.size(); ++i) {
AvoidLine combine{};
Expand All @@ -922,13 +927,13 @@
utils::avoidance::setStartData(
combine, base_line.start_shift_length, base_line.start, base_line.start_idx,
base_line.start_longitudinal);
utils::avoidance::setEndData(

Check warning on line 930 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L930

Added line #L930 was not covered by tests
combine, input.at(i).end_shift_length, input.at(i).end, input.at(i).end_idx,
input.at(i).end_longitudinal);

combine_buffer.push_back(input.at(i));

const auto violates = [&]() {

Check warning on line 936 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L936

Added line #L936 was not covered by tests
if (is_negative_shift(input.at(i)) && is_positive_shift(base_line)) {
return true;
}
Expand All @@ -937,9 +942,9 @@
return true;
}

const auto lon_combine = combine.getRelativeLongitudinal();
const auto base_length = base_line.getGradient() * lon_combine;
return std::abs(combine.getRelativeLength() - base_length) > threshold;

Check warning on line 947 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L945-L947

Added lines #L945 - L947 were not covered by tests
}();

if (violates) {
Expand All @@ -950,10 +955,10 @@
} else {
avoid_lines.back() = combine;
}
}

Check warning on line 958 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L958

Added line #L958 was not covered by tests

helper_->alignShiftLinesOrder(avoid_lines);
}

Check warning on line 961 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L961

Added line #L961 was not covered by tests

AvoidLineArray ShiftLineGenerator::addReturnShiftLine(
const AvoidLineArray & shift_lines, const AvoidancePlanningData & data, DebugData & debug) const
Expand Down Expand Up @@ -992,7 +997,7 @@
// avoidance points: Yes, shift points: No -> select last avoidance point.
if (has_candidate_point && !has_registered_point) {
helper_->alignShiftLinesOrder(ret, false);
last_sl = ret.back();

Check warning on line 1000 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1000

Added line #L1000 was not covered by tests
}

// avoidance points: No, shift points: Yes -> select last shift point.
Expand All @@ -1006,14 +1011,14 @@
const auto & al = ret.back();
const auto & sl = utils::avoidance::fillAdditionalInfo(data, AvoidLine{last_.value()});
last_sl = (sl.end_longitudinal > al.end_longitudinal) ? sl : al;
}

Check warning on line 1014 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1014

Added line #L1014 was not covered by tests

// avoidance points: No, shift points: No -> set the ego position to the last shift point
// so that the return-shift will be generated from ego position.
if (!has_candidate_point && !has_registered_point) {
last_sl.end_idx = data.ego_closest_path_index;
last_sl.end = data.reference_path.points.at(last_sl.end_idx).point.pose;
last_sl.end_shift_length = base_offset_;

Check warning on line 1021 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1020-L1021

Added lines #L1020 - L1021 were not covered by tests
}
}

Expand Down Expand Up @@ -1053,7 +1058,7 @@

const auto & arclength_from_ego = data.arclength_from_ego;

const auto nominal_prepare_distance = helper_->getNominalPrepareDistance();

Check warning on line 1061 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1061

Added line #L1061 was not covered by tests
const auto nominal_avoid_distance = helper_->getMaxAvoidanceDistance(last_sl.end_shift_length);

if (arclength_from_ego.empty()) {
Expand All @@ -1064,7 +1069,7 @@
arclength_from_ego.back() - parameters_->dead_line_buffer_for_goal, data.to_return_point);

// If the avoidance point has already been set, the return shift must be set after the point.
const auto last_sl_distance = data.arclength_from_ego.at(last_sl.end_idx);

Check warning on line 1072 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1072

Added line #L1072 was not covered by tests

// check if there is enough distance for return.
if (last_sl_distance > remaining_distance) { // tmp: add some small number (+1.0)
Expand All @@ -1091,31 +1096,31 @@
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);

Check warning on line 1099 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1099

Added line #L1099 was not covered by tests
double avoid_distance_scaled = nominal_avoid_distance;
if (remaining_distance < prepare_distance_scaled + avoid_distance_scaled) {
const auto scale = (remaining_distance - last_sl_distance) /

Check warning on line 1102 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1102

Added line #L1102 was not covered by tests
std::max(nominal_avoid_distance + variable_prepare_distance, 0.1);
prepare_distance_scaled = last_sl_distance + scale * nominal_prepare_distance;
avoid_distance_scaled *= scale;

Check warning on line 1105 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1104-L1105

Added lines #L1104 - L1105 were not covered by tests
}

// shift point for prepare distance: from last shift to return-start point.
if (nominal_prepare_distance > last_sl_distance) {
AvoidLine al;
al.id = generateUUID();
al.start_idx = last_sl.end_idx;

Check warning on line 1112 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1112

Added line #L1112 was not covered by tests
al.start = last_sl.end;
al.start_longitudinal = arclength_from_ego.at(al.start_idx);

Check warning on line 1114 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1114

Added line #L1114 was not covered by tests
al.end_idx =
utils::avoidance::findPathIndexFromArclength(arclength_from_ego, prepare_distance_scaled);
al.end = data.reference_path.points.at(al.end_idx).point.pose;
al.end_longitudinal = arclength_from_ego.at(al.end_idx);
al.end_shift_length = last_sl.end_shift_length;
al.start_shift_length = last_sl.end_shift_length;

Check warning on line 1120 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1118-L1120

Added lines #L1118 - L1120 were not covered by tests
ret.push_back(al);
debug.step1_return_shift_line.push_back(al);
}

Check warning on line 1123 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1123

Added line #L1123 was not covered by tests

// shift point for return to center line
{
Expand All @@ -1124,19 +1129,19 @@
al.start_idx =
utils::avoidance::findPathIndexFromArclength(arclength_from_ego, prepare_distance_scaled);
al.start = data.reference_path.points.at(al.start_idx).point.pose;
al.start_longitudinal = arclength_from_ego.at(al.start_idx);

Check warning on line 1132 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1132

Added line #L1132 was not covered by tests
al.end_idx = utils::avoidance::findPathIndexFromArclength(
arclength_from_ego, prepare_distance_scaled + avoid_distance_scaled);
al.end = data.reference_path.points.at(al.end_idx).point.pose;
al.end_longitudinal = arclength_from_ego.at(al.end_idx);
al.end_shift_length = 0.0;
al.start_shift_length = last_sl.end_shift_length;

Check warning on line 1138 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1136-L1138

Added lines #L1136 - L1138 were not covered by tests
ret.push_back(al);
debug.step1_return_shift_line.push_back(al);
}

Check warning on line 1141 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1141

Added line #L1141 was not covered by tests

return ret;
}

Check warning on line 1144 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1143-L1144

Added lines #L1143 - L1144 were not covered by tests

AvoidLineArray ShiftLineGenerator::findNewShiftLine(
const AvoidLineArray & shift_lines, DebugData & debug) const
Expand All @@ -1147,9 +1152,9 @@

// add small shift lines.
const auto add_straight_shift =
[&, this](auto & subsequent, bool has_large_shift, const size_t start_idx) {

Check warning on line 1155 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1155

Added line #L1155 was not covered by tests
for (size_t i = start_idx; i < shift_lines.size(); ++i) {
if (

Check warning on line 1157 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1157

Added line #L1157 was not covered by tests
std::abs(shift_lines.at(i).getRelativeLength()) >
parameters_->lateral_small_shift_threshold) {
if (has_large_shift) {
Expand All @@ -1163,12 +1168,12 @@
return;
}

subsequent.push_back(shift_lines.at(i));

Check warning on line 1171 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1171

Added line #L1171 was not covered by tests
}
};

Check warning on line 1173 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1173

Added line #L1173 was not covered by tests

// get subsequent shift lines.
const auto get_subsequent_shift = [&, this](size_t i) {

Check warning on line 1176 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1176

Added line #L1176 was not covered by tests
AvoidLineArray subsequent{shift_lines.at(i)};

if (!helper_->isComfortable(subsequent)) {
Expand All @@ -1183,11 +1188,11 @@
return subsequent;
}

if (

Check warning on line 1191 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1191

Added line #L1191 was not covered by tests
std::abs(shift_lines.at(i).getRelativeLength()) <
parameters_->lateral_small_shift_threshold) {
const auto has_large_shift =
shift_lines.at(i + 1).getRelativeLength() > parameters_->lateral_small_shift_threshold;

Check warning on line 1195 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1195

Added line #L1195 was not covered by tests

// candidate.at(i) is small length shift line. add large length shift line.
subsequent.push_back(shift_lines.at(i + 1));
Expand All @@ -1198,12 +1203,12 @@
}

return subsequent;
};

Check warning on line 1206 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1206

Added line #L1206 was not covered by tests

// check ignore or not.
const auto is_ignore_shift = [this](const auto & s) {
return std::abs(helper_->getRelativeShiftToPath(s)) < parameters_->lateral_execution_threshold;
};

Check warning on line 1211 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1209-L1211

Added lines #L1209 - L1211 were not covered by tests

for (size_t i = 0; i < shift_lines.size(); ++i) {
const auto & candidate = shift_lines.at(i);
Expand All @@ -1213,14 +1218,21 @@
break;
}

if (!is_ignore_shift(candidate)) {
const auto new_shift_lines = get_subsequent_shift(i);
debug.step4_new_shift_line = new_shift_lines;
return new_shift_lines;
if (is_ignore_shift(candidate)) {
continue;

Check warning on line 1222 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1222

Added line #L1222 was not covered by tests
}

if (perManeuver(parameters_->policy_approval)) {
debug.step4_new_shift_line = shift_lines;
return shift_lines;

Check warning on line 1227 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1226-L1227

Added lines #L1226 - L1227 were not covered by tests
}

const auto new_shift_lines = get_subsequent_shift(i);

Check warning on line 1230 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1230

Added line #L1230 was not covered by tests
debug.step4_new_shift_line = new_shift_lines;
return new_shift_lines;

Check warning on line 1232 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

ShiftLineGenerator::findNewShiftLine increases in cyclomatic complexity from 13 to 15, 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 1233 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1233

Added line #L1233 was not covered by tests

return {};

Check warning on line 1235 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1235

Added line #L1235 was not covered by tests
}

void ShiftLineGenerator::updateRegisteredRawShiftLines(const AvoidancePlanningData & data)
Expand All @@ -1229,20 +1241,20 @@

AvoidLineArray avoid_lines;

const auto has_large_offset = [this](const auto & s) {

Check warning on line 1244 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1244

Added line #L1244 was not covered by tests
constexpr double THRESHOLD = 0.1;
const auto ego_shift_length = helper_->getEgoLinearShift();

Check warning on line 1246 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1246

Added line #L1246 was not covered by tests

const auto start_to_ego_longitudinal = -1.0 * s.start_longitudinal;

Check warning on line 1248 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1248

Added line #L1248 was not covered by tests

if (start_to_ego_longitudinal < 0.0) {
return false;
}

const auto reg_shift_length =
s.getGradient() * start_to_ego_longitudinal + s.start_shift_length;

Check warning on line 1255 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1254-L1255

Added lines #L1254 - L1255 were not covered by tests

return std::abs(ego_shift_length - reg_shift_length) > THRESHOLD;

Check warning on line 1257 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1257

Added line #L1257 was not covered by tests
};

const auto ego_idx = data.ego_closest_path_index;
Expand All @@ -1250,12 +1262,12 @@
for (const auto & s : raw_registered_) {
// invalid
if (s.end_idx < ego_idx) {
continue;

Check warning on line 1265 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1265

Added line #L1265 was not covered by tests
}

// invalid
if (has_large_offset(s)) {
continue;

Check warning on line 1270 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1270

Added line #L1270 was not covered by tests
}

// valid
Expand All @@ -1265,41 +1277,41 @@
raw_registered_ = avoid_lines;
}

void ShiftLineGenerator::setRawRegisteredShiftLine(

Check warning on line 1280 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1280

Added line #L1280 was not covered by tests
const AvoidLineArray & shift_lines, const AvoidancePlanningData & data)
{
if (shift_lines.empty()) {
RCLCPP_ERROR(rclcpp::get_logger(""), "future is empty! return.");
return;

Check warning on line 1285 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1285

Added line #L1285 was not covered by tests
}

auto future_with_info = shift_lines;

Check warning on line 1288 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1288

Added line #L1288 was not covered by tests
utils::avoidance::fillAdditionalInfoFromPoint(data, future_with_info);

// sort by longitudinal
std::sort(future_with_info.begin(), future_with_info.end(), [](auto a, auto b) {
return a.end_longitudinal < b.end_longitudinal;

Check warning on line 1293 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1292-L1293

Added lines #L1292 - L1293 were not covered by tests
});

// calc relative lateral length
future_with_info.front().start_shift_length = base_offset_;

Check warning on line 1297 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1297

Added line #L1297 was not covered by tests
for (size_t i = 1; i < future_with_info.size(); ++i) {
future_with_info.at(i).start_shift_length = future_with_info.at(i - 1).end_shift_length;
}

const auto is_registered = [this](const auto id) {

Check warning on line 1302 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1302

Added line #L1302 was not covered by tests
const auto & r = raw_registered_;
return std::any_of(r.begin(), r.end(), [id](const auto & s) { return s.id == id; });
};

Check warning on line 1305 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1304-L1305

Added lines #L1304 - L1305 were not covered by tests

const auto same_id_shift_line = [this](const auto id) {

Check warning on line 1307 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1307

Added line #L1307 was not covered by tests
const auto & r = raw_;
const auto itr = std::find_if(r.begin(), r.end(), [id](const auto & s) { return s.id == id; });
if (itr != r.end()) {
return *itr;

Check warning on line 1311 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1311

Added line #L1311 was not covered by tests
}
throw std::logic_error("not found same id current raw shift line.");
};

Check warning on line 1314 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1314

Added line #L1314 was not covered by tests

for (const auto & s : future_with_info) {
if (s.parent_ids.empty()) {
Expand All @@ -1308,11 +1320,11 @@

for (const auto id : s.parent_ids) {
if (is_registered(id)) {
continue;

Check warning on line 1323 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1323

Added line #L1323 was not covered by tests
}

raw_registered_.push_back(same_id_shift_line(id));
}
}
}

Check warning on line 1329 in planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/shift_line_generator.cpp#L1329

Added line #L1329 was not covered by tests
} // namespace behavior_path_planner::utils::avoidance
Loading