Skip to content

Commit e11b1f4

Browse files
refactor(lane_change): make return previous output a common function (#6784)
* refactor(lane_change): make return previous output a common function Signed-off-by: Zulfaqar Azmi <zulfaqar.azmi@tier4.jp> * Replace all prev module's variable Signed-off-by: Zulfaqar Azmi <zulfaqar.azmi@tier4.jp> * fix build error in ablc Signed-off-by: Zulfaqar Azmi <zulfaqar.azmi@tier4.jp> * slight refactoring Signed-off-by: Zulfaqar Azmi <zulfaqar.azmi@tier4.jp> --------- Signed-off-by: Zulfaqar Azmi <zulfaqar.azmi@tier4.jp>
1 parent b34e520 commit e11b1f4

File tree

4 files changed

+29
-69
lines changed

4 files changed

+29
-69
lines changed

planning/behavior_path_avoidance_by_lane_change_module/src/scene.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ AvoidancePlanningData AvoidanceByLaneChange::calcAvoidancePlanningData(
125125
// reference pose
126126
data.reference_pose = getEgoPose();
127127

128-
data.reference_path_rough = prev_module_path_;
128+
data.reference_path_rough = prev_module_output_.path;
129129

130130
const auto resample_interval = avoidance_parameters_->resample_interval_for_planning;
131131
data.reference_path = utils::resamplePathWithSpline(data.reference_path_rough, resample_interval);

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

+3-22
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,9 @@ class LaneChangeBase
111111

112112
virtual bool specialExpiredCheck() const { return false; }
113113

114-
virtual void setPreviousModulePaths(
115-
const PathWithLaneId & prev_module_reference_path, const PathWithLaneId & prev_module_path)
114+
void setPreviousModuleOutput(const BehaviorModuleOutput & prev_module_output)
116115
{
117-
if (!prev_module_reference_path.points.empty()) {
118-
prev_module_reference_path_ = prev_module_reference_path;
119-
}
120-
if (!prev_module_path.points.empty()) {
121-
prev_module_path_ = prev_module_path;
122-
}
123-
};
124-
125-
virtual void setPreviousDrivableAreaInfo(const DrivableAreaInfo & prev_drivable_area_info)
126-
{
127-
prev_drivable_area_info_ = prev_drivable_area_info;
128-
}
129-
130-
virtual void setPreviousTurnSignalInfo(const TurnSignalInfo & prev_turn_signal_info)
131-
{
132-
prev_turn_signal_info_ = prev_turn_signal_info;
116+
prev_module_output_ = prev_module_output;
133117
}
134118

135119
virtual void updateSpecialData() {}
@@ -233,10 +217,7 @@ class LaneChangeBase
233217
std::shared_ptr<LaneChangeParameters> lane_change_parameters_{};
234218
std::shared_ptr<LaneChangePath> abort_path_{};
235219
std::shared_ptr<const PlannerData> planner_data_{};
236-
PathWithLaneId prev_module_reference_path_{};
237-
PathWithLaneId prev_module_path_{};
238-
DrivableAreaInfo prev_drivable_area_info_{};
239-
TurnSignalInfo prev_turn_signal_info_{};
220+
BehaviorModuleOutput prev_module_output_{};
240221
std::optional<Pose> lane_change_stop_pose_{std::nullopt};
241222

242223
PathWithLaneId prev_approved_path_{};

planning/behavior_path_lane_change_module/src/interface.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ bool LaneChangeInterface::isExecutionReady() const
7676

7777
void LaneChangeInterface::updateData()
7878
{
79-
module_type_->setPreviousModulePaths(
80-
getPreviousModuleOutput().reference_path, getPreviousModuleOutput().path);
81-
module_type_->setPreviousDrivableAreaInfo(getPreviousModuleOutput().drivable_area_info);
82-
module_type_->setPreviousTurnSignalInfo(getPreviousModuleOutput().turn_signal_info);
79+
module_type_->setPreviousModuleOutput(getPreviousModuleOutput());
8380
module_type_->updateSpecialData();
8481

8582
if (isWaitingApproval()) {

planning/behavior_path_lane_change_module/src/scene.cpp

+24-42
Original file line numberDiff line numberDiff line change
@@ -140,73 +140,56 @@ LaneChangePath NormalLaneChange::getLaneChangePath() const
140140

141141
BehaviorModuleOutput NormalLaneChange::getTerminalLaneChangePath() const
142142
{
143-
BehaviorModuleOutput output;
143+
auto output = prev_module_output_;
144144

145145
if (isAbortState() && abort_path_) {
146146
output.path = abort_path_->path;
147-
output.reference_path = prev_module_reference_path_;
148-
output.turn_signal_info = prev_turn_signal_info_;
149147
extendOutputDrivableArea(output);
150148
const auto current_seg_idx = planner_data_->findEgoSegmentIndex(output.path.points);
151149
output.turn_signal_info = planner_data_->turn_signal_decider.use_prior_turn_signal(
152-
output.path, getEgoPose(), current_seg_idx, prev_turn_signal_info_, output.turn_signal_info,
153-
planner_data_->parameters.ego_nearest_dist_threshold,
150+
output.path, getEgoPose(), current_seg_idx, prev_module_output_.turn_signal_info,
151+
output.turn_signal_info, planner_data_->parameters.ego_nearest_dist_threshold,
154152
planner_data_->parameters.ego_nearest_yaw_threshold);
155153
return output;
156154
}
157155

158156
const auto current_lanes = getCurrentLanes();
159157
if (current_lanes.empty()) {
160-
RCLCPP_WARN(logger_, "Current lanes not found!!! Something wrong.");
161-
output.path = prev_module_path_;
162-
output.reference_path = prev_module_reference_path_;
163-
output.drivable_area_info = prev_drivable_area_info_;
164-
output.turn_signal_info = prev_turn_signal_info_;
165-
return output;
158+
RCLCPP_DEBUG(logger_, "Current lanes not found. Returning previous module's path as output.");
159+
return prev_module_output_;
166160
}
167161

168162
const auto terminal_path =
169163
calcTerminalLaneChangePath(current_lanes, getLaneChangeLanes(current_lanes, direction_));
170164
if (!terminal_path) {
171-
RCLCPP_DEBUG(logger_, "Terminal path not found!!!");
172-
output.path = prev_module_path_;
173-
output.reference_path = prev_module_reference_path_;
174-
output.drivable_area_info = prev_drivable_area_info_;
175-
output.turn_signal_info = prev_turn_signal_info_;
176-
return output;
165+
RCLCPP_DEBUG(logger_, "Terminal path not found. Returning previous module's path as output.");
166+
return prev_module_output_;
177167
}
178168

179169
output.path = terminal_path->path;
180-
output.reference_path = prev_module_reference_path_;
181170
output.turn_signal_info = updateOutputTurnSignal();
182171

183172
extendOutputDrivableArea(output);
184173

185174
const auto current_seg_idx = planner_data_->findEgoSegmentIndex(output.path.points);
186175
output.turn_signal_info = planner_data_->turn_signal_decider.use_prior_turn_signal(
187-
output.path, getEgoPose(), current_seg_idx, prev_turn_signal_info_, output.turn_signal_info,
188-
planner_data_->parameters.ego_nearest_dist_threshold,
176+
output.path, getEgoPose(), current_seg_idx, prev_module_output_.turn_signal_info,
177+
output.turn_signal_info, planner_data_->parameters.ego_nearest_dist_threshold,
189178
planner_data_->parameters.ego_nearest_yaw_threshold);
190179

191180
return output;
192181
}
193182

194183
BehaviorModuleOutput NormalLaneChange::generateOutput()
195184
{
196-
BehaviorModuleOutput output;
197-
198185
if (!status_.is_valid_path) {
199-
output.path = prev_module_path_;
200-
output.reference_path = prev_module_reference_path_;
201-
output.drivable_area_info = prev_drivable_area_info_;
202-
output.turn_signal_info = prev_turn_signal_info_;
203-
return output;
186+
RCLCPP_DEBUG(logger_, "No valid path found. Returning previous module's path as output.");
187+
return prev_module_output_;
204188
}
205189

190+
auto output = prev_module_output_;
206191
if (isAbortState() && abort_path_) {
207192
output.path = abort_path_->path;
208-
output.reference_path = prev_module_reference_path_;
209-
output.turn_signal_info = prev_turn_signal_info_;
210193
insertStopPoint(status_.current_lanes, output.path);
211194
} else {
212195
output.path = getLaneChangePath().path;
@@ -235,8 +218,8 @@ BehaviorModuleOutput NormalLaneChange::generateOutput()
235218

236219
const auto current_seg_idx = planner_data_->findEgoSegmentIndex(output.path.points);
237220
output.turn_signal_info = planner_data_->turn_signal_decider.use_prior_turn_signal(
238-
output.path, getEgoPose(), current_seg_idx, prev_turn_signal_info_, output.turn_signal_info,
239-
planner_data_->parameters.ego_nearest_dist_threshold,
221+
output.path, getEgoPose(), current_seg_idx, prev_module_output_.turn_signal_info,
222+
output.turn_signal_info, planner_data_->parameters.ego_nearest_dist_threshold,
240223
planner_data_->parameters.ego_nearest_yaw_threshold);
241224

242225
return output;
@@ -256,8 +239,8 @@ void NormalLaneChange::extendOutputDrivableArea(BehaviorModuleOutput & output) c
256239
// for new architecture
257240
DrivableAreaInfo current_drivable_area_info;
258241
current_drivable_area_info.drivable_lanes = expanded_lanes;
259-
output.drivable_area_info =
260-
utils::combineDrivableAreaInfo(current_drivable_area_info, prev_drivable_area_info_);
242+
output.drivable_area_info = utils::combineDrivableAreaInfo(
243+
current_drivable_area_info, prev_module_output_.drivable_area_info);
261244
}
262245

263246
void NormalLaneChange::insertStopPoint(
@@ -506,7 +489,7 @@ TurnSignalInfo NormalLaneChange::updateOutputTurnSignal() const
506489

507490
lanelet::ConstLanelets NormalLaneChange::getCurrentLanes() const
508491
{
509-
return utils::getCurrentLanesFromPath(prev_module_path_, planner_data_);
492+
return utils::getCurrentLanesFromPath(prev_module_output_.path, planner_data_);
510493
}
511494

512495
lanelet::ConstLanelets NormalLaneChange::getLaneChangeLanes(
@@ -738,10 +721,10 @@ std::pair<double, double> NormalLaneChange::calcCurrentMinMaxAcceleration() cons
738721
const auto vehicle_max_acc = std::min(p.max_acc, lane_change_parameters_->max_longitudinal_acc);
739722

740723
const auto ego_seg_idx = motion_utils::findFirstNearestSegmentIndexWithSoftConstraints(
741-
prev_module_path_.points, getEgoPose(), p.ego_nearest_dist_threshold,
724+
prev_module_output_.path.points, getEgoPose(), p.ego_nearest_dist_threshold,
742725
p.ego_nearest_yaw_threshold);
743726
const auto max_path_velocity =
744-
prev_module_path_.points.at(ego_seg_idx).point.longitudinal_velocity_mps;
727+
prev_module_output_.path.points.at(ego_seg_idx).point.longitudinal_velocity_mps;
745728

746729
// calculate minimum and maximum acceleration
747730
const auto min_acc = utils::lane_change::calcMinimumAcceleration(
@@ -765,7 +748,7 @@ double NormalLaneChange::calcMaximumLaneChangeLength(
765748
std::vector<double> NormalLaneChange::sampleLongitudinalAccValues(
766749
const lanelet::ConstLanelets & current_lanes, const lanelet::ConstLanelets & target_lanes) const
767750
{
768-
if (prev_module_path_.points.empty()) {
751+
if (prev_module_output_.path.points.empty()) {
769752
return {};
770753
}
771754

@@ -852,7 +835,7 @@ PathWithLaneId NormalLaneChange::getPrepareSegment(
852835
return PathWithLaneId();
853836
}
854837

855-
auto prepare_segment = prev_module_path_;
838+
auto prepare_segment = prev_module_output_.path;
856839
const size_t current_seg_idx = motion_utils::findFirstNearestSegmentIndexWithSoftConstraints(
857840
prepare_segment.points, getEgoPose(), 3.0, 1.0);
858841
utils::clipPathLength(prepare_segment, current_seg_idx, prepare_length, backward_path_length);
@@ -1570,7 +1553,7 @@ std::optional<LaneChangePath> NormalLaneChange::calcTerminalLaneChangePath(
15701553
}
15711554

15721555
const auto lane_changing_start_pose = motion_utils::calcLongitudinalOffsetPose(
1573-
prev_module_path_.points, current_lane_terminal_point,
1556+
prev_module_output_.path.points, current_lane_terminal_point,
15741557
-(lane_change_buffer + next_lane_change_buffer + distance_to_terminal_from_goal));
15751558

15761559
if (!lane_changing_start_pose) {
@@ -1653,7 +1636,7 @@ std::optional<LaneChangePath> NormalLaneChange::calcTerminalLaneChangePath(
16531636
lane_changing_start_pose.value(), target_segment.points.front().point.pose,
16541637
target_lane_reference_path, shift_length);
16551638

1656-
auto reference_segment = prev_module_path_;
1639+
auto reference_segment = prev_module_output_.path;
16571640
const double length_to_lane_changing_start = motion_utils::calcSignedArcLength(
16581641
reference_segment.points, reference_segment.points.front().point.pose.position,
16591642
lane_changing_start_pose->position);
@@ -1877,7 +1860,7 @@ bool NormalLaneChange::calcAbortPath()
18771860
RCLCPP_ERROR(logger_, "failed to generate abort shifted path.");
18781861
}
18791862

1880-
PathWithLaneId reference_lane_segment = prev_module_path_;
1863+
auto reference_lane_segment = prev_module_output_.path;
18811864
{
18821865
const auto terminal_path =
18831866
calcTerminalLaneChangePath(reference_lanelets, selected_path.info.target_lanes);
@@ -2163,5 +2146,4 @@ bool NormalLaneChange::check_prepare_phase() const
21632146

21642147
return check_in_intersection || check_in_turns || check_in_general_lanes;
21652148
}
2166-
21672149
} // namespace behavior_path_planner

0 commit comments

Comments
 (0)