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(lane_change): cancel hysteresis #6288

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
24 changes: 24 additions & 0 deletions planning/behavior_path_lane_change_module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,29 @@ detach
@enduml
```

To preventive measure for lane change path oscillations caused by alternating safe and unsafe conditions, an additional hysteresis count check is implemented before executing an abort or cancel maneuver. If unsafe, the `unsafe_hysteresis_count_` is incremented and compared against `unsafe_hysteresis_threshold`; exceeding it prompts an abort condition check, ensuring decisions are made with consideration to recent safety assessments as shown in flow chart above. This mechanism stabilizes decision-making, preventing abrupt changes due to transient unsafe conditions.

```plantuml
@startuml
skinparam defaultTextAlignment center
skinparam backgroundColor #WHITE

title Abort Lane Change

if (Perform collision check?) then (<color:green><b>SAFE</b></color>)
:Reset unsafe_hysteresis_count_;
else (<color:red><b>UNSAFE</b></color>)
:Increase unsafe_hysteresis_count_;
if (unsafe_hysteresis_count_ > unsafe_hysteresis_threshold?) then (<color:green><b>FALSE</b></color>)
else (<color:red><b>TRUE</b></color>)
#LightPink:Check abort condition;
stop
endif
endif
:Continue lane changing;
@enduml
```

#### Cancel

Suppose the lane change trajectory is evaluated as unsafe. In that case, if the ego vehicle has not departed from the current lane yet, the trajectory will be reset, and the ego vehicle will resume the lane following the maneuver.
Expand Down Expand Up @@ -430,6 +453,7 @@ The following parameters are configurable in `lane_change.param.yaml`.
| `cancel.duration` | [s] | double | The time taken to complete returning to the center line. | 3.0 |
| `cancel.max_lateral_jerk` | [m/sss] | double | The maximum lateral jerk for abort path | 1000.0 |
| `cancel.overhang_tolerance` | [m] | double | Lane change cancel is prohibited if the vehicle head exceeds the lane boundary more than this tolerance distance | 0.0 |
| `unsafe_hysteresis_threshold` | [-] | int | threshold that helps prevent frequent switching between safe and unsafe decisions | 10 |

### Debug

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
duration: 5.0 # [s]
max_lateral_jerk: 1000.0 # [m/s3]
overhang_tolerance: 0.0 # [m]
unsafe_hysteresis_threshold: 10 # [/]

finish_judge_lateral_threshold: 0.2 # [m]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define BEHAVIOR_PATH_LANE_CHANGE_MODULE__SCENE_HPP_

#include "behavior_path_lane_change_module/utils/base_class.hpp"
#include "behavior_path_lane_change_module/utils/data_structs.hpp"

#include <memory>
#include <utility>
Expand Down Expand Up @@ -73,6 +74,9 @@ class NormalLaneChange : public LaneChangeBase

PathSafetyStatus isApprovedPathSafe() const override;

PathSafetyStatus evaluateApprovedPathWithUnsafeHysteresis(
PathSafetyStatus approved_path_safety_status) override;

bool isRequiredStop(const bool is_object_coming_from_rear) override;

bool isNearEndOfCurrentLanes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class LaneChangeBase

virtual PathSafetyStatus isApprovedPathSafe() const = 0;

virtual PathSafetyStatus evaluateApprovedPathWithUnsafeHysteresis(
PathSafetyStatus approve_path_safety_status) = 0;

virtual bool isNearEndOfCurrentLanes(
const lanelet::ConstLanelets & current_lanes, const lanelet::ConstLanelets & target_lanes,
const double threshold) const = 0;
Expand Down Expand Up @@ -240,6 +243,7 @@ class LaneChangeBase

PathWithLaneId prev_approved_path_{};

int unsafe_hysteresis_count_{0};
bool is_abort_path_approved_{false};
bool is_abort_approval_requested_{false};
bool is_activated_{false};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ struct LaneChangeCancelParameters
double duration{5.0};
double max_lateral_jerk{10.0};
double overhang_tolerance{0.0};

// unsafe_hysteresis_threshold will be compare with the number of detected unsafe instance. If the
// number of unsafe exceeds unsafe_hysteresis_threshold, the lane change will be cancelled or
// aborted.
int unsafe_hysteresis_threshold{2};
};

struct LaneChangeParameters
Expand Down
7 changes: 6 additions & 1 deletion planning/behavior_path_lane_change_module/src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
{
module_type_->resetParameters();
debug_marker_.markers.clear();
post_process_safety_status_ = {};
resetPathCandidate();
}

Expand Down Expand Up @@ -91,7 +92,11 @@

void LaneChangeInterface::postProcess()
{
post_process_safety_status_ = module_type_->isApprovedPathSafe();
if (getCurrentStatus() == ModuleStatus::RUNNING) {
const auto safety_status = module_type_->isApprovedPathSafe();

Check warning on line 96 in planning/behavior_path_lane_change_module/src/interface.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_lane_change_module/src/interface.cpp#L96

Added line #L96 was not covered by tests
post_process_safety_status_ =
module_type_->evaluateApprovedPathWithUnsafeHysteresis(safety_status);

Check warning on line 98 in planning/behavior_path_lane_change_module/src/interface.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_lane_change_module/src/interface.cpp#L98

Added line #L98 was not covered by tests
}
}

BehaviorModuleOutput LaneChangeInterface::plan()
Expand Down
4 changes: 4 additions & 0 deletions planning/behavior_path_lane_change_module/src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@
getOrDeclareParameter<double>(*node, parameter("cancel.max_lateral_jerk"));
p.cancel.overhang_tolerance =
getOrDeclareParameter<double>(*node, parameter("cancel.overhang_tolerance"));
p.cancel.unsafe_hysteresis_threshold =
getOrDeclareParameter<int>(*node, parameter("cancel.unsafe_hysteresis_threshold"));

Check warning on line 219 in planning/behavior_path_lane_change_module/src/manager.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

LaneChangeModuleManager::initParams already has high cyclomatic complexity, and now it increases in Lines of Code from 191 to 193. 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.finish_judge_lateral_threshold =
getOrDeclareParameter<double>(*node, parameter("finish_judge_lateral_threshold"));
Expand Down Expand Up @@ -376,6 +378,8 @@
updateParam<double>(parameters, ns + "duration", p->cancel.duration);
updateParam<double>(parameters, ns + "max_lateral_jerk", p->cancel.max_lateral_jerk);
updateParam<double>(parameters, ns + "overhang_tolerance", p->cancel.overhang_tolerance);
updateParam<int>(
parameters, ns + "unsafe_hysteresis_threshold", p->cancel.unsafe_hysteresis_threshold);

Check warning on line 382 in planning/behavior_path_lane_change_module/src/manager.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Large Method

LaneChangeModuleManager::updateModuleParams increases from 91 to 93 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.
}
std::for_each(observers_.begin(), observers_.end(), [&p](const auto & observer) {
if (!observer.expired()) observer.lock()->updateModuleParams(p);
Expand Down
23 changes: 23 additions & 0 deletions planning/behavior_path_lane_change_module/src/scene.cpp
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_lane_change_module/src/scene.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 1631 to 1653, 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.

Check notice on line 1 in planning/behavior_path_lane_change_module/src/scene.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 5.41 to 5.40, 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 @@ -474,6 +474,7 @@
current_lane_change_state_ = LaneChangeStates::Normal;
abort_path_ = nullptr;
status_ = {};
unsafe_hysteresis_count_ = 0;

Check warning on line 477 in planning/behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_lane_change_module/src/scene.cpp#L477

Added line #L477 was not covered by tests
lane_change_debug_.reset();

RCLCPP_DEBUG(logger_, "reset all flags and debug information.");
Expand Down Expand Up @@ -1665,6 +1666,28 @@
return safety_status;
}

PathSafetyStatus NormalLaneChange::evaluateApprovedPathWithUnsafeHysteresis(

Check warning on line 1669 in planning/behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_lane_change_module/src/scene.cpp#L1669

Added line #L1669 was not covered by tests
PathSafetyStatus approved_path_safety_status)
{
if (!approved_path_safety_status.is_safe) {
++unsafe_hysteresis_count_;

Check warning on line 1673 in planning/behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_lane_change_module/src/scene.cpp#L1673

Added line #L1673 was not covered by tests
RCLCPP_DEBUG(
logger_, "%s: Increasing hysteresis count to %d.", __func__, unsafe_hysteresis_count_);
} else {
if (unsafe_hysteresis_count_ > 0) {
RCLCPP_DEBUG(logger_, "%s: Lane change is now SAFE. Resetting hysteresis count.", __func__);
}
unsafe_hysteresis_count_ = 0;

Check warning on line 1680 in planning/behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_lane_change_module/src/scene.cpp#L1680

Added line #L1680 was not covered by tests
}
if (unsafe_hysteresis_count_ > lane_change_parameters_->cancel.unsafe_hysteresis_threshold) {
RCLCPP_DEBUG(
logger_, "%s: hysteresis count exceed threshold. lane change is now %s", __func__,
(approved_path_safety_status.is_safe ? "safe" : "UNSAFE"));
return approved_path_safety_status;

Check warning on line 1686 in planning/behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_lane_change_module/src/scene.cpp#L1686

Added line #L1686 was not covered by tests
}
return {};

Check warning on line 1688 in planning/behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_lane_change_module/src/scene.cpp#L1688

Added line #L1688 was not covered by tests
}

TurnSignalInfo NormalLaneChange::calcTurnSignalInfo() const
{
const auto get_blinker_pose = [](const PathWithLaneId & path, const double length) {
Expand Down
Loading