Skip to content

Commit 0cd297f

Browse files
danielsanchezarankarishma1911
authored andcommitted
feat(start_planner): move collision check to plan method (autowarefoundation#6564)
* move collision check to a member function of planner base Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> * refactor Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> * add empty polygon and point checks Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> --------- Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com>
1 parent 2ea3e1c commit 0cd297f

File tree

9 files changed

+83
-66
lines changed

9 files changed

+83
-66
lines changed

planning/behavior_path_start_planner_module/include/behavior_path_start_planner_module/freespace_pull_out.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class FreespacePullOut : public PullOutPlannerBase
3838
rclcpp::Node & node, const StartPlannerParameters & parameters,
3939
const vehicle_info_util::VehicleInfo & vehicle_info);
4040

41-
PlannerType getPlannerType() override { return PlannerType::FREESPACE; }
41+
PlannerType getPlannerType() const override { return PlannerType::FREESPACE; }
4242

4343
std::optional<PullOutPath> plan(const Pose & start_pose, const Pose & end_pose) override;
4444

planning/behavior_path_start_planner_module/include/behavior_path_start_planner_module/geometric_pull_out.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class GeometricPullOut : public PullOutPlannerBase
3434
rclcpp::Node & node, const StartPlannerParameters & parameters,
3535
const std::shared_ptr<lane_departure_checker::LaneDepartureChecker> lane_departure_checker);
3636

37-
PlannerType getPlannerType() override { return PlannerType::GEOMETRIC; };
37+
PlannerType getPlannerType() const override { return PlannerType::GEOMETRIC; };
3838
std::optional<PullOutPath> plan(const Pose & start_pose, const Pose & goal_pose) override;
3939

4040
GeometricParallelParking planner_;

planning/behavior_path_start_planner_module/include/behavior_path_start_planner_module/pull_out_planner_base.hpp

+33-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
#define BEHAVIOR_PATH_START_PLANNER_MODULE__PULL_OUT_PLANNER_BASE_HPP_
1717

1818
#include "behavior_path_planner_common/data_manager.hpp"
19+
#include "behavior_path_planner_common/utils/path_safety_checker/objects_filtering.hpp"
1920
#include "behavior_path_start_planner_module/data_structs.hpp"
2021
#include "behavior_path_start_planner_module/pull_out_path.hpp"
22+
#include "behavior_path_start_planner_module/util.hpp"
2123

2224
#include <autoware_auto_planning_msgs/msg/path_with_lane_id.hpp>
2325
#include <geometry_msgs/msg/pose_stamped.hpp>
@@ -54,14 +56,44 @@ class PullOutPlannerBase
5456
planner_data_ = planner_data;
5557
}
5658

57-
virtual PlannerType getPlannerType() = 0;
59+
void setCollisionCheckMargin(const double collision_check_margin)
60+
{
61+
collision_check_margin_ = collision_check_margin;
62+
};
63+
virtual PlannerType getPlannerType() const = 0;
5864
virtual std::optional<PullOutPath> plan(const Pose & start_pose, const Pose & goal_pose) = 0;
5965

6066
protected:
67+
bool isPullOutPathCollided(
68+
behavior_path_planner::PullOutPath & pull_out_path,
69+
double collision_check_distance_from_end) const
70+
{
71+
// check for collisions
72+
const auto & dynamic_objects = planner_data_->dynamic_object;
73+
const auto pull_out_lanes = start_planner_utils::getPullOutLanes(
74+
planner_data_,
75+
planner_data_->parameters.backward_path_length + parameters_.max_back_distance);
76+
const auto & vehicle_footprint = vehicle_info_.createFootprint();
77+
// extract stop objects in pull out lane for collision check
78+
const auto stop_objects = utils::path_safety_checker::filterObjectsByVelocity(
79+
*dynamic_objects, parameters_.th_moving_object_velocity);
80+
auto [pull_out_lane_stop_objects, others] =
81+
utils::path_safety_checker::separateObjectsByLanelets(
82+
stop_objects, pull_out_lanes, utils::path_safety_checker::isPolygonOverlapLanelet);
83+
utils::path_safety_checker::filterObjectsByClass(
84+
pull_out_lane_stop_objects, parameters_.object_types_to_check_for_path_generation);
85+
86+
return utils::checkCollisionBetweenPathFootprintsAndObjects(
87+
vehicle_footprint_,
88+
behavior_path_planner::start_planner_utils::extractCollisionCheckSection(
89+
pull_out_path, collision_check_distance_from_end),
90+
pull_out_lane_stop_objects, collision_check_margin_);
91+
};
6192
std::shared_ptr<const PlannerData> planner_data_;
6293
vehicle_info_util::VehicleInfo vehicle_info_;
6394
LinearRing2d vehicle_footprint_;
6495
StartPlannerParameters parameters_;
96+
double collision_check_margin_;
6597
};
6698
} // namespace behavior_path_planner
6799

planning/behavior_path_start_planner_module/include/behavior_path_start_planner_module/shift_pull_out.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ShiftPullOut : public PullOutPlannerBase
3636
rclcpp::Node & node, const StartPlannerParameters & parameters,
3737
std::shared_ptr<LaneDepartureChecker> & lane_departure_checker);
3838

39-
PlannerType getPlannerType() override { return PlannerType::SHIFT; };
39+
PlannerType getPlannerType() const override { return PlannerType::SHIFT; };
4040
std::optional<PullOutPath> plan(const Pose & start_pose, const Pose & goal_pose) override;
4141

4242
std::vector<PullOutPath> calcPullOutPaths(

planning/behavior_path_start_planner_module/include/behavior_path_start_planner_module/util.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "behavior_path_planner_common/utils/drivable_area_expansion/static_drivable_area.hpp"
2020
#include "behavior_path_planner_common/utils/path_safety_checker/path_safety_checker_parameters.hpp"
2121
#include "behavior_path_planner_common/utils/path_safety_checker/safety_check.hpp"
22+
#include "behavior_path_start_planner_module/pull_out_path.hpp"
2223

2324
#include <route_handler/route_handler.hpp>
2425

@@ -50,6 +51,8 @@ lanelet::ConstLanelets getPullOutLanes(
5051
const std::shared_ptr<const PlannerData> & planner_data, const double backward_length);
5152
Pose getBackedPose(
5253
const Pose & current_pose, const double & yaw_shoulder_lane, const double & back_distance);
54+
PathWithLaneId extractCollisionCheckSection(
55+
const PullOutPath & path, const double collision_check_distance_from_end);
5356
} // namespace behavior_path_planner::start_planner_utils
5457

5558
#endif // BEHAVIOR_PATH_START_PLANNER_MODULE__UTIL_HPP_

planning/behavior_path_start_planner_module/src/geometric_pull_out.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ std::optional<PullOutPath> GeometricPullOut::plan(const Pose & start_pose, const
114114
output.start_pose = planner_.getArcPaths().at(0).points.front().point.pose;
115115
output.end_pose = planner_.getArcPaths().at(1).points.back().point.pose;
116116

117+
if (isPullOutPathCollided(output, parameters_.geometric_collision_check_distance_from_end)) {
118+
return {};
119+
}
120+
117121
return output;
118122
}
119123
} // namespace behavior_path_planner

planning/behavior_path_start_planner_module/src/shift_pull_out.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ std::optional<PullOutPath> ShiftPullOut::plan(const Pose & start_pose, const Pos
114114
shift_path.points = cropped_path.points;
115115
shift_path.header = planner_data_->route_handler->getRouteHeader();
116116

117+
if (isPullOutPathCollided(pull_out_path, parameters_.shift_collision_check_distance_from_end)) {
118+
continue;
119+
}
120+
117121
return pull_out_path;
118122
}
119123

planning/behavior_path_start_planner_module/src/start_planner_module.cpp

+1-62
Original file line numberDiff line numberDiff line change
@@ -767,22 +767,11 @@ bool StartPlannerModule::findPullOutPath(
767767
const Pose & start_pose_candidate, const std::shared_ptr<PullOutPlannerBase> & planner,
768768
const Pose & refined_start_pose, const Pose & goal_pose, const double collision_check_margin)
769769
{
770-
const auto & dynamic_objects = planner_data_->dynamic_object;
771-
const auto pull_out_lanes = start_planner_utils::getPullOutLanes(
772-
planner_data_, planner_data_->parameters.backward_path_length + parameters_->max_back_distance);
773-
const auto & vehicle_footprint = vehicle_info_.createFootprint();
774-
// extract stop objects in pull out lane for collision check
775-
const auto stop_objects = utils::path_safety_checker::filterObjectsByVelocity(
776-
*dynamic_objects, parameters_->th_moving_object_velocity);
777-
auto [pull_out_lane_stop_objects, others] = utils::path_safety_checker::separateObjectsByLanelets(
778-
stop_objects, pull_out_lanes, utils::path_safety_checker::isPolygonOverlapLanelet);
779-
utils::path_safety_checker::filterObjectsByClass(
780-
pull_out_lane_stop_objects, parameters_->object_types_to_check_for_path_generation);
781-
782770
// if start_pose_candidate is far from refined_start_pose, backward driving is necessary
783771
const bool backward_is_unnecessary =
784772
tier4_autoware_utils::calcDistance2d(start_pose_candidate, refined_start_pose) < 0.01;
785773

774+
planner->setCollisionCheckMargin(collision_check_margin);
786775
planner->setPlannerData(planner_data_);
787776
const auto pull_out_path = planner->plan(start_pose_candidate, goal_pose);
788777

@@ -791,13 +780,6 @@ bool StartPlannerModule::findPullOutPath(
791780
return false;
792781
}
793782

794-
// check collision
795-
if (utils::checkCollisionBetweenPathFootprintsAndObjects(
796-
vehicle_footprint, extractCollisionCheckSection(*pull_out_path, planner->getPlannerType()),
797-
pull_out_lane_stop_objects, collision_check_margin)) {
798-
return false;
799-
}
800-
801783
if (backward_is_unnecessary) {
802784
updateStatusWithCurrentPath(*pull_out_path, start_pose_candidate, planner->getPlannerType());
803785
return true;
@@ -808,49 +790,6 @@ bool StartPlannerModule::findPullOutPath(
808790
return true;
809791
}
810792

811-
PathWithLaneId StartPlannerModule::extractCollisionCheckSection(
812-
const PullOutPath & path, const behavior_path_planner::PlannerType & planner_type)
813-
{
814-
const std::map<PlannerType, double> collision_check_distances = {
815-
{behavior_path_planner::PlannerType::SHIFT,
816-
parameters_->shift_collision_check_distance_from_end},
817-
{behavior_path_planner::PlannerType::GEOMETRIC,
818-
parameters_->geometric_collision_check_distance_from_end}};
819-
820-
const double collision_check_distance_from_end = collision_check_distances.at(planner_type);
821-
822-
PathWithLaneId full_path;
823-
for (const auto & partial_path : path.partial_paths) {
824-
full_path.points.insert(
825-
full_path.points.end(), partial_path.points.begin(), partial_path.points.end());
826-
}
827-
828-
// Find the start index for collision check section based on the shift start pose
829-
const auto shift_start_idx =
830-
motion_utils::findNearestIndex(full_path.points, path.start_pose.position);
831-
832-
// Find the end index for collision check section based on the end pose and collision check
833-
// distance
834-
const auto collision_check_end_idx = [&]() -> size_t {
835-
const auto end_pose_offset = motion_utils::calcLongitudinalOffsetPose(
836-
full_path.points, path.end_pose.position, collision_check_distance_from_end);
837-
838-
return end_pose_offset
839-
? motion_utils::findNearestIndex(full_path.points, end_pose_offset->position)
840-
: full_path.points.size() - 1; // Use the last point if offset pose is not calculable
841-
}();
842-
843-
// Extract the collision check section from the full path
844-
PathWithLaneId collision_check_section;
845-
if (shift_start_idx < collision_check_end_idx) {
846-
collision_check_section.points.assign(
847-
full_path.points.begin() + shift_start_idx,
848-
full_path.points.begin() + collision_check_end_idx + 1);
849-
}
850-
851-
return collision_check_section;
852-
}
853-
854793
void StartPlannerModule::updateStatusWithCurrentPath(
855794
const behavior_path_planner::PullOutPath & path, const Pose & start_pose,
856795
const behavior_path_planner::PlannerType & planner_type)

planning/behavior_path_start_planner_module/src/util.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,39 @@ lanelet::ConstLanelets getPullOutLanes(
104104
/*forward_only_in_route*/ true);
105105
}
106106

107+
PathWithLaneId extractCollisionCheckSection(
108+
const PullOutPath & path, const double collision_check_distance_from_end)
109+
{
110+
PathWithLaneId full_path;
111+
for (const auto & partial_path : path.partial_paths) {
112+
full_path.points.insert(
113+
full_path.points.end(), partial_path.points.begin(), partial_path.points.end());
114+
}
115+
116+
// Find the start index for collision check section based on the shift start pose
117+
const auto shift_start_idx =
118+
motion_utils::findNearestIndex(full_path.points, path.start_pose.position);
119+
120+
// Find the end index for collision check section based on the end pose and collision check
121+
// distance
122+
const auto collision_check_end_idx = [&]() -> size_t {
123+
const auto end_pose_offset = motion_utils::calcLongitudinalOffsetPose(
124+
full_path.points, path.end_pose.position, collision_check_distance_from_end);
125+
126+
return end_pose_offset
127+
? motion_utils::findNearestIndex(full_path.points, end_pose_offset->position)
128+
: full_path.points.size() - 1; // Use the last point if offset pose is not calculable
129+
}();
130+
131+
// Extract the collision check section from the full path
132+
PathWithLaneId collision_check_section;
133+
if (shift_start_idx < collision_check_end_idx) {
134+
collision_check_section.points.assign(
135+
full_path.points.begin() + shift_start_idx,
136+
full_path.points.begin() + collision_check_end_idx + 1);
137+
}
138+
139+
return collision_check_section;
140+
}
141+
107142
} // namespace behavior_path_planner::start_planner_utils

0 commit comments

Comments
 (0)