Skip to content

Commit

Permalink
fix(lane_change): relax finish judge
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Zulfaqar Azmi <zulfaqar.azmi@tier4.jp>
  • Loading branch information
zulfaqar-azmi-t4 committed Jul 24, 2024
1 parent f33635c commit 8b1c4f1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <autoware/behavior_path_planner_common/parameters.hpp>
#include <autoware/route_handler/route_handler.hpp>
#include <autoware/universe_utils/math/unit_conversion.hpp>
#include <interpolation/linear_interpolation.hpp>

#include <nav_msgs/msg/odometry.hpp>
Expand Down Expand Up @@ -109,7 +110,6 @@ struct Parameters
double lane_changing_lateral_jerk{0.5};
double minimum_lane_changing_velocity{5.6};
double lane_change_prepare_duration{4.0};
double lane_change_finish_judge_buffer{3.0};
LateralAccelerationMap lane_change_lat_acc_map;

// parked vehicle
Expand Down Expand Up @@ -157,7 +157,10 @@ struct Parameters
// abort
CancelParameters cancel{};

// finish judge parameter
double lane_change_finish_judge_buffer{3.0};
double finish_judge_lateral_threshold{0.2};
double finish_judge_lateral_angle_deviation{autoware::universe_utils::deg2rad(3.0)};

// debug marker
bool publish_debug_marker{false};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ LanesPolygon create_lanes_polygon(const CommonDataPtr & common_data_ptr);
bool is_same_lane_with_prev_iteration(
const CommonDataPtr & common_data_ptr, const lanelet::ConstLanelets & current_lanes,
const lanelet::ConstLanelets & target_lanes);

double calc_angle_to_lanelet_segment(const lanelet::ConstLanelets & lanelets, const Pose & pose);
} // namespace autoware::behavior_path_planner::utils::lane_change

namespace autoware::behavior_path_planner::utils::lane_change::debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ void LaneChangeModuleManager::initParams(rclcpp::Node * node)
getOrDeclareParameter<double>(*node, parameter("minimum_lane_changing_velocity"));
p.minimum_lane_changing_velocity =
std::min(p.minimum_lane_changing_velocity, max_acc * p.lane_change_prepare_duration);
p.lane_change_finish_judge_buffer =
getOrDeclareParameter<double>(*node, parameter("lane_change_finish_judge_buffer"));

if (p.backward_length_buffer_for_end_of_lane < 1.0) {
RCLCPP_WARN_STREAM(
Expand Down Expand Up @@ -224,8 +222,15 @@ void LaneChangeModuleManager::initParams(rclcpp::Node * node)
p.cancel.unsafe_hysteresis_threshold =
getOrDeclareParameter<int>(*node, parameter("cancel.unsafe_hysteresis_threshold"));

// finish judge parameters
p.lane_change_finish_judge_buffer =
getOrDeclareParameter<double>(*node, parameter("lane_change_finish_judge_buffer"));
p.finish_judge_lateral_threshold =
getOrDeclareParameter<double>(*node, parameter("finish_judge_lateral_threshold"));
const auto finish_judge_lateral_angle_deviation =
getOrDeclareParameter<double>(*node, parameter("finish_judge_lateral_angle_deviation"));
p.finish_judge_lateral_angle_deviation =
autoware::universe_utils::deg2rad(finish_judge_lateral_angle_deviation);

Check warning on line 233 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/manager.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

LaneChangeModuleManager::initParams already has high cyclomatic complexity, and now it increases in Lines of Code from 199 to 203. 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
p.publish_debug_marker = getOrDeclareParameter<bool>(*node, parameter("publish_debug_marker"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "autoware/behavior_path_planner_common/utils/utils.hpp"

#include <autoware/universe_utils/geometry/boost_polygon_utils.hpp>
#include <autoware/universe_utils/math/unit_conversion.hpp>
#include <autoware/universe_utils/system/time_keeper.hpp>
#include <autoware_lanelet2_extension/utility/message_conversion.hpp>
#include <autoware_lanelet2_extension/utility/utilities.hpp>
Expand Down Expand Up @@ -686,21 +687,33 @@ bool NormalLaneChange::hasFinishedLaneChange() const
const auto & lane_change_end = status_.lane_change_path.info.shift_line.end;
const auto & target_lanes = get_target_lanes();
const double dist_to_lane_change_end =
utils::getSignedDistance(current_pose, lane_change_end, get_target_lanes());
double finish_judge_buffer = lane_change_parameters_->lane_change_finish_judge_buffer;
utils::getSignedDistance(current_pose, lane_change_end, target_lanes);

// If ego velocity is low, relax finish judge buffer
const double ego_velocity = getEgoVelocity();
if (std::abs(ego_velocity) < 1.0) {
finish_judge_buffer = 0.0;
}
const auto finish_judge_buffer = std::invoke([&]() {
const double ego_velocity = getEgoVelocity();
// If ego velocity is low, relax finish judge buffer
if (std::abs(ego_velocity) < 1.0) {
return 0.0;
}
return lane_change_parameters_->lane_change_finish_judge_buffer;
});

const auto reach_lane_change_end = dist_to_lane_change_end + finish_judge_buffer < 0.0;
const auto has_passed_end_pose = dist_to_lane_change_end + finish_judge_buffer < 0.0;

lane_change_debug_.distance_to_lane_change_finished =
dist_to_lane_change_end + finish_judge_buffer;

if (!reach_lane_change_end) {
if (has_passed_end_pose) {
const auto & lanes_polygon = common_data_ptr_->lanes_polygon_ptr->target;
return !boost::geometry::disjoint(
lanes_polygon.value(),
lanelet::utils::to2D(lanelet::utils::conversion::toLaneletPoint(current_pose.position)));
}

const auto yaw_deviation_to_centerline =
utils::lane_change::calc_angle_to_lanelet_segment(target_lanes, current_pose);

if (yaw_deviation_to_centerline > lane_change_parameters_->finish_judge_lateral_angle_deviation) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,18 @@ bool is_same_lane_with_prev_iteration(
return (prev_target_lanes.front().id() == target_lanes.front().id()) &&
(prev_target_lanes.back().id() == prev_target_lanes.back().id());
}

double calc_angle_to_lanelet_segment(const lanelet::ConstLanelets & lanelets, const Pose & pose)
{
lanelet::ConstLanelet closest_lanelet;

if (!lanelet::utils::query::getClosestLanelet(lanelets, pose, &closest_lanelet)) {
return autoware::universe_utils::deg2rad(180);
}
const auto closest_pose = lanelet::utils::getClosestCenterPose(closest_lanelet, pose.position);
return std::abs(autoware::universe_utils::calcYawDeviation(closest_pose, pose));
}

} // namespace autoware::behavior_path_planner::utils::lane_change

namespace autoware::behavior_path_planner::utils::lane_change::debug
Expand Down

0 comments on commit 8b1c4f1

Please sign in to comment.