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(map_based_prediction): prediction with acc constraints #5960

Merged
Show file tree
Hide file tree
Changes from 14 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
20 changes: 19 additions & 1 deletion perception/map_based_prediction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Lane change logics is illustrated in the figure below.An example of how to tune

### Tuning lane change detection logic

Currently we provide two parameters to tune lane change detection:
Currently we provide three parameters to tune lane change detection:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️


- `dist_threshold_to_bound_`: maximum distance from lane boundary allowed for lane changing vehicle
- `time_threshold_to_bound_`: maximum time allowed for lane change vehicle to reach the boundary
Expand Down Expand Up @@ -124,6 +124,24 @@ See paper [2] for more details.

`lateral_control_time_horizon` parameter supports the tuning of the lateral path shape. This parameter is used to calculate the time to reach the reference path. The smaller the value, the more the path will be generated to reach the reference path quickly. (Mostly the center of the lane.)

#### Pruning predicted paths with lateral acceleration constraint

It is possible to apply a maximum lateral acceleration constraint to generated vehicle paths. This check verifies if it is possible for the vehicle to perform the predicted path without surpassing a lateral acceleration threshold `max_lateral_accel` when taking a curve. If it is not possible, it checks if the vehicle can slow down on time to take the curve with a deceleration of `min_acceleration_before_curve` and comply with the constraint. If that is also not possible, the path is eliminated.

Currently we provide three parameters to tune the lateral acceleration constraint:

- `check_lateral_acceleration_constraints_`: to enable the constraint check.
- `max_lateral_accel_`: max acceptable lateral acceleration for predicted paths (absolute value).
- `min_acceleration_before_curve_`: the minimum acceleration the vehicle would theoretically use to slow down before a curve is taken (must be negative).

You can change these parameters in rosparam in the table below.

| param name | default value |
| ----------------------------------------- | -------------- |
| `check_lateral_acceleration_constraints_` | `false` [bool] |
| `max_lateral_accel` | `2.0` [m/s^2] |
| `min_acceleration_before_curve` | `-2.0` [m/s^2] |

### Path prediction for crosswalk users

This module treats **Pedestrians** and **Bicycles** as objects using the crosswalk, and outputs prediction path based on map and estimated object's velocity, assuming the object has intention to cross the crosswalk, if the objects satisfies at least one of the following conditions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
sigma_yaw_angle_deg: 5.0 #[angle degree]
object_buffer_time_length: 2.0 #[s]
history_time_length: 1.0 #[s]
check_lateral_acceleration_constraints: false # whether to check if the predicted path complies with lateral acceleration constraints
max_lateral_accel: 2.0 # [m/ss] max acceptable lateral acceleration for predicted vehicle paths
min_acceleration_before_curve: -2.0 # [m/ss] min acceleration a vehicle might take to decelerate before a curve
# parameter for shoulder lane prediction
prediction_time_horizon_rate_for_validate_shoulder_lane_length: 0.8

Expand All @@ -29,6 +32,6 @@
diff_dist_threshold_to_left_bound: 0.29 #[m]
diff_dist_threshold_to_right_bound: -0.29 #[m]
num_continuous_state_transition: 3
consider_only_routable_neighbours: false

Check warning on line 35 in perception/map_based_prediction/config/map_based_prediction.param.yaml

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (routable)

reference_path_resolution: 0.5 #[m]
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
#define MAP_BASED_PREDICTION__MAP_BASED_PREDICTION_NODE_HPP_

#include "map_based_prediction/path_generator.hpp"
#include "tf2/LinearMath/Quaternion.h"
#include "tier4_autoware_utils/geometry/geometry.hpp"
#include "tier4_autoware_utils/ros/update_param.hpp"

#include <rclcpp/rclcpp.hpp>
#include <tier4_autoware_utils/ros/transform_listener.hpp>
#include <tier4_autoware_utils/system/stop_watch.hpp>

#include "autoware_auto_planning_msgs/msg/trajectory_point.hpp"
#include <autoware_auto_mapping_msgs/msg/had_map_bin.hpp>
#include <autoware_auto_perception_msgs/msg/predicted_objects.hpp>
#include <autoware_auto_perception_msgs/msg/tracked_objects.hpp>
Expand All @@ -34,6 +38,7 @@
#include <lanelet2_routing/Forward.h>
#include <lanelet2_traffic_rules/TrafficRules.h>

#include <algorithm>
#include <deque>
#include <memory>
#include <string>
Expand Down Expand Up @@ -99,9 +104,10 @@
using autoware_auto_perception_msgs::msg::TrackedObject;
using autoware_auto_perception_msgs::msg::TrackedObjectKinematics;
using autoware_auto_perception_msgs::msg::TrackedObjects;
using autoware_auto_planning_msgs::msg::TrajectoryPoint;
using tier4_autoware_utils::StopWatch;
using tier4_debug_msgs::msg::StringStamped;

using TrajectoryPoints = std::vector<TrajectoryPoint>;
class MapBasedPredictionNode : public rclcpp::Node
{
public:
Expand All @@ -123,6 +129,11 @@
std::shared_ptr<lanelet::routing::RoutingGraph> routing_graph_ptr_;
std::shared_ptr<lanelet::traffic_rules::TrafficRules> traffic_rules_ptr_;

// parameter update
OnSetParametersCallbackHandle::SharedPtr set_param_res_;
rcl_interfaces::msg::SetParametersResult onParam(
const std::vector<rclcpp::Parameter> & parameters);

// Pose Transform Listener
tier4_autoware_utils::TransformListener transform_listener_{this};

Expand Down Expand Up @@ -160,6 +171,10 @@
bool consider_only_routable_neighbours_;
double reference_path_resolution_;

bool check_lateral_acceleration_constraints_;
double max_lateral_accel_;
double min_acceleration_before_curve_;

// Stop watch
StopWatch<std::chrono::milliseconds> stop_watch_;

Expand Down Expand Up @@ -237,6 +252,114 @@
Maneuver predictObjectManeuverByLatDiffDistance(
const TrackedObject & object, const LaneletData & current_lanelet_data,
const double object_detected_time);

inline std::vector<double> calcTrajectoryCurvatureFrom3Points(

Check warning on line 256 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L256

Added line #L256 was not covered by tests
danielsanchezaran marked this conversation as resolved.
Show resolved Hide resolved
const TrajectoryPoints & trajectory, size_t idx_dist)
{
using tier4_autoware_utils::calcCurvature;
using tier4_autoware_utils::getPoint;

if (trajectory.size() < 3) {
const std::vector<double> k_arr(trajectory.size(), 0.0);
return k_arr;

Check warning on line 264 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L262-L264

Added lines #L262 - L264 were not covered by tests
}

// if the idx size is not enough, change the idx_dist
const auto max_idx_dist = static_cast<size_t>(std::floor((trajectory.size() - 1) / 2.0));
idx_dist = std::max(1ul, std::min(idx_dist, max_idx_dist));

Check warning on line 269 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L268-L269

Added lines #L268 - L269 were not covered by tests

if (idx_dist < 1) {
throw std::logic_error("idx_dist less than 1 is not expected");

Check warning on line 272 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L271-L272

Added lines #L271 - L272 were not covered by tests
}

// calculate curvature by circle fitting from three points
std::vector<double> k_arr(trajectory.size(), 0.0);

Check warning on line 276 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L276

Added line #L276 was not covered by tests

for (size_t i = 1; i + 1 < trajectory.size(); i++) {

Check warning on line 278 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L278

Added line #L278 was not covered by tests
double curvature = 0.0;
const auto p0 = getPoint(trajectory.at(i - std::min(idx_dist, i)));

Check warning on line 280 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L280

Added line #L280 was not covered by tests
const auto p1 = getPoint(trajectory.at(i));
const auto p2 = getPoint(trajectory.at(i + std::min(idx_dist, trajectory.size() - 1 - i)));

Check warning on line 282 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L282

Added line #L282 was not covered by tests
try {
curvature = calcCurvature(p0, p1, p2);
} catch (std::exception const & e) {

Check warning on line 285 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L284-L285

Added lines #L284 - L285 were not covered by tests
// ...code that handles the error...
RCLCPP_WARN(

Check warning on line 287 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L287

Added line #L287 was not covered by tests
rclcpp::get_logger("motion_velocity_smoother").get_child("trajectory_utils"), "%s",
danielsanchezaran marked this conversation as resolved.
Show resolved Hide resolved
e.what());
if (i > 1) {
curvature = k_arr.at(i - 1); // previous curvature

Check warning on line 291 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L290-L291

Added lines #L290 - L291 were not covered by tests
} else {
curvature = 0.0;
}
}
k_arr.at(i) = curvature;

Check warning on line 296 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L295-L296

Added lines #L295 - L296 were not covered by tests
}
// copy curvatures for the last and first points;
k_arr.at(0) = k_arr.at(1);
k_arr.back() = k_arr.at((trajectory.size() - 2));

Check warning on line 300 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L299-L300

Added lines #L299 - L300 were not covered by tests

return k_arr;
}

inline TrajectoryPoints toTrajectoryPoints(const PredictedPath & path, const double velocity)

Check warning on line 305 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L305

Added line #L305 was not covered by tests
{
TrajectoryPoints out_trajectory;
std::for_each(
path.path.begin(), path.path.end(), [&out_trajectory, velocity](const auto & pose) {

Check warning on line 309 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L308-L309

Added lines #L308 - L309 were not covered by tests
TrajectoryPoint p;
p.pose = pose;
p.longitudinal_velocity_mps = velocity;
out_trajectory.push_back(p);
});
return out_trajectory;

Check warning on line 315 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L311-L315

Added lines #L311 - L315 were not covered by tests
};

inline bool isLateralAccelerationConstraintSatisfied(

Check warning on line 318 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L318

Added line #L318 was not covered by tests
const TrajectoryPoints & trajectory [[maybe_unused]], const double delta_time)
{
if (trajectory.size() < 3) return true;
const double max_lateral_accel_abs = std::fabs(max_lateral_accel_);

Check warning on line 322 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L321-L322

Added lines #L321 - L322 were not covered by tests

double arc_length = 0.0;
for (size_t i = 1; i < trajectory.size(); ++i) {
const auto current_pose = trajectory.at(i).pose;
const auto next_pose = trajectory.at(i - 1).pose;

Check warning on line 327 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L325-L327

Added lines #L325 - L327 were not covered by tests
// Compute distance between poses
const double delta_s = std::hypot(

Check warning on line 329 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L329

Added line #L329 was not covered by tests
next_pose.position.x - current_pose.position.x,
next_pose.position.y - current_pose.position.y);
arc_length += delta_s;

Check warning on line 332 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L332

Added line #L332 was not covered by tests

// Compute change in heading
tf2::Quaternion q_current, q_next;
tf2::convert(current_pose.orientation, q_current);
tf2::convert(next_pose.orientation, q_next);
double delta_theta = q_current.angleShortestPath(q_next);

Check warning on line 338 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L338

Added line #L338 was not covered by tests
// Handle wrap-around
if (delta_theta > 3.14159) {
danielsanchezaran marked this conversation as resolved.
Show resolved Hide resolved
delta_theta -= 2.0 * 3.14159;
} else if (delta_theta < -3.14159) {
delta_theta += 2.0 * 3.14159;

Check warning on line 343 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L340-L343

Added lines #L340 - L343 were not covered by tests
}

const double yaw_rate = std::max(delta_theta / delta_time, 1.0E-5);

Check warning on line 346 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L346

Added line #L346 was not covered by tests

const double current_speed = std::abs(trajectory.at(i).longitudinal_velocity_mps);

Check warning on line 348 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L348

Added line #L348 was not covered by tests
// Compute lateral acceleration
const double lateral_acceleration = std::abs(current_speed * yaw_rate);
if (lateral_acceleration < max_lateral_accel_abs) continue;

Check warning on line 351 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L350-L351

Added lines #L350 - L351 were not covered by tests

const double v_curvature_max = std::sqrt(max_lateral_accel_abs / yaw_rate);
const double t =
(v_curvature_max - current_speed) / min_acceleration_before_curve_; // acc is negative

Check warning on line 355 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L353-L355

Added lines #L353 - L355 were not covered by tests
const double distance_to_slow_down =
current_speed * t + 0.5 * min_acceleration_before_curve_ * std::pow(t, 2);

Check warning on line 357 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L357

Added line #L357 was not covered by tests

if (distance_to_slow_down > arc_length) return false;

Check warning on line 359 in perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp#L359

Added line #L359 was not covered by tests
}
return true;
};
};
} // namespace map_based_prediction

Expand Down
68 changes: 66 additions & 2 deletions perception/map_based_prediction/src/map_based_prediction_node.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 perception/map_based_prediction/src/map_based_prediction_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 1539 to 1588, 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 perception/map_based_prediction/src/map_based_prediction_node.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 6.12 to 6.18, 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 @@ -740,6 +740,12 @@
sigma_yaw_angle_deg_ = declare_parameter<double>("sigma_yaw_angle_deg");
object_buffer_time_length_ = declare_parameter<double>("object_buffer_time_length");
history_time_length_ = declare_parameter<double>("history_time_length");

check_lateral_acceleration_constraints_ =
declare_parameter<bool>("check_lateral_acceleration_constraints");
max_lateral_accel_ = declare_parameter<double>("max_lateral_accel");
min_acceleration_before_curve_ = declare_parameter<double>("min_acceleration_before_curve");

Check warning on line 747 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/src/map_based_prediction_node.cpp#L744-L747

Added lines #L744 - L747 were not covered by tests

{ // lane change detection
lane_change_detection_method_ = declare_parameter<std::string>("lane_change_detection.method");

Expand Down Expand Up @@ -789,6 +795,25 @@
pub_debug_markers_ =
this->create_publisher<visualization_msgs::msg::MarkerArray>("maneuver", rclcpp::QoS{1});
pub_calculation_time_ = create_publisher<StringStamped>("~/debug/calculation_time", 1);

set_param_res_ = this->add_on_set_parameters_callback(
std::bind(&MapBasedPredictionNode::onParam, this, std::placeholders::_1));
}

Check warning on line 801 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/src/map_based_prediction_node.cpp#L799-L801

Added lines #L799 - L801 were not covered by tests

rcl_interfaces::msg::SetParametersResult MapBasedPredictionNode::onParam(

Check warning on line 803 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/src/map_based_prediction_node.cpp#L803

Added line #L803 was not covered by tests
const std::vector<rclcpp::Parameter> & parameters)
{
using tier4_autoware_utils::updateParam;

updateParam(parameters, "max_lateral_accel", max_lateral_accel_);
updateParam(parameters, "min_acceleration_before_curve", min_acceleration_before_curve_);
updateParam(
parameters, "check_lateral_acceleration_constraints", check_lateral_acceleration_constraints_);

Check warning on line 811 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/src/map_based_prediction_node.cpp#L808-L811

Added lines #L808 - L811 were not covered by tests

rcl_interfaces::msg::SetParametersResult result;
result.successful = true;
result.reason = "success";
return result;

Check warning on line 816 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/src/map_based_prediction_node.cpp#L813-L816

Added lines #L813 - L816 were not covered by tests
}

PredictedObjectKinematics MapBasedPredictionNode::convertToPredictedKinematics(
Expand Down Expand Up @@ -972,16 +997,55 @@
}
// Generate Predicted Path
std::vector<PredictedPath> predicted_paths;
double min_avg_curvature = std::numeric_limits<double>::max();
PredictedPath path_with_smallest_avg_curvature;

for (const auto & ref_path : ref_paths) {
PredictedPath predicted_path = path_generator_->generatePathForOnLaneVehicle(
yaw_fixed_transformed_object, ref_path.path);
if (predicted_path.path.empty()) {
continue;
}
danielsanchezaran marked this conversation as resolved.
Show resolved Hide resolved
predicted_path.confidence = ref_path.probability;
predicted_paths.push_back(predicted_path);

if (!check_lateral_acceleration_constraints_) {
danielsanchezaran marked this conversation as resolved.
Show resolved Hide resolved
predicted_path.confidence = ref_path.probability;
predicted_paths.push_back(predicted_path);
continue;

Check warning on line 1013 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/src/map_based_prediction_node.cpp#L1010-L1013

Added lines #L1010 - L1013 were not covered by tests
}

// Check lat. acceleration constraints
const auto trajectory_with_const_velocity =
toTrajectoryPoints(predicted_path, abs_obj_speed);

Check warning on line 1018 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/src/map_based_prediction_node.cpp#L1018

Added line #L1018 was not covered by tests

if (isLateralAccelerationConstraintSatisfied(

Check warning on line 1020 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/src/map_based_prediction_node.cpp#L1020

Added line #L1020 was not covered by tests
trajectory_with_const_velocity, prediction_sampling_time_interval_)) {
predicted_path.confidence = ref_path.probability;
predicted_paths.push_back(predicted_path);
continue;

Check warning on line 1024 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/src/map_based_prediction_node.cpp#L1022-L1024

Added lines #L1022 - L1024 were not covered by tests
}

// Calculate curvature assuming the trajectory points interval is constant
// In case all paths are deleted, a copy of the straightest path is kept

constexpr double curvature_calculation_distance = 2.0;
constexpr double points_interval = 1.0;
const size_t idx_dist = static_cast<size_t>(
std::max(static_cast<int>((curvature_calculation_distance) / points_interval), 1));
const auto curvature_v =
calcTrajectoryCurvatureFrom3Points(trajectory_with_const_velocity, idx_dist);
if (curvature_v.empty()) {

Check warning on line 1036 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/src/map_based_prediction_node.cpp#L1035-L1036

Added lines #L1035 - L1036 were not covered by tests
continue;
}
const auto curvature_avg =
std::accumulate(curvature_v.begin(), curvature_v.end(), 0.0) / curvature_v.size();
if (curvature_avg < min_avg_curvature) {

Check warning on line 1041 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/src/map_based_prediction_node.cpp#L1040-L1041

Added lines #L1040 - L1041 were not covered by tests
min_avg_curvature = curvature_avg;
path_with_smallest_avg_curvature = predicted_path;
path_with_smallest_avg_curvature.confidence = ref_path.probability;

Check warning on line 1044 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/src/map_based_prediction_node.cpp#L1044

Added line #L1044 was not covered by tests
}
}

if (predicted_paths.empty()) predicted_paths.push_back(path_with_smallest_avg_curvature);

Check warning on line 1048 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

MapBasedPredictionNode::objectsCallback increases in cyclomatic complexity from 28 to 36, 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 warning on line 1048 in perception/map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/map_based_prediction/src/map_based_prediction_node.cpp#L1048

Added line #L1048 was not covered by tests
// Normalize Path Confidence and output the predicted object

float sum_confidence = 0.0;
Expand Down
Loading