@@ -158,6 +158,58 @@ std::optional<PullOutPath> ShiftPullOut::plan(const Pose & start_pose, const Pos
158
158
return std::nullopt;
159
159
}
160
160
161
+ bool ShiftPullOut::refineShiftedPathToStartPose (
162
+ ShiftedPath & shifted_path, const Pose & start_pose, const Pose & end_pose,
163
+ const double longitudinal_acc, const double lateral_acc)
164
+ {
165
+ constexpr double TOLERANCE = 0.01 ;
166
+ constexpr size_t MAX_ITERATION = 100 ;
167
+
168
+ // Lambda to check if change is above tolerance
169
+ auto is_within_tolerance =
170
+ [](const auto & prev_val, const auto & current_val, const auto & tolerance) {
171
+ return std::abs (current_val - prev_val) < tolerance;
172
+ };
173
+
174
+ size_t iteration = 0 ;
175
+ while (iteration < MAX_ITERATION) {
176
+ const double lateral_offset =
177
+ motion_utils::calcLateralOffset (shifted_path.path .points , start_pose.position );
178
+
179
+ PathShifter path_shifter;
180
+ path_shifter.setPath (shifted_path.path );
181
+ ShiftLine shift_line{};
182
+ shift_line.start = start_pose;
183
+ shift_line.end = end_pose;
184
+ shift_line.end_shift_length = lateral_offset;
185
+ path_shifter.addShiftLine (shift_line);
186
+ path_shifter.setVelocity (0.0 );
187
+ path_shifter.setLongitudinalAcceleration (longitudinal_acc);
188
+ path_shifter.setLateralAccelerationLimit (lateral_acc);
189
+
190
+ if (!path_shifter.generate (&shifted_path, false )) {
191
+ RCLCPP_WARN (
192
+ rclcpp::get_logger (" ShiftPullOut:refineShiftedPathToStartPose()" ),
193
+ " Failed to generate shifted path" );
194
+ return false ;
195
+ }
196
+
197
+ if (is_within_tolerance (
198
+ lateral_offset,
199
+ motion_utils::calcLateralOffset (shifted_path.path .points , start_pose.position ),
200
+ TOLERANCE)) {
201
+ return true ;
202
+ }
203
+
204
+ iteration++;
205
+ }
206
+
207
+ RCLCPP_WARN (
208
+ rclcpp::get_logger (" ShiftPullOut:refineShiftedPathToStartPose()" ),
209
+ " Failed to converge lateral offset until max iteration" );
210
+ return false ;
211
+ }
212
+
161
213
std::vector<PullOutPath> ShiftPullOut::calcPullOutPaths (
162
214
const RouteHandler & route_handler, const lanelet::ConstLanelets & road_lanes,
163
215
const Pose & start_pose, const Pose & goal_pose)
@@ -303,6 +355,8 @@ std::vector<PullOutPath> ShiftPullOut::calcPullOutPaths(
303
355
if (!path_shifter.generate (&shifted_path, offset_back)) {
304
356
continue ;
305
357
}
358
+ refineShiftedPathToStartPose (
359
+ shifted_path, start_pose, *shift_end_pose_ptr, longitudinal_acc, lateral_acc);
306
360
307
361
// set velocity
308
362
const size_t pull_out_end_idx =
0 commit comments