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(static_obstacle_avoidance): keep object clipping even after the object becomes non-target #7591

Merged
merged 1 commit into from
Jun 20, 2024
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 @@ -5,10 +5,6 @@
resample_interval_for_planning: 0.3 # [m] FOR DEVELOPER
resample_interval_for_output: 4.0 # [m] FOR DEVELOPER

# avoidance module common setting
enable_bound_clipping: false
disable_path_update: false

# drivable area setting
use_adjacent_lane: true
use_opposite_lane: true
Expand Down Expand Up @@ -284,6 +280,19 @@
max_acceleration: 0.5 # [m/ss]
min_velocity_to_limit_max_acceleration: 2.78 # [m/ss]

# path generation method. select "shift_line_base" or "optimization_base" or "both".
# "shift_line_base" : Create avoidance path based on shift line.
# User can control avoidance maneuver execution via RTC.
# However, this method doesn't support complex avoidance scenario (e.g. S-shape maneuver).
# "optimization_base": This module selects avoidance target object
# and bpp module clips drivable area based on avoidance target object polygon shape.
# But this module doesn't modify the path shape.
# On the other hand, autoware_path_optimizer module optimizes path shape instead of this module
# so that the path can be within drivable area. This method is able to deal with complex avoidance scenario.
# However, user can't control avoidance manuever execution.
# "both" : Use both method.
path_generation_method: "shift_line_base"

shift_line_pipeline:
trim:
quantize_size: 0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ struct AvoidanceParameters
// enable yield maneuver.
bool enable_yield_maneuver_during_shifting{false};

// disable path update
bool disable_path_update{false};

// use hatched road markings for avoidance
bool use_hatched_road_markings{false};

Expand Down Expand Up @@ -313,6 +310,9 @@ struct AvoidanceParameters
// policy
std::string policy_lateral_margin{"best_effort"};

// path generation method.
std::string path_generation_method{"shift_line_base"};

// target velocity matrix
std::vector<double> velocity_map;

Expand All @@ -334,9 +334,6 @@ struct AvoidanceParameters
// rss parameters
utils::path_safety_checker::RSSparams rss_params{};

// clip left and right bounds for objects
bool enable_bound_clipping{false};

// debug
bool enable_other_objects_marker{false};
bool enable_other_objects_info{false};
Expand Down Expand Up @@ -438,6 +435,9 @@ struct ObjectData // avoidance target
// is ambiguous stopped vehicle.
bool is_ambiguous{false};

// is clip targe.
bool is_clip_target{false};

// object direction.
Direction direction{Direction::NONE};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ AvoidanceParameters getParameter(rclcpp::Node * node)
getOrDeclareParameter<double>(*node, ns + "resample_interval_for_planning");
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.disable_path_update = getOrDeclareParameter<bool>(*node, ns + "disable_path_update");
p.path_generation_method =
getOrDeclareParameter<std::string>(*node, ns + "path_generation_method");
}

// drivable area
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ class StaticObstacleAvoidanceModule : public SceneModuleInterface

UUID candidate_uuid_;

ObjectDataArray clip_objects_;

// TODO(Satoshi OTA) create detected object manager.
ObjectDataArray registered_objects_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ void updateRegisteredObject(
ObjectDataArray & registered_objects, const ObjectDataArray & now_objects,
const std::shared_ptr<AvoidanceParameters> & parameters);

void updateClipObject(ObjectDataArray & clip_objects, AvoidancePlanningData & data);

void compensateDetectionLost(
const ObjectDataArray & registered_objects, ObjectDataArray & now_objects,
ObjectDataArray & other_objects);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@
"description": "Path resample interval for output path. Too short interval increases computational cost for latter modules.",
"default": "4.0"
},
"enable_bound_clipping": {
"type": "boolean",
"description": "Enable clipping left and right bound of drivable area when obstacles are in the drivable area.",
"default": "false"
},
"disable_path_update": {
"type": "boolean",
"description": "Disable path update.",
"default": "false"
"path_generation_method": {
"enum": ["shift_line_base", "optimization_base", "both"],
"description": "Path generation method.",
"default": "shift_line_base"
},
"use_adjacent_lane": {
"type": "boolean",
Expand Down Expand Up @@ -1445,7 +1440,7 @@
"required": [
"resample_interval_for_planning",
"resample_interval_for_output",
"enable_bound_clipping",
"path_generation_method",
"use_adjacent_lane",
"use_opposite_lane",
"use_hatched_road_markings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ MarkerArray createObjectInfoMarkerArray(
string_stream << std::fixed << std::setprecision(2) << std::boolalpha;
string_stream << "ratio:" << object.shiftable_ratio << " [-]\n"
<< "lateral:" << object.to_centerline << " [m]\n"
<< "clip:" << object.is_clip_target << " [-]\n"
<< "necessity:" << object.avoid_required << " [-]\n"
<< "stoppable:" << object.is_stoppable << " [-]\n"
<< "stop_factor:" << object.to_stop_factor_distance << " [m]\n"
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_static_obstacle_avoidance_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 1266 to 1263, 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.
//
// 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 @@ -294,6 +294,7 @@
registered_objects_, data.target_objects, parameters_);
utils::static_obstacle_avoidance::compensateDetectionLost(
registered_objects_, data.target_objects, data.other_objects);
utils::static_obstacle_avoidance::updateClipObject(clip_objects_, data);

Check warning on line 297 in planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/scene.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Large Method

StaticObstacleAvoidanceModule::fillFundamentalData increases from 85 to 86 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.

// sort object order by longitudinal distance
std::sort(data.target_objects.begin(), data.target_objects.end(), [](auto a, auto b) {
Expand Down Expand Up @@ -653,7 +654,7 @@
void StaticObstacleAvoidanceModule::updateEgoBehavior(
const AvoidancePlanningData & data, ShiftedPath & path)
{
if (parameters_->disable_path_update) {
if (parameters_->path_generation_method == "optimization_base") {
return;
}

Expand Down Expand Up @@ -998,19 +999,14 @@
// expand freespace areas
current_drivable_area_info.enable_expanding_freespace_areas = parameters_->use_freespace_areas;
// generate obstacle polygons
if (parameters_->enable_bound_clipping) {
ObjectDataArray clip_objects;
// If avoidance is executed by both behavior and motion, only non-avoidable object will be
// extracted from the drivable area.
std::for_each(
data.target_objects.begin(), data.target_objects.end(), [&](const auto & object) {
if (!object.is_avoidable) clip_objects.push_back(object);
});
current_drivable_area_info.obstacles.clear();

if (
parameters_->path_generation_method == "optimization_base" ||
parameters_->path_generation_method == "both") {

Check warning on line 1006 in planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/scene.cpp#L1006

Added line #L1006 was not covered by tests
current_drivable_area_info.obstacles =
utils::static_obstacle_avoidance::generateObstaclePolygonsForDrivableArea(
clip_objects, parameters_, planner_data_->parameters.vehicle_width / 2.0);
} else {
current_drivable_area_info.obstacles.clear();
clip_objects_, parameters_, planner_data_->parameters.vehicle_width / 2.0);
}

output.drivable_area_info = utils::combineDrivableAreaInfo(
Expand Down Expand Up @@ -1077,7 +1073,7 @@

void StaticObstacleAvoidanceModule::updatePathShifter(const AvoidLineArray & shift_lines)
{
if (parameters_->disable_path_update) {
if (parameters_->path_generation_method == "optimization_base") {
return;
}

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_static_obstacle_avoidance_module/src/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 1859 to 1901, 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_static_obstacle_avoidance_module/src/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.25 to 5.27, 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 @@ -1690,6 +1690,59 @@
}
}

void updateClipObject(ObjectDataArray & clip_objects, AvoidancePlanningData & data)
{
std::for_each(data.target_objects.begin(), data.target_objects.end(), [](auto & o) {
if (o.is_avoidable) {
o.is_clip_target = true;

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

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/utils.cpp#L1697

Added line #L1697 was not covered by tests
}
});

const auto itr =
std::remove_if(clip_objects.begin(), clip_objects.end(), [&data](const auto & clip_object) {
const auto id = clip_object.object.object_id;

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

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/utils.cpp#L1703

Added line #L1703 was not covered by tests

// update target objects
{
const auto same_id_obj = std::find_if(
data.target_objects.begin(), data.target_objects.end(),
[&id](const auto & o) { return o.object.object_id == id; });
if (same_id_obj != data.target_objects.end()) {
same_id_obj->is_clip_target = true;

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

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/utils.cpp#L1711

Added line #L1711 was not covered by tests
return false;
}
}

// update other objects
{
const auto same_id_obj = std::find_if(
data.other_objects.begin(), data.other_objects.end(),
[&id](const auto & o) { return o.object.object_id == id; });
if (same_id_obj != data.other_objects.end()) {
same_id_obj->is_clip_target = true;

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

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/utils.cpp#L1722

Added line #L1722 was not covered by tests
return false;
}
}

return true;
});

clip_objects.erase(itr, clip_objects.end());

for (const auto & object : data.target_objects) {
const auto id = object.object.object_id;

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

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/utils.cpp#L1733

Added line #L1733 was not covered by tests
const auto same_id_obj = std::find_if(
clip_objects.begin(), clip_objects.end(),
[&id](const auto & o) { return o.object.object_id == id; });

if (same_id_obj != clip_objects.end()) {
continue;

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

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/utils.cpp#L1739

Added line #L1739 was not covered by tests
}

clip_objects.push_back(object);

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

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_static_obstacle_avoidance_module/src/utils.cpp#L1742

Added line #L1742 was not covered by tests
}
}

void updateRoadShoulderDistance(
AvoidancePlanningData & data, const std::shared_ptr<const PlannerData> & planner_data,
const std::shared_ptr<AvoidanceParameters> & parameters)
Expand Down
Loading