@@ -133,12 +133,35 @@ bool GoalPlannerModule::hasPreviousModulePathShapeChanged(
133
133
return true ;
134
134
}
135
135
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 ;
142
165
}
143
166
144
167
bool GoalPlannerModule::hasDeviatedFromLastPreviousModulePath (
@@ -157,9 +180,10 @@ bool GoalPlannerModule::hasDeviatedFromCurrentPreviousModulePath(
157
180
const std::shared_ptr<const PlannerData> planner_data,
158
181
const BehaviorModuleOutput & previous_module_output) const
159
182
{
183
+ constexpr double LATERAL_DEVIATION_THRESH = 0.3 ;
160
184
return std::abs (motion_utils::calcLateralOffset (
161
185
previous_module_output.path .points , planner_data->self_odometry ->pose .pose .position )) >
162
- 0.3 ;
186
+ LATERAL_DEVIATION_THRESH ;
163
187
}
164
188
165
189
// generate pull over candidate paths
0 commit comments