Skip to content

Commit

Permalink
refactor stuck/yield_stuck for right turn
Browse files Browse the repository at this point in the history
Signed-off-by: Mamoru Sobue <mamoru.sobue@tier4.jp>
  • Loading branch information
soblin committed Dec 18, 2023
1 parent a861078 commit 35a55ab
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion planning/behavior_velocity_intersection_module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ If there is any object on the path inside the intersection and at the exit of th

## Yield stuck vehicle detection

If there is any stopped object on the attention lanelet between the intersection point with ego path and the position which is `yield_stuck.distance_threshold` before that position, the object is regarded as yielding to ego vehicle. In this case ego is given the right-of-way by the yielding object but this module inserts stopline to prevent entry into the intersection.
If there is any stopped object on the attention lanelet between the intersection point with ego path and the position which is `yield_stuck.distance_threshold` before that position, the object is regarded as yielding to ego vehicle. In this case ego is given the right-of-way by the yielding object but this module inserts stopline to prevent entry into the intersection. This scene happens when the object is yieling against ego or the object is waiting before the crosswalk around the exit of the intersection.

Check warning on line 189 in planning/behavior_velocity_intersection_module/README.md

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (yieling)

Check warning on line 189 in planning/behavior_velocity_intersection_module/README.md

View workflow job for this annotation

GitHub Actions / spell-check-partial

Unknown word (yieling)

![yield_stuck_detection](./docs/yield-stuck.drawio.svg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1056,17 +1056,26 @@ IntersectionModule::DecisionResult IntersectionModule::modifyPathVelocityDetail(
// stuck vehicle detection is viable even if attention area is empty
// so this needs to be checked before attention area validation
const bool stuck_detected = checkStuckVehicle(planner_data_, path_lanelets);
if (stuck_detected && stuck_stopline_idx_opt) {
auto stuck_stopline_idx = stuck_stopline_idx_opt.value();
if (stuck_detected) {
if (is_private_area_ && planner_param_.stuck_vehicle.enable_private_area_stuck_disregard) {
if (
default_stopline_idx_opt &&
fromEgoDist(stuck_stopline_idx) < -planner_param_.common.stopline_overshoot_margin) {
stuck_stopline_idx = default_stopline_idx_opt.value();
}
} else {
return IntersectionModule::StuckStop{
closest_idx, stuck_stopline_idx, occlusion_peeking_stopline_idx_opt};
std::optional<size_t> stopline_idx = std::nullopt;
if (stuck_stopline_idx_opt) {
stopline_idx = stuck_stopline_idx_opt.value();
} else if (
default_stopline_idx_opt && fromEgoDist(default_stopline_idx_opt.value()) >
-planner_param_.common.stopline_overshoot_margin) {
stopline_idx = default_stopline_idx_opt.value();
} else if (
first_attention_stopline_idx_opt &&
fromEgoDist(first_attention_stopline_idx_opt.value()) >= 0.0) {
stopline_idx = closest_idx;
}

if (stopline_idx) {
return IntersectionModule::StuckStop{
closest_idx, stopline_idx.value(), occlusion_peeking_stopline_idx_opt};
}
}
}

Expand Down Expand Up @@ -1115,13 +1124,22 @@ IntersectionModule::DecisionResult IntersectionModule::modifyPathVelocityDetail(
// filter objects
auto target_objects = generateTargetObjects(intersection_lanelets, intersection_area);

// yield stuck vehicle detection is viable even if attention area is empty
// so this needs to be checked before attention area validation
const bool yield_stuck_detected = checkYieldStuckVehicle(
target_objects, interpolated_path_info, intersection_lanelets.attention_non_preceding_);
if (yield_stuck_detected && stuck_stopline_idx_opt) {
const auto stuck_stopline_idx = stuck_stopline_idx_opt.value();
return IntersectionModule::YieldStuckStop{closest_idx, stuck_stopline_idx};
std::optional<size_t> stopline_idx = std::nullopt;
if (stuck_stopline_idx_opt) {
stopline_idx = stuck_stopline_idx_opt.value();
} else if (
fromEgoDist(default_stopline_idx) > -planner_param_.common.stopline_overshoot_margin) {
stopline_idx = default_stopline_idx;
} else if (fromEgoDist(first_attention_stopline_idx) >= 0.0) {
stopline_idx = closest_idx;
}

if (stopline_idx) {
return IntersectionModule::YieldStuckStop{closest_idx, stopline_idx.value()};
}
}

Check notice on line 1144 in planning/behavior_velocity_intersection_module/src/scene_intersection.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Bumpy Road Ahead

IntersectionModule::modifyPathVelocityDetail increases from 5 to 7 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.

Check warning on line 1144 in planning/behavior_velocity_intersection_module/src/scene_intersection.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

IntersectionModule::modifyPathVelocityDetail increases in cyclomatic complexity from 82 to 89, 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.
const double is_amber_or_red =
Expand Down

0 comments on commit 35a55ab

Please sign in to comment.