Skip to content

Commit

Permalink
refactor(lane_change): separate path-related function to utils/path (a…
Browse files Browse the repository at this point in the history
…utowarefoundation#9633)

* refactor(lane_change): separate path-related function to utils/path

Signed-off-by: Zulfaqar Azmi <[email protected]>

* remove old terminal lane change computation

Signed-off-by: Zulfaqar Azmi <[email protected]>

* doxygen comments

Signed-off-by: Zulfaqar Azmi <[email protected]>

* remove frenet planner header

Signed-off-by: Zulfaqar Azmi <[email protected]>

* minor refactoring by throwing instead

Signed-off-by: Zulfaqar Azmi <[email protected]>

* minor refactoring

Signed-off-by: Zulfaqar Azmi <[email protected]>

* fix docstring and remove redundant argument

Signed-off-by: Zulfaqar Azmi <[email protected]>

* get logger in header

Signed-off-by: Zulfaqar Azmi <[email protected]>

* add docstring

Signed-off-by: Zulfaqar Azmi <[email protected]>

* rename function is_colliding

Signed-off-by: Zulfaqar Azmi <[email protected]>

* Fix failing test

Signed-off-by: Zulfaqar Azmi <[email protected]>

* fix for failing scenario caused by prepare velocity

Signed-off-by: Zulfaqar Azmi <[email protected]>

* fix error message

Signed-off-by: Zulfaqar Azmi <[email protected]>

---------

Signed-off-by: Zulfaqar Azmi <[email protected]>
  • Loading branch information
zulfaqar-azmi-t4 authored and kminoda committed Dec 25, 2024
1 parent d34ab32 commit 8645ab5
Show file tree
Hide file tree
Showing 10 changed files with 561 additions and 667 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ament_auto_add_library(${PROJECT_NAME} SHARED
src/utils/calculation.cpp
src/utils/markers.cpp
src/utils/utils.cpp
src/utils/path.cpp
)

if(BUILD_TESTING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ class LaneChangeBase

virtual LaneChangePath getLaneChangePath() const = 0;

virtual BehaviorModuleOutput getTerminalLaneChangePath() const = 0;

virtual bool isEgoOnPreparePhase() const = 0;

virtual bool isRequiredStop(const bool is_trailing_object) = 0;
Expand Down Expand Up @@ -235,9 +233,6 @@ class LaneChangeBase
protected:
virtual int getNumToPreferredLane(const lanelet::ConstLanelet & lane) const = 0;

virtual bool get_prepare_segment(
PathWithLaneId & prepare_segment, const double prepare_length) const = 0;

virtual bool isValidPath(const PathWithLaneId & path) const = 0;

virtual bool isAbleToStopSafely() const = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ class NormalLaneChange : public LaneChangeBase

LaneChangePath getLaneChangePath() const override;

BehaviorModuleOutput getTerminalLaneChangePath() const override;

BehaviorModuleOutput generateOutput() override;

void extendOutputDrivableArea(BehaviorModuleOutput & output) const override;
Expand Down Expand Up @@ -128,47 +126,26 @@ class NormalLaneChange : public LaneChangeBase

void filterOncomingObjects(PredictedObjects & objects) const;

bool get_prepare_segment(
PathWithLaneId & prepare_segment, const double prepare_length) const override;

PathWithLaneId getTargetSegment(
const lanelet::ConstLanelets & target_lanes, const Pose & lane_changing_start_pose,
const double target_lane_length, const double lane_changing_length,
const double lane_changing_velocity, const double buffer_for_next_lane_change) const;

std::vector<LaneChangePhaseMetrics> get_prepare_metrics() const;
std::vector<LaneChangePhaseMetrics> get_lane_changing_metrics(
const PathWithLaneId & prep_segment, const LaneChangePhaseMetrics & prep_metrics,
const double shift_length, const double dist_to_reg_element) const;

bool get_lane_change_paths(LaneChangePaths & candidate_paths) const;

LaneChangePath get_candidate_path(
const LaneChangePhaseMetrics & prep_metrics, const LaneChangePhaseMetrics & lc_metrics,
const PathWithLaneId & prep_segment, const std::vector<std::vector<int64_t>> & sorted_lane_ids,
const Pose & lc_start_pose, const double shift_length) const;

bool check_candidate_path_safety(
const LaneChangePath & candidate_path, const lane_change::TargetObjects & target_objects) const;

std::optional<LaneChangePath> calcTerminalLaneChangePath(
const lanelet::ConstLanelets & current_lanes,
const lanelet::ConstLanelets & target_lanes) const;

bool isValidPath(const PathWithLaneId & path) const override;

PathSafetyStatus isLaneChangePathSafe(
const LaneChangePath & lane_change_path,
const std::vector<std::vector<PoseWithVelocityStamped>> & ego_predicted_paths,
const lane_change::TargetObjects & collision_check_objects,
const utils::path_safety_checker::RSSparams & rss_params,
const size_t deceleration_sampling_num, CollisionCheckDebugMap & debug_data) const;

bool has_collision_with_decel_patterns(
const LaneChangePath & lane_change_path, const ExtendedPredictedObjects & objects,
const size_t deceleration_sampling_num, const RSSparams & rss_param,
const bool check_prepare_phase, CollisionCheckDebugMap & debug_data) const;
CollisionCheckDebugMap & debug_data) const;

bool is_collided(
bool is_colliding(
const LaneChangePath & lane_change_path, const ExtendedPredictedObject & obj,
const std::vector<PoseWithVelocityStamped> & ego_predicted_path,
const RSSparams & selected_rss_param, const bool check_prepare_phase,
Expand All @@ -178,24 +155,6 @@ class NormalLaneChange : public LaneChangeBase

bool is_ego_stuck() const;

/**
* @brief Checks if the given pose is a valid starting point for a lane change.
*
* This function determines whether the given pose (position) of the vehicle is within
* the area of either the target neighbor lane or the target lane itself. It uses geometric
* checks to see if the start point of the lane change is covered by the polygons representing
* these lanes.
*
* @param common_data_ptr Shared pointer to a CommonData structure, which should include:
* - Non-null `lanes_polygon_ptr` that contains the polygon data for lanes.
* @param pose The current pose of the vehicle
*
* @return `true` if the pose is within either the target neighbor lane or the target lane;
* `false` otherwise.
*/
bool is_valid_start_point(
const lane_change::CommonDataPtr & common_data_ptr, const Pose & pose) const;

bool check_prepare_phase() const;

void set_stop_pose(const double arc_length_to_stop_pose, PathWithLaneId & path);
Expand All @@ -213,7 +172,6 @@ class NormalLaneChange : public LaneChangeBase

std::vector<PathPointWithLaneId> path_after_intersection_;
double stop_time_{0.0};
static constexpr double floating_err_th{1e-3};
};
} // namespace autoware::behavior_path_planner
#endif // AUTOWARE__BEHAVIOR_PATH_LANE_CHANGE_MODULE__SCENE_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ struct TargetObjects
: leading(std::move(leading)), trailing(std::move(trailing))
{
}

[[nodiscard]] bool empty() const { return leading.empty() && trailing.empty(); }
};

enum class ModuleType {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright 2024 TIER IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef AUTOWARE__BEHAVIOR_PATH_LANE_CHANGE_MODULE__UTILS__PATH_HPP_
#define AUTOWARE__BEHAVIOR_PATH_LANE_CHANGE_MODULE__UTILS__PATH_HPP_

#include "autoware/behavior_path_lane_change_module/structs/data.hpp"
#include "autoware/behavior_path_lane_change_module/structs/path.hpp"

#include <autoware/behavior_path_planner_common/utils/utils.hpp>

#include <vector>

namespace autoware::behavior_path_planner::utils::lane_change
{
using behavior_path_planner::LaneChangePath;
using behavior_path_planner::lane_change::CommonDataPtr;

/**
* @brief Generates a prepare segment for a lane change maneuver.
*
* This function generates the "prepare segment" of the path by trimming it to the specified length,
* adjusting longitudinal velocity for acceleration or deceleration, and ensuring the starting point
* meets necessary constraints for a lane change.
*
* @param common_data_ptr Shared pointer to CommonData containing current and target lane
* information, vehicle parameters, and ego state.
* @param prev_module_path The input path from the previous module, which will be used
* as the base for the prepare segment.
* @param prep_metric Preparation metrics containing desired length and velocity for the segment.
* @param prepare_segment Output parameter where the resulting prepare segment path will be stored.
*
* @throws std::logic_error If the lane change start point is behind the target lanelet or
* if lane information is invalid.
*
* @return true if the prepare segment is successfully generated, false otherwise.
*/
bool get_prepare_segment(
const CommonDataPtr & common_data_ptr, const PathWithLaneId & prev_module_path,
const LaneChangePhaseMetrics prep_metric, PathWithLaneId & prepare_segment);

/**
* @brief Generates the candidate path for a lane change maneuver.
*
* This function calculates the candidate lane change path based on the provided preparation
* and lane change metrics. It resamples the target lane reference path, determines the start
* and end poses for the lane change, and constructs the shift line required for the maneuver.
* The function ensures that the resulting path satisfies length and distance constraints.
*
* @param common_data_ptr Shared pointer to CommonData containing route, lane, and transient data.
* @param prep_metric Metrics for the preparation phase, including path length and velocity.
* @param lc_metric Metrics for the lane change phase, including path length and velocity.
* @param prep_segment The path segment prepared before initiating the lane change.
* @param sorted_lane_ids A vector of sorted lane IDs used for updating lane information in the
* path.
* @param lc_start_pose The pose where the lane change begins.
* @param shift_length The lateral distance to shift during the lane change maneuver.
*
* @throws std::logic_error If the target lane reference path is empty, candidate path generation
* fails, or the resulting path length exceeds terminal constraints.
*
* @return LaneChangePath The constructed candidate lane change path.
*/
LaneChangePath get_candidate_path(
const CommonDataPtr & common_data_ptr, const LaneChangePhaseMetrics & prep_metric,
const LaneChangePhaseMetrics & lc_metric, const PathWithLaneId & prep_segment,
const std::vector<std::vector<int64_t>> & sorted_lane_ids, const double shift_length);

/**
* @brief Constructs a candidate path for a lane change maneuver.
*
* This function generates a candidate lane change path by shifting the target lane's reference path
* and combining it with the prepare segment. It verifies the path's validity by checking the yaw
* difference, adjusting longitudinal velocity, and updating lane IDs based on the provided lane
* sorting information.
*
* @param lane_change_info Information about the lane change, including shift line and target
* velocity.
* @param prepare_segment The path segment leading up to the lane change.
* @param target_lane_reference_path The reference path of the target lane.
* @param sorted_lane_ids A vector of sorted lane IDs used to update the candidate path's lane IDs.
*
* @return std::optional<LaneChangePath> The constructed candidate path if valid, or std::nullopt
* if the path fails any constraints.
*/
LaneChangePath construct_candidate_path(
const LaneChangeInfo & lane_change_info, const PathWithLaneId & prepare_segment,
const PathWithLaneId & target_lane_reference_path,
const std::vector<std::vector<int64_t>> & sorted_lane_ids);
} // namespace autoware::behavior_path_planner::utils::lane_change
#endif // AUTOWARE__BEHAVIOR_PATH_LANE_CHANGE_MODULE__UTILS__PATH_HPP_
Loading

0 comments on commit 8645ab5

Please sign in to comment.