Skip to content

Commit 1c2e5ea

Browse files
cherry-pick LC PRs 2
Signed-off-by: Muhammad Zulfaqar Azmi <zulfaqar.azmi@tier4.jp> Signed-off-by: Zulfaqar Azmi <zulfaqar.azmi@tier4.jp>
1 parent b1a785d commit 1c2e5ea

File tree

17 files changed

+503
-229
lines changed

17 files changed

+503
-229
lines changed

planning/behavior_path_lane_change_module/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ament_auto_add_library(${PROJECT_NAME} SHARED
99
src/interface.cpp
1010
src/manager.cpp
1111
src/scene.cpp
12+
src/utils/calculation.cpp
1213
src/utils/markers.cpp
1314
src/utils/utils.cpp
1415
)

planning/behavior_path_lane_change_module/config/lane_change.param.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
min_longitudinal_acc: -1.0
2828
max_longitudinal_acc: 1.0
2929

30+
skip_process:
31+
longitudinal_distance_diff_threshold:
32+
prepare: 0.5
33+
lane_changing: 0.5
34+
3035
# safety check
3136
safety_check:
3237
allow_loose_check_for_cancel: true

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/scene.hpp

+28-13
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class NormalLaneChange : public LaneChangeBase
8181
PathSafetyStatus evaluateApprovedPathWithUnsafeHysteresis(
8282
PathSafetyStatus approved_path_safety_status) override;
8383

84-
bool isRequiredStop(const bool is_object_coming_from_rear) override;
84+
bool isRequiredStop(const bool is_trailing_object) override;
8585

8686
bool isNearEndOfCurrentLanes(
8787
const lanelet::ConstLanelets & current_lanes, const lanelet::ConstLanelets & target_lanes,
@@ -91,6 +91,8 @@ class NormalLaneChange : public LaneChangeBase
9191

9292
bool isAbleToReturnCurrentLane() const override;
9393

94+
bool is_near_terminal() const final;
95+
9496
bool isEgoOnPreparePhase() const override;
9597

9698
bool isAbleToStopSafely() const override;
@@ -119,19 +121,16 @@ class NormalLaneChange : public LaneChangeBase
119121
const lanelet::ConstLanelets & current_lanes,
120122
const lanelet::ConstLanelets & target_lanes) const;
121123

122-
ExtendedPredictedObjects getTargetObjects(
123-
const LaneChangeLanesFilteredObjects & predicted_objects,
124+
lane_change::TargetObjects getTargetObjects(
125+
const FilteredByLanesExtendedObjects & predicted_objects,
124126
const lanelet::ConstLanelets & current_lanes) const;
125127

126-
LaneChangeLanesFilteredObjects filterObjects() const;
128+
FilteredByLanesExtendedObjects filterObjects() const;
127129

128130
void filterOncomingObjects(PredictedObjects & objects) const;
129131

130-
void filterObjectsByLanelets(
131-
const PredictedObjects & objects, const PathWithLaneId & current_lanes_ref_path,
132-
std::vector<PredictedObject> & current_lane_objects,
133-
std::vector<PredictedObject> & target_lane_objects,
134-
std::vector<PredictedObject> & other_lane_objects) const;
132+
FilteredByLanesObjects filterObjectsByLanelets(
133+
const PredictedObjects & objects, const PathWithLaneId & current_lanes_ref_path) const;
135134

136135
PathWithLaneId getPrepareSegment(
137136
const lanelet::ConstLanelets & current_lanes, const double backward_path_length,
@@ -157,9 +156,7 @@ class NormalLaneChange : public LaneChangeBase
157156

158157
bool getLaneChangePaths(
159158
const lanelet::ConstLanelets & current_lanes, const lanelet::ConstLanelets & target_lanes,
160-
Direction direction, LaneChangePaths * candidate_paths,
161-
const utils::path_safety_checker::RSSparams rss_params, const bool is_stuck,
162-
const bool check_safety = true) const override;
159+
Direction direction, const bool is_stuck, LaneChangePaths * candidate_paths) const;
163160

164161
std::optional<LaneChangePath> calcTerminalLaneChangePath(
165162
const lanelet::ConstLanelets & current_lanes,
@@ -169,7 +166,7 @@ class NormalLaneChange : public LaneChangeBase
169166

170167
PathSafetyStatus isLaneChangePathSafe(
171168
const LaneChangePath & lane_change_path,
172-
const ExtendedPredictedObjects & collision_check_objects,
169+
const lane_change::TargetObjects & collision_check_objects,
173170
const utils::path_safety_checker::RSSparams & rss_params,
174171
CollisionCheckDebugMap & debug_data) const;
175172

@@ -183,6 +180,24 @@ class NormalLaneChange : public LaneChangeBase
183180

184181
bool isVehicleStuck(const lanelet::ConstLanelets & current_lanes) const;
185182

183+
/**
184+
* @brief Checks if the given pose is a valid starting point for a lane change.
185+
*
186+
* This function determines whether the given pose (position) of the vehicle is within
187+
* the area of either the target neighbor lane or the target lane itself. It uses geometric
188+
* checks to see if the start point of the lane change is covered by the polygons representing
189+
* these lanes.
190+
*
191+
* @param common_data_ptr Shared pointer to a CommonData structure, which should include:
192+
* - Non-null `lanes_polygon_ptr` that contains the polygon data for lanes.
193+
* @param pose The current pose of the vehicle
194+
*
195+
* @return `true` if the pose is within either the target neighbor lane or the target lane;
196+
* `false` otherwise.
197+
*/
198+
bool is_valid_start_point(
199+
const lane_change::CommonDataPtr & common_data_ptr, const Pose & pose) const;
200+
186201
bool check_prepare_phase() const;
187202

188203
double calcMaximumLaneChangeLength(

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/utils/base_class.hpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,15 @@ class LaneChangeBase
9191

9292
virtual bool isAbleToReturnCurrentLane() const = 0;
9393

94+
virtual bool is_near_terminal() const = 0;
95+
9496
virtual LaneChangePath getLaneChangePath() const = 0;
9597

9698
virtual BehaviorModuleOutput getTerminalLaneChangePath() const = 0;
9799

98100
virtual bool isEgoOnPreparePhase() const = 0;
99101

100-
virtual bool isRequiredStop(const bool is_object_coming_from_rear) = 0;
102+
virtual bool isRequiredStop(const bool is_trailing_object) = 0;
101103

102104
virtual PathSafetyStatus isApprovedPathSafe() const = 0;
103105

@@ -227,12 +229,6 @@ class LaneChangeBase
227229
const lanelet::ConstLanelets & current_lanes, const double backward_path_length,
228230
const double prepare_length) const = 0;
229231

230-
virtual bool getLaneChangePaths(
231-
const lanelet::ConstLanelets & original_lanelets,
232-
const lanelet::ConstLanelets & target_lanelets, Direction direction,
233-
LaneChangePaths * candidate_paths, const utils::path_safety_checker::RSSparams rss_params,
234-
const bool is_stuck, const bool check_safety) const = 0;
235-
236232
virtual bool isValidPath(const PathWithLaneId & path) const = 0;
237233

238234
virtual bool isAbleToStopSafely() const = 0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2024 TIER IV, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
#ifndef BEHAVIOR_PATH_LANE_CHANGE_MODULE__UTILS__CALCULATION_HPP_
15+
#define BEHAVIOR_PATH_LANE_CHANGE_MODULE__UTILS__CALCULATION_HPP_
16+
17+
#include "behavior_path_lane_change_module/utils/data_structs.hpp"
18+
19+
namespace behavior_path_planner::utils::lane_change::calculation
20+
{
21+
using behavior_path_planner::lane_change::CommonDataPtr;
22+
using behavior_path_planner::lane_change::LCParamPtr;
23+
24+
/**
25+
* @brief Calculates the distance from the ego vehicle to the terminal point.
26+
*
27+
* This function computes the distance from the current position of the ego vehicle
28+
* to either the goal pose or the end of the current lane, depending on whether
29+
* the vehicle's current lane is within the goal section.
30+
*
31+
* @param common_data_ptr Shared pointer to a CommonData structure, which should include:
32+
* - Non null `lanes_ptr` that points to the current lanes data.
33+
* - Non null `self_odometry_ptr` that contains the current pose of the ego vehicle.
34+
* - Non null `route_handler_ptr` that contains the goal pose of the route.
35+
*
36+
* @return The distance to the terminal point (either the goal pose or the end of the current lane)
37+
* in meters.
38+
*/
39+
double calc_ego_dist_to_terminal_end(const CommonDataPtr & common_data_ptr);
40+
41+
double calc_dist_from_pose_to_terminal_end(
42+
const CommonDataPtr & common_data_ptr, const lanelet::ConstLanelets & lanes,
43+
const Pose & src_pose);
44+
45+
/**
46+
* @brief Calculates the backward buffer distance required for safe lane changing.
47+
*
48+
* This function computes the minimum required backward buffer distance based on the
49+
* minimum lane changing velocity and the minimum longitudinal acceleration. It then
50+
* compares this calculated distance with a pre-defined backward length buffer parameter
51+
* and returns the larger of the two values to ensure safe lane changing.
52+
*
53+
* @param lc_param_ptr Shared pointer to an LCParam structure, which should include:
54+
* - `minimum_lane_changing_velocity`: The minimum velocity required for lane changing.
55+
* - `min_longitudinal_acc`: The minimum longitudinal acceleration used for deceleration.
56+
* - `backward_length_buffer_for_end_of_lane`: A predefined backward buffer length parameter.
57+
*
58+
* @return The required backward buffer distance in meters.
59+
*/
60+
double calc_backward_buffer(const LCParamPtr & lc_param_ptr);
61+
} // namespace behavior_path_planner::utils::lane_change::calculation
62+
63+
#endif // BEHAVIOR_PATH_LANE_CHANGE_MODULE__UTILS__CALCULATION_HPP_

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/utils/data_structs.hpp

+40-5
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ struct Parameters
124124
double min_longitudinal_acc{-1.0};
125125
double max_longitudinal_acc{1.0};
126126

127+
double skip_process_lon_diff_th_prepare{0.5};
128+
double skip_process_lon_diff_th_lane_changing{1.0};
129+
127130
// collision check
128131
bool enable_collision_check_for_prepare_phase_in_general_lanes{false};
129132
bool enable_collision_check_for_prepare_phase_in_intersection{true};
@@ -186,6 +189,7 @@ struct Lanes
186189
{
187190
bool current_lane_in_goal_section{false};
188191
lanelet::ConstLanelets current;
192+
lanelet::ConstLanelets target_neighbor;
189193
lanelet::ConstLanelets target;
190194
std::vector<lanelet::ConstLanelets> preceding_target;
191195
};
@@ -206,11 +210,33 @@ struct Info
206210
double terminal_lane_changing_velocity{0.0};
207211
};
208212

213+
template <typename Object>
209214
struct LanesObjects
210215
{
211-
ExtendedPredictedObjects current_lane{};
212-
ExtendedPredictedObjects target_lane{};
213-
ExtendedPredictedObjects other_lane{};
216+
Object current_lane{};
217+
Object target_lane_leading{};
218+
Object target_lane_trailing{};
219+
Object other_lane{};
220+
221+
LanesObjects() = default;
222+
LanesObjects(
223+
Object current_lane, Object target_lane_leading, Object target_lane_trailing, Object other_lane)
224+
: current_lane(std::move(current_lane)),
225+
target_lane_leading(std::move(target_lane_leading)),
226+
target_lane_trailing(std::move(target_lane_trailing)),
227+
other_lane(std::move(other_lane))
228+
{
229+
}
230+
};
231+
232+
struct TargetObjects
233+
{
234+
ExtendedPredictedObjects leading;
235+
ExtendedPredictedObjects trailing;
236+
TargetObjects(ExtendedPredictedObjects leading, ExtendedPredictedObjects trailing)
237+
: leading(std::move(leading)), trailing(std::move(trailing))
238+
{
239+
}
214240
};
215241

216242
enum class ModuleType {
@@ -222,7 +248,13 @@ enum class ModuleType {
222248
struct PathSafetyStatus
223249
{
224250
bool is_safe{true};
225-
bool is_object_coming_from_rear{false};
251+
bool is_trailing_object{false};
252+
253+
PathSafetyStatus() = default;
254+
PathSafetyStatus(const bool is_safe, const bool is_trailing_object)
255+
: is_safe(is_safe), is_trailing_object(is_trailing_object)
256+
{
257+
}
226258
};
227259

228260
struct LanesPolygon
@@ -271,12 +303,15 @@ using CommonDataPtr = std::shared_ptr<CommonData>;
271303

272304
namespace behavior_path_planner
273305
{
306+
using autoware_auto_perception_msgs::msg::PredictedObject;
307+
using utils::path_safety_checker::ExtendedPredictedObjects;
274308
using LaneChangeModuleType = lane_change::ModuleType;
275309
using LaneChangeParameters = lane_change::Parameters;
276310
using LaneChangeStates = lane_change::States;
277311
using LaneChangePhaseInfo = lane_change::PhaseInfo;
278312
using LaneChangeInfo = lane_change::Info;
279-
using LaneChangeLanesFilteredObjects = lane_change::LanesObjects;
313+
using FilteredByLanesObjects = lane_change::LanesObjects<std::vector<PredictedObject>>;
314+
using FilteredByLanesExtendedObjects = lane_change::LanesObjects<ExtendedPredictedObjects>;
280315
using LateralAccelerationMap = lane_change::LateralAccelerationMap;
281316
} // namespace behavior_path_planner
282317

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/utils/debug_structs.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct Debug
3535
LaneChangePaths valid_paths;
3636
CollisionCheckDebugMap collision_check_objects;
3737
CollisionCheckDebugMap collision_check_objects_after_approval;
38-
LaneChangeLanesFilteredObjects filtered_objects;
38+
FilteredByLanesExtendedObjects filtered_objects;
3939
geometry_msgs::msg::Polygon execution_area;
4040
geometry_msgs::msg::Pose ego_pose;
4141
lanelet::ConstLanelets current_lanes;
@@ -55,7 +55,8 @@ struct Debug
5555
collision_check_objects.clear();
5656
collision_check_objects_after_approval.clear();
5757
filtered_objects.current_lane.clear();
58-
filtered_objects.target_lane.clear();
58+
filtered_objects.target_lane_leading.clear();
59+
filtered_objects.target_lane_trailing.clear();
5960
filtered_objects.other_lane.clear();
6061
execution_area.points.clear();
6162
current_lanes.clear();

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/utils/markers.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
namespace marker_utils::lane_change_markers
3131
{
32+
using behavior_path_planner::FilteredByLanesExtendedObjects;
3233
using behavior_path_planner::LaneChangePath;
3334
using behavior_path_planner::lane_change::Debug;
3435
using behavior_path_planner::utils::path_safety_checker::ExtendedPredictedObjects;
@@ -39,9 +40,7 @@ MarkerArray createLaneChangingVirtualWallMarker(
3940
const geometry_msgs::msg::Pose & lane_changing_pose, const std::string & module_name,
4041
const rclcpp::Time & now, const std::string & ns);
4142
MarkerArray showFilteredObjects(
42-
const ExtendedPredictedObjects & current_lane_objects,
43-
const ExtendedPredictedObjects & target_lane_objects,
44-
const ExtendedPredictedObjects & other_lane_objects, const std::string & ns);
43+
const FilteredByLanesExtendedObjects & filtered_objects, const std::string & ns);
4544
MarkerArray createExecutionArea(const geometry_msgs::msg::Polygon & execution_area);
4645
MarkerArray showExecutionInfo(const Debug & debug_data, const geometry_msgs::msg::Pose & ego_pose);
4746
MarkerArray createDebugMarkerArray(

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/utils/utils.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ lanelet::ConstLanelets getTargetNeighborLanes(
104104
const RouteHandler & route_handler, const lanelet::ConstLanelets & target_lanes,
105105
const LaneChangeModuleType & type);
106106

107-
lanelet::BasicPolygon2d getTargetNeighborLanesPolygon(
108-
const RouteHandler & route_handler, const lanelet::ConstLanelets & current_lanes,
109-
const LaneChangeModuleType & type);
110-
111107
bool isPathInLanelets(
112108
const PathWithLaneId & path, const lanelet::ConstLanelets & current_lanes,
113109
const lanelet::ConstLanelets & target_lanes);

planning/behavior_path_lane_change_module/src/interface.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,21 @@ bool LaneChangeInterface::canTransitFailureState()
262262
return false;
263263
}
264264

265+
if (!module_type_->isValidPath()) {
266+
log_debug_throttled("Transit to failure state due not to find valid path");
267+
return true;
268+
}
269+
270+
if (module_type_->isAbortState() && module_type_->hasFinishedAbort()) {
271+
log_debug_throttled("Abort process has completed.");
272+
return true;
273+
}
274+
275+
if (module_type_->is_near_terminal()) {
276+
log_debug_throttled("Unsafe, but ego is approaching terminal. Continue lane change");
277+
return false;
278+
}
279+
265280
if (module_type_->isCancelEnabled() && module_type_->isEgoOnPreparePhase()) {
266281
if (module_type_->isStoppedAtRedTrafficLight()) {
267282
log_debug_throttled("Stopping at traffic light while in prepare phase. Cancel lane change");
@@ -287,6 +302,11 @@ bool LaneChangeInterface::canTransitFailureState()
287302

288303
if (post_process_safety_status_.is_safe) {
289304
log_debug_throttled("Can't transit to failure state. Ego is on prepare, and it's safe.");
305+
306+
if (module_type_->isRequiredStop(post_process_safety_status_.is_trailing_object)) {
307+
log_debug_throttled("Module require stopping");
308+
}
309+
290310
return false;
291311
}
292312

@@ -304,7 +324,7 @@ bool LaneChangeInterface::canTransitFailureState()
304324
return false;
305325
}
306326

307-
if (module_type_->isRequiredStop(post_process_safety_status_.is_object_coming_from_rear)) {
327+
if (module_type_->isRequiredStop(post_process_safety_status_.is_trailing_object)) {
308328
log_debug_throttled("Module require stopping");
309329
}
310330

planning/behavior_path_lane_change_module/src/manager.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ void LaneChangeModuleManager::updateModuleParams(const std::vector<rclcpp::Param
330330
updateParam<double>(parameters, ns + "max_longitudinal_acc", p->max_longitudinal_acc);
331331
}
332332

333+
{
334+
const std::string ns = "lane_change.skip_process.longitudinal_distance_diff_threshold.";
335+
updateParam<double>(parameters, ns + "prepare", p->skip_process_lon_diff_th_prepare);
336+
updateParam<double>(
337+
parameters, ns + "lane_changing", p->skip_process_lon_diff_th_lane_changing);
338+
}
339+
333340
{
334341
const std::string ns = "lane_change.safety_check.lane_expansion.";
335342
updateParam<double>(parameters, ns + "left_offset", p->lane_expansion_left_offset);

0 commit comments

Comments
 (0)