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(lane_change): cap ego's predicted path velocity (RT1-8505) #9341

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 @@ -115,10 +115,9 @@ CandidateOutput assignToCandidate(
std::optional<lanelet::ConstLanelet> get_lane_change_target_lane(
const CommonDataPtr & common_data_ptr, const lanelet::ConstLanelets & current_lanes);

std::vector<PoseWithVelocityStamped> convertToPredictedPath(
const LaneChangePath & lane_change_path, const Twist & vehicle_twist, const Pose & pose,
const double lane_changing_acceleration, const BehaviorPathPlannerParameters & common_parameters,
const LaneChangeParameters & lane_change_parameters, const double resolution);
std::vector<PoseWithVelocityStamped> convert_to_predicted_path(
const CommonDataPtr & common_data_ptr, const LaneChangePath & lane_change_path,
const double lane_changing_acceleration);

bool isParkedObject(
const PathWithLaneId & path, const RouteHandler & route_handler,
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_lane_change_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 1664 to 1658, 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 @@ -1888,8 +1888,6 @@
return false;
}

const auto current_pose = common_data_ptr_->get_ego_pose();
const auto current_twist = common_data_ptr_->get_ego_twist();
const auto bpp_param = *common_data_ptr_->bpp_param_ptr;
const auto global_min_acc = bpp_param.min_acc;
const auto lane_changing_acc = lane_change_path.info.longitudinal_acceleration.lane_changing;
Expand All @@ -1906,15 +1904,10 @@
acceleration_values.begin(), acceleration_values.end(), acceleration_values.begin(),
[&](double n) { return lane_changing_acc + n * acc_resolution; });

const auto time_resolution = lane_change_parameters_->prediction_time_resolution;

const auto all_collided = std::all_of(
acceleration_values.begin(), acceleration_values.end(), [&](const auto acceleration) {
const auto ego_predicted_path = utils::lane_change::convertToPredictedPath(
lane_change_path, current_twist, current_pose, acceleration, bpp_param,
*lane_change_parameters_, time_resolution);
const auto debug_predicted_path =
utils::path_safety_checker::convertToPredictedPath(ego_predicted_path, time_resolution);
const auto ego_predicted_path = utils::lane_change::convert_to_predicted_path(
common_data_ptr_, lane_change_path, acceleration);

return std::any_of(objects.begin(), objects.end(), [&](const auto & obj) {
const auto selected_rss_param =
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/autoware_behavior_path_lane_change_module/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 1034 to 1040, 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 @@ -597,52 +597,58 @@
return route_handler_ptr->getLaneChangeTargetExceptPreferredLane(current_lanes, direction);
}

std::vector<PoseWithVelocityStamped> convertToPredictedPath(
const LaneChangePath & lane_change_path, const Twist & vehicle_twist, const Pose & vehicle_pose,
const double lane_changing_acceleration, const BehaviorPathPlannerParameters & common_parameters,
const LaneChangeParameters & lane_change_parameters, const double resolution)
std::vector<PoseWithVelocityStamped> convert_to_predicted_path(
const CommonDataPtr & common_data_ptr, const LaneChangePath & lane_change_path,
const double lane_changing_acceleration)
{
if (lane_change_path.path.points.empty()) {
return {};
}

const auto & path = lane_change_path.path;
const auto prepare_acc = lane_change_path.info.longitudinal_acceleration.prepare;
const auto duration = lane_change_path.info.duration.sum();
const auto prepare_time = lane_change_path.info.duration.prepare;
const auto & minimum_lane_changing_velocity =
lane_change_parameters.minimum_lane_changing_velocity;

const auto & vehicle_pose = common_data_ptr->get_ego_pose();
const auto & bpp_param_ptr = common_data_ptr->bpp_param_ptr;
const auto nearest_seg_idx =
autoware::motion_utils::findFirstNearestSegmentIndexWithSoftConstraints(
path.points, vehicle_pose, common_parameters.ego_nearest_dist_threshold,
common_parameters.ego_nearest_yaw_threshold);
path.points, vehicle_pose, bpp_param_ptr->ego_nearest_dist_threshold,
bpp_param_ptr->ego_nearest_yaw_threshold);

std::vector<PoseWithVelocityStamped> predicted_path;
const auto vehicle_pose_frenet =
convertToFrenetPoint(path.points, vehicle_pose.position, nearest_seg_idx);
const double initial_velocity = std::abs(vehicle_twist.linear.x);

const auto initial_velocity = common_data_ptr->get_ego_speed();
const auto prepare_acc = lane_change_path.info.longitudinal_acceleration.prepare;
const auto duration = lane_change_path.info.duration.sum();
const auto prepare_time = lane_change_path.info.duration.prepare;
const auto & lc_param_ptr = common_data_ptr->lc_param_ptr;
const auto minimum_lane_changing_velocity = lc_param_ptr->minimum_lane_changing_velocity;
const auto resolution = lc_param_ptr->prediction_time_resolution;
std::vector<PoseWithVelocityStamped> predicted_path;

// prepare segment
for (double t = 0.0; t < prepare_time; t += resolution) {
const double velocity =
std::max(initial_velocity + prepare_acc * t, minimum_lane_changing_velocity);
const double length = initial_velocity * t + 0.5 * prepare_acc * t * t;
const auto velocity = std::min(
std::max(initial_velocity + prepare_acc * t, minimum_lane_changing_velocity),
lane_change_path.info.velocity.prepare);
const auto length = initial_velocity * t + 0.5 * prepare_acc * t * t;
const auto pose = autoware::motion_utils::calcInterpolatedPose(
path.points, vehicle_pose_frenet.length + length);
predicted_path.emplace_back(t, pose, velocity);
}

// lane changing segment
const double lane_changing_velocity =
std::max(initial_velocity + prepare_acc * prepare_time, minimum_lane_changing_velocity);
const double offset =
const auto lane_changing_velocity = std::min(
std::max(initial_velocity + prepare_acc * prepare_time, minimum_lane_changing_velocity),
lane_change_path.info.velocity.prepare);
const auto offset =
initial_velocity * prepare_time + 0.5 * prepare_acc * prepare_time * prepare_time;
for (double t = prepare_time; t < duration; t += resolution) {
const double delta_t = t - prepare_time;
const double velocity = lane_changing_velocity + lane_changing_acceleration * delta_t;
const double length = lane_changing_velocity * delta_t +
0.5 * lane_changing_acceleration * delta_t * delta_t + offset;
const auto delta_t = t - prepare_time;
const auto velocity = std::min(
lane_changing_velocity + lane_changing_acceleration * delta_t,
lane_change_path.info.velocity.lane_changing);
const auto length = lane_changing_velocity * delta_t +
0.5 * lane_changing_acceleration * delta_t * delta_t + offset;

Check notice on line 651 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/utils/utils.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Excess Number of Function Arguments

convertToPredictedPath is no longer above the threshold for number of arguments. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.
const auto pose = autoware::motion_utils::calcInterpolatedPose(
path.points, vehicle_pose_frenet.length + length);
predicted_path.emplace_back(t, pose, velocity);
Expand Down
Loading