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(obstacle_cruise_planner): single slow down virtual wall #4374

Merged
merged 2 commits into from
Jul 24, 2023
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 @@ -217,6 +217,7 @@ struct DebugData
std::vector<StopObstacle> obstacles_to_stop;
std::vector<CruiseObstacle> obstacles_to_cruise;
std::vector<SlowDownObstacle> obstacles_to_slow_down;
MarkerArray slow_down_debug_wall_marker;
MarkerArray stop_wall_marker;
MarkerArray cruise_wall_marker;
MarkerArray slow_down_wall_marker;
Expand Down
4 changes: 4 additions & 0 deletions planning/obstacle_cruise_planner/src/node.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 TIER IV, Inc.

Check notice on line 1 in planning/obstacle_cruise_planner/src/node.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 1004 to 1006, 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 @@ -995,7 +995,7 @@
}
return true;
}
// check if entrying slow down

Check warning on line 998 in planning/obstacle_cruise_planner/src/node.cpp

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (entrying)
if (is_lat_dist_low) {
const int count = slow_down_condition_counter_.increaseCounter(obstacle.uuid);
if (p.successive_num_to_entry_slow_down_condition <= count) {
Expand All @@ -1016,7 +1016,7 @@
const auto obstacle_poly = obstacle.toPolygon();

// calculate collision points with trajectory with lateral stop margin
// NOTE: For additional margin, hysteresis is not devided by two.

Check warning on line 1019 in planning/obstacle_cruise_planner/src/node.cpp

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (devided)
const auto traj_polys_with_lat_margin = polygon_utils::createOneStepPolygons(
traj_points, vehicle_info_,
p.max_lat_margin_for_slow_down + p.lat_hysteresis_margin_for_slow_down);
Expand Down Expand Up @@ -1342,6 +1342,10 @@
debug_marker.markers.push_back(marker);
}

// slow down debug wall marker
tier4_autoware_utils::appendMarkerArray(
debug_data_ptr_->slow_down_debug_wall_marker, &debug_marker);

Check warning on line 1348 in planning/obstacle_cruise_planner/src/node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

ObstacleCruisePlannerNode::publishDebugMarker already has high cyclomatic complexity, and now it increases in Lines of Code from 87 to 89. 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.
debug_marker_pub_->publish(debug_marker);

// 2. publish virtual wall for cruise and stop
Expand Down
45 changes: 30 additions & 15 deletions planning/obstacle_cruise_planner/src/planner_interface.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 TIER IV, Inc.

Check notice on line 1 in planning/obstacle_cruise_planner/src/planner_interface.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.31 to 5.38, 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 @@ -410,78 +410,93 @@
return inserted_idx.get();
}
return std::nullopt;
};
const auto add_slow_down_marker =
[&](const size_t obstacle_idx, const auto slow_down_traj_idx, const bool is_start) {
if (!slow_down_traj_idx) return;

const int id = obstacle_idx * 2 + (is_start ? 0 : 1);
const auto text = is_start ? "obstacle slow down start" : "obstacle slow down end";
const auto pose = slow_down_traj_points.at(*slow_down_traj_idx).pose;
const auto markers = motion_utils::createSlowDownVirtualWallMarker(
pose, text, planner_data.current_time, id, abs_ego_offset);
tier4_autoware_utils::appendMarkerArray(markers, &debug_data_ptr_->slow_down_wall_marker);
};

std::vector<SlowDownOutput> new_prev_slow_down_output;
for (size_t i = 0; i < obstacles.size(); ++i) {
const auto & obstacle = obstacles.at(i);
const auto prev_output = getObjectFromUuid(prev_slow_down_output_, obstacle.uuid);

// calculate slow down start distance, and insert slow down velocity
const auto dist_vec_to_slow_down = calculateDistanceToSlowDownWithConstraints(
planner_data, slow_down_traj_points, obstacle, prev_output, dist_to_ego);
if (!dist_vec_to_slow_down) {
RCLCPP_INFO_EXPRESSION(
rclcpp::get_logger("ObstacleCruisePlanner::Plannerinterface"), enable_debug_info_,
rclcpp::get_logger("ObstacleCruisePlanner::PlannerInterface"), enable_debug_info_,
"[SlowDown] Ignore obstacle (%s) since distance to slow down is not valid",
obstacle.uuid.c_str());
continue;
}
const auto [dist_to_slow_down_start, dist_to_slow_down_end, feasible_slow_down_vel] =
*dist_vec_to_slow_down;

// calculate slow down end distance, and insert slow down velocity
// NOTE: slow_down_start_idx will not be wrong since inserted back point is after inserted
// front point.
const auto slow_down_start_idx = insert_point_in_trajectory(dist_to_slow_down_start);
const auto slow_down_end_idx = dist_to_slow_down_start < dist_to_slow_down_end
? insert_point_in_trajectory(dist_to_slow_down_end)
: std::nullopt;
if (!slow_down_end_idx) {
continue;
}

// calculate slow down velocity
const double stable_slow_down_vel = [&]() {
if (prev_output) {
return signal_processing::lowpassFilter(
feasible_slow_down_vel, prev_output->target_vel, slow_down_param_.lpf_gain_slow_down_vel);
}
return feasible_slow_down_vel;
}();

// insert slow down velocity between slow start and end
for (size_t i = (slow_down_start_idx ? *slow_down_start_idx : 0); i <= *slow_down_end_idx;
++i) {
auto & traj_point = slow_down_traj_points.at(i);
traj_point.longitudinal_velocity_mps =
std::min(traj_point.longitudinal_velocity_mps, static_cast<float>(stable_slow_down_vel));
}

// add debug data and virtual wall
// add debug data
slow_down_debug_multi_array_.data.push_back(obstacle.precise_lat_dist);
slow_down_debug_multi_array_.data.push_back(dist_to_slow_down_start);
slow_down_debug_multi_array_.data.push_back(dist_to_slow_down_end);
slow_down_debug_multi_array_.data.push_back(feasible_slow_down_vel);
slow_down_debug_multi_array_.data.push_back(stable_slow_down_vel);
slow_down_debug_multi_array_.data.push_back(slow_down_start_idx ? *slow_down_start_idx : -1.0);
slow_down_debug_multi_array_.data.push_back(slow_down_end_idx ? *slow_down_end_idx : -1.0);

// add virtual wall
if (slow_down_start_idx && slow_down_end_idx) {
const size_t ego_idx =
ego_nearest_param_.findIndex(slow_down_traj_points, planner_data.ego_pose);
const size_t slow_down_wall_idx = [&]() {
if (ego_idx < *slow_down_start_idx) return *slow_down_start_idx;
if (ego_idx < *slow_down_end_idx) return ego_idx;
return *slow_down_end_idx;
}();

const auto markers = motion_utils::createSlowDownVirtualWallMarker(
slow_down_traj_points.at(slow_down_wall_idx).pose, "obstacle slow down",

Check warning on line 481 in planning/obstacle_cruise_planner/src/planner_interface.cpp

View check run for this annotation

Codecov / codecov/patch

planning/obstacle_cruise_planner/src/planner_interface.cpp#L481

Added line #L481 was not covered by tests
planner_data.current_time, i, abs_ego_offset);
tier4_autoware_utils::appendMarkerArray(markers, &debug_data_ptr_->slow_down_wall_marker);
}

// add debug virtual wall
if (slow_down_start_idx) {
add_slow_down_marker(i, slow_down_start_idx, true);
const auto markers = motion_utils::createSlowDownVirtualWallMarker(
slow_down_traj_points.at(*slow_down_start_idx).pose, "obstacle slow down start",
planner_data.current_time, i * 2, abs_ego_offset);
tier4_autoware_utils::appendMarkerArray(
markers, &debug_data_ptr_->slow_down_debug_wall_marker);
}
if (slow_down_end_idx) {
add_slow_down_marker(i, slow_down_end_idx, false);
const auto markers = motion_utils::createSlowDownVirtualWallMarker(
slow_down_traj_points.at(*slow_down_end_idx).pose, "obstacle slow down end",

Check warning on line 496 in planning/obstacle_cruise_planner/src/planner_interface.cpp

View check run for this annotation

Codecov / codecov/patch

planning/obstacle_cruise_planner/src/planner_interface.cpp#L496

Added line #L496 was not covered by tests
planner_data.current_time, i * 2 + 1, abs_ego_offset);
tier4_autoware_utils::appendMarkerArray(
markers, &debug_data_ptr_->slow_down_debug_wall_marker);

Check warning on line 499 in planning/obstacle_cruise_planner/src/planner_interface.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

PlannerInterface::generateSlowDownTrajectory increases in cyclomatic complexity from 20 to 21, 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 499 in planning/obstacle_cruise_planner/src/planner_interface.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Bumpy Road Ahead

PlannerInterface::generateSlowDownTrajectory increases from 2 to 3 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.
}

debug_data_ptr_->obstacles_to_slow_down.push_back(obstacle);
Expand Down
Loading