@@ -87,6 +87,9 @@ void NormalLaneChange::update_lanes(const bool is_approved)
87
87
common_data_ptr_->lanes_ptr ->target = target_lanes;
88
88
89
89
const auto & route_handler_ptr = common_data_ptr_->route_handler_ptr ;
90
+ common_data_ptr_->lanes_ptr ->target_neighbor = utils::lane_change::getTargetNeighborLanes (
91
+ *route_handler_ptr, current_lanes, common_data_ptr_->lc_type );
92
+
90
93
common_data_ptr_->lanes_ptr ->current_lane_in_goal_section =
91
94
route_handler_ptr->isInGoalRouteSection (current_lanes.back ());
92
95
common_data_ptr_->lanes_ptr ->preceding_target = utils::getPrecedingLanelets (
@@ -1464,6 +1467,9 @@ bool NormalLaneChange::getLaneChangePaths(
1464
1467
RCLCPP_DEBUG (logger_, " - sampling num for lat_acc: %lu" , sample_lat_acc.size ());
1465
1468
1466
1469
debug_print (" Prepare path satisfy constraints" );
1470
+ const auto dist_lc_start_to_end_of_lanes = calculation::calc_dist_from_pose_to_terminal_end (
1471
+ common_data_ptr_, common_data_ptr_->lanes_ptr ->target_neighbor , lane_changing_start_pose);
1472
+
1467
1473
for (const auto & lateral_acc : sample_lat_acc) {
1468
1474
const auto lane_changing_time = PathShifter::calcShiftTimeFromJerk (
1469
1475
shift_length, lane_change_parameters_->lane_changing_lateral_jerk , lateral_acc);
@@ -1474,11 +1480,6 @@ bool NormalLaneChange::getLaneChangePaths(
1474
1480
const auto lane_changing_length = utils::lane_change::calcPhaseLength (
1475
1481
initial_lane_changing_velocity, getCommonParam ().max_vel ,
1476
1482
longitudinal_acc_on_lane_changing, lane_changing_time);
1477
- const auto terminal_lane_changing_velocity = std::min (
1478
- initial_lane_changing_velocity + longitudinal_acc_on_lane_changing * lane_changing_time,
1479
- getCommonParam ().max_vel );
1480
- utils::lane_change::setPrepareVelocity (
1481
- prepare_segment, current_velocity, terminal_lane_changing_velocity);
1482
1483
1483
1484
const auto debug_print_lat = [&](const auto & s) {
1484
1485
RCLCPP_DEBUG (
@@ -1493,26 +1494,30 @@ bool NormalLaneChange::getLaneChangePaths(
1493
1494
continue ;
1494
1495
}
1495
1496
1496
- if (is_goal_in_route) {
1497
- const double s_start =
1498
- lanelet::utils::getArcCoordinates (target_lanes, lane_changing_start_pose).length ;
1499
- const double s_goal =
1500
- lanelet::utils::getArcCoordinates (target_lanes, route_handler.getGoalPose ()).length ;
1501
- const auto num =
1497
+ // if multiple lane change is necessary, does the remaining distance is sufficient
1498
+ const auto remaining_dist_in_target = std::invoke ([&]() {
1499
+ const auto finish_judge_buffer = lane_change_parameters_->lane_change_finish_judge_buffer ;
1500
+ const auto num_to_preferred_lane_from_target_lane =
1502
1501
std::abs (route_handler.getNumLaneToPreferredLane (target_lanes.back (), direction));
1503
- const double backward_buffer =
1504
- num == 0 ? 0.0 : lane_change_parameters_->backward_length_buffer_for_end_of_lane ;
1505
- const double finish_judge_buffer =
1506
- lane_change_parameters_-> lane_change_finish_judge_buffer ;
1507
- if (
1508
- s_start + lane_changing_length + finish_judge_buffer + backward_buffer +
1509
- next_lane_change_buffer >
1510
- s_goal) {
1511
- debug_print_lat ( " Reject: length of lane changing path is longer than length to goal!! " );
1512
- continue ;
1513
- }
1502
+ const auto backward_len_buffer =
1503
+ lane_change_parameters_->backward_length_buffer_for_end_of_lane ;
1504
+ const auto backward_buffer_to_target_lane =
1505
+ num_to_preferred_lane_from_target_lane == 0 ? 0.0 : backward_len_buffer ;
1506
+ return lane_changing_length + finish_judge_buffer + backward_buffer_to_target_lane +
1507
+ next_lane_change_buffer;
1508
+ });
1509
+
1510
+ if (remaining_dist_in_target > dist_lc_start_to_end_of_lanes) {
1511
+ debug_print_lat ( " Reject: length of lane changing path is longer than length to goal!! " ) ;
1512
+ continue ;
1514
1513
}
1515
1514
1515
+ const auto terminal_lane_changing_velocity = std::min (
1516
+ initial_lane_changing_velocity + longitudinal_acc_on_lane_changing * lane_changing_time,
1517
+ getCommonParam ().max_vel );
1518
+ utils::lane_change::setPrepareVelocity (
1519
+ prepare_segment, current_velocity, terminal_lane_changing_velocity);
1520
+
1516
1521
const auto target_segment = getTargetSegment (
1517
1522
target_lanes, lane_changing_start_pose, target_lane_length, lane_changing_length,
1518
1523
initial_lane_changing_velocity, next_lane_change_buffer);
0 commit comments