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(avoidance): expand detection area to prevent chattering #5267

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 @@ -164,7 +164,7 @@ std::vector<ExtendedPredictedObject> getSafetyCheckTargetObjects(
std::pair<PredictedObjects, PredictedObjects> separateObjectsByPath(
const PathWithLaneId & path, const std::shared_ptr<const PlannerData> & planner_data,
const AvoidancePlanningData & data, const std::shared_ptr<AvoidanceParameters> & parameters,
DebugData & debug);
const bool is_running, DebugData & debug);

DrivableLanes generateExpandDrivableLanes(
const lanelet::ConstLanelet & lanelet, const std::shared_ptr<const PlannerData> & planner_data,
Expand Down
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/scene_module/avoidance/avoidance_module.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 2120 to 2122, 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/avoidance/avoidance_module.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Overall Code Complexity

The mean cyclomatic complexity increases from 5.95 to 5.97, 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 @@ -174,7 +174,7 @@
return std::any_of(
avoid_data_.target_objects.begin(), avoid_data_.target_objects.end(), [](const auto & o) {
return o.is_avoidable || o.reason == AvoidanceDebugFactor::TOO_LARGE_JERK;
});

Check warning on line 177 in planning/behavior_path_planner/src/scene_module/avoidance/avoidance_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/scene_module/avoidance/avoidance_module.cpp#L177

Added line #L177 was not covered by tests
}

bool AvoidanceModule::isExecutionReady() const
Expand Down Expand Up @@ -292,12 +292,16 @@
using utils::avoidance::filterTargetObjects;
using utils::avoidance::getTargetLanelets;

// Add margin in order to prevent avoidance request chattering only when the module is running.
const auto is_running = getCurrentStatus() == ModuleStatus::RUNNING ||
getCurrentStatus() == ModuleStatus::WAITING_APPROVAL;

// Separate dynamic objects based on whether they are inside or outside of the expanded lanelets.
const auto [object_within_target_lane, object_outside_target_lane] =
utils::avoidance::separateObjectsByPath(
utils::resamplePathWithSpline(
helper_.getPreviousSplineShiftPath().path, parameters_->resample_interval_for_output),
planner_data_, data, parameters_, debug);
planner_data_, data, parameters_, is_running, debug);

for (const auto & object : object_outside_target_lane.objects) {
ObjectData other_object;
Expand Down
24 changes: 23 additions & 1 deletion 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 1344 to 1360, 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 worse: Overall Code Complexity

The mean cyclomatic complexity increases from 5.46 to 5.50, 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 @@ -29,9 +29,12 @@

#include <tier4_planning_msgs/msg/avoidance_debug_factor.hpp>

#include <boost/geometry.hpp>
#include <boost/geometry/algorithms/convex_hull.hpp>
#include <boost/geometry/algorithms/correct.hpp>
#include <boost/geometry/algorithms/union.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/strategies/convex_hull.hpp>

#include <lanelet2_routing/RoutingGraphContainer.h>
Expand Down Expand Up @@ -1602,43 +1605,62 @@
std::pair<PredictedObjects, PredictedObjects> separateObjectsByPath(
const PathWithLaneId & path, const std::shared_ptr<const PlannerData> & planner_data,
const AvoidancePlanningData & data, const std::shared_ptr<AvoidanceParameters> & parameters,
DebugData & debug)
const bool is_running, DebugData & debug)
{
PredictedObjects target_objects;
PredictedObjects other_objects;

double max_offset = 0.0;
for (const auto & object_parameter : parameters->object_parameters) {
const auto p = object_parameter.second;
const auto offset =
2.0 * p.envelope_buffer_margin + p.safety_buffer_lateral + p.avoid_margin_lateral;
max_offset = std::max(max_offset, offset);
}

const auto detection_area =
createVehiclePolygon(planner_data->parameters.vehicle_info, max_offset);
const auto ego_idx = planner_data->findEgoIndex(path.points);

Polygon2d attention_area;
for (size_t i = 0; i < path.points.size() - 1; ++i) {
const auto & p_ego_front = path.points.at(i).point.pose;
const auto & p_ego_back = path.points.at(i + 1).point.pose;

const auto distance_from_ego = calcSignedArcLength(path.points, ego_idx, i);
if (distance_from_ego > parameters->object_check_forward_distance) {
break;
}

const auto ego_one_step_polygon = createOneStepPolygon(p_ego_front, p_ego_back, detection_area);

std::vector<Polygon2d> unions;
boost::geometry::union_(attention_area, ego_one_step_polygon, unions);
if (!unions.empty()) {
attention_area = unions.front();
boost::geometry::correct(attention_area);
}
}

// expand detection area width only when the module is running.
if (is_running) {
constexpr int PER_CIRCLE = 36;
constexpr double MARGIN = 1.0; // [m]
boost::geometry::strategy::buffer::distance_symmetric<double> distance_strategy(MARGIN);
boost::geometry::strategy::buffer::join_round join_strategy(PER_CIRCLE);
boost::geometry::strategy::buffer::end_round end_strategy(PER_CIRCLE);
boost::geometry::strategy::buffer::point_circle circle_strategy(PER_CIRCLE);
boost::geometry::strategy::buffer::side_straight side_strategy;
boost::geometry::model::multi_polygon<Polygon2d> result;
// Create the buffer of a multi polygon
boost::geometry::buffer(
attention_area, result, distance_strategy, side_strategy, join_strategy, end_strategy,
circle_strategy);
if (!result.empty()) {
attention_area = result.front();
}
}

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

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

separateObjectsByPath has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested 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 notice on line 1663 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: Excess Number of Function Arguments

separateObjectsByPath increases from 5 to 6 arguments, threshold = 4. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.
debug.detection_area = toMsg(attention_area, data.reference_pose.position.z);

const auto objects = planner_data->dynamic_object->objects;
Expand Down
Loading