Skip to content

Commit 2c42fdb

Browse files
authored
Merge pull request #1141 from tier4/feat/wait_approval_at_abort
feat(lane_change): terminal lane change and abort behavior
2 parents 3669810 + 196a688 commit 2c42fdb

File tree

7 files changed

+312
-68
lines changed

7 files changed

+312
-68
lines changed

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/scene.hpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ class NormalLaneChange : public LaneChangeBase
5353

5454
LaneChangePath getLaneChangePath() const override;
5555

56+
BehaviorModuleOutput getTerminalLaneChangePath() const override;
57+
5658
BehaviorModuleOutput generateOutput() override;
5759

58-
void extendOutputDrivableArea(BehaviorModuleOutput & output) override;
60+
void extendOutputDrivableArea(BehaviorModuleOutput & output) const override;
5961

6062
void insertStopPoint(const lanelet::ConstLanelets & lanelets, PathWithLaneId & path) override;
6163

@@ -65,7 +67,7 @@ class NormalLaneChange : public LaneChangeBase
6567

6668
void resetParameters() override;
6769

68-
TurnSignalInfo updateOutputTurnSignal() override;
70+
TurnSignalInfo updateOutputTurnSignal() const override;
6971

7072
bool calcAbortPath() override;
7173

@@ -89,7 +91,7 @@ class NormalLaneChange : public LaneChangeBase
8991

9092
bool isAbortState() const override;
9193

92-
bool isLaneChangeRequired() const override;
94+
bool isLaneChangeRequired() override;
9395

9496
bool isStoppedAtRedTrafficLight() const override;
9597

@@ -141,7 +143,11 @@ class NormalLaneChange : public LaneChangeBase
141143
const utils::path_safety_checker::RSSparams rss_params, const bool is_stuck,
142144
const bool check_safety = true) const override;
143145

144-
TurnSignalInfo calcTurnSignalInfo() override;
146+
std::optional<LaneChangePath> calcTerminalLaneChangePath(
147+
const lanelet::ConstLanelets & current_lanes,
148+
const lanelet::ConstLanelets & target_lanes) const;
149+
150+
TurnSignalInfo calcTurnSignalInfo() const override;
145151

146152
bool isValidPath(const PathWithLaneId & path) const override;
147153

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,30 @@ class LaneChangeBase
6666

6767
virtual BehaviorModuleOutput generateOutput() = 0;
6868

69-
virtual void extendOutputDrivableArea(BehaviorModuleOutput & output) = 0;
69+
virtual void extendOutputDrivableArea(BehaviorModuleOutput & output) const = 0;
7070

7171
virtual PathWithLaneId getReferencePath() const = 0;
7272

7373
virtual std::optional<PathWithLaneId> extendPath() = 0;
7474

7575
virtual void resetParameters() = 0;
7676

77-
virtual TurnSignalInfo updateOutputTurnSignal() = 0;
77+
virtual TurnSignalInfo updateOutputTurnSignal() const = 0;
7878

7979
virtual bool hasFinishedLaneChange() const = 0;
8080

8181
virtual bool hasFinishedAbort() const = 0;
8282

83-
virtual bool isLaneChangeRequired() const = 0;
83+
virtual bool isLaneChangeRequired() = 0;
8484

8585
virtual bool isAbortState() const = 0;
8686

8787
virtual bool isAbleToReturnCurrentLane() const = 0;
8888

8989
virtual LaneChangePath getLaneChangePath() const = 0;
9090

91+
virtual BehaviorModuleOutput getTerminalLaneChangePath() const = 0;
92+
9193
virtual bool isEgoOnPreparePhase() const = 0;
9294

9395
virtual bool isRequiredStop(const bool is_object_coming_from_rear) = 0;
@@ -225,7 +227,7 @@ class LaneChangeBase
225227
LaneChangePaths * candidate_paths, const utils::path_safety_checker::RSSparams rss_params,
226228
const bool is_stuck, const bool check_safety) const = 0;
227229

228-
virtual TurnSignalInfo calcTurnSignalInfo() = 0;
230+
virtual TurnSignalInfo calcTurnSignalInfo() const = 0;
229231

230232
virtual bool isValidPath(const PathWithLaneId & path) const = 0;
231233

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/utils/path.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct LaneChangeStatus
4545
std::vector<lanelet::Id> lane_follow_lane_ids{};
4646
std::vector<lanelet::Id> lane_change_lane_ids{};
4747
bool is_safe{false};
48-
bool is_valid_path{true};
48+
bool is_valid_path{false};
4949
double start_distance{0.0};
5050
};
5151

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

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ ShiftLine getLaneChangingShiftLine(
115115
const PathWithLaneId & prepare_segment, const PathWithLaneId & target_segment,
116116
const PathWithLaneId & reference_path, const double shift_length);
117117

118+
ShiftLine getLaneChangingShiftLine(
119+
const Pose & lane_changing_start_pose, const Pose & lane_changing_end_pose,
120+
const PathWithLaneId & reference_path, const double shift_length);
121+
118122
PathWithLaneId getReferencePathFromTargetLane(
119123
const RouteHandler & route_handler, const lanelet::ConstLanelets & target_lanes,
120124
const Pose & lane_changing_start_pose, const double target_lane_length,

planning/behavior_path_lane_change_module/src/interface.cpp

+26-27
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ LaneChangeInterface::LaneChangeInterface(
5050
void LaneChangeInterface::processOnEntry()
5151
{
5252
waitApproval();
53-
module_type_->setPreviousModulePaths(
54-
getPreviousModuleOutput().reference_path, getPreviousModuleOutput().path);
55-
module_type_->updateLaneChangeStatus();
5653
}
5754

5855
void LaneChangeInterface::processOnExit()
@@ -73,13 +70,21 @@ bool LaneChangeInterface::isExecutionRequested() const
7370

7471
bool LaneChangeInterface::isExecutionReady() const
7572
{
76-
return module_type_->isSafe();
73+
return module_type_->isSafe() && !module_type_->isAbortState();
7774
}
7875

7976
void LaneChangeInterface::updateData()
8077
{
8178
module_type_->setPreviousModulePaths(
8279
getPreviousModuleOutput().reference_path, getPreviousModuleOutput().path);
80+
module_type_->setPreviousDrivableAreaInfo(getPreviousModuleOutput().drivable_area_info);
81+
module_type_->setPreviousTurnSignalInfo(getPreviousModuleOutput().turn_signal_info);
82+
83+
if (isWaitingApproval()) {
84+
module_type_->updateLaneChangeStatus();
85+
}
86+
setObjectDebugVisualization();
87+
8388
module_type_->updateSpecialData();
8489
module_type_->resetStopPose();
8590
}
@@ -98,8 +103,6 @@ BehaviorModuleOutput LaneChangeInterface::plan()
98103
return {};
99104
}
100105

101-
module_type_->setPreviousDrivableAreaInfo(getPreviousModuleOutput().drivable_area_info);
102-
module_type_->setPreviousTurnSignalInfo(getPreviousModuleOutput().turn_signal_info);
103106
auto output = module_type_->generateOutput();
104107
path_reference_ = std::make_shared<PathWithLaneId>(output.reference_path);
105108
*prev_approved_path_ = getPreviousModuleOutput().path;
@@ -112,38 +115,36 @@ BehaviorModuleOutput LaneChangeInterface::plan()
112115
}
113116

114117
updateSteeringFactorPtr(output);
115-
clearWaitingApproval();
118+
if (module_type_->isAbortState()) {
119+
waitApproval();
120+
removeRTCStatus();
121+
const auto candidate = planCandidate();
122+
path_candidate_ = std::make_shared<PathWithLaneId>(candidate.path_candidate);
123+
updateRTCStatus(
124+
candidate.start_distance_to_path_change, candidate.finish_distance_to_path_change);
125+
} else {
126+
clearWaitingApproval();
127+
}
116128

117129
return output;
118130
}
119131

120132
BehaviorModuleOutput LaneChangeInterface::planWaitingApproval()
121133
{
122134
*prev_approved_path_ = getPreviousModuleOutput().path;
123-
module_type_->insertStopPoint(
124-
module_type_->getLaneChangeStatus().current_lanes, *prev_approved_path_);
125135

126136
BehaviorModuleOutput out;
127-
out.path = *prev_approved_path_;
128-
out.reference_path = getPreviousModuleOutput().reference_path;
129-
out.turn_signal_info = getPreviousModuleOutput().turn_signal_info;
130-
out.drivable_area_info = getPreviousModuleOutput().drivable_area_info;
131-
132-
module_type_->setPreviousModulePaths(
133-
getPreviousModuleOutput().reference_path, getPreviousModuleOutput().path);
134-
module_type_->updateLaneChangeStatus();
135-
setObjectDebugVisualization();
137+
out = module_type_->getTerminalLaneChangePath();
138+
module_type_->insertStopPoint(module_type_->getLaneChangeStatus().current_lanes, out.path);
139+
out.turn_signal_info =
140+
getCurrentTurnSignalInfo(out.path, getPreviousModuleOutput().turn_signal_info);
136141

137142
for (const auto & [uuid, data] : module_type_->getDebugData()) {
138143
const auto color = data.is_safe ? ColorName::GREEN : ColorName::RED;
139144
setObjectsOfInterestData(data.current_obj_pose, data.obj_shape, color);
140145
}
141146

142-
// change turn signal when the vehicle reaches at the end of the path for waiting lane change
143-
out.turn_signal_info = getCurrentTurnSignalInfo(out.path, out.turn_signal_info);
144-
145147
path_reference_ = std::make_shared<PathWithLaneId>(getPreviousModuleOutput().reference_path);
146-
147148
stop_pose_ = module_type_->getStopPose();
148149

149150
if (!module_type_->isValidPath()) {
@@ -211,6 +212,7 @@ bool LaneChangeInterface::canTransitSuccessState()
211212
}
212213

213214
if (module_type_->hasFinishedLaneChange()) {
215+
module_type_->resetParameters();
214216
log_debug_throttled("Lane change process has completed.");
215217
return true;
216218
}
@@ -468,16 +470,13 @@ TurnSignalInfo LaneChangeInterface::getCurrentTurnSignalInfo(
468470
const double buffer =
469471
next_lane_change_buffer + min_length_for_turn_signal_activation + base_to_front;
470472
const double path_length = motion_utils::calcArcLength(path.points);
471-
const auto & front_point = path.points.front().point.pose.position;
472473
const size_t & current_nearest_seg_idx =
473474
motion_utils::findFirstNearestSegmentIndexWithSoftConstraints(
474475
path.points, current_pose, nearest_dist_threshold, nearest_yaw_threshold);
475-
const double length_front_to_ego = motion_utils::calcSignedArcLength(
476-
path.points, front_point, static_cast<size_t>(0), current_pose.position,
477-
current_nearest_seg_idx);
476+
const double dist_to_terminal = utils::getDistanceToEndOfLane(current_pose, current_lanes);
478477
const auto start_pose =
479478
motion_utils::calcLongitudinalOffsetPose(path.points, 0, std::max(path_length - buffer, 0.0));
480-
if (path_length - length_front_to_ego < buffer && start_pose) {
479+
if (dist_to_terminal - base_to_front < buffer && start_pose) {
481480
// modify turn signal
482481
current_turn_signal_info.desired_start_point = *start_pose;
483482
current_turn_signal_info.desired_end_point = lane_change_path.info.lane_changing_end;

0 commit comments

Comments
 (0)