Skip to content

Commit 08bf607

Browse files
kosuke55mkuri
andauthored
fix(goal_planner): check lateral distance for previous output path shape change check (#1326)
Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> Co-authored-by: Makoto Kurihara <mkuri8m@gmail.com>
1 parent d8826bb commit 08bf607

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

+32-6
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,52 @@ void GoalPlannerModule::updateOccupancyGrid()
138138

139139
bool GoalPlannerModule::hasPreviousModulePathShapeChanged() const
140140
{
141+
constexpr double LATERAL_DEVIATION_THRESH = 0.3;
141142
if (!last_previous_module_output_) {
142143
return true;
143144
}
144145

146+
// Calculate the lateral distance between each point of the current path and the nearest point of
147+
// the last path
145148
const auto current_path = getPreviousModuleOutput().path;
146-
147-
// the terminal distance is far
148-
return calcDistance2d(
149-
last_previous_module_output_->path.points.back().point,
150-
current_path.points.back().point) > 0.3;
149+
for (const auto & p : current_path.points) {
150+
const size_t nearest_seg_idx = motion_utils::findNearestSegmentIndex(
151+
last_previous_module_output_->path.points, p.point.pose.position);
152+
const auto seg_front = last_previous_module_output_->path.points.at(nearest_seg_idx);
153+
const auto seg_back = last_previous_module_output_->path.points.at(nearest_seg_idx + 1);
154+
// Check if the target point is within the segment
155+
const Eigen::Vector3d segment_vec{
156+
seg_back.point.pose.position.x - seg_front.point.pose.position.x,
157+
seg_back.point.pose.position.y - seg_front.point.pose.position.y, 0.0};
158+
const Eigen::Vector3d target_vec{
159+
p.point.pose.position.x - seg_front.point.pose.position.x,
160+
p.point.pose.position.y - seg_front.point.pose.position.y, 0.0};
161+
const double dot_product = segment_vec.x() * target_vec.x() + segment_vec.y() * target_vec.y();
162+
const double segment_length_squared =
163+
segment_vec.x() * segment_vec.x() + segment_vec.y() * segment_vec.y();
164+
if (dot_product < 0 || dot_product > segment_length_squared) {
165+
// p.point.pose.position is not within the segment, skip lateral distance check
166+
continue;
167+
}
168+
const double lateral_distance = std::abs(motion_utils::calcLateralOffset(
169+
last_previous_module_output_->path.points, p.point.pose.position, nearest_seg_idx));
170+
if (lateral_distance > LATERAL_DEVIATION_THRESH) {
171+
return true;
172+
}
173+
}
174+
return false;
151175
}
152176

153177
bool GoalPlannerModule::hasDeviatedFromLastPreviousModulePath() const
154178
{
179+
constexpr double LATERAL_DEVIATION_THRESH = 0.3;
180+
155181
if (!last_previous_module_output_) {
156182
return true;
157183
}
158184
return std::abs(motion_utils::calcLateralOffset(
159185
last_previous_module_output_->path.points,
160-
planner_data_->self_odometry->pose.pose.position)) > 0.3;
186+
planner_data_->self_odometry->pose.pose.position)) > LATERAL_DEVIATION_THRESH;
161187
}
162188

163189
// generate pull over candidate paths

0 commit comments

Comments
 (0)