Skip to content

Commit 47bcea4

Browse files
danielsanchezaransaka1-s
authored andcommitted
feat(lane_change_module): add general method to get turn signal for LC module (autowarefoundation#6627)
add general method to get turn signal for LC module Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com>
1 parent ea2d701 commit 47bcea4

File tree

3 files changed

+35
-56
lines changed

3 files changed

+35
-56
lines changed

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/scene.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ class NormalLaneChange : public LaneChangeBase
141141
const utils::path_safety_checker::RSSparams rss_params, const bool is_stuck,
142142
const bool check_safety = true) const override;
143143

144-
TurnSignalInfo calcTurnSignalInfo() override;
144+
std::optional<LaneChangePath> calcTerminalLaneChangePath(
145+
const lanelet::ConstLanelets & current_lanes,
146+
const lanelet::ConstLanelets & target_lanes) const;
145147

146148
bool isValidPath(const PathWithLaneId & path) const override;
147149

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

-2
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,6 @@ class LaneChangeBase
225225
LaneChangePaths * candidate_paths, const utils::path_safety_checker::RSSparams rss_params,
226226
const bool is_stuck, const bool check_safety) const = 0;
227227

228-
virtual TurnSignalInfo calcTurnSignalInfo() = 0;
229-
230228
virtual bool isValidPath(const PathWithLaneId & path) const = 0;
231229

232230
virtual bool isAbleToStopSafely() const = 0;

planning/behavior_path_lane_change_module/src/scene.cpp

+32-53
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,20 @@ void NormalLaneChange::resetParameters()
426426

427427
TurnSignalInfo NormalLaneChange::updateOutputTurnSignal()
428428
{
429-
TurnSignalInfo turn_signal_info = calcTurnSignalInfo();
430-
const auto [turn_signal_command, distance_to_vehicle_front] = utils::getPathTurnSignal(
431-
status_.current_lanes, status_.lane_change_path.shifted_path,
432-
status_.lane_change_path.info.shift_line, getEgoPose(), getEgoTwist().linear.x,
433-
planner_data_->parameters);
434-
turn_signal_info.turn_signal.command = turn_signal_command.command;
435-
436-
return turn_signal_info;
429+
const auto & pose = getEgoPose();
430+
const auto & current_lanes = status_.current_lanes;
431+
const auto & shift_line = status_.lane_change_path.info.shift_line;
432+
const auto & shift_path = status_.lane_change_path.shifted_path;
433+
const auto current_shift_length = lanelet::utils::getArcCoordinates(current_lanes, pose).distance;
434+
constexpr bool is_driving_forward = true;
435+
// The getBehaviorTurnSignalInfo method expects the shifted line to be generated off of the ego's
436+
// current lane, lane change is different, so we set this flag to false.
437+
constexpr bool egos_lane_is_shifted = false;
438+
439+
const auto [new_signal, is_ignore] = planner_data_->getBehaviorTurnSignalInfo(
440+
shift_path, shift_line, current_lanes, current_shift_length, is_driving_forward,
441+
egos_lane_is_shifted);
442+
return new_signal;
437443
}
438444

439445
lanelet::ConstLanelets NormalLaneChange::getCurrentLanes() const
@@ -1445,53 +1451,26 @@ PathSafetyStatus NormalLaneChange::isApprovedPathSafe() const
14451451
return safety_status;
14461452
}
14471453

1448-
TurnSignalInfo NormalLaneChange::calcTurnSignalInfo()
1454+
PathSafetyStatus NormalLaneChange::evaluateApprovedPathWithUnsafeHysteresis(
1455+
PathSafetyStatus approved_path_safety_status)
14491456
{
1450-
const auto get_blinker_pose = [](const PathWithLaneId & path, const double length) {
1451-
double accumulated_length = 0.0;
1452-
for (size_t i = 0; i < path.points.size() - 1; ++i) {
1453-
accumulated_length +=
1454-
tier4_autoware_utils::calcDistance2d(path.points.at(i), path.points.at(i + 1));
1455-
if (accumulated_length > length) {
1456-
return path.points.at(i).point.pose;
1457-
}
1458-
}
1459-
1460-
return path.points.front().point.pose;
1461-
};
1462-
1463-
const auto & path = status_.lane_change_path;
1464-
const auto & shifted_path = path.shifted_path.path;
1465-
1466-
TurnSignalInfo turn_signal_info{};
1467-
1468-
// desired start pose = prepare start pose
1469-
turn_signal_info.desired_start_point = std::invoke([&]() {
1470-
const auto blinker_start_duration = planner_data_->parameters.turn_signal_search_time;
1471-
const auto diff_time = path.info.duration.prepare - blinker_start_duration;
1472-
if (diff_time < 1e-5) {
1473-
return path.path.points.front().point.pose;
1457+
if (!approved_path_safety_status.is_safe) {
1458+
++unsafe_hysteresis_count_;
1459+
RCLCPP_DEBUG(
1460+
logger_, "%s: Increasing hysteresis count to %d.", __func__, unsafe_hysteresis_count_);
1461+
} else {
1462+
if (unsafe_hysteresis_count_ > 0) {
1463+
RCLCPP_DEBUG(logger_, "%s: Lane change is now SAFE. Resetting hysteresis count.", __func__);
14741464
}
1475-
1476-
const auto current_twist = getEgoTwist();
1477-
const auto diff_length = std::abs(current_twist.linear.x) * diff_time;
1478-
return get_blinker_pose(path.path, diff_length);
1479-
});
1480-
1481-
// desired end pose
1482-
const auto length_ratio =
1483-
std::clamp(lane_change_parameters_->length_ratio_for_turn_signal_deactivation, 0.0, 1.0);
1484-
const auto desired_end_length = path.info.length.lane_changing * length_ratio;
1485-
turn_signal_info.desired_end_point = get_blinker_pose(shifted_path, desired_end_length);
1486-
1487-
// required start pose = lane changing start pose
1488-
turn_signal_info.required_start_point = path.info.shift_line.start;
1489-
1490-
// required end pose = in the middle of the lane change
1491-
const auto mid_lane_change_length = path.info.length.lane_changing / 2;
1492-
turn_signal_info.required_end_point = get_blinker_pose(shifted_path, mid_lane_change_length);
1493-
1494-
return turn_signal_info;
1465+
unsafe_hysteresis_count_ = 0;
1466+
}
1467+
if (unsafe_hysteresis_count_ > lane_change_parameters_->cancel.unsafe_hysteresis_threshold) {
1468+
RCLCPP_DEBUG(
1469+
logger_, "%s: hysteresis count exceed threshold. lane change is now %s", __func__,
1470+
(approved_path_safety_status.is_safe ? "safe" : "UNSAFE"));
1471+
return approved_path_safety_status;
1472+
}
1473+
return {};
14951474
}
14961475

14971476
bool NormalLaneChange::isValidPath(const PathWithLaneId & path) const

0 commit comments

Comments
 (0)