@@ -138,26 +138,52 @@ void GoalPlannerModule::updateOccupancyGrid()
138
138
139
139
bool GoalPlannerModule::hasPreviousModulePathShapeChanged () const
140
140
{
141
+ constexpr double LATERAL_DEVIATION_THRESH = 0.3 ;
141
142
if (!last_previous_module_output_) {
142
143
return true ;
143
144
}
144
145
146
+ // Calculate the lateral distance between each point of the current path and the nearest point of
147
+ // the last path
145
148
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 ;
151
175
}
152
176
153
177
bool GoalPlannerModule::hasDeviatedFromLastPreviousModulePath () const
154
178
{
179
+ constexpr double LATERAL_DEVIATION_THRESH = 0.3 ;
180
+
155
181
if (!last_previous_module_output_) {
156
182
return true ;
157
183
}
158
184
return std::abs (motion_utils::calcLateralOffset (
159
185
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 ;
161
187
}
162
188
163
189
// generate pull over candidate paths
0 commit comments