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): regulate at the traffic light #5457

Merged
Show file tree
Hide file tree
Changes from all 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 @@ -81,6 +81,7 @@
regulation:
crosswalk: false
intersection: false
traffic_light: true

# ego vehicle stuck detection
stuck_detection:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ class NormalLaneChange : public LaneChangeBase
bool hasEnoughLengthToIntersection(
const LaneChangePath & path, const lanelet::ConstLanelets & current_lanes) const;

bool hasEnoughLengthToTrafficLight(
const LaneChangePath & path, const lanelet::ConstLanelets & current_lanes) const;

bool getLaneChangePaths(
const lanelet::ConstLanelets & current_lanes, const lanelet::ConstLanelets & target_lanes,
Direction direction, LaneChangePaths * candidate_paths,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct LaneChangeParameters
// regulatory elements
bool regulate_on_crosswalk{false};
bool regulate_on_intersection{false};
bool regulate_on_traffic_light{false};

// ego vehicle stuck detection
double stop_velocity_threshold{0.1};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <limits>
#include <memory>
#include <string>
#include <utility>
#include <vector>

namespace behavior_path_planner::utils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ LaneChangeModuleManager::LaneChangeModuleManager(
p.regulate_on_crosswalk = getOrDeclareParameter<bool>(*node, parameter("regulation.crosswalk"));
p.regulate_on_intersection =
getOrDeclareParameter<bool>(*node, parameter("regulation.intersection"));
p.regulate_on_traffic_light =
getOrDeclareParameter<bool>(*node, parameter("regulation.traffic_light"));

// ego vehicle stuck detection
p.stop_velocity_threshold =
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/src/scene_module/lane_change/normal.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Lines of Code in a Single File

The lines of code increases from 1412 to 1428, 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/src/scene_module/lane_change/normal.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.22 to 5.22, 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 All @@ -19,6 +19,7 @@
#include "behavior_path_planner/utils/path_safety_checker/objects_filtering.hpp"
#include "behavior_path_planner/utils/path_safety_checker/safety_check.hpp"
#include "behavior_path_planner/utils/path_utils.hpp"
#include "behavior_path_planner/utils/traffic_light_utils.hpp"
#include "behavior_path_planner/utils/utils.hpp"

#include <lanelet2_extension/utility/message_conversion.hpp>
Expand All @@ -38,6 +39,7 @@
namespace behavior_path_planner
{
using motion_utils::calcSignedArcLength;
using utils::traffic_light::getDistanceToNextTrafficLight;

NormalLaneChange::NormalLaneChange(
const std::shared_ptr<LaneChangeParameters> & parameters, LaneChangeModuleType type,
Expand Down Expand Up @@ -1081,6 +1083,19 @@
return true;
}

bool NormalLaneChange::hasEnoughLengthToTrafficLight(

Check warning on line 1086 in planning/behavior_path_planner/src/scene_module/lane_change/normal.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/scene_module/lane_change/normal.cpp#L1086

Added line #L1086 was not covered by tests
const LaneChangePath & path, const lanelet::ConstLanelets & current_lanes) const
{
const auto current_pose = getEgoPose();

Check warning on line 1089 in planning/behavior_path_planner/src/scene_module/lane_change/normal.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/scene_module/lane_change/normal.cpp#L1089

Added line #L1089 was not covered by tests
const auto dist_to_next_traffic_light =
getDistanceToNextTrafficLight(current_pose, current_lanes);
const auto dist_to_next_traffic_light_from_lc_start_pose =
dist_to_next_traffic_light - path.info.length.prepare;

Check warning on line 1093 in planning/behavior_path_planner/src/scene_module/lane_change/normal.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/scene_module/lane_change/normal.cpp#L1091-L1093

Added lines #L1091 - L1093 were not covered by tests

return dist_to_next_traffic_light_from_lc_start_pose <= 0.0 ||
dist_to_next_traffic_light_from_lc_start_pose >= path.info.length.lane_changing;
}

bool NormalLaneChange::getLaneChangePaths(
const lanelet::ConstLanelets & current_lanes, const lanelet::ConstLanelets & target_lanes,
Direction direction, LaneChangePaths * candidate_paths,
Expand Down Expand Up @@ -1340,6 +1355,12 @@
logger_, "Stop time is over threshold. Allow lane change in intersection.");
}

if (

Check warning on line 1358 in planning/behavior_path_planner/src/scene_module/lane_change/normal.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/scene_module/lane_change/normal.cpp#L1358

Added line #L1358 was not covered by tests
lane_change_parameters_->regulate_on_traffic_light &&
!hasEnoughLengthToTrafficLight(*candidate_path, current_lanes)) {
continue;

Check warning on line 1361 in planning/behavior_path_planner/src/scene_module/lane_change/normal.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/scene_module/lane_change/normal.cpp#L1361

Added line #L1361 was not covered by tests
}

Check warning on line 1363 in planning/behavior_path_planner/src/scene_module/lane_change/normal.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

NormalLaneChange::getLaneChangePaths increases in cyclomatic complexity from 41 to 44, threshold = 9. 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.
candidate_paths->push_back(*candidate_path);

std::vector<ExtendedPredictedObject> filtered_objects =
Expand Down
Loading