Skip to content

Commit

Permalink
feat(goal_planner): calculate stop pose from closest goal candidate
Browse files Browse the repository at this point in the history
Signed-off-by: kosuke55 <[email protected]>
  • Loading branch information
kosuke55 committed Oct 25, 2023
1 parent 5a76057 commit 76ca367
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class PullOverStatus
DEFINE_SETTER_GETTER(std::optional<GoalCandidate>, modified_goal_pose)
DEFINE_SETTER_GETTER(Pose, refined_goal_pose)
DEFINE_SETTER_GETTER(GoalCandidates, goal_candidates)
DEFINE_SETTER_GETTER(Pose, closest_goal_candidate_pose)
DEFINE_SETTER_GETTER(std::vector<PullOverPath>, pull_over_path_candidates)
DEFINE_SETTER_GETTER(std::optional<Pose>, closest_start_pose)

Expand Down Expand Up @@ -174,6 +175,7 @@ class PullOverStatus
std::optional<GoalCandidate> modified_goal_pose_;
Pose refined_goal_pose_{};
GoalCandidates goal_candidates_{};
Pose closest_goal_candidate_pose_{};

// pull over path
std::vector<PullOverPath> pull_over_path_candidates_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class GoalSearcher : public GoalSearcherBase

GoalCandidates search() override;
void update(GoalCandidates & goal_candidates) const override;
GoalCandidate getClosetGoalCandidateAlongLanes(const GoalCandidates & goal_candidates) const override;

private:
void countObjectsToAvoid(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class GoalSearcherBase
MultiPolygon2d getAreaPolygons() { return area_polygons_; }
virtual GoalCandidates search() = 0;
virtual void update([[maybe_unused]] GoalCandidates & goal_candidates) const { return; }
virtual GoalCandidate getClosetGoalCandidateAlongLanes(const GoalCandidates & goal_candidates) const = 0;

protected:
GoalPlannerParameters parameters_{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,19 @@ void GoalPlannerModule::generateGoalCandidates()
goal_searcher_->setPlannerData(planner_data_);
goal_searcher_->setReferenceGoal(status_.get_refined_goal_pose());
status_.set_goal_candidates(goal_searcher_->search());
const auto current_lanes = utils::getExtendedCurrentLanes(
planner_data_, parameters_->backward_goal_search_length,
parameters_->forward_goal_search_length, false);
status_.set_closest_goal_candidate_pose(
goal_searcher_->getClosetGoalCandidateAlongLanes(status_.get_goal_candidates()).goal_pose);
} else {
GoalCandidate goal_candidate{};
goal_candidate.goal_pose = goal_pose;
goal_candidate.distance_from_original_goal = 0.0;
GoalCandidates goal_candidates{};
goal_candidates.push_back(goal_candidate);
status_.set_goal_candidates(goal_candidates);
status_.set_closest_goal_candidate_pose(goal_pose);
}
}

Expand Down Expand Up @@ -1082,20 +1088,23 @@ PathWithLaneId GoalPlannerModule::generateStopPath()
// difference between the outer and inner sides)
// 4. feasible stop
const auto search_start_offset_pose = calcLongitudinalOffsetPose(
reference_path.points, status_.get_refined_goal_pose().position,
-parameters_->backward_goal_search_length - common_parameters.base_link2front -
approximate_pull_over_distance_);
reference_path.points, status_.get_closest_goal_candidate_pose().position,
-approximate_pull_over_distance_);
if (
!status_.get_is_safe_static_objects() && !status_.get_closest_start_pose() &&
!search_start_offset_pose) {
return generateFeasibleStopPath();
}

const Pose stop_pose =
status_.get_is_safe_static_objects()
? status_.get_pull_over_path()->start_pose
: (status_.get_closest_start_pose() ? status_.get_closest_start_pose().value()
: *search_start_offset_pose);
const Pose stop_pose = [&]() -> Pose {
if (status_.get_is_safe_static_objects()) {
return status_.get_pull_over_path()->start_pose;
}
if (status_.get_closest_start_pose()) {
return status_.get_closest_start_pose().value();
}
return *search_start_offset_pose;
}();

// if stop pose is closer than min_stop_distance, stop as soon as possible
const double ego_to_stop_distance = calcSignedArcLengthFromEgo(reference_path, stop_pose);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,28 @@ bool GoalSearcher::isInAreas(const LinearRing2d & footprint, const BasicPolygons
return false;
}

GoalCandidate GoalSearcher::getClosetGoalCandidateAlongLanes(
const GoalCandidates & goal_candidates) const
{
const auto current_lanes = utils::getExtendedCurrentLanes(
planner_data_, parameters_.backward_goal_search_length, parameters_.forward_goal_search_length,
/*forward_only_in_route*/ false);

const auto closest_goal_candidate = std::min_element(
goal_candidates.begin(), goal_candidates.end(),
[&current_lanes](const auto & a, const auto & b) {
const auto goal_arc_length_a =
lanelet::utils::getArcCoordinates(current_lanes, a.goal_pose).length;
const auto goal_arc_length_b =
lanelet::utils::getArcCoordinates(current_lanes, b.goal_pose).length;
return goal_arc_length_a < goal_arc_length_b;
});

if (closest_goal_candidate == goal_candidates.end()) {
return {}; // return empty GoalCandidate in case no valid candidates are found.
}

return *closest_goal_candidate;
}

} // namespace behavior_path_planner

0 comments on commit 76ca367

Please sign in to comment.