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

refactor(start_planner): improve readability of end condition #7181

Merged
Show file tree
Hide file tree
Changes from 3 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
76 changes: 53 additions & 23 deletions planning/behavior_path_start_planner_module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,36 +91,66 @@ The `StartPlannerModule` is designed to initiate its execution based on specific

### **End Conditions**

The `StartPlannerModule` terminates if the pull out / freespace maneuver has been completed. The `canTransitSuccessState` function assesses these conditions to decide if the module should terminate its execution.
The `StartPlannerModule` terminates when specific conditions are met, depending on the type of planner being used. The `canTransitSuccessState` function determines whether the module should transition to the success state based on the following criteria:

```plantuml
@startuml
start
:Start hasFinishedPullOut();
#### When the Freespace Planner is active

if (status_.driving_forward && status_.found_pull_out_path) then (yes)
- If the end point of the freespace path is reached, the module transitions to the success state.

if (status_.planner_type == FREESPACE) then (yes)
:Calculate distance\nto pull_out_path.end_pose;
if (distance < th_arrived_distance) then (yes)
:return true;\n(Terminate module);
else (no)
:return false;\n(Continue running);
endif
else (no)
:Calculate arclength for\ncurrent_pose and pull_out_path.end_pose;
if (arclength_current - arclength_pull_out_end > offset) then (yes)
:return true;\n(Terminate module);
else (no)
:return false;\n(Continue running);
endif
endif
#### When any other type of planner is active

The transition to the success state is determined by the following conditions:

- If a reverse path is being generated or the search for a pull out path fails:
- The module does not transition to the success state.
- If the end point of the pull out path's shift section is reached:
- The module transitions to the success state.

The flowchart below illustrates the decision-making process in the `canTransitSuccessState` function:

```plantuml
@startuml
@startuml
skinparam ActivityBackgroundColor #white
skinparam ActivityBorderColor #black
skinparam ActivityBorderThickness 1
skinparam ActivityArrowColor #black
skinparam ActivityArrowThickness 1
skinparam ActivityStartColor #black
skinparam ActivityEndColor #black
skinparam ActivityDiamondBackgroundColor #white
skinparam ActivityDiamondBorderColor #black
skinparam ActivityDiamondFontColor #black
partition canTransitSuccessState() {
start
if (planner type is FREESPACE?) then (yes)
if (Has reached freespace end?) then (yes)
#FF006C:true;
stop
else (no)
:return false;\n(Continue running);
:false;
stop
endif
else (no)
if (driving is forward?) then (yes)
if (pull out path is found?) then (yes)
if (Has reached pull out end?) then (yes)
#FF006C:true;
stop
else (no)
:false;
stop
endif
else (no)
:false;
stop
endif
else (no)
:false;
stop
endif
endif
}
@enduml
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ class StartPlannerModule : public SceneModuleInterface
const double velocity_threshold, const double object_check_backward_distance,
const double object_check_forward_distance) const;
bool needToPrepareBlinkerBeforeStartDrivingForward() const;
bool hasFinishedPullOut() const;
bool hasReachedFreespaceEnd() const;
bool hasReachedPullOutEnd() const;
bool hasFinishedBackwardDriving() const;
bool hasCollisionWithDynamicObjects() const;
bool isStopped();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 TIER IV, Inc.

Check notice on line 1 in planning/behavior_path_start_planner_module/src/start_planner_module.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Lines of Code in a Single File

The lines of code increases from 1359 to 1363, improve code health by reducing it to 1000. The number of Lines of Code in a single file. More Lines of Code lowers the code health.
//
// 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 @@ -579,7 +579,25 @@

bool StartPlannerModule::canTransitSuccessState()
{
return hasFinishedPullOut();
// Freespace Planner:
// - Can transit to success if the goal position is reached.
// - Cannot transit to success if the goal position is not reached.
if (status_.planner_type == PlannerType::FREESPACE) {
return hasReachedFreespaceEnd();
}

// Other Planners:
// - Cannot transit to success if the vehicle is driving in reverse.
// - Cannot transit to success if a safe path cannot be found due to:
// - Insufficient margin against static objects.
// - No path found that stays within the lane.
// In such cases, a stop point needs to be embedded and keep running start_planner.
// - Can transit to success if the end point of the pullout path is reached.
if (!status_.driving_forward || !status_.found_pull_out_path) {
return false;
}

return hasReachedPullOutEnd();
}

BehaviorModuleOutput StartPlannerModule::plan()
Expand Down Expand Up @@ -1180,17 +1198,16 @@
return stop_objects_in_pull_out_lanes;
}

bool StartPlannerModule::hasFinishedPullOut() const
bool StartPlannerModule::hasReachedFreespaceEnd() const
{
if (!status_.driving_forward || !status_.found_pull_out_path) {
return false;
}
const auto current_pose = planner_data_->self_odometry->pose.pose;
kyoichi-sugahara marked this conversation as resolved.
Show resolved Hide resolved
return tier4_autoware_utils::calcDistance2d(current_pose, status_.pull_out_path.end_pose) <
parameters_->th_arrived_distance;
}

bool StartPlannerModule::hasReachedPullOutEnd() const
{
const auto current_pose = planner_data_->self_odometry->pose.pose;
if (status_.planner_type == PlannerType::FREESPACE) {
return tier4_autoware_utils::calcDistance2d(current_pose, status_.pull_out_path.end_pose) <
parameters_->th_arrived_distance;
}

// check that ego has passed pull out end point
const double backward_path_length =
Expand All @@ -1205,9 +1222,8 @@

// offset to not finish the module before engage
constexpr double offset = 0.1;
const bool has_finished = arclength_current.length - arclength_pull_out_end.length > offset;

return has_finished;
return arclength_current.length - arclength_pull_out_end.length > offset;
kyoichi-sugahara marked this conversation as resolved.
Show resolved Hide resolved
}

bool StartPlannerModule::needToPrepareBlinkerBeforeStartDrivingForward() const
Expand Down
Loading