Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lane_change): activate turn signal as soon as we have the intention to change lanes #8571

Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,16 @@ class NormalLaneChange : public LaneChangeBase

bool isStoppedAtRedTrafficLight() const override;

TurnSignalInfo get_current_turn_signal_info() override;
TurnSignalInfo get_current_turn_signal_info() const override;
mkquda marked this conversation as resolved.
Show resolved Hide resolved

protected:
lanelet::ConstLanelets getLaneChangeLanes(
const lanelet::ConstLanelets & current_lanes, Direction direction) const override;

int getNumToPreferredLane(const lanelet::ConstLanelet & lane) const override;

TurnSignalInfo get_terminal_turn_signal_info() const override;

std::vector<double> sampleLongitudinalAccValues(
const lanelet::ConstLanelets & current_lanes,
const lanelet::ConstLanelets & target_lanes) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@

LaneChangeModuleType getModuleType() const { return type_; }

TurnSignalDecider getTurnSignalDecider() { return planner_data_->turn_signal_decider; }
TurnSignalDecider getTurnSignalDecider() const { return planner_data_->turn_signal_decider; }

Direction getDirection() const
{
Expand All @@ -229,7 +229,7 @@

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

virtual TurnSignalInfo get_current_turn_signal_info() = 0;
virtual TurnSignalInfo get_current_turn_signal_info() const = 0;

protected:
virtual int getNumToPreferredLane(const lanelet::ConstLanelet & lane) const = 0;
Expand All @@ -245,6 +245,31 @@
virtual lanelet::ConstLanelets getLaneChangeLanes(
const lanelet::ConstLanelets & current_lanes, Direction direction) const = 0;

virtual TurnSignalInfo get_terminal_turn_signal_info() const = 0;

TurnSignalInfo get_turn_signal(const Pose & start, const Pose & end) const

Check warning on line 250 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/include/autoware/behavior_path_lane_change_module/utils/base_class.hpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/include/autoware/behavior_path_lane_change_module/utils/base_class.hpp#L250

Added line #L250 was not covered by tests
{
TurnSignalInfo turn_signal;

Check warning on line 252 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/include/autoware/behavior_path_lane_change_module/utils/base_class.hpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/include/autoware/behavior_path_lane_change_module/utils/base_class.hpp#L252

Added line #L252 was not covered by tests
switch (direction_) {
case Direction::LEFT:
turn_signal.turn_signal.command = TurnIndicatorsCommand::ENABLE_LEFT;
break;
case Direction::RIGHT:
turn_signal.turn_signal.command = TurnIndicatorsCommand::ENABLE_RIGHT;
break;
default:
turn_signal.turn_signal.command = TurnIndicatorsCommand::NO_COMMAND;
break;

Check warning on line 262 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/include/autoware/behavior_path_lane_change_module/utils/base_class.hpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/include/autoware/behavior_path_lane_change_module/utils/base_class.hpp#L254-L262

Added lines #L254 - L262 were not covered by tests
}

turn_signal.desired_start_point = start;
turn_signal.desired_end_point = end;
turn_signal.required_start_point = turn_signal.desired_start_point;
turn_signal.required_end_point = turn_signal.desired_end_point;

Check warning on line 268 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/include/autoware/behavior_path_lane_change_module/utils/base_class.hpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/include/autoware/behavior_path_lane_change_module/utils/base_class.hpp#L265-L268

Added lines #L265 - L268 were not covered by tests

return turn_signal;

Check warning on line 270 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/include/autoware/behavior_path_lane_change_module/utils/base_class.hpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/include/autoware/behavior_path_lane_change_module/utils/base_class.hpp#L270

Added line #L270 was not covered by tests
}

LaneChangeStatus status_{};
PathShifter path_shifter_{};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ double calc_stopping_distance(const LCParamPtr & lc_param_ptr);
* @return distance to last fit width position along the lane
*/
double calc_dist_to_last_fit_width(
const lanelet::ConstLanelets lanelets, const Pose & src_pose,
const lanelet::ConstLanelets & lanelets, const Pose & src_pose,
const BehaviorPathPlannerParameters & bpp_param, const double margin = 0.1);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 TIER IV, Inc.

Check notice on line 1 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Lines of Code in a Single File

The lines of code decreases from 1908 to 1893, improve code health by reducing it to 1000. The number of Lines of Code in a single file. More Lines of Code lowers the code health.

Check notice on line 1 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 5.34 to 5.24, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -181,81 +181,64 @@
status_.lane_change_path.info.length.sum());
}

TurnSignalInfo NormalLaneChange::get_current_turn_signal_info()
TurnSignalInfo NormalLaneChange::get_current_turn_signal_info() const

Check warning on line 184 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp#L184

Added line #L184 was not covered by tests
{
const auto original_turn_signal_info = prev_module_output_.turn_signal_info;

const auto & current_lanes = get_current_lanes();
const auto is_valid = getLaneChangeStatus().is_valid_path;
const auto & lane_change_path = getLaneChangeStatus().lane_change_path;
const auto & lane_change_param = getLaneChangeParam();

if (getModuleType() != LaneChangeModuleType::NORMAL || current_lanes.empty() || !is_valid) {
if (getModuleType() != LaneChangeModuleType::NORMAL || get_current_lanes().empty()) {
return original_turn_signal_info;
}

// check direction
TurnSignalInfo current_turn_signal_info;
const auto & current_pose = getEgoPose();
const auto direction = getDirection();
if (direction == Direction::LEFT) {
current_turn_signal_info.turn_signal.command = TurnIndicatorsCommand::ENABLE_LEFT;
} else if (direction == Direction::RIGHT) {
current_turn_signal_info.turn_signal.command = TurnIndicatorsCommand::ENABLE_RIGHT;
if (direction_ != Direction::LEFT && direction_ != Direction::RIGHT) {
return original_turn_signal_info;

Check warning on line 193 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp#L193

Added line #L193 was not covered by tests
}

const auto & path = prev_module_output_.path;
if (path.points.empty()) {
current_turn_signal_info.desired_start_point = current_pose;
current_turn_signal_info.required_start_point = current_pose;
current_turn_signal_info.desired_end_point = lane_change_path.info.lane_changing_end;
current_turn_signal_info.required_end_point = lane_change_path.info.lane_changing_end;
return current_turn_signal_info;
const auto & original_command = original_turn_signal_info.turn_signal.command;
if (
!path.points.empty() && original_command != TurnIndicatorsCommand::DISABLE &&
original_command != TurnIndicatorsCommand::NO_COMMAND) {
return get_terminal_turn_signal_info();

Check warning on line 201 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp#L201

Added line #L201 was not covered by tests
}

const auto min_length_for_turn_signal_activation =
lane_change_param.min_length_for_turn_signal_activation;
const auto & route_handler = getRouteHandler();
const auto & common_parameter = getCommonParam();
return get_turn_signal(getEgoPose(), getLaneChangePath().info.lane_changing_end);

Check warning on line 204 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp#L204

Added line #L204 was not covered by tests
}

TurnSignalInfo NormalLaneChange::get_terminal_turn_signal_info() const

Check warning on line 207 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp#L207

Added line #L207 was not covered by tests
{
const auto & lane_change_param = getLaneChangeParam();
const auto & common_param = getCommonParam();
const auto & current_pose = getEgoPose();
const auto & path = prev_module_output_.path;

Check warning on line 212 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp#L212

Added line #L212 was not covered by tests

const auto original_turn_signal_info = prev_module_output_.turn_signal_info;

Check warning on line 214 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp#L214

Added line #L214 was not covered by tests

const auto shift_intervals =
route_handler->getLateralIntervalsToPreferredLane(current_lanes.back());
getRouteHandler()->getLateralIntervalsToPreferredLane(get_current_lanes().back());
const double next_lane_change_buffer =
utils::lane_change::calcMinimumLaneChangeLength(lane_change_param, shift_intervals);
const double nearest_dist_threshold = common_parameter.ego_nearest_dist_threshold;
const double nearest_yaw_threshold = common_parameter.ego_nearest_yaw_threshold;
const double base_to_front = common_parameter.base_link2front;

const double buffer =
next_lane_change_buffer + min_length_for_turn_signal_activation + base_to_front;
const double buffer = next_lane_change_buffer +
lane_change_param.min_length_for_turn_signal_activation +
common_param.base_link2front;

Check warning on line 223 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp#L221-L223

Added lines #L221 - L223 were not covered by tests
const double path_length = autoware::motion_utils::calcArcLength(path.points);
const size_t current_nearest_seg_idx =
autoware::motion_utils::findFirstNearestSegmentIndexWithSoftConstraints(
path.points, current_pose, nearest_dist_threshold, nearest_yaw_threshold);
const double dist_to_terminal = utils::getDistanceToEndOfLane(current_pose, current_lanes);
const auto start_pose = autoware::motion_utils::calcLongitudinalOffsetPose(
path.points, 0, std::max(path_length - buffer, 0.0));
if (dist_to_terminal - base_to_front < buffer && start_pose) {
// modify turn signal
current_turn_signal_info.desired_start_point = *start_pose;
current_turn_signal_info.desired_end_point = lane_change_path.info.lane_changing_end;
current_turn_signal_info.required_start_point = current_turn_signal_info.desired_start_point;
current_turn_signal_info.required_end_point = current_turn_signal_info.desired_end_point;

const auto & original_command = original_turn_signal_info.turn_signal.command;
if (
original_command == TurnIndicatorsCommand::DISABLE ||
original_command == TurnIndicatorsCommand::NO_COMMAND) {
return current_turn_signal_info;
}

// check the priority of turn signals
return getTurnSignalDecider().overwrite_turn_signal(
path, current_pose, current_nearest_seg_idx, original_turn_signal_info,
current_turn_signal_info, nearest_dist_threshold, nearest_yaw_threshold);
}
if (!start_pose) return original_turn_signal_info;

const auto terminal_turn_signal_info =
get_turn_signal(*start_pose, getLaneChangePath().info.lane_changing_end);

const double nearest_dist_threshold = common_param.ego_nearest_dist_threshold;
const double nearest_yaw_threshold = common_param.ego_nearest_yaw_threshold;

Check warning on line 234 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp#L233-L234

Added lines #L233 - L234 were not covered by tests
const size_t current_nearest_seg_idx =
autoware::motion_utils::findFirstNearestSegmentIndexWithSoftConstraints(
path.points, current_pose, nearest_dist_threshold, nearest_yaw_threshold);

// not in the vicinity of the end of the path. return original
return original_turn_signal_info;
return getTurnSignalDecider().overwrite_turn_signal(
path, current_pose, current_nearest_seg_idx, original_turn_signal_info,
terminal_turn_signal_info, nearest_dist_threshold, nearest_yaw_threshold);

Check notice on line 241 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Complex Method

NormalLaneChange::get_current_turn_signal_info is no longer above the threshold for cyclomatic complexity. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
}

LaneChangePath NormalLaneChange::getLaneChangePath() const
Expand Down Expand Up @@ -319,14 +302,15 @@
output.path = abort_path_->path;
insertStopPoint(get_current_lanes(), output.path);
} else {
output.path = getLaneChangePath().path;
output.path = status_.lane_change_path.path;
zulfaqar-azmi-t4 marked this conversation as resolved.
Show resolved Hide resolved

const auto found_extended_path = extendPath();
if (found_extended_path) {
output.path = utils::combinePath(output.path, *found_extended_path);
}
output.reference_path = getReferencePath();
output.turn_signal_info = updateOutputTurnSignal();
output.turn_signal_info =
get_turn_signal(getEgoPose(), status_.lane_change_path.info.lane_changing_end);

Check warning on line 313 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp#L313

Added line #L313 was not covered by tests

if (isStopState()) {
const auto current_velocity = getEgoVelocity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ double calc_stopping_distance(const LCParamPtr & lc_param_ptr)
}

double calc_dist_to_last_fit_width(
const lanelet::ConstLanelets lanelets, const Pose & src_pose,
const lanelet::ConstLanelets & lanelets, const Pose & src_pose,
const BehaviorPathPlannerParameters & bpp_param, const double margin)
{
if (lanelets.empty()) return 0.0;
Expand Down
Loading