Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(lane_change): refactor getLaneChangePaths function #8909

Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
66cd111
refactor lane change utility funcions
mkquda Aug 26, 2024
adc0960
Merge branch 'awf-latest' into RT1-7577-improve-execution-condition-o…
mkquda Aug 26, 2024
4f9bc8b
LC utility function to get distance to next regulatory element
mkquda Aug 27, 2024
bf23445
don't activate LC module when close to regulatory element
mkquda Aug 27, 2024
c2ceeaa
Merge branch 'awf-latest' into RT1-7577-improve-execution-condition-o…
mkquda Aug 27, 2024
06db58d
modify threshold distance calculation
mkquda Aug 27, 2024
f7cb53e
Merge branch 'awf-latest' into RT1-7577-improve-execution-condition-o…
mkquda Aug 27, 2024
c05c050
move regulatory element check to canTransitFailureState() function
mkquda Aug 28, 2024
8e4e952
Merge branch 'awf-latest' into RT1-7577-improve-execution-condition-o…
mkquda Aug 30, 2024
3072dcb
Merge branch 'awf-latest' into RT1-7577-improve-execution-condition-o…
mkquda Sep 2, 2024
ac23111
always run LC module if approaching terminal point
mkquda Sep 2, 2024
a4c2024
Merge branch 'awf-latest' into RT1-7577-improve-execution-condition-o…
mkquda Sep 4, 2024
6eef49e
use max possible LC length as threshold
mkquda Sep 9, 2024
8c22547
update LC readme
mkquda Sep 9, 2024
fb15b3c
Merge branch 'awf-latest' into RT1-7577-improve-execution-condition-o…
mkquda Sep 9, 2024
d2f0459
refactor implementation
mkquda Sep 9, 2024
2d22773
update readme
mkquda Sep 9, 2024
7fa64f9
refactor checking data validity
mkquda Sep 10, 2024
1ae7b63
Merge branch 'RT1-7577-improve-execution-condition-of-lane-change-mod…
mkquda Sep 10, 2024
b08abaf
refactor sampling of prepare phase metrics and lane changing phase me…
mkquda Sep 11, 2024
bf9b3e3
add route handler function to get pose from 2d arc length
mkquda Sep 13, 2024
06c01fe
refactor candidate path generation
mkquda Sep 13, 2024
784a60b
Merge branch 'awf-latest' into RT1-7829-refactor-code-get-lane-change…
mkquda Sep 13, 2024
066fb7c
refactor candidate path safety check
mkquda Sep 13, 2024
88b6333
Merge branch 'awf-latest' into RT1-7829-refactor-code-get-lane-change…
mkquda Sep 18, 2024
f7df44f
Merge branch 'awf-latest' into RT1-7829-refactor-code-get-lane-change…
mkquda Sep 19, 2024
5274a1e
fix variable name
mkquda Sep 19, 2024
d0b83cf
Update planning/autoware_route_handler/src/route_handler.cpp
mkquda Sep 19, 2024
2f4741c
Merge branch 'awf-latest' into RT1-7829-refactor-code-get-lane-change…
mkquda Sep 19, 2024
a510fcd
correct parameter name
mkquda Sep 20, 2024
b65477f
set prepare segment velocity after taking max path velocity value
mkquda Sep 20, 2024
da1ac8f
update LC README
mkquda Sep 20, 2024
766a439
minor changes
mkquda Sep 20, 2024
b0ab583
Merge branch 'awf-latest' into RT1-7829-refactor-code-get-lane-change…
mkquda Sep 20, 2024
78ed340
Merge branch 'awf-latest' into RT1-7829-refactor-code-get-lane-change…
mkquda Sep 23, 2024
55f330d
check phase length difference with previos valid candidate path
mkquda Sep 25, 2024
dea4f81
Merge branch 'awf-latest' into RT1-7829-refactor-code-get-lane-change…
mkquda Sep 25, 2024
fa5a5fe
change logger name
mkquda Sep 25, 2024
f64d80a
change functions names to snake case
mkquda Sep 25, 2024
a57b585
use snake case for function names
mkquda Sep 25, 2024
e89ef23
add colors to flow chart in README
mkquda Sep 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ class RouteHandler
*/
lanelet::ConstLanelets getShoulderLaneletsAtPose(const Pose & pose) const;

Pose getPoseFrom2DArcLength(
mkquda marked this conversation as resolved.
Show resolved Hide resolved
const lanelet::ConstLanelets & lanelet_sequence, const double s) const;

private:
// MUST
lanelet::routing::RoutingGraphPtr routing_graph_ptr_;
Expand Down
27 changes: 27 additions & 0 deletions planning/autoware_route_handler/src/route_handler.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2024 TIER IV, Inc.

Check notice on line 1 in planning/autoware_route_handler/src/route_handler.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Lines of Code in a Single File

The lines of code increases from 1685 to 1709, improve code health by reducing it to 1000. The number of Lines of Code in a single file. More Lines of Code lowers the code health.

Check notice on line 1 in planning/autoware_route_handler/src/route_handler.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Number of Functions in a Single Module

The number of functions increases from 92 to 93, threshold = 75. This file contains too many functions. Beyond a certain threshold, more functions lower the code health.

Check notice on line 1 in planning/autoware_route_handler/src/route_handler.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 4.78 to 4.77, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,6 +47,8 @@
{
namespace
{
using autoware::universe_utils::createPoint;
using autoware::universe_utils::createQuaternionFromYaw;
using autoware_planning_msgs::msg::LaneletPrimitive;
using autoware_planning_msgs::msg::Path;
using geometry_msgs::msg::Pose;
Expand Down Expand Up @@ -2035,4 +2037,29 @@
if (route) return route->shortestPath();
return {};
}

Pose RouteHandler::getPoseFrom2DArcLength(
const lanelet::ConstLanelets & lanelet_sequence, const double s) const
{
double accumulated_distance2d = 0;
for (const auto & llt : lanelet_sequence) {
const auto & centerline = llt.centerline();
for (auto it = centerline.begin(); std::next(it) != centerline.end(); ++it) {
const auto pt = *it;
const auto next_pt = *std::next(it);
const double distance2d = lanelet::geometry::distance2d(to2D(pt), to2D(next_pt));
if (accumulated_distance2d + distance2d > s) {
const double ratio = (s - accumulated_distance2d) / distance2d;
const auto interpolated_pt = pt.basicPoint() * (1 - ratio) + next_pt.basicPoint() * ratio;
const auto yaw = std::atan2(next_pt.y() - pt.y(), next_pt.x() - pt.x());
Pose pose;
pose.position = createPoint(interpolated_pt.x(), interpolated_pt.y(), interpolated_pt.z());
pose.orientation = createQuaternionFromYaw(yaw);
return pose;
}
accumulated_distance2d += distance2d;
}
}
return Pose{};
}
} // namespace autoware::route_handler
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,17 @@ class NormalLaneChange : public LaneChangeBase
bool hasEnoughLengthToTrafficLight(
const LaneChangePath & path, const lanelet::ConstLanelets & current_lanes) const;

bool getLaneChangePaths(
const lanelet::ConstLanelets & current_lanes, const lanelet::ConstLanelets & target_lanes,
Direction direction, const bool is_stuck, LaneChangePaths * candidate_paths) const;
bool getLaneChangePaths(LaneChangePaths * candidate_paths) const;

LaneChangePath getCandidatePath(
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 target_lane_length, const double shift_length,
const double next_lc_buffer, const bool is_goal_in_route) const;

bool checkCandidatePathSafety(
const LaneChangePath & candidate_path, const lane_change::TargetObjects & target_objects,
const double lane_change_buffer, const bool is_stuck) const;

std::optional<LaneChangePath> calcTerminalLaneChangePath(
const lanelet::ConstLanelets & current_lanes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ using autoware::route_handler::Direction;
using autoware::route_handler::RouteHandler;
using behavior_path_planner::lane_change::CommonDataPtr;
using behavior_path_planner::lane_change::LCParamPtr;
using behavior_path_planner::lane_change::PhaseMetrics;

/**
* @brief Calculates the distance from the ego vehicle to the terminal point.
Expand Down Expand Up @@ -132,6 +133,38 @@ double calc_maximum_lane_change_length(
double calc_maximum_lane_change_length(
const CommonDataPtr & common_data_ptr, const lanelet::ConstLanelet & current_terminal_lanelet,
const double max_acc);

/**
* @brief Calculates the distance required during a lane change operation.
*
* Used for computing prepare or lane change length based on current and maximum velocity,
* acceleration, and duration, returning the lesser of accelerated distance or distance at max
* velocity.
*
* @param velocity The current velocity of the vehicle in meters per second (m/s).
* @param maximum_velocity The maximum velocity the vehicle can reach in meters per second (m/s).
* @param acceleration The acceleration of the vehicle in meters per second squared (m/s^2).
* @param duration The duration of the lane change in seconds (s).
* @return The calculated minimum distance in meters (m).
*/
double calc_phase_length(
const double velocity, const double maximum_velocity, const double acceleration,
const double duration);

double calc_lane_changing_acceleration(
const double initial_lane_changing_velocity, const double max_path_velocity,
const double lane_changing_time, const double prepare_longitudinal_acc);

std::vector<PhaseMetrics> calc_prepare_phase_metrics(
const CommonDataPtr & common_data_ptr, const std::vector<double> & prepare_durations,
const std::vector<double> & lon_accel_values, const double current_velocity,
const double min_length_threshold = 0.0,
const double max_length_threshold = std::numeric_limits<double>::max());

std::vector<PhaseMetrics> calc_shift_phase_metrics(
const CommonDataPtr & common_data_ptr, const double shift_length, const double initial_velocity,
const double max_velocity, const double lon_accel,
const double max_length_threshold = std::numeric_limits<double>::max());
} // namespace autoware::behavior_path_planner::utils::lane_change::calculation

#endif // AUTOWARE__BEHAVIOR_PATH_LANE_CHANGE_MODULE__UTILS__CALCULATION_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ struct PhaseInfo
}
};

struct PhaseMetrics
{
double duration{0.0};
double length{0.0};
double velocity{0.0};
double lon_accel{0.0};
double lat_accel{0.0};
};

struct Lanes
{
bool current_lane_in_goal_section{false};
Expand All @@ -215,6 +224,22 @@ struct Info

double lateral_acceleration{0.0};
double terminal_lane_changing_velocity{0.0};

Info() = default;
Info(
const PhaseMetrics & _prep_metrics, const PhaseMetrics & _lc_metrics,
const Pose & _lc_start_pose, const Pose & _lc_end_pose, const ShiftLine & _shift_line)
{
longitudinal_acceleration = PhaseInfo{_prep_metrics.lon_accel, _lc_metrics.lon_accel};
duration = PhaseInfo{_prep_metrics.duration, _lc_metrics.duration};
velocity = PhaseInfo{_prep_metrics.velocity, _prep_metrics.velocity};
length = PhaseInfo{_prep_metrics.length, _lc_metrics.length};
lane_changing_start = _lc_start_pose;
lane_changing_end = _lc_end_pose;
lateral_acceleration = _lc_metrics.lat_accel;
terminal_lane_changing_velocity = _lc_metrics.velocity;
shift_line = _shift_line;
}
};

template <typename Object>
Expand Down Expand Up @@ -316,6 +341,7 @@ using LaneChangeModuleType = lane_change::ModuleType;
using LaneChangeParameters = lane_change::Parameters;
using LaneChangeStates = lane_change::States;
using LaneChangePhaseInfo = lane_change::PhaseInfo;
using LaneChangePhaseMetrics = lane_change::PhaseMetrics;
using LaneChangeInfo = lane_change::Info;
using FilteredByLanesObjects = lane_change::LanesObjects<std::vector<PredictedObject>>;
using FilteredByLanesExtendedObjects = lane_change::LanesObjects<ExtendedPredictedObjects>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ double calcMaximumAcceleration(
const double current_velocity, const double current_max_velocity,
const double max_longitudinal_acc, const LaneChangeParameters & lane_change_parameters);

double calcLaneChangingAcceleration(
const double initial_lane_changing_velocity, const double max_path_velocity,
const double lane_changing_time, const double prepare_longitudinal_acc);

void setPrepareVelocity(
PathWithLaneId & prepare_segment, const double current_velocity, const double prepare_velocity);

Expand All @@ -96,14 +92,9 @@ bool isPathInLanelets(

std::optional<LaneChangePath> constructCandidatePath(
const CommonDataPtr & common_data_ptr, const LaneChangeInfo & lane_change_info,
const PathWithLaneId & prepare_segment, const PathWithLaneId & target_segment,
const PathWithLaneId & target_lane_reference_path,
const PathWithLaneId & prepare_segment, const PathWithLaneId & target_lane_reference_path,
const std::vector<std::vector<int64_t>> & sorted_lane_ids);

ShiftLine getLaneChangingShiftLine(
const PathWithLaneId & prepare_segment, const PathWithLaneId & target_segment,
const PathWithLaneId & reference_path, const double shift_length);

ShiftLine getLaneChangingShiftLine(
const Pose & lane_changing_start_pose, const Pose & lane_changing_end_pose,
const PathWithLaneId & reference_path, const double shift_length);
Expand Down Expand Up @@ -254,23 +245,6 @@ bool isWithinIntersection(
*/
bool isWithinTurnDirectionLanes(const lanelet::ConstLanelet & lanelet, const Polygon2d & polygon);

/**
* @brief Calculates the distance required during a lane change operation.
*
* Used for computing prepare or lane change length based on current and maximum velocity,
* acceleration, and duration, returning the lesser of accelerated distance or distance at max
* velocity.
*
* @param velocity The current velocity of the vehicle in meters per second (m/s).
* @param maximum_velocity The maximum velocity the vehicle can reach in meters per second (m/s).
* @param acceleration The acceleration of the vehicle in meters per second squared (m/s^2).
* @param duration The duration of the lane change in seconds (s).
* @return The calculated minimum distance in meters (m).
*/
double calcPhaseLength(
const double velocity, const double maximum_velocity, const double acceleration,
const double time);

LanesPolygon create_lanes_polygon(const CommonDataPtr & common_data_ptr);

bool is_same_lane_with_prev_iteration(
Expand Down
Loading
Loading