Skip to content

Commit 08b905a

Browse files
refactor(start_planner): refactor backward path calculation in StartPlannerModule (#5529)
* refactor(start_planner): refactor backward path calculation in StartPlannerModule The method "calcStartPoseCandidatesBackwardPath" has been renamed to "calcBackwardPathFromStartPose" to better reflect its purpose. The method now calculates the backward path by shifting the original start pose coordinates to align with the pull out lanes. The stop objects in the pull out lanes are filtered by velocity, using the new "filterStopObjectsInPullOutLanes" method. Additionally, the redundant "isOverlappedWithLane" method has been removed. Signed-off-by: kyoichi-sugahara <kyoichi.sugahara@tier4.jp> --------- Signed-off-by: kyoichi-sugahara <kyoichi.sugahara@tier4.jp> Co-authored-by: Kosuke Takeuchi <kosuke.tnp@gmail.com>
1 parent ff255eb commit 08b905a

File tree

3 files changed

+55
-58
lines changed

3 files changed

+55
-58
lines changed

planning/behavior_path_planner/docs/behavior_path_planner_start_planner_design.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ If a safe path cannot be generated from the current position, search backwards f
252252
| max_back_distance | [m] | double | maximum back distance | 30.0 |
253253
| backward_search_resolution | [m] | double | distance interval for searching backward pull out start point | 2.0 |
254254
| backward_path_update_duration | [s] | double | time interval for searching backward pull out start point. this prevents chattering between back driving and pull_out | 3.0 |
255-
| ignore_distance_from_lane_end | [m] | double | distance from end of pull out lanes for ignoring start candidates | 15.0 |
255+
| ignore_distance_from_lane_end | [m] | double | If distance from shift start pose to end of shoulder lane is less than this value, this start pose candidate is ignored | 15.0 |
256256

257257
### **freespace pull out**
258258

planning/behavior_path_planner/include/behavior_path_planner/scene_module/start_planner/start_planner_module.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ class StartPlannerModule : public SceneModuleInterface
176176
std::mutex mutex_;
177177

178178
PathWithLaneId getFullPath() const;
179-
PathWithLaneId calcStartPoseCandidatesBackwardPath() const;
180-
std::vector<Pose> searchPullOutStartPoses(const PathWithLaneId & start_pose_candidates) const;
179+
PathWithLaneId calcBackwardPathFromStartPose() const;
180+
std::vector<Pose> searchPullOutStartPoseCandidates(
181+
const PathWithLaneId & back_path_from_start_pose) const;
181182

182183
std::shared_ptr<LaneDepartureChecker> lane_departure_checker_;
183184

@@ -194,9 +195,8 @@ class StartPlannerModule : public SceneModuleInterface
194195
std::vector<DrivableLanes> generateDrivableLanes(const PathWithLaneId & path) const;
195196
void updatePullOutStatus();
196197
void updateStatusAfterBackwardDriving();
197-
static bool isOverlappedWithLane(
198-
const lanelet::ConstLanelet & candidate_lanelet,
199-
const tier4_autoware_utils::LinearRing2d & vehicle_footprint);
198+
PredictedObjects filterStopObjectsInPullOutLanes(
199+
const lanelet::ConstLanelets & pull_out_lanes, const double velocity_threshold) const;
200200
bool hasFinishedPullOut() const;
201201
bool isBackwardDrivingComplete() const;
202202
bool isStopped();

planning/behavior_path_planner/src/scene_module/start_planner/start_planner_module.cpp

+49-52
Original file line numberDiff line numberDiff line change
@@ -718,15 +718,15 @@ void StartPlannerModule::updatePullOutStatus()
718718
// refine start pose with pull out lanes.
719719
// 1) backward driving is not allowed: use refined pose just as start pose.
720720
// 2) backward driving is allowed: use refined pose to check if backward driving is needed.
721-
const PathWithLaneId start_pose_candidates_path = calcStartPoseCandidatesBackwardPath();
721+
const PathWithLaneId start_pose_candidates_path = calcBackwardPathFromStartPose();
722722
const auto refined_start_pose = calcLongitudinalOffsetPose(
723723
start_pose_candidates_path.points, planner_data_->self_odometry->pose.pose.position, 0.0);
724724
if (!refined_start_pose) return;
725725

726726
// search pull out start candidates backward
727727
const std::vector<Pose> start_pose_candidates = std::invoke([&]() -> std::vector<Pose> {
728728
if (parameters_->enable_back) {
729-
return searchPullOutStartPoses(start_pose_candidates_path);
729+
return searchPullOutStartPoseCandidates(start_pose_candidates_path);
730730
}
731731
return {*refined_start_pose};
732732
});
@@ -739,6 +739,7 @@ void StartPlannerModule::updatePullOutStatus()
739739

740740
if (isBackwardDrivingComplete()) {
741741
updateStatusAfterBackwardDriving();
742+
// should be moved to transition state
742743
current_state_ = ModuleStatus::SUCCESS; // for breaking loop
743744
} else {
744745
status_.backward_path = start_planner_utils::getBackwardPath(
@@ -760,71 +761,66 @@ void StartPlannerModule::updateStatusAfterBackwardDriving()
760761
}
761762
}
762763

763-
PathWithLaneId StartPlannerModule::calcStartPoseCandidatesBackwardPath() const
764+
PathWithLaneId StartPlannerModule::calcBackwardPathFromStartPose() const
764765
{
765-
const Pose & current_pose = planner_data_->self_odometry->pose.pose;
766-
766+
const Pose & start_pose = planner_data_->route_handler->getOriginalStartPose();
767767
const auto pull_out_lanes = start_planner_utils::getPullOutLanes(
768768
planner_data_, planner_data_->parameters.backward_path_length + parameters_->max_back_distance);
769769

770-
// get backward shoulder path
771-
const auto arc_position_pose = lanelet::utils::getArcCoordinates(pull_out_lanes, current_pose);
772-
const double check_distance = parameters_->max_back_distance + 30.0; // buffer
773-
auto path = planner_data_->route_handler->getCenterLinePath(
774-
pull_out_lanes, arc_position_pose.length - check_distance,
775-
arc_position_pose.length + check_distance);
776-
777-
// lateral shift to current_pose
778-
const double distance_from_center_line = arc_position_pose.distance;
779-
for (auto & p : path.points) {
780-
p.point.pose = calcOffsetPose(p.point.pose, 0, distance_from_center_line, 0);
770+
const auto arc_position_pose = lanelet::utils::getArcCoordinates(pull_out_lanes, start_pose);
771+
772+
// common buffer distance for both front and back
773+
static constexpr double buffer = 30.0;
774+
const double check_distance = parameters_->max_back_distance + buffer;
775+
776+
const double start_distance = arc_position_pose.length - check_distance;
777+
const double end_distance = arc_position_pose.length + buffer;
778+
779+
auto path =
780+
planner_data_->route_handler->getCenterLinePath(pull_out_lanes, start_distance, end_distance);
781+
782+
// shift all path points laterally to align with the start pose
783+
for (auto & path_point : path.points) {
784+
path_point.point.pose = calcOffsetPose(path_point.point.pose, 0, arc_position_pose.distance, 0);
781785
}
782786

783787
return path;
784788
}
785789

786-
std::vector<Pose> StartPlannerModule::searchPullOutStartPoses(
787-
const PathWithLaneId & start_pose_candidates) const
790+
std::vector<Pose> StartPlannerModule::searchPullOutStartPoseCandidates(
791+
const PathWithLaneId & back_path_from_start_pose) const
788792
{
789-
const Pose & current_pose = planner_data_->self_odometry->pose.pose;
790-
791-
std::vector<Pose> pull_out_start_pose{};
792-
793+
std::vector<Pose> pull_out_start_pose_candidates{};
794+
const auto & start_pose = planner_data_->route_handler->getOriginalStartPose();
795+
const auto local_vehicle_footprint = createVehicleFootprint(vehicle_info_);
793796
const auto pull_out_lanes = start_planner_utils::getPullOutLanes(
794797
planner_data_, planner_data_->parameters.backward_path_length + parameters_->max_back_distance);
795798

796-
// filter pull out lanes stop objects
797-
const auto [pull_out_lane_objects, others] =
798-
utils::path_safety_checker::separateObjectsByLanelets(
799-
*planner_data_->dynamic_object, pull_out_lanes,
800-
utils::path_safety_checker::isPolygonOverlapLanelet);
801-
const auto pull_out_lane_stop_objects = utils::path_safety_checker::filterObjectsByVelocity(
802-
pull_out_lane_objects, parameters_->th_moving_object_velocity);
799+
const auto stop_objects_in_pull_out_lanes =
800+
filterStopObjectsInPullOutLanes(pull_out_lanes, parameters_->th_moving_object_velocity);
803801

804802
// Set the maximum backward distance less than the distance from the vehicle's base_link to the
805803
// lane's rearmost point to prevent lane departure.
806-
const double s_current = lanelet::utils::getArcCoordinates(pull_out_lanes, current_pose).length;
807-
const double max_back_distance = std::clamp(
808-
s_current - planner_data_->parameters.base_link2rear, 0.0, parameters_->max_back_distance);
804+
const double current_arc_length =
805+
lanelet::utils::getArcCoordinates(pull_out_lanes, start_pose).length;
806+
const double allowed_backward_distance = std::clamp(
807+
current_arc_length - planner_data_->parameters.base_link2rear, 0.0,
808+
parameters_->max_back_distance);
809809

810-
// check collision between footprint and object at the backed pose
811-
const auto local_vehicle_footprint = createVehicleFootprint(vehicle_info_);
812-
for (double back_distance = 0.0; back_distance <= max_back_distance;
810+
for (double back_distance = 0.0; back_distance <= allowed_backward_distance;
813811
back_distance += parameters_->backward_search_resolution) {
814812
const auto backed_pose = calcLongitudinalOffsetPose(
815-
start_pose_candidates.points, current_pose.position, -back_distance);
813+
back_path_from_start_pose.points, start_pose.position, -back_distance);
816814
if (!backed_pose) {
817815
continue;
818816
}
819817

820-
// check the back pose is near the lane end
821-
const double length_to_backed_pose =
818+
const double backed_pose_arc_length =
822819
lanelet::utils::getArcCoordinates(pull_out_lanes, *backed_pose).length;
823-
824820
const double length_to_lane_end = std::accumulate(
825821
std::begin(pull_out_lanes), std::end(pull_out_lanes), 0.0,
826822
[](double acc, const auto & lane) { return acc + lanelet::utils::getLaneletLength2d(lane); });
827-
const double distance_from_lane_end = length_to_lane_end - length_to_backed_pose;
823+
const double distance_from_lane_end = length_to_lane_end - backed_pose_arc_length;
828824
if (distance_from_lane_end < parameters_->ignore_distance_from_lane_end) {
829825
RCLCPP_WARN_THROTTLE(
830826
getLogger(), *clock_, 5000,
@@ -833,27 +829,28 @@ std::vector<Pose> StartPlannerModule::searchPullOutStartPoses(
833829
}
834830

835831
if (utils::checkCollisionBetweenFootprintAndObjects(
836-
local_vehicle_footprint, *backed_pose, pull_out_lane_stop_objects,
832+
local_vehicle_footprint, *backed_pose, stop_objects_in_pull_out_lanes,
837833
parameters_->collision_check_margin)) {
838834
break; // poses behind this has a collision, so break.
839835
}
840836

841-
pull_out_start_pose.push_back(*backed_pose);
837+
pull_out_start_pose_candidates.push_back(*backed_pose);
842838
}
843-
return pull_out_start_pose;
839+
return pull_out_start_pose_candidates;
844840
}
845841

846-
bool StartPlannerModule::isOverlappedWithLane(
847-
const lanelet::ConstLanelet & candidate_lanelet,
848-
const tier4_autoware_utils::LinearRing2d & vehicle_footprint)
842+
PredictedObjects StartPlannerModule::filterStopObjectsInPullOutLanes(
843+
const lanelet::ConstLanelets & pull_out_lanes, const double velocity_threshold) const
849844
{
850-
for (const auto & point : vehicle_footprint) {
851-
if (boost::geometry::within(point, candidate_lanelet.polygon2d().basicPolygon())) {
852-
return true;
853-
}
854-
}
845+
const auto stop_objects = utils::path_safety_checker::filterObjectsByVelocity(
846+
*planner_data_->dynamic_object, velocity_threshold);
855847

856-
return false;
848+
// filter for objects located in pull_out_lanes and moving at a speed below the threshold
849+
const auto [stop_objects_in_pull_out_lanes, others] =
850+
utils::path_safety_checker::separateObjectsByLanelets(
851+
stop_objects, pull_out_lanes, utils::path_safety_checker::isPolygonOverlapLanelet);
852+
853+
return stop_objects_in_pull_out_lanes;
857854
}
858855

859856
bool StartPlannerModule::hasFinishedPullOut() const

0 commit comments

Comments
 (0)