Skip to content

Commit da9df0c

Browse files
refactor(lane_change): move getCurrentTurnSignalInfo to scene file (#6943)
* refactor(lane_change): move getCurrentTurnSignalInfo to scene file Signed-off-by: Zulfaqar Azmi <zulfaqar.azmi@tier4.jp> * style(pre-commit): autofix * removed reference from trivial variable Signed-off-by: Zulfaqar Azmi <zulfaqar.azmi@tier4.jp> --------- Signed-off-by: Zulfaqar Azmi <zulfaqar.azmi@tier4.jp> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent db38f04 commit da9df0c

File tree

5 files changed

+82
-82
lines changed

5 files changed

+82
-82
lines changed

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/interface.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ class LaneChangeInterface : public SceneModuleInterface
9393

9494
MarkerArray getModuleVirtualWall() override;
9595

96-
TurnSignalInfo getCurrentTurnSignalInfo(
97-
const PathWithLaneId & path, const TurnSignalInfo & original_turn_signal_info);
98-
9996
// TODO(someone): remove this, and use base class function
10097
[[deprecated]] BehaviorModuleOutput run() override
10198
{

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/scene.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class NormalLaneChange : public LaneChangeBase
101101

102102
bool isStoppedAtRedTrafficLight() const override;
103103

104+
TurnSignalInfo get_current_turn_signal_info() override;
105+
104106
protected:
105107
lanelet::ConstLanelets getCurrentLanes() const override;
106108

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
@@ -187,6 +187,8 @@ class LaneChangeBase
187187

188188
void resetStopPose() { lane_change_stop_pose_ = std::nullopt; }
189189

190+
virtual TurnSignalInfo get_current_turn_signal_info() = 0;
191+
190192
protected:
191193
virtual lanelet::ConstLanelets getCurrentLanes() const = 0;
192194

planning/behavior_path_lane_change_module/src/interface.cpp

+1-79
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ BehaviorModuleOutput LaneChangeInterface::planWaitingApproval()
135135

136136
BehaviorModuleOutput out = getPreviousModuleOutput();
137137
module_type_->insertStopPoint(module_type_->getLaneChangeStatus().current_lanes, out.path);
138-
out.turn_signal_info =
139-
getCurrentTurnSignalInfo(out.path, getPreviousModuleOutput().turn_signal_info);
138+
out.turn_signal_info = module_type_->get_current_turn_signal_info();
140139

141140
const auto & lane_change_debug = module_type_->getDebugData();
142141
for (const auto & [uuid, data] : lane_change_debug.collision_check_objects) {
@@ -367,81 +366,4 @@ void LaneChangeInterface::updateSteeringFactorPtr(
367366
{output.start_distance_to_path_change, output.finish_distance_to_path_change},
368367
PlanningBehavior::LANE_CHANGE, steering_factor_direction, SteeringFactor::APPROACHING, "");
369368
}
370-
371-
TurnSignalInfo LaneChangeInterface::getCurrentTurnSignalInfo(
372-
const PathWithLaneId & path, const TurnSignalInfo & original_turn_signal_info)
373-
{
374-
const auto & current_lanes = module_type_->getLaneChangeStatus().current_lanes;
375-
const auto & is_valid = module_type_->getLaneChangeStatus().is_valid_path;
376-
const auto & lane_change_path = module_type_->getLaneChangeStatus().lane_change_path;
377-
const auto & lane_change_param = module_type_->getLaneChangeParam();
378-
379-
if (
380-
module_type_->getModuleType() != LaneChangeModuleType::NORMAL || current_lanes.empty() ||
381-
!is_valid) {
382-
return original_turn_signal_info;
383-
}
384-
385-
// check direction
386-
TurnSignalInfo current_turn_signal_info;
387-
const auto & current_pose = module_type_->getEgoPose();
388-
const auto direction = module_type_->getDirection();
389-
if (direction == Direction::LEFT) {
390-
current_turn_signal_info.turn_signal.command = TurnIndicatorsCommand::ENABLE_LEFT;
391-
} else if (direction == Direction::RIGHT) {
392-
current_turn_signal_info.turn_signal.command = TurnIndicatorsCommand::ENABLE_RIGHT;
393-
}
394-
395-
if (path.points.empty()) {
396-
current_turn_signal_info.desired_start_point = current_pose;
397-
current_turn_signal_info.required_start_point = current_pose;
398-
current_turn_signal_info.desired_end_point = lane_change_path.info.lane_changing_end;
399-
current_turn_signal_info.required_end_point = lane_change_path.info.lane_changing_end;
400-
return current_turn_signal_info;
401-
}
402-
403-
const auto & min_length_for_turn_signal_activation =
404-
lane_change_param.min_length_for_turn_signal_activation;
405-
const auto & route_handler = module_type_->getRouteHandler();
406-
const auto & common_parameter = module_type_->getCommonParam();
407-
const auto shift_intervals =
408-
route_handler->getLateralIntervalsToPreferredLane(current_lanes.back());
409-
const double next_lane_change_buffer =
410-
utils::lane_change::calcMinimumLaneChangeLength(lane_change_param, shift_intervals);
411-
const double & nearest_dist_threshold = common_parameter.ego_nearest_dist_threshold;
412-
const double & nearest_yaw_threshold = common_parameter.ego_nearest_yaw_threshold;
413-
const double & base_to_front = common_parameter.base_link2front;
414-
415-
const double buffer =
416-
next_lane_change_buffer + min_length_for_turn_signal_activation + base_to_front;
417-
const double path_length = motion_utils::calcArcLength(path.points);
418-
const size_t & current_nearest_seg_idx =
419-
motion_utils::findFirstNearestSegmentIndexWithSoftConstraints(
420-
path.points, current_pose, nearest_dist_threshold, nearest_yaw_threshold);
421-
const double dist_to_terminal = utils::getDistanceToEndOfLane(current_pose, current_lanes);
422-
const auto start_pose =
423-
motion_utils::calcLongitudinalOffsetPose(path.points, 0, std::max(path_length - buffer, 0.0));
424-
if (dist_to_terminal - base_to_front < buffer && start_pose) {
425-
// modify turn signal
426-
current_turn_signal_info.desired_start_point = *start_pose;
427-
current_turn_signal_info.desired_end_point = lane_change_path.info.lane_changing_end;
428-
current_turn_signal_info.required_start_point = current_turn_signal_info.desired_start_point;
429-
current_turn_signal_info.required_end_point = current_turn_signal_info.desired_end_point;
430-
431-
const auto & original_command = original_turn_signal_info.turn_signal.command;
432-
if (
433-
original_command == TurnIndicatorsCommand::DISABLE ||
434-
original_command == TurnIndicatorsCommand::NO_COMMAND) {
435-
return current_turn_signal_info;
436-
}
437-
438-
// check the priority of turn signals
439-
return module_type_->getTurnSignalDecider().use_prior_turn_signal(
440-
path, current_pose, current_nearest_seg_idx, original_turn_signal_info,
441-
current_turn_signal_info, nearest_dist_threshold, nearest_yaw_threshold);
442-
}
443-
444-
// not in the vicinity of the end of the path. return original
445-
return original_turn_signal_info;
446-
}
447369
} // namespace behavior_path_planner

planning/behavior_path_lane_change_module/src/scene.cpp

+77
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,83 @@ bool NormalLaneChange::isStoppedAtRedTrafficLight() const
136136
status_.lane_change_path.info.length.sum());
137137
}
138138

139+
TurnSignalInfo NormalLaneChange::get_current_turn_signal_info()
140+
{
141+
const auto original_turn_signal_info = prev_module_output_.turn_signal_info;
142+
143+
const auto & current_lanes = getLaneChangeStatus().current_lanes;
144+
const auto is_valid = getLaneChangeStatus().is_valid_path;
145+
const auto & lane_change_path = getLaneChangeStatus().lane_change_path;
146+
const auto & lane_change_param = getLaneChangeParam();
147+
148+
if (getModuleType() != LaneChangeModuleType::NORMAL || current_lanes.empty() || !is_valid) {
149+
return original_turn_signal_info;
150+
}
151+
152+
// check direction
153+
TurnSignalInfo current_turn_signal_info;
154+
const auto & current_pose = getEgoPose();
155+
const auto direction = getDirection();
156+
if (direction == Direction::LEFT) {
157+
current_turn_signal_info.turn_signal.command = TurnIndicatorsCommand::ENABLE_LEFT;
158+
} else if (direction == Direction::RIGHT) {
159+
current_turn_signal_info.turn_signal.command = TurnIndicatorsCommand::ENABLE_RIGHT;
160+
}
161+
162+
const auto & path = prev_module_output_.path;
163+
if (path.points.empty()) {
164+
current_turn_signal_info.desired_start_point = current_pose;
165+
current_turn_signal_info.required_start_point = current_pose;
166+
current_turn_signal_info.desired_end_point = lane_change_path.info.lane_changing_end;
167+
current_turn_signal_info.required_end_point = lane_change_path.info.lane_changing_end;
168+
return current_turn_signal_info;
169+
}
170+
171+
const auto min_length_for_turn_signal_activation =
172+
lane_change_param.min_length_for_turn_signal_activation;
173+
const auto & route_handler = getRouteHandler();
174+
const auto & common_parameter = getCommonParam();
175+
const auto shift_intervals =
176+
route_handler->getLateralIntervalsToPreferredLane(current_lanes.back());
177+
const double next_lane_change_buffer =
178+
utils::lane_change::calcMinimumLaneChangeLength(lane_change_param, shift_intervals);
179+
const double nearest_dist_threshold = common_parameter.ego_nearest_dist_threshold;
180+
const double nearest_yaw_threshold = common_parameter.ego_nearest_yaw_threshold;
181+
const double base_to_front = common_parameter.base_link2front;
182+
183+
const double buffer =
184+
next_lane_change_buffer + min_length_for_turn_signal_activation + base_to_front;
185+
const double path_length = motion_utils::calcArcLength(path.points);
186+
const size_t current_nearest_seg_idx =
187+
motion_utils::findFirstNearestSegmentIndexWithSoftConstraints(
188+
path.points, current_pose, nearest_dist_threshold, nearest_yaw_threshold);
189+
const double dist_to_terminal = utils::getDistanceToEndOfLane(current_pose, current_lanes);
190+
const auto start_pose =
191+
motion_utils::calcLongitudinalOffsetPose(path.points, 0, std::max(path_length - buffer, 0.0));
192+
if (dist_to_terminal - base_to_front < buffer && start_pose) {
193+
// modify turn signal
194+
current_turn_signal_info.desired_start_point = *start_pose;
195+
current_turn_signal_info.desired_end_point = lane_change_path.info.lane_changing_end;
196+
current_turn_signal_info.required_start_point = current_turn_signal_info.desired_start_point;
197+
current_turn_signal_info.required_end_point = current_turn_signal_info.desired_end_point;
198+
199+
const auto & original_command = original_turn_signal_info.turn_signal.command;
200+
if (
201+
original_command == TurnIndicatorsCommand::DISABLE ||
202+
original_command == TurnIndicatorsCommand::NO_COMMAND) {
203+
return current_turn_signal_info;
204+
}
205+
206+
// check the priority of turn signals
207+
return getTurnSignalDecider().use_prior_turn_signal(
208+
path, current_pose, current_nearest_seg_idx, original_turn_signal_info,
209+
current_turn_signal_info, nearest_dist_threshold, nearest_yaw_threshold);
210+
}
211+
212+
// not in the vicinity of the end of the path. return original
213+
return original_turn_signal_info;
214+
}
215+
139216
LaneChangePath NormalLaneChange::getLaneChangePath() const
140217
{
141218
return status_.lane_change_path;

0 commit comments

Comments
 (0)