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): fix invalid optional access #5804

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
Expand Up @@ -40,41 +40,41 @@
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_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#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_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#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_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#L51-L53

Added lines #L51 - L53 were not covered by tests

ret.id = id;

Check warning on line 55 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#L55

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

return ret;
}

Check warning on line 59 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#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_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#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_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#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_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#L69-L71

Added lines #L69 - L71 were not covered by tests

ret.id = id;

Check warning on line 73 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#L73

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

return ret;
}

Check warning on line 77 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#L76-L77

Added lines #L76 - L77 were not covered by tests

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

Check warning on line 91 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#L91

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

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

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

Check warning on line 128 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#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_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#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_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#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_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#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_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#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_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#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 @@ -175,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_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#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 @@ -184,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_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#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_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#L192

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

// relax lateral jerk limit. avoidable.
Expand All @@ -199,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_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#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_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#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_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#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_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#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_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#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_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#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_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#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 @@ -241,7 +241,7 @@
if (o.avoid_required && is_forward_object(o)) {
break;
} else {
continue;

Check warning on line 244 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#L244

Added line #L244 was not covered by tests
}
}

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

Check warning on line 256 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#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_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#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_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#L269

Added line #L269 was not covered by tests
}
}

Expand All @@ -279,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_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#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_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#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_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#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 @@ -293,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_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#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 @@ -306,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_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#L309-L310

Added lines #L309 - L310 were not covered by tests

// misc
al_avoid.id = generateUUID();
Expand All @@ -317,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_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#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_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#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_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#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_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#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_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#L336

Added line #L336 was not covered by tests

// misc
al_return.id = generateUUID();
Expand All @@ -341,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_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#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_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#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_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#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 @@ -454,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_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#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_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#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_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#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_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#L472

Added line #L472 was not covered by tests
}
}

Expand Down Expand Up @@ -509,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_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#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_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#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_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#L520

Added line #L520 was not covered by tests
}

AvoidLineArray ShiftLineGenerator::extractShiftLinesFromLine(
Expand All @@ -538,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_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#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 @@ -549,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_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#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 @@ -623,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_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#L626

Added line #L626 was not covered by tests
};

const auto within = [](const auto & line, const size_t idx) {
Expand All @@ -636,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_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#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_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#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_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#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_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#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_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#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_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#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_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#L672

Added line #L672 was not covered by tests
}
}

Check warning on line 674 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#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 @@ -689,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_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#L692

Added line #L692 was not covered by tests

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

Expand All @@ -697,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_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#L700

Added line #L700 was not covered by tests

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

Expand All @@ -705,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_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#L708

Added line #L708 was not covered by tests

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

return ret;
}

Check warning on line 717 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#L717

Added line #L717 was not covered by tests

AvoidLineArray ShiftLineGenerator::applyFillGapProcess(
const AvoidLineArray & shift_lines, const AvoidancePlanningData & data, DebugData & debug) const
Expand All @@ -739,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_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#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_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#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_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#L755

Added line #L755 was not covered by tests

helper_->alignShiftLinesOrder(ret, false);

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

AvoidLineArray sl_array_trimmed = shift_lines;

Check warning on line 813 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#L813

Added line #L813 was not covered by tests

// sort shift points from front to back.
helper_->alignShiftLinesOrder(sl_array_trimmed);
Expand All @@ -824,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_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#L827

Added line #L827 was not covered by tests
applySimilarGradFilter(sl_array_trimmed, THRESHOLD);
debug.step3_grad_filtered_1st = sl_array_trimmed;
}
Expand All @@ -832,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_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#L835

Added line #L835 was not covered by tests
applyQuantizeProcess(sl_array_trimmed, THRESHOLD);
debug.step3_quantize_filtered = sl_array_trimmed;
}
Expand All @@ -846,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_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#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_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#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_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#L862

Added line #L862 was not covered by tests

void ShiftLineGenerator::applyQuantizeProcess(

Check warning on line 864 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#L864

Added line #L864 was not covered by tests
AvoidLineArray & shift_lines, const double threshold) const
{
if (threshold < 1.0e-5) {
Expand All @@ -869,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_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#L872

Added line #L872 was not covered by tests
}

helper_->alignShiftLinesOrder(shift_lines);

Check warning on line 875 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#L875

Added line #L875 was not covered by tests
}

void ShiftLineGenerator::applySmallShiftFilter(

Check warning on line 878 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#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_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#L882

Added line #L882 was not covered by tests
}

AvoidLineArray input = shift_lines;

Check warning on line 885 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#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_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#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_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#L894

Added line #L894 was not covered by tests
}

shift_lines.push_back(s);
}
}

Check warning on line 899 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#L899

Added line #L899 was not covered by tests

void ShiftLineGenerator::applySimilarGradFilter(

Check warning on line 901 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#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_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#L905

Added line #L905 was not covered by tests
}

AvoidLineArray input = avoid_lines;

Check warning on line 908 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#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 @@ -914,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_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#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_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#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_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#L922

Added line #L922 was not covered by tests

for (size_t i = 1; i < input.size(); ++i) {
AvoidLine combine{};
Expand All @@ -927,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_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#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_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#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 @@ -942,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_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#L945-L947

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

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

Check warning on line 958 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#L958

Added line #L958 was not covered by tests

helper_->alignShiftLinesOrder(avoid_lines);
}

Check warning on line 961 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#L961

Added line #L961 was not covered by tests

AvoidLineArray ShiftLineGenerator::addReturnShiftLine(
const AvoidLineArray & shift_lines, const AvoidancePlanningData & data, DebugData & debug) const
Expand All @@ -966,25 +966,27 @@
AvoidLineArray ret = shift_lines;

constexpr double ep = 1.0e-3;
constexpr double RETURN_SHIFT_THRESHOLD = 0.1;
const bool has_candidate_point = !ret.empty();
const bool has_registered_point = last_.has_value();

const auto exist_unavoidable_object = std::any_of(
data.target_objects.begin(), data.target_objects.end(),
[](const auto & o) { return !o.is_avoidable && o.longitudinal > 0.0; });

if (exist_unavoidable_object) {
return ret;
}

// If the return-to-center shift points are already registered, do nothing.
if (!has_registered_point && std::fabs(base_offset_) < ep) {
return ret;
}

constexpr double RETURN_SHIFT_THRESHOLD = 0.1;
if (std::abs(last_.value().end_shift_length) < RETURN_SHIFT_THRESHOLD) {
return ret;
if (last_.has_value()) {
if (std::abs(last_.value().end_shift_length) < RETURN_SHIFT_THRESHOLD) {
return ret;
}
} else {
// If the return-to-center shift points are already registered, do nothing.
if (std::abs(base_offset_) < ep) {
return ret;
}

Check warning on line 989 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 116 to 119. 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 notice on line 989 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: Bumpy Road Ahead

ShiftLineGenerator::addReturnShiftLine increases from 2 to 4 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.
}

// From here, the return-to-center is not registered. But perhaps the candidate is
Expand All @@ -997,7 +999,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 1002 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#L1002

Added line #L1002 was not covered by tests
}

// avoidance points: No, shift points: Yes -> select last shift point.
Expand All @@ -1011,14 +1013,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 1016 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#L1016

Added line #L1016 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 1023 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#L1022-L1023

Added lines #L1022 - L1023 were not covered by tests
}
}

Expand Down Expand Up @@ -1052,13 +1054,13 @@

// set the return-shift from ego.
last_sl.end_idx = data.ego_closest_path_index;
last_sl.end = data.reference_path.points.at(last_sl.end_idx).point.pose;

Check warning on line 1057 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#L1057

Added line #L1057 was not covered by tests
last_sl.end_shift_length = current_base_shift;
}

const auto & arclength_from_ego = data.arclength_from_ego;

const auto nominal_prepare_distance = helper_->getNominalPrepareDistance();

Check warning on line 1063 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#L1063

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

if (arclength_from_ego.empty()) {
Expand All @@ -1069,7 +1071,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 1074 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#L1074

Added line #L1074 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 @@ -1096,31 +1098,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 1101 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#L1101

Added line #L1101 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 1104 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#L1104

Added line #L1104 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 1107 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#L1106-L1107

Added lines #L1106 - L1107 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 1114 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#L1114

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

Check warning on line 1116 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#L1116

Added line #L1116 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 1122 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#L1120-L1122

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

Check warning on line 1125 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#L1125

Added line #L1125 was not covered by tests

// shift point for return to center line
{
Expand All @@ -1129,19 +1131,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 1134 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#L1134

Added line #L1134 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 1140 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#L1138-L1140

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

Check warning on line 1143 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#L1143

Added line #L1143 was not covered by tests

return ret;
}

Check warning on line 1146 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#L1145-L1146

Added lines #L1145 - L1146 were not covered by tests

AvoidLineArray ShiftLineGenerator::findNewShiftLine(
const AvoidLineArray & shift_lines, DebugData & debug) const
Expand All @@ -1152,9 +1154,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 1157 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#L1157

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

Check warning on line 1159 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#L1159

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

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

Check warning on line 1173 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#L1173

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

Check warning on line 1175 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#L1175

Added line #L1175 was not covered by tests

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

Check warning on line 1178 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#L1178

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

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

if (

Check warning on line 1193 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#L1193

Added line #L1193 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 1197 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#L1197

Added line #L1197 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 @@ -1203,12 +1205,12 @@
}

return subsequent;
};

Check warning on line 1208 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#L1208

Added line #L1208 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 1213 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#L1211-L1213

Added lines #L1211 - L1213 were not covered by tests

for (size_t i = 0; i < shift_lines.size(); ++i) {
const auto & candidate = shift_lines.at(i);
Expand All @@ -1219,20 +1221,20 @@
}

if (is_ignore_shift(candidate)) {
continue;

Check warning on line 1224 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#L1224

Added line #L1224 was not covered by tests
}

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

Check warning on line 1229 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#L1228-L1229

Added lines #L1228 - L1229 were not covered by tests
}

const auto new_shift_lines = get_subsequent_shift(i);

Check warning on line 1232 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#L1232

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

Check warning on line 1235 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#L1235

Added line #L1235 was not covered by tests

return {};

Check warning on line 1237 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#L1237

Added line #L1237 was not covered by tests
}

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

AvoidLineArray avoid_lines;

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

Check warning on line 1246 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#L1246

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

Check warning on line 1248 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#L1248

Added line #L1248 was not covered by tests

const auto start_to_ego_longitudinal = -1.0 * s.start_longitudinal;

Check warning on line 1250 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#L1250

Added line #L1250 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 1257 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#L1256-L1257

Added lines #L1256 - L1257 were not covered by tests

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

Check warning on line 1259 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#L1259

Added line #L1259 was not covered by tests
};

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

Check warning on line 1267 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#L1267

Added line #L1267 was not covered by tests
}

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

Check warning on line 1272 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#L1272

Added line #L1272 was not covered by tests
}

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

void ShiftLineGenerator::setRawRegisteredShiftLine(

Check warning on line 1282 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#L1282

Added line #L1282 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 1287 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#L1287

Added line #L1287 was not covered by tests
}

auto future_with_info = shift_lines;

Check warning on line 1290 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#L1290

Added line #L1290 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 1295 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#L1294-L1295

Added lines #L1294 - L1295 were not covered by tests
});

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

Check warning on line 1299 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#L1299

Added line #L1299 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 1304 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#L1304

Added line #L1304 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 1307 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#L1306-L1307

Added lines #L1306 - L1307 were not covered by tests

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

Check warning on line 1309 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#L1309

Added line #L1309 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 1313 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#L1313

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

Check warning on line 1316 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#L1316

Added line #L1316 was not covered by tests

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

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

Check warning on line 1325 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#L1325

Added line #L1325 was not covered by tests
}

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

Check warning on line 1331 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#L1331

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