Skip to content

Commit

Permalink
refactor(goal_planner): remove enable_safety_check because it is default
Browse files Browse the repository at this point in the history
Signed-off-by: Mamoru Sobue <[email protected]>
  • Loading branch information
soblin committed Jan 31, 2025
1 parent 9d29658 commit 8dcce5d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ In addition, the safety check has a time hysteresis, and if the path is judged "

| Name | Unit | Type | Description | Default value |
| :----------------------------------- | :---- | :----- | :------------------------------------------------------------------------------------------------------- | :--------------------------- |
| enable_safety_check | [-] | bool | flag whether to use safety check | true |
| method | [-] | string | method for safety check. `RSS` or `integral_predicted_polygon` | `integral_predicted_polygon` |
| keep_unsafe_time | [s] | double | safety check Hysteresis time. if the path is judged "safe" for the time it is finally treated as "safe". | 3.0 |
| check_all_predicted_path | - | bool | Flag to check all predicted paths | true |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,18 @@ PathDecisionState PathDecisionStateController::get_next_state(
auto next_state = current_state_;

// update safety
if (!parameters.safety_check_params.enable_safety_check) {
next_state.is_stable_safe = true;
} else {
if (is_current_safe) {
if (!next_state.safe_start_time) {
next_state.safe_start_time = now;
next_state.is_stable_safe = false;
} else {
next_state.is_stable_safe =
((now - next_state.safe_start_time.value()).seconds() >
parameters.safety_check_params.keep_unsafe_time);
}
} else {
next_state.safe_start_time = std::nullopt;
if (is_current_safe) {
if (!next_state.safe_start_time) {
next_state.safe_start_time = now;
next_state.is_stable_safe = false;
} else {
next_state.is_stable_safe =
((now - next_state.safe_start_time.value()).seconds() >
parameters.safety_check_params.keep_unsafe_time);
}
} else {
next_state.safe_start_time = std::nullopt;
next_state.is_stable_safe = false;
}

// Once this function returns true, it will continue to return true thereafter
Expand All @@ -87,10 +83,9 @@ PathDecisionState PathDecisionStateController::get_next_state(
}

const auto & pull_over_path = pull_over_path_opt.value();
const bool enable_safety_check = parameters.safety_check_params.enable_safety_check;
// If it is dangerous against dynamic objects before approval, do not determine the path.
// This eliminates a unsafe path to be approved
if (enable_safety_check && !next_state.is_stable_safe && !is_activated) {
if (!next_state.is_stable_safe && !is_activated) {

Check notice on line 88 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Complex Conditional

PathDecisionStateController::get_next_state no longer has a complex conditional
RCLCPP_DEBUG(
logger_,
"[DecidingPathStatus]: NOT_DECIDED. path is not safe against dynamic objects before "
Expand Down Expand Up @@ -132,7 +127,7 @@ PathDecisionState PathDecisionStateController::get_next_state(
return next_state;
}

if (enable_safety_check && !next_state.is_stable_safe) {
if (!next_state.is_stable_safe) {
RCLCPP_DEBUG(
logger_,
"[DecidingPathStatus]: DECIDING->NOT_DECIDED. path is not safe against dynamic objects");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ GoalPlannerModule::GoalPlannerModule(
is_lane_parking_cb_running_{false},
is_freespace_parking_cb_running_{false}
{
// TODO(soblin): remove safety_check_params.enable_safety_check because it does not make sense
if (!parameters_.safety_check_params.enable_safety_check) {
throw std::domain_error("goal_planner never works without safety check");
}

occupancy_grid_map_ = std::make_shared<OccupancyGridBasedCollisionDetector>();

// planner when goal modification is not allowed
Expand Down Expand Up @@ -2406,7 +2401,6 @@ std::pair<bool, utils::path_safety_checker::CollisionCheckDebugMap> GoalPlannerM
void GoalPlannerModule::setDebugData(const PullOverContextData & context_data)
{
universe_utils::ScopedTimeTrack st(__func__, *time_keeper_);

debug_marker_.markers.clear();

using autoware::motion_utils::createStopVirtualWallMarker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ GoalPlannerParameters GoalPlannerModuleManager::initGoalPlannerParameters(
{
p.safety_check_params.enable_safety_check =
node->declare_parameter<bool>(safety_check_ns + "enable_safety_check");
// NOTE(soblin): remove safety_check_params.enable_safety_check because it does not make sense
if (!p.safety_check_params.enable_safety_check) {
throw std::domain_error("goal_planner never works without safety check");
}

Check warning on line 374 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/manager.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Method

GoalPlannerModuleManager::initGoalPlannerParameters has a cyclomatic complexity of 9, 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 notice on line 374 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/manager.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Large Method

GoalPlannerModuleManager::initGoalPlannerParameters is no longer above the threshold for lines of code. Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function.
p.safety_check_params.keep_unsafe_time =
node->declare_parameter<double>(safety_check_ns + "keep_unsafe_time");
p.safety_check_params.method = node->declare_parameter<std::string>(safety_check_ns + "method");
Expand Down Expand Up @@ -786,9 +790,6 @@ void GoalPlannerModuleManager::updateModuleParams(
// SafetyCheckParams
const std::string safety_check_ns = path_safety_check_ns + "safety_check_params.";
{

Check notice on line 792 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/manager.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Large Method

GoalPlannerModuleManager::updateModuleParams decreases from 354 to 350 lines of code, threshold = 70. Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function.
updateParam<bool>(
parameters, safety_check_ns + "enable_safety_check",
p->safety_check_params.enable_safety_check);
updateParam<double>(
parameters, safety_check_ns + "keep_unsafe_time", p->safety_check_params.keep_unsafe_time);
updateParam<std::string>(parameters, safety_check_ns + "method", p->safety_check_params.method);
Expand Down

0 comments on commit 8dcce5d

Please sign in to comment.