Skip to content

Commit 656a78e

Browse files
refactor(lane_change): refactor getLaneChangePaths function (#8909)
* refactor lane change utility funcions Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * LC utility function to get distance to next regulatory element Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * don't activate LC module when close to regulatory element Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * modify threshold distance calculation Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * move regulatory element check to canTransitFailureState() function Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * always run LC module if approaching terminal point Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * use max possible LC length as threshold Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * update LC readme Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * refactor implementation Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * update readme Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * refactor checking data validity Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * refactor sampling of prepare phase metrics and lane changing phase metrics Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * add route handler function to get pose from 2d arc length Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * refactor candidate path generation Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * refactor candidate path safety check Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * fix variable name Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * Update planning/autoware_route_handler/src/route_handler.cpp Co-authored-by: Zulfaqar Azmi <93502286+zulfaqar-azmi-t4@users.noreply.github.com> * correct parameter name Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * set prepare segment velocity after taking max path velocity value Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * update LC README Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * minor changes Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * check phase length difference with previos valid candidate path Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * change logger name Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * change functions names to snake case Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * use snake case for function names Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * add colors to flow chart in README Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> --------- Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> Co-authored-by: Zulfaqar Azmi <93502286+zulfaqar-azmi-t4@users.noreply.github.com>
1 parent 73a9788 commit 656a78e

File tree

10 files changed

+559
-396
lines changed

10 files changed

+559
-396
lines changed

planning/autoware_route_handler/include/autoware/route_handler/route_handler.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ class RouteHandler
326326
*/
327327
lanelet::ConstLanelets getShoulderLaneletsAtPose(const Pose & pose) const;
328328

329+
Pose get_pose_from_2d_arc_length(
330+
const lanelet::ConstLanelets & lanelet_sequence, const double s) const;
331+
329332
private:
330333
// MUST
331334
lanelet::routing::RoutingGraphPtr routing_graph_ptr_;

planning/autoware_route_handler/src/route_handler.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ namespace autoware::route_handler
4747
{
4848
namespace
4949
{
50+
using autoware::universe_utils::createPoint;
51+
using autoware::universe_utils::createQuaternionFromYaw;
5052
using autoware_planning_msgs::msg::LaneletPrimitive;
5153
using autoware_planning_msgs::msg::Path;
5254
using geometry_msgs::msg::Pose;
@@ -2035,4 +2037,29 @@ std::optional<lanelet::routing::LaneletPath> RouteHandler::findDrivableLanePath(
20352037
if (route) return route->shortestPath();
20362038
return {};
20372039
}
2040+
2041+
Pose RouteHandler::get_pose_from_2d_arc_length(
2042+
const lanelet::ConstLanelets & lanelet_sequence, const double s) const
2043+
{
2044+
double accumulated_distance2d = 0;
2045+
for (const auto & llt : lanelet_sequence) {
2046+
const auto & centerline = llt.centerline();
2047+
for (auto it = centerline.begin(); std::next(it) != centerline.end(); ++it) {
2048+
const auto pt = *it;
2049+
const auto next_pt = *std::next(it);
2050+
const double distance2d = lanelet::geometry::distance2d(to2D(pt), to2D(next_pt));
2051+
if (accumulated_distance2d + distance2d > s) {
2052+
const double ratio = (s - accumulated_distance2d) / distance2d;
2053+
const auto interpolated_pt = pt.basicPoint() * (1 - ratio) + next_pt.basicPoint() * ratio;
2054+
const auto yaw = std::atan2(next_pt.y() - pt.y(), next_pt.x() - pt.x());
2055+
Pose pose;
2056+
pose.position = createPoint(interpolated_pt.x(), interpolated_pt.y(), interpolated_pt.z());
2057+
pose.orientation = createQuaternionFromYaw(yaw);
2058+
return pose;
2059+
}
2060+
accumulated_distance2d += distance2d;
2061+
}
2062+
}
2063+
return Pose{};
2064+
}
20382065
} // namespace autoware::route_handler

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/README.md

+102
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,108 @@ The lane change candidate path is divided into two phases: preparation and lane-
2424

2525
![lane-change-phases](./images/lane_change-lane_change_phases.png)
2626

27+
The following chart illustrates the process of sampling candidate paths for lane change.
28+
29+
```plantuml
30+
@startuml
31+
skinparam defaultTextAlignment center
32+
skinparam backgroundColor #WHITE
33+
34+
start
35+
36+
if (Is current lanes, target lanes OR target neighbor lanes polygon empty?) then (yes)
37+
#LightPink:Return prev approved path;
38+
stop
39+
else (no)
40+
endif
41+
42+
:Get target objects;
43+
44+
:Calculate prepare phase metrics;
45+
46+
:Start loop through prepare phase metrics;
47+
48+
repeat
49+
:Get prepare segment;
50+
51+
if (Is LC start point outside target lanes range) then (yes)
52+
if (Is found a valid path) then (yes)
53+
#Orange:Return first valid path;
54+
stop
55+
else (no)
56+
#LightPink:Return prev approved path;
57+
stop
58+
endif
59+
else (no)
60+
endif
61+
62+
:Calculate shift phase metrics;
63+
64+
:Start loop through shift phase metrics;
65+
repeat
66+
:Get candidate path;
67+
note left: Details shown in the next chart
68+
if (Is valid candidate path?) then (yes)
69+
:Store candidate path;
70+
if (Is candidate path safe?) then (yes)
71+
#LightGreen:Return candidate path;
72+
stop
73+
else (no)
74+
endif
75+
else (no)
76+
endif
77+
repeat while (Finished looping shift phase metrics) is (FALSE)
78+
repeat while (Is finished looping prepare phase metrics) is (FALSE)
79+
80+
if (Is found a valid path) then (yes)
81+
#Orange:Return first valid path;
82+
stop
83+
else (no)
84+
endif
85+
86+
#LightPink:Return prev approved path;
87+
stop
88+
89+
@enduml
90+
```
91+
92+
While the following chart demonstrates the process of generating a valid candidate path.
93+
94+
```plantuml
95+
@startuml
96+
skinparam defaultTextAlignment center
97+
skinparam backgroundColor #WHITE
98+
99+
start
100+
101+
:Calculate resample interval;
102+
103+
:Get reference path from target lanes;
104+
105+
if (Is reference path empty?) then (yes)
106+
#LightPink:Return;
107+
stop
108+
else (no)
109+
endif
110+
111+
:Get LC shift line;
112+
113+
:Set lane change Info;
114+
note left: set information from sampled prepare phase and shift phase metrics\n<color:red>(duration, length, velocity, and acceleration)
115+
116+
:Construct candidate path;
117+
118+
if (Candidate path has enough length?) then (yes)
119+
#LightGreen:Return valid candidate path;
120+
stop
121+
else (no)
122+
#LightPink:Return;
123+
stop
124+
endif
125+
126+
@enduml
127+
```
128+
27129
### Preparation phase
28130

29131
The preparation trajectory is the candidate path's first and the straight portion generated along the ego vehicle's current lane. The length of the preparation trajectory is computed as follows.

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/include/autoware/behavior_path_lane_change_module/scene.hpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,17 @@ class NormalLaneChange : public LaneChangeBase
153153
const LaneChangePath & path, const lanelet::ConstLanelets & current_lanes,
154154
const lanelet::ConstLanelets & target_lanes, const Direction direction = Direction::NONE) const;
155155

156-
bool hasEnoughLengthToCrosswalk(
157-
const LaneChangePath & path, const lanelet::ConstLanelets & current_lanes) const;
156+
bool get_lane_change_paths(LaneChangePaths & candidate_paths) const;
158157

159-
bool hasEnoughLengthToIntersection(
160-
const LaneChangePath & path, const lanelet::ConstLanelets & current_lanes) const;
158+
LaneChangePath get_candidate_path(
159+
const LaneChangePhaseMetrics & prep_metrics, const LaneChangePhaseMetrics & lc_metrics,
160+
const PathWithLaneId & prep_segment, const std::vector<std::vector<int64_t>> & sorted_lane_ids,
161+
const Pose & lc_start_pose, const double target_lane_length, const double shift_length,
162+
const double next_lc_buffer, const bool is_goal_in_route) const;
161163

162-
bool hasEnoughLengthToTrafficLight(
163-
const LaneChangePath & path, const lanelet::ConstLanelets & current_lanes) const;
164-
165-
bool getLaneChangePaths(
166-
const lanelet::ConstLanelets & current_lanes, const lanelet::ConstLanelets & target_lanes,
167-
Direction direction, const bool is_stuck, LaneChangePaths * candidate_paths) const;
164+
bool check_candidate_path_safety(
165+
const LaneChangePath & candidate_path, const lane_change::TargetObjects & target_objects,
166+
const double lane_change_buffer, const bool is_stuck) const;
168167

169168
std::optional<LaneChangePath> calcTerminalLaneChangePath(
170169
const lanelet::ConstLanelets & current_lanes,

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/include/autoware/behavior_path_lane_change_module/utils/calculation.hpp

+33
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ using autoware::route_handler::Direction;
2424
using autoware::route_handler::RouteHandler;
2525
using behavior_path_planner::lane_change::CommonDataPtr;
2626
using behavior_path_planner::lane_change::LCParamPtr;
27+
using behavior_path_planner::lane_change::PhaseMetrics;
2728

2829
/**
2930
* @brief Calculates the distance from the ego vehicle to the terminal point.
@@ -132,6 +133,38 @@ double calc_maximum_lane_change_length(
132133
double calc_maximum_lane_change_length(
133134
const CommonDataPtr & common_data_ptr, const lanelet::ConstLanelet & current_terminal_lanelet,
134135
const double max_acc);
136+
137+
/**
138+
* @brief Calculates the distance required during a lane change operation.
139+
*
140+
* Used for computing prepare or lane change length based on current and maximum velocity,
141+
* acceleration, and duration, returning the lesser of accelerated distance or distance at max
142+
* velocity.
143+
*
144+
* @param velocity The current velocity of the vehicle in meters per second (m/s).
145+
* @param maximum_velocity The maximum velocity the vehicle can reach in meters per second (m/s).
146+
* @param acceleration The acceleration of the vehicle in meters per second squared (m/s^2).
147+
* @param duration The duration of the lane change in seconds (s).
148+
* @return The calculated minimum distance in meters (m).
149+
*/
150+
double calc_phase_length(
151+
const double velocity, const double maximum_velocity, const double acceleration,
152+
const double duration);
153+
154+
double calc_lane_changing_acceleration(
155+
const double initial_lane_changing_velocity, const double max_path_velocity,
156+
const double lane_changing_time, const double prepare_longitudinal_acc);
157+
158+
std::vector<PhaseMetrics> calc_prepare_phase_metrics(
159+
const CommonDataPtr & common_data_ptr, const std::vector<double> & prepare_durations,
160+
const std::vector<double> & lon_accel_values, const double current_velocity,
161+
const double min_length_threshold = 0.0,
162+
const double max_length_threshold = std::numeric_limits<double>::max());
163+
164+
std::vector<PhaseMetrics> calc_shift_phase_metrics(
165+
const CommonDataPtr & common_data_ptr, const double shift_length, const double initial_velocity,
166+
const double max_velocity, const double lon_accel,
167+
const double max_length_threshold = std::numeric_limits<double>::max());
135168
} // namespace autoware::behavior_path_planner::utils::lane_change::calculation
136169

137170
#endif // AUTOWARE__BEHAVIOR_PATH_LANE_CHANGE_MODULE__UTILS__CALCULATION_HPP_

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/include/autoware/behavior_path_lane_change_module/utils/data_structs.hpp

+40
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,28 @@ struct PhaseInfo
193193
}
194194
};
195195

196+
struct PhaseMetrics
197+
{
198+
double duration{0.0};
199+
double length{0.0};
200+
double velocity{0.0};
201+
double sampled_lon_accel{0.0};
202+
double actual_lon_accel{0.0};
203+
double lat_accel{0.0};
204+
205+
PhaseMetrics(
206+
const double _duration, const double _length, const double _velocity,
207+
const double _sampled_lon_accel, const double _actual_lon_accel, const double _lat_accel)
208+
: duration(_duration),
209+
length(_length),
210+
velocity(_velocity),
211+
sampled_lon_accel(_sampled_lon_accel),
212+
actual_lon_accel(_actual_lon_accel),
213+
lat_accel(_lat_accel)
214+
{
215+
}
216+
};
217+
196218
struct Lanes
197219
{
198220
bool current_lane_in_goal_section{false};
@@ -216,6 +238,23 @@ struct Info
216238

217239
double lateral_acceleration{0.0};
218240
double terminal_lane_changing_velocity{0.0};
241+
242+
Info() = default;
243+
Info(
244+
const PhaseMetrics & _prep_metrics, const PhaseMetrics & _lc_metrics,
245+
const Pose & _lc_start_pose, const Pose & _lc_end_pose, const ShiftLine & _shift_line)
246+
{
247+
longitudinal_acceleration =
248+
PhaseInfo{_prep_metrics.actual_lon_accel, _lc_metrics.actual_lon_accel};
249+
duration = PhaseInfo{_prep_metrics.duration, _lc_metrics.duration};
250+
velocity = PhaseInfo{_prep_metrics.velocity, _prep_metrics.velocity};
251+
length = PhaseInfo{_prep_metrics.length, _lc_metrics.length};
252+
lane_changing_start = _lc_start_pose;
253+
lane_changing_end = _lc_end_pose;
254+
lateral_acceleration = _lc_metrics.lat_accel;
255+
terminal_lane_changing_velocity = _lc_metrics.velocity;
256+
shift_line = _shift_line;
257+
}
219258
};
220259

221260
template <typename Object>
@@ -317,6 +356,7 @@ using LaneChangeModuleType = lane_change::ModuleType;
317356
using LaneChangeParameters = lane_change::Parameters;
318357
using LaneChangeStates = lane_change::States;
319358
using LaneChangePhaseInfo = lane_change::PhaseInfo;
359+
using LaneChangePhaseMetrics = lane_change::PhaseMetrics;
320360
using LaneChangeInfo = lane_change::Info;
321361
using FilteredByLanesObjects = lane_change::LanesObjects<std::vector<PredictedObject>>;
322362
using FilteredByLanesExtendedObjects = lane_change::LanesObjects<ExtendedPredictedObjects>;

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/include/autoware/behavior_path_lane_change_module/utils/utils.hpp

+3-29
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ double calcMaximumAcceleration(
6969
const double current_velocity, const double current_max_velocity,
7070
const double max_longitudinal_acc, const LaneChangeParameters & lane_change_parameters);
7171

72-
double calcLaneChangingAcceleration(
73-
const double initial_lane_changing_velocity, const double max_path_velocity,
74-
const double lane_changing_time, const double prepare_longitudinal_acc);
75-
7672
void setPrepareVelocity(
7773
PathWithLaneId & prepare_segment, const double current_velocity, const double prepare_velocity);
7874

@@ -99,17 +95,12 @@ bool pathFootprintExceedsTargetLaneBound(
9995
const CommonDataPtr & common_data_ptr, const PathWithLaneId & path, const VehicleInfo & ego_info,
10096
const double margin = 0.1);
10197

102-
std::optional<LaneChangePath> constructCandidatePath(
98+
std::optional<LaneChangePath> construct_candidate_path(
10399
const CommonDataPtr & common_data_ptr, const LaneChangeInfo & lane_change_info,
104-
const PathWithLaneId & prepare_segment, const PathWithLaneId & target_segment,
105-
const PathWithLaneId & target_lane_reference_path,
100+
const PathWithLaneId & prepare_segment, const PathWithLaneId & target_lane_reference_path,
106101
const std::vector<std::vector<int64_t>> & sorted_lane_ids);
107102

108-
ShiftLine getLaneChangingShiftLine(
109-
const PathWithLaneId & prepare_segment, const PathWithLaneId & target_segment,
110-
const PathWithLaneId & reference_path, const double shift_length);
111-
112-
ShiftLine getLaneChangingShiftLine(
103+
ShiftLine get_lane_changing_shift_line(
113104
const Pose & lane_changing_start_pose, const Pose & lane_changing_end_pose,
114105
const PathWithLaneId & reference_path, const double shift_length);
115106

@@ -260,23 +251,6 @@ bool isWithinIntersection(
260251
*/
261252
bool isWithinTurnDirectionLanes(const lanelet::ConstLanelet & lanelet, const Polygon2d & polygon);
262253

263-
/**
264-
* @brief Calculates the distance required during a lane change operation.
265-
*
266-
* Used for computing prepare or lane change length based on current and maximum velocity,
267-
* acceleration, and duration, returning the lesser of accelerated distance or distance at max
268-
* velocity.
269-
*
270-
* @param velocity The current velocity of the vehicle in meters per second (m/s).
271-
* @param maximum_velocity The maximum velocity the vehicle can reach in meters per second (m/s).
272-
* @param acceleration The acceleration of the vehicle in meters per second squared (m/s^2).
273-
* @param duration The duration of the lane change in seconds (s).
274-
* @return The calculated minimum distance in meters (m).
275-
*/
276-
double calcPhaseLength(
277-
const double velocity, const double maximum_velocity, const double acceleration,
278-
const double time);
279-
280254
LanesPolygon create_lanes_polygon(const CommonDataPtr & common_data_ptr);
281255

282256
bool is_same_lane_with_prev_iteration(

0 commit comments

Comments
 (0)