Skip to content

Commit 0dee512

Browse files
authored
fix(start_planner): refine shift pull out path to start pose (#5874)
* fix(start_planner): refine shift pull out path to start pose Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> * fix typo Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> --------- Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
1 parent 4225f4e commit 0dee512

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

planning/behavior_path_start_planner_module/include/behavior_path_start_planner_module/shift_pull_out.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class ShiftPullOut : public PullOutPlannerBase
4646
double calcBeforeShiftedArcLength(
4747
const PathWithLaneId & path, const double target_after_arc_length, const double dr);
4848

49+
bool refineShiftedPathToStartPose(
50+
ShiftedPath & shifted_path, const Pose & start_pose, const Pose & end_pose,
51+
const double longitudinal_acc, const double lateral_acc);
52+
4953
std::shared_ptr<LaneDepartureChecker> lane_departure_checker_;
5054

5155
private:

planning/behavior_path_start_planner_module/src/shift_pull_out.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,58 @@ std::optional<PullOutPath> ShiftPullOut::plan(const Pose & start_pose, const Pos
158158
return std::nullopt;
159159
}
160160

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+
161213
std::vector<PullOutPath> ShiftPullOut::calcPullOutPaths(
162214
const RouteHandler & route_handler, const lanelet::ConstLanelets & road_lanes,
163215
const Pose & start_pose, const Pose & goal_pose)
@@ -303,6 +355,8 @@ std::vector<PullOutPath> ShiftPullOut::calcPullOutPaths(
303355
if (!path_shifter.generate(&shifted_path, offset_back)) {
304356
continue;
305357
}
358+
refineShiftedPathToStartPose(
359+
shifted_path, start_pose, *shift_end_pose_ptr, longitudinal_acc, lateral_acc);
306360

307361
// set velocity
308362
const size_t pull_out_end_idx =

0 commit comments

Comments
 (0)