Skip to content

Commit 9c41554

Browse files
authored
fix(goal_planner): check lateral distance for previous output path shape change check (autowarefoundation#7283)
Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
1 parent dfbf26c commit 9c41554

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

planning/autoware_behavior_path_goal_planner_module/src/goal_planner_module.cpp

+31-7
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,35 @@ bool GoalPlannerModule::hasPreviousModulePathShapeChanged(
133133
return true;
134134
}
135135

136-
const auto current_path = previous_module_output.path;
137-
138-
// the terminal distance is far
139-
return calcDistance2d(
140-
last_previous_module_output->path.points.back().point,
141-
current_path.points.back().point) > 0.3;
136+
// Calculate the lateral distance between each point of the current path and the nearest point of
137+
// the last path
138+
constexpr double LATERAL_DEVIATION_THRESH = 0.3;
139+
for (const auto & p : previous_module_output.path.points) {
140+
const size_t nearest_seg_idx = motion_utils::findNearestSegmentIndex(
141+
last_previous_module_output->path.points, p.point.pose.position);
142+
const auto seg_front = last_previous_module_output->path.points.at(nearest_seg_idx);
143+
const auto seg_back = last_previous_module_output->path.points.at(nearest_seg_idx + 1);
144+
// Check if the target point is within the segment
145+
const Eigen::Vector3d segment_vec{
146+
seg_back.point.pose.position.x - seg_front.point.pose.position.x,
147+
seg_back.point.pose.position.y - seg_front.point.pose.position.y, 0.0};
148+
const Eigen::Vector3d target_vec{
149+
p.point.pose.position.x - seg_front.point.pose.position.x,
150+
p.point.pose.position.y - seg_front.point.pose.position.y, 0.0};
151+
const double dot_product = segment_vec.x() * target_vec.x() + segment_vec.y() * target_vec.y();
152+
const double segment_length_squared =
153+
segment_vec.x() * segment_vec.x() + segment_vec.y() * segment_vec.y();
154+
if (dot_product < 0 || dot_product > segment_length_squared) {
155+
// p.point.pose.position is not within the segment, skip lateral distance check
156+
continue;
157+
}
158+
const double lateral_distance = std::abs(motion_utils::calcLateralOffset(
159+
last_previous_module_output->path.points, p.point.pose.position, nearest_seg_idx));
160+
if (lateral_distance > LATERAL_DEVIATION_THRESH) {
161+
return true;
162+
}
163+
}
164+
return false;
142165
}
143166

144167
bool GoalPlannerModule::hasDeviatedFromLastPreviousModulePath(
@@ -157,9 +180,10 @@ bool GoalPlannerModule::hasDeviatedFromCurrentPreviousModulePath(
157180
const std::shared_ptr<const PlannerData> planner_data,
158181
const BehaviorModuleOutput & previous_module_output) const
159182
{
183+
constexpr double LATERAL_DEVIATION_THRESH = 0.3;
160184
return std::abs(motion_utils::calcLateralOffset(
161185
previous_module_output.path.points, planner_data->self_odometry->pose.pose.position)) >
162-
0.3;
186+
LATERAL_DEVIATION_THRESH;
163187
}
164188

165189
// generate pull over candidate paths

0 commit comments

Comments
 (0)