@@ -456,6 +456,8 @@ PidLongitudinalController::ControlData PidLongitudinalController::getControlData
456
456
current_interpolated_pose.first );
457
457
control_data.nearest_idx = current_interpolated_pose.second + 1 ;
458
458
control_data.target_idx = control_data.nearest_idx ;
459
+ const auto nearest_point = current_interpolated_pose.first ;
460
+ auto target_point = current_interpolated_pose.first ;
459
461
460
462
// check if the deviation is worth emergency
461
463
m_diagnostic_data.trans_deviation =
@@ -491,11 +493,25 @@ PidLongitudinalController::ControlData PidLongitudinalController::getControlData
491
493
control_data.interpolated_traj .points .insert (
492
494
control_data.interpolated_traj .points .begin () + control_data.target_idx ,
493
495
target_interpolated_point.first );
496
+ target_point = target_interpolated_point.first ;
494
497
}
495
498
499
+ // ==========================================================================================
500
+ // NOTE: due to removeOverlapPoints(), the obtained control_data.target_idx and
501
+ // control_data.nearest_idx may become invalid if the number of points decreased.
502
+ // current API does not provide the way to check duplication beforehand and this function
503
+ // does not tell how many/which index points were removed, so there is no way
504
+ // to tell if our `control_data.target_idx` point still exists or removed.
505
+ // ==========================================================================================
496
506
// Remove overlapped points after inserting the interpolated points
497
507
control_data.interpolated_traj .points =
498
508
motion_utils::removeOverlapPoints (control_data.interpolated_traj .points );
509
+ control_data.nearest_idx = motion_utils::findFirstNearestIndexWithSoftConstraints (
510
+ control_data.interpolated_traj .points , nearest_point.pose , m_ego_nearest_dist_threshold,
511
+ m_ego_nearest_yaw_threshold);
512
+ control_data.target_idx = motion_utils::findFirstNearestIndexWithSoftConstraints (
513
+ control_data.interpolated_traj .points , target_point.pose , m_ego_nearest_dist_threshold,
514
+ m_ego_nearest_yaw_threshold);
499
515
500
516
// send debug values
501
517
m_debug_values.setValues (DebugValues::TYPE::PREDICTED_VEL, control_data.state_after_delay .vel );
@@ -610,8 +626,12 @@ void PidLongitudinalController::updateControlState(const ControlData & control_d
610
626
? (clock_->now () - *m_last_running_time).seconds () > p.stopped_state_entry_duration_time
611
627
: false ;
612
628
613
- const double current_vel_cmd =
614
- std::fabs (m_trajectory.points .at (control_data.nearest_idx ).longitudinal_velocity_mps );
629
+ // ==========================================================================================
630
+ // NOTE: due to removeOverlapPoints() in getControlData() m_trajectory and
631
+ // control_data.interpolated_traj have different size.
632
+ // ==========================================================================================
633
+ const double current_vel_cmd = std::fabs (
634
+ control_data.interpolated_traj .points .at (control_data.nearest_idx ).longitudinal_velocity_mps );
615
635
const bool emergency_condition = m_enable_overshoot_emergency &&
616
636
stop_dist < -p.emergency_state_overshoot_stop_dist &&
617
637
current_vel_cmd < vel_epsilon;
0 commit comments