Skip to content

Commit bc1868b

Browse files
authored
fix(pid_longitudinal_controller): fixed nearest/target index before/after insertion and removal of path points (#6391)
Signed-off-by: Mamoru Sobue <mamoru.sobue@tier4.jp>
1 parent b68cdd6 commit bc1868b

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

control/pid_longitudinal_controller/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<maintainer email="takamasa.horibe@tier4.jp">Takamasa Horibe</maintainer>
99
<maintainer email="takayuki.murooka@tier4.jp">Takayuki Murooka</maintainer>
10+
<maintainer email="mamoru.sobue@tier4.jp">Mamoru Sobue</maintainer>
1011

1112
<license>Apache 2.0</license>
1213

control/pid_longitudinal_controller/src/pid_longitudinal_controller.cpp

+22-2
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ PidLongitudinalController::ControlData PidLongitudinalController::getControlData
456456
current_interpolated_pose.first);
457457
control_data.nearest_idx = current_interpolated_pose.second + 1;
458458
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;
459461

460462
// check if the deviation is worth emergency
461463
m_diagnostic_data.trans_deviation =
@@ -491,11 +493,25 @@ PidLongitudinalController::ControlData PidLongitudinalController::getControlData
491493
control_data.interpolated_traj.points.insert(
492494
control_data.interpolated_traj.points.begin() + control_data.target_idx,
493495
target_interpolated_point.first);
496+
target_point = target_interpolated_point.first;
494497
}
495498

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+
// ==========================================================================================
496506
// Remove overlapped points after inserting the interpolated points
497507
control_data.interpolated_traj.points =
498508
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);
499515

500516
// send debug values
501517
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
610626
? (clock_->now() - *m_last_running_time).seconds() > p.stopped_state_entry_duration_time
611627
: false;
612628

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);
615635
const bool emergency_condition = m_enable_overshoot_emergency &&
616636
stop_dist < -p.emergency_state_overshoot_stop_dist &&
617637
current_vel_cmd < vel_epsilon;

0 commit comments

Comments
 (0)