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

feat(avoidance): improve force avoidance judge logic in order to suppress unnecessary avoidance path #5441

Merged
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 @@ -9,7 +9,6 @@

# avoidance module common setting
enable_bound_clipping: false
enable_force_avoidance_for_stopped_vehicle: false
enable_yield_maneuver: true
enable_yield_maneuver_during_shifting: false
enable_cancel_maneuver: false
Expand Down Expand Up @@ -120,11 +119,6 @@

# For target object filtering
target_filtering:
# params for avoidance of not-parked objects
threshold_time_force_avoidance_for_stopped_vehicle: 10.0 # [s]
object_ignore_section_traffic_light_in_front_distance: 30.0 # [m]
object_ignore_section_crosswalk_in_front_distance: 30.0 # [m]
object_ignore_section_crosswalk_behind_distance: 30.0 # [m]
# detection range
object_check_goal_distance: 20.0 # [m]
# filtering parking objects
Expand All @@ -141,6 +135,17 @@
max_forward_distance: 150.0 # [m]
backward_distance: 10.0 # [m]

# params for avoidance of vehicle type objects that are ambiguous as to whether they are parked.
force_avoidance:
enable: false # [-]
time_threshold: 1.0 # [s]
ignore_area:
traffic_light:
front_distance: 100.0 # [m]
crosswalk:
front_distance: 30.0 # [m]
behind_distance: 30.0 # [m]

# For safety check
safety_check:
# safety check configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ struct ObjectData // avoidance target
// is stoppable under the constraints
bool is_stoppable{false};

// is within intersection area
bool is_within_intersection{false};

// unavoidable reason
std::string reason{""};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ bool isWithinCrosswalk(
const ObjectData & object,
const std::shared_ptr<const lanelet::routing::RoutingGraphContainer> & overall_graphs);

bool isWithinIntersection(
const ObjectData & object, const std::shared_ptr<RouteHandler> & route_handler);

bool isTargetObjectType(
const PredictedObject & object, const std::shared_ptr<AvoidanceParameters> & parameters);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ std::optional<double> getSignedDistanceFromBoundary(

Polygon2d toPolygon2d(const lanelet::ConstLanelet & lanelet);

Polygon2d toPolygon2d(const lanelet::BasicPolygon2d & polygon);

std::vector<Polygon2d> getTargetLaneletPolygons(
const lanelet::ConstLanelets & lanelets, const Pose & pose, const double check_length,
const std::string & target_type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,92 +42,96 @@
p.resample_interval_for_output =
getOrDeclareParameter<double>(*node, ns + "resample_interval_for_output");
p.enable_bound_clipping = getOrDeclareParameter<bool>(*node, ns + "enable_bound_clipping");
p.enable_cancel_maneuver = getOrDeclareParameter<bool>(*node, ns + "enable_cancel_maneuver");
p.enable_force_avoidance_for_stopped_vehicle =
getOrDeclareParameter<bool>(*node, ns + "enable_force_avoidance_for_stopped_vehicle");
p.enable_yield_maneuver = getOrDeclareParameter<bool>(*node, ns + "enable_yield_maneuver");
p.enable_yield_maneuver_during_shifting =
getOrDeclareParameter<bool>(*node, ns + "enable_yield_maneuver_during_shifting");
p.disable_path_update = getOrDeclareParameter<bool>(*node, ns + "disable_path_update");
p.publish_debug_marker = getOrDeclareParameter<bool>(*node, ns + "publish_debug_marker");
p.print_debug_info = getOrDeclareParameter<bool>(*node, ns + "print_debug_info");
}

// drivable area
{
std::string ns = "avoidance.";
p.use_adjacent_lane = getOrDeclareParameter<bool>(*node, ns + "use_adjacent_lane");
p.use_opposite_lane = getOrDeclareParameter<bool>(*node, ns + "use_opposite_lane");
p.use_intersection_areas = getOrDeclareParameter<bool>(*node, ns + "use_intersection_areas");
p.use_hatched_road_markings =
getOrDeclareParameter<bool>(*node, ns + "use_hatched_road_markings");
}

// target object
{
const auto get_object_param = [&](std::string && ns) {
ObjectParameter param{};
param.is_target = getOrDeclareParameter<bool>(*node, ns + "is_target");
param.execute_num = getOrDeclareParameter<int>(*node, ns + "execute_num");
param.moving_speed_threshold =
getOrDeclareParameter<double>(*node, ns + "moving_speed_threshold");
param.moving_time_threshold =
getOrDeclareParameter<double>(*node, ns + "moving_time_threshold");
param.max_expand_ratio = getOrDeclareParameter<double>(*node, ns + "max_expand_ratio");
param.envelope_buffer_margin =
getOrDeclareParameter<double>(*node, ns + "envelope_buffer_margin");
param.avoid_margin_lateral =
getOrDeclareParameter<double>(*node, ns + "avoid_margin_lateral");
param.safety_buffer_lateral =
getOrDeclareParameter<double>(*node, ns + "safety_buffer_lateral");
param.safety_buffer_longitudinal =
getOrDeclareParameter<double>(*node, ns + "safety_buffer_longitudinal");
param.use_conservative_buffer_longitudinal =
getOrDeclareParameter<bool>(*node, ns + "use_conservative_buffer_longitudinal");
return param;
};

const std::string ns = "avoidance.target_object.";
p.object_parameters.emplace(
ObjectClassification::MOTORCYCLE, get_object_param(ns + "motorcycle."));
p.object_parameters.emplace(ObjectClassification::CAR, get_object_param(ns + "car."));
p.object_parameters.emplace(ObjectClassification::TRUCK, get_object_param(ns + "truck."));
p.object_parameters.emplace(ObjectClassification::TRAILER, get_object_param(ns + "trailer."));
p.object_parameters.emplace(ObjectClassification::BUS, get_object_param(ns + "bus."));
p.object_parameters.emplace(
ObjectClassification::PEDESTRIAN, get_object_param(ns + "pedestrian."));
p.object_parameters.emplace(ObjectClassification::BICYCLE, get_object_param(ns + "bicycle."));
p.object_parameters.emplace(ObjectClassification::UNKNOWN, get_object_param(ns + "unknown."));

p.lower_distance_for_polygon_expansion =
getOrDeclareParameter<double>(*node, ns + "lower_distance_for_polygon_expansion");
p.upper_distance_for_polygon_expansion =
getOrDeclareParameter<double>(*node, ns + "upper_distance_for_polygon_expansion");
}

// target filtering
{
std::string ns = "avoidance.target_filtering.";
p.threshold_time_force_avoidance_for_stopped_vehicle = getOrDeclareParameter<double>(
*node, ns + "threshold_time_force_avoidance_for_stopped_vehicle");
p.object_ignore_section_traffic_light_in_front_distance = getOrDeclareParameter<double>(
*node, ns + "object_ignore_section_traffic_light_in_front_distance");
p.object_ignore_section_crosswalk_in_front_distance = getOrDeclareParameter<double>(
*node, ns + "object_ignore_section_crosswalk_in_front_distance");
p.object_ignore_section_crosswalk_behind_distance =
getOrDeclareParameter<double>(*node, ns + "object_ignore_section_crosswalk_behind_distance");
p.object_check_goal_distance =
getOrDeclareParameter<double>(*node, ns + "object_check_goal_distance");
p.threshold_distance_object_is_on_center =
getOrDeclareParameter<double>(*node, ns + "threshold_distance_object_is_on_center");
p.object_check_shiftable_ratio =
getOrDeclareParameter<double>(*node, ns + "object_check_shiftable_ratio");
p.object_check_min_road_shoulder_width =
getOrDeclareParameter<double>(*node, ns + "object_check_min_road_shoulder_width");
p.object_last_seen_threshold =
getOrDeclareParameter<double>(*node, ns + "object_last_seen_threshold");
}

{
std::string ns = "avoidance.target_filtering.force_avoidance.";
p.enable_force_avoidance_for_stopped_vehicle =
getOrDeclareParameter<bool>(*node, ns + "enable");
p.threshold_time_force_avoidance_for_stopped_vehicle =
getOrDeclareParameter<double>(*node, ns + "time_threshold");
p.object_ignore_section_traffic_light_in_front_distance =
getOrDeclareParameter<double>(*node, ns + "ignore_area.traffic_light.front_distance");
p.object_ignore_section_crosswalk_in_front_distance =
getOrDeclareParameter<double>(*node, ns + "ignore_area.crosswalk.front_distance");
p.object_ignore_section_crosswalk_behind_distance =
getOrDeclareParameter<double>(*node, ns + "ignore_area.crosswalk.behind_distance");
}

Check warning on line 134 in planning/behavior_path_planner/src/scene_module/avoidance/manager.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

AvoidanceModuleManager::AvoidanceModuleManager already has high cyclomatic complexity, and now it increases in Lines of Code from 245 to 248. 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.
{
std::string ns = "avoidance.target_filtering.detection_area.";
p.use_static_detection_area = getOrDeclareParameter<bool>(*node, ns + "static");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,72 +274,76 @@
p.resample_interval_for_planning =
getOrDeclareParameter<double>(*node, ns + "resample_interval_for_planning");
p.resample_interval_for_output =
getOrDeclareParameter<double>(*node, ns + "resample_interval_for_output");
p.enable_force_avoidance_for_stopped_vehicle =
getOrDeclareParameter<bool>(*node, ns + "enable_force_avoidance_for_stopped_vehicle");
}

// target object
{
const auto get_object_param = [&](std::string && ns) {
ObjectParameter param{};
param.is_target = getOrDeclareParameter<bool>(*node, ns + "is_target");
param.execute_num = getOrDeclareParameter<int>(*node, ns + "execute_num");
param.moving_speed_threshold =
getOrDeclareParameter<double>(*node, ns + "moving_speed_threshold");
param.moving_time_threshold =
getOrDeclareParameter<double>(*node, ns + "moving_time_threshold");
param.max_expand_ratio = getOrDeclareParameter<double>(*node, ns + "max_expand_ratio");
param.envelope_buffer_margin =
getOrDeclareParameter<double>(*node, ns + "envelope_buffer_margin");
param.avoid_margin_lateral =
getOrDeclareParameter<double>(*node, ns + "avoid_margin_lateral");
param.safety_buffer_lateral =
getOrDeclareParameter<double>(*node, ns + "safety_buffer_lateral");
return param;
};

const std::string ns = "avoidance_by_lane_change.target_object.";
p.object_parameters.emplace(
ObjectClassification::MOTORCYCLE, get_object_param(ns + "motorcycle."));
p.object_parameters.emplace(ObjectClassification::CAR, get_object_param(ns + "car."));
p.object_parameters.emplace(ObjectClassification::TRUCK, get_object_param(ns + "truck."));
p.object_parameters.emplace(ObjectClassification::TRAILER, get_object_param(ns + "trailer."));
p.object_parameters.emplace(ObjectClassification::BUS, get_object_param(ns + "bus."));
p.object_parameters.emplace(
ObjectClassification::PEDESTRIAN, get_object_param(ns + "pedestrian."));
p.object_parameters.emplace(ObjectClassification::BICYCLE, get_object_param(ns + "bicycle."));
p.object_parameters.emplace(ObjectClassification::UNKNOWN, get_object_param(ns + "unknown."));

p.lower_distance_for_polygon_expansion =
getOrDeclareParameter<double>(*node, ns + "lower_distance_for_polygon_expansion");
p.upper_distance_for_polygon_expansion =
getOrDeclareParameter<double>(*node, ns + "upper_distance_for_polygon_expansion");
}

// target filtering
{
std::string ns = "avoidance.target_filtering.";
p.threshold_time_force_avoidance_for_stopped_vehicle = getOrDeclareParameter<double>(
*node, ns + "threshold_time_force_avoidance_for_stopped_vehicle");
p.object_ignore_section_traffic_light_in_front_distance = getOrDeclareParameter<double>(
*node, ns + "object_ignore_section_traffic_light_in_front_distance");
p.object_ignore_section_crosswalk_in_front_distance = getOrDeclareParameter<double>(
*node, ns + "object_ignore_section_crosswalk_in_front_distance");
p.object_ignore_section_crosswalk_behind_distance =
getOrDeclareParameter<double>(*node, ns + "object_ignore_section_crosswalk_behind_distance");
p.object_check_goal_distance =
getOrDeclareParameter<double>(*node, ns + "object_check_goal_distance");
p.threshold_distance_object_is_on_center =
getOrDeclareParameter<double>(*node, ns + "threshold_distance_object_is_on_center");
p.object_check_shiftable_ratio =
getOrDeclareParameter<double>(*node, ns + "object_check_shiftable_ratio");
p.object_check_min_road_shoulder_width =
getOrDeclareParameter<double>(*node, ns + "object_check_min_road_shoulder_width");
p.object_last_seen_threshold =
getOrDeclareParameter<double>(*node, ns + "object_last_seen_threshold");
}

{
std::string ns = "avoidance.target_filtering.force_avoidance.";
p.enable_force_avoidance_for_stopped_vehicle =
getOrDeclareParameter<bool>(*node, ns + "enable");
p.threshold_time_force_avoidance_for_stopped_vehicle =
getOrDeclareParameter<double>(*node, ns + "time_threshold");
p.object_ignore_section_traffic_light_in_front_distance =
getOrDeclareParameter<double>(*node, ns + "ignore_area.traffic_light.front_distance");
p.object_ignore_section_crosswalk_in_front_distance =
getOrDeclareParameter<double>(*node, ns + "ignore_area.crosswalk.front_distance");
p.object_ignore_section_crosswalk_behind_distance =
getOrDeclareParameter<double>(*node, ns + "ignore_area.crosswalk.behind_distance");
}

Check warning on line 346 in planning/behavior_path_planner/src/scene_module/lane_change/manager.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Large Method

AvoidanceByLaneChangeModuleManager::AvoidanceByLaneChangeModuleManager increases from 104 to 107 lines of code, threshold = 70. Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function.
{
std::string ns = "avoidance.target_filtering.detection_area.";
p.use_static_detection_area = getOrDeclareParameter<bool>(*node, ns + "static");
Expand Down
117 changes: 82 additions & 35 deletions planning/behavior_path_planner/src/utils/avoidance/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Tier IV, Inc.

Check notice on line 1 in planning/behavior_path_planner/src/utils/avoidance/utils.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 1380 to 1416, 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/utils/avoidance/utils.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.43 to 5.34, 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 @@ -292,6 +292,81 @@
return false;
}

bool isWithinIntersection(

Check warning on line 295 in planning/behavior_path_planner/src/utils/avoidance/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/utils.cpp#L295

Added line #L295 was not covered by tests
const ObjectData & object, const std::shared_ptr<RouteHandler> & route_handler)
{
const std::string id = object.overhang_lanelet.attributeOr("intersection_area", "else");
if (id == "else") {
return false;
}

const auto object_polygon = tier4_autoware_utils::toPolygon2d(object.object);

const auto polygon = route_handler->getLaneletMapPtr()->polygonLayer.get(std::atoi(id.c_str()));

return boost::geometry::within(
object_polygon, utils::toPolygon2d(lanelet::utils::to2D(polygon.basicPolygon())));
}

Check warning on line 309 in planning/behavior_path_planner/src/utils/avoidance/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/utils.cpp#L309

Added line #L309 was not covered by tests

bool isForceAvoidanceTarget(

Check warning on line 311 in planning/behavior_path_planner/src/utils/avoidance/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/utils.cpp#L311

Added line #L311 was not covered by tests
ObjectData & object, const lanelet::ConstLanelets & extend_lanelets,
const std::shared_ptr<const PlannerData> & planner_data,
const std::shared_ptr<AvoidanceParameters> & parameters)
{
if (!parameters->enable_force_avoidance_for_stopped_vehicle) {
return false;
}

const auto stop_time_longer_than_threshold =
object.stop_time > parameters->threshold_time_force_avoidance_for_stopped_vehicle;

Check warning on line 321 in planning/behavior_path_planner/src/utils/avoidance/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/utils.cpp#L321

Added line #L321 was not covered by tests

if (!stop_time_longer_than_threshold) {
return false;
}

if (object.is_within_intersection) {
RCLCPP_DEBUG(rclcpp::get_logger(__func__), "object is in the intersection area.");
return false;

Check warning on line 329 in planning/behavior_path_planner/src/utils/avoidance/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/utils.cpp#L329

Added line #L329 was not covered by tests
}

const auto rh = planner_data->route_handler;

if (

Check warning on line 334 in planning/behavior_path_planner/src/utils/avoidance/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/utils.cpp#L334

Added line #L334 was not covered by tests
!!rh->getRoutingGraphPtr()->right(object.overhang_lanelet) &&
!!rh->getRoutingGraphPtr()->left(object.overhang_lanelet)) {
RCLCPP_DEBUG(rclcpp::get_logger(__func__), "object isn't on the edge lane.");
return false;

Check warning on line 338 in planning/behavior_path_planner/src/utils/avoidance/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/utils.cpp#L338

Added line #L338 was not covered by tests
}

const auto & ego_pose = planner_data->self_odometry->pose.pose;
const auto & object_pose = object.object.kinematics.initial_pose_with_covariance.pose;

Check warning on line 342 in planning/behavior_path_planner/src/utils/avoidance/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/utils.cpp#L341-L342

Added lines #L341 - L342 were not covered by tests

// force avoidance for stopped vehicle
bool not_parked_object = true;

// check traffic light
const auto to_traffic_light = utils::getDistanceToNextTrafficLight(object_pose, extend_lanelets);
{
not_parked_object =
to_traffic_light < parameters->object_ignore_section_traffic_light_in_front_distance;

Check warning on line 351 in planning/behavior_path_planner/src/utils/avoidance/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/utils.cpp#L350-L351

Added lines #L350 - L351 were not covered by tests
}

// check crosswalk
const auto to_crosswalk =
utils::getDistanceToCrosswalk(ego_pose, extend_lanelets, *rh->getOverallGraphPtr()) -
object.longitudinal;
{
const auto stop_for_crosswalk =
to_crosswalk < parameters->object_ignore_section_crosswalk_in_front_distance &&
to_crosswalk > -1.0 * parameters->object_ignore_section_crosswalk_behind_distance;
not_parked_object = not_parked_object || stop_for_crosswalk;
}

object.to_stop_factor_distance = std::min(to_traffic_light, to_crosswalk);

Check warning on line 365 in planning/behavior_path_planner/src/utils/avoidance/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/utils.cpp#L365

Added line #L365 was not covered by tests

return !not_parked_object;

Check warning on line 367 in planning/behavior_path_planner/src/utils/avoidance/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/utils.cpp#L367

Added line #L367 was not covered by tests
}

double calcShiftLength(
const bool & is_object_on_right, const double & overhang_dist, const double & avoid_margin)
{
Expand Down Expand Up @@ -1127,42 +1202,14 @@
continue;
}

// from here condition check for vehicle type objects.
o.is_within_intersection = isWithinIntersection(o, rh);

const auto stop_time_longer_than_threshold =
o.stop_time > parameters->threshold_time_force_avoidance_for_stopped_vehicle;

if (stop_time_longer_than_threshold && parameters->enable_force_avoidance_for_stopped_vehicle) {
// force avoidance for stopped vehicle
bool not_parked_object = true;

// check traffic light
const auto to_traffic_light =
utils::getDistanceToNextTrafficLight(object_pose, extend_lanelets);
{
not_parked_object =
to_traffic_light < parameters->object_ignore_section_traffic_light_in_front_distance;
}

// check crosswalk
const auto to_crosswalk =
utils::getDistanceToCrosswalk(ego_pose, extend_lanelets, *rh->getOverallGraphPtr()) -
o.longitudinal;
{
const auto stop_for_crosswalk =
to_crosswalk < parameters->object_ignore_section_crosswalk_in_front_distance &&
to_crosswalk > -1.0 * parameters->object_ignore_section_crosswalk_behind_distance;
not_parked_object = not_parked_object || stop_for_crosswalk;
}

o.to_stop_factor_distance = std::min(to_traffic_light, to_crosswalk);

if (!not_parked_object) {
o.last_seen = now;
o.avoid_margin = avoid_margin;
data.target_objects.push_back(o);
continue;
}
// from here condition check for vehicle type objects.
if (isForceAvoidanceTarget(o, extend_lanelets, planner_data, parameters)) {
o.last_seen = now;
o.avoid_margin = avoid_margin;

Check warning on line 1210 in planning/behavior_path_planner/src/utils/avoidance/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/utils.cpp#L1210

Added line #L1210 was not covered by tests
data.target_objects.push_back(o);
continue;

Check notice on line 1212 in planning/behavior_path_planner/src/utils/avoidance/utils.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Complex Method

filterTargetObjects decreases in cyclomatic complexity from 62 to 58, 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.

Check notice on line 1212 in planning/behavior_path_planner/src/utils/avoidance/utils.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Bumpy Road Ahead

filterTargetObjects decreases from 9 to 8 logical blocks with deeply nested code, threshold is one single block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

Check warning on line 1212 in planning/behavior_path_planner/src/utils/avoidance/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/avoidance/utils.cpp#L1212

Added line #L1212 was not covered by tests
}

// Object is on center line -> ignore.
Expand Down
11 changes: 11 additions & 0 deletions planning/behavior_path_planner/src/utils/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2023 Tier IV, Inc.

Check notice on line 1 in planning/behavior_path_planner/src/utils/utils.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 2801 to 2810, 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/utils/utils.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Number of Functions in a Single Module

The number of functions increases from 92 to 93, threshold = 75. This file contains too many functions. Beyond a certain threshold, more functions lower the code health.

Check notice on line 1 in planning/behavior_path_planner/src/utils/utils.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 6.29 to 6.26, 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 @@ -2708,6 +2708,17 @@
: tier4_autoware_utils::inverseClockwise(polygon);
}

Polygon2d toPolygon2d(const lanelet::BasicPolygon2d & polygon)

Check warning on line 2711 in planning/behavior_path_planner/src/utils/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/utils.cpp#L2711

Added line #L2711 was not covered by tests
{
Polygon2d ret;
for (const auto & p : polygon) {
ret.outer().emplace_back(p.x(), p.y());
}
ret.outer().push_back(ret.outer().front());

return tier4_autoware_utils::isClockwise(ret) ? ret : tier4_autoware_utils::inverseClockwise(ret);
}

Check warning on line 2720 in planning/behavior_path_planner/src/utils/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/utils.cpp#L2720

Added line #L2720 was not covered by tests

std::vector<Polygon2d> getTargetLaneletPolygons(
const lanelet::PolygonLayer & map_polygons, lanelet::ConstLanelets & lanelets, const Pose & pose,
const double check_length, const std::string & target_type)
Expand Down
Loading