Skip to content

Commit c8c1eb2

Browse files
feat(lane_change): cancel hysteresis
Signed-off-by: Muhammad Zulfaqar Azmi <zulfaqar.azmi@tier4.jp>
1 parent 2e4b25a commit c8c1eb2

File tree

7 files changed

+50
-1
lines changed

7 files changed

+50
-1
lines changed

planning/behavior_path_lane_change_module/config/lane_change.param.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
duration: 5.0 # [s]
104104
max_lateral_jerk: 1000.0 # [m/s3]
105105
overhang_tolerance: 0.0 # [m]
106+
unsafe_hysteresis_threshold: 10 # [/]
106107

107108
finish_judge_lateral_threshold: 0.2 # [m]
108109

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/scene.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define BEHAVIOR_PATH_LANE_CHANGE_MODULE__SCENE_HPP_
1616

1717
#include "behavior_path_lane_change_module/utils/base_class.hpp"
18+
#include "behavior_path_lane_change_module/utils/data_structs.hpp"
1819

1920
#include <memory>
2021
#include <utility>
@@ -73,6 +74,9 @@ class NormalLaneChange : public LaneChangeBase
7374

7475
PathSafetyStatus isApprovedPathSafe() const override;
7576

77+
PathSafetyStatus evaluateApprovedPathWithUnsafeHysteresis(
78+
PathSafetyStatus approved_path_safety_status) override;
79+
7680
bool isRequiredStop(const bool is_object_coming_from_rear) override;
7781

7882
bool isNearEndOfCurrentLanes(

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/utils/base_class.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class LaneChangeBase
9696

9797
virtual PathSafetyStatus isApprovedPathSafe() const = 0;
9898

99+
virtual PathSafetyStatus evaluateApprovedPathWithUnsafeHysteresis(
100+
PathSafetyStatus approve_path_safety_status) = 0;
101+
99102
virtual bool isNearEndOfCurrentLanes(
100103
const lanelet::ConstLanelets & current_lanes, const lanelet::ConstLanelets & target_lanes,
101104
const double threshold) const = 0;
@@ -240,6 +243,7 @@ class LaneChangeBase
240243

241244
PathWithLaneId prev_approved_path_{};
242245

246+
int unsafe_hysteresis_count_{0};
243247
bool is_abort_path_approved_{false};
244248
bool is_abort_approval_requested_{false};
245249
bool is_activated_{false};

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/utils/data_structs.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ struct LaneChangeCancelParameters
7575
double duration{5.0};
7676
double max_lateral_jerk{10.0};
7777
double overhang_tolerance{0.0};
78+
79+
// unsafe_hysteresis_threshold will be compare with the number of detected unsafe instance. If the
80+
// number of unsafe exceeds unsafe_hysteresis_threshold, the lane change will be cancelled or
81+
// aborted.
82+
int unsafe_hysteresis_threshold{2};
7883
};
7984

8085
struct LaneChangeParameters

planning/behavior_path_lane_change_module/src/interface.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ void LaneChangeInterface::processOnExit()
5656
{
5757
module_type_->resetParameters();
5858
debug_marker_.markers.clear();
59+
post_process_safety_status_ = {};
5960
resetPathCandidate();
6061
}
6162

@@ -91,7 +92,11 @@ void LaneChangeInterface::updateData()
9192

9293
void LaneChangeInterface::postProcess()
9394
{
94-
post_process_safety_status_ = module_type_->isApprovedPathSafe();
95+
if (getCurrentStatus() == ModuleStatus::RUNNING) {
96+
const auto safety_status = module_type_->isApprovedPathSafe();
97+
post_process_safety_status_ =
98+
module_type_->evaluateApprovedPathWithUnsafeHysteresis(safety_status);
99+
}
95100
}
96101

97102
BehaviorModuleOutput LaneChangeInterface::plan()

planning/behavior_path_lane_change_module/src/manager.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ void LaneChangeModuleManager::initParams(rclcpp::Node * node)
215215
getOrDeclareParameter<double>(*node, parameter("cancel.max_lateral_jerk"));
216216
p.cancel.overhang_tolerance =
217217
getOrDeclareParameter<double>(*node, parameter("cancel.overhang_tolerance"));
218+
p.cancel.unsafe_hysteresis_threshold =
219+
getOrDeclareParameter<int>(*node, parameter("cancel.unsafe_hysteresis_threshold"));
218220

219221
p.finish_judge_lateral_threshold =
220222
getOrDeclareParameter<double>(*node, parameter("finish_judge_lateral_threshold"));
@@ -283,6 +285,11 @@ void LaneChangeModuleManager::updateModuleParams(const std::vector<rclcpp::Param
283285
updateParam<double>(
284286
parameters, ns + "finish_judge_lateral_threshold", p->finish_judge_lateral_threshold);
285287

288+
{
289+
const std::string ns = "lane_change.cancel.";
290+
updateParam<int>(
291+
parameters, ns + "unsafe_hysteresis_threshold", p->cancel.unsafe_hysteresis_threshold);
292+
}
286293
std::for_each(observers_.begin(), observers_.end(), [&p](const auto & observer) {
287294
if (!observer.expired()) observer.lock()->updateModuleParams(p);
288295
});

planning/behavior_path_lane_change_module/src/scene.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ void NormalLaneChange::resetParameters()
474474
current_lane_change_state_ = LaneChangeStates::Normal;
475475
abort_path_ = nullptr;
476476
status_ = {};
477+
unsafe_hysteresis_count_ = 0;
477478
lane_change_debug_.reset();
478479

479480
RCLCPP_DEBUG(logger_, "reset all flags and debug information.");
@@ -1665,6 +1666,28 @@ PathSafetyStatus NormalLaneChange::isApprovedPathSafe() const
16651666
return safety_status;
16661667
}
16671668

1669+
PathSafetyStatus NormalLaneChange::evaluateApprovedPathWithUnsafeHysteresis(
1670+
PathSafetyStatus approved_path_safety_status)
1671+
{
1672+
if (!approved_path_safety_status.is_safe) {
1673+
++unsafe_hysteresis_count_;
1674+
RCLCPP_DEBUG(
1675+
logger_, "%s: Increasing hysteresis count to %d.", __func__, unsafe_hysteresis_count_);
1676+
} else {
1677+
if (unsafe_hysteresis_count_ > 0) {
1678+
RCLCPP_DEBUG(logger_, "%s: Lane change is now SAFE. Resetting hysteresis count.", __func__);
1679+
}
1680+
unsafe_hysteresis_count_ = 0;
1681+
}
1682+
if (unsafe_hysteresis_count_ > lane_change_parameters_->cancel.unsafe_hysteresis_threshold) {
1683+
RCLCPP_DEBUG(
1684+
logger_, "%s: hysteresis count exceed threshold. lane change is now %s", __func__,
1685+
(approved_path_safety_status.is_safe ? "safe" : "UNSAFE"));
1686+
return approved_path_safety_status;
1687+
}
1688+
return {};
1689+
}
1690+
16681691
TurnSignalInfo NormalLaneChange::calcTurnSignalInfo() const
16691692
{
16701693
const auto get_blinker_pose = [](const PathWithLaneId & path, const double length) {

0 commit comments

Comments
 (0)