Skip to content

Commit 65503db

Browse files
fix(avoidance_by_lane_change): loosen execution condition
Signed-off-by: Muhammad Zulfaqar Azmi <zulfaqar.azmi@tier4.jp>
1 parent a9525bf commit 65503db

File tree

9 files changed

+119
-99
lines changed

9 files changed

+119
-99
lines changed

planning/behavior_path_avoidance_by_lane_change_module/include/behavior_path_avoidance_by_lane_change_module/scene.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ class AvoidanceByLaneChange : public NormalLaneChange
5454
const AvoidancePlanningData & data, const PredictedObject & object) const;
5555

5656
void fillAvoidanceTargetObjects(AvoidancePlanningData & data, AvoidanceDebugData & debug) const;
57+
58+
double calcMinAvoidanceLength(const ObjectData & nearest_object) const;
59+
double calcMinimumLaneChangeLength() const;
60+
double calcLateralOffset() const;
5761
};
5862
} // namespace behavior_path_planner
5963

planning/behavior_path_avoidance_by_lane_change_module/src/interface.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@
1616

1717
#include "behavior_path_planner_common/interface/scene_module_interface.hpp"
1818
#include "behavior_path_planner_common/interface/scene_module_visitor.hpp"
19-
#include "behavior_path_planner_common/marker_utils/utils.hpp"
2019

21-
#include <algorithm>
2220
#include <memory>
2321
#include <string>
24-
#include <utility>
25-
#include <vector>
2622

2723
namespace behavior_path_planner
2824
{

planning/behavior_path_avoidance_by_lane_change_module/src/scene.cpp

+55-93
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "behavior_path_planner_common/utils/utils.hpp"
2222
#include "lanelet2_extension/utility/message_conversion.hpp"
2323

24+
#include <behavior_path_avoidance_module/data_structs.hpp>
25+
#include <behavior_path_lane_change_module/utils/utils.hpp>
2426
#include <lanelet2_extension/utility/utilities.hpp>
2527
#include <rclcpp/logging.hpp>
2628
#include <tier4_autoware_utils/geometry/geometry.hpp>
@@ -32,11 +34,13 @@
3234
#include <boost/geometry/algorithms/centroid.hpp>
3335
#include <boost/geometry/strategies/cartesian/centroid_bashein_detmer.hpp>
3436

35-
#include <cstddef>
37+
#include <limits>
3638
#include <utility>
3739

3840
namespace behavior_path_planner
3941
{
42+
using behavior_path_planner::utils::lane_change::debug::createExecutionArea;
43+
4044
AvoidanceByLaneChange::AvoidanceByLaneChange(
4145
const std::shared_ptr<LaneChangeParameters> & parameters,
4246
std::shared_ptr<AvoidanceByLCParameters> avoidance_parameters)
@@ -76,101 +80,15 @@ bool AvoidanceByLaneChange::specialRequiredCheck() const
7680
return false;
7781
}
7882

79-
const auto current_lanes = getCurrentLanes();
80-
if (current_lanes.empty()) {
81-
RCLCPP_DEBUG(logger_, "no empty lanes");
82-
return false;
83-
}
84-
8583
const auto & nearest_object = data.target_objects.front();
84+
const auto minimum_avoid_length = calcMinAvoidanceLength(nearest_object);
85+
const auto minimum_lane_change_length = calcMinimumLaneChangeLength();
8686

87-
// get minimum lane change distance
88-
const auto shift_intervals =
89-
getRouteHandler()->getLateralIntervalsToPreferredLane(current_lanes.back(), direction_);
90-
const double minimum_lane_change_length = utils::lane_change::calcMinimumLaneChangeLength(
91-
*lane_change_parameters_, shift_intervals,
92-
lane_change_parameters_->backward_length_buffer_for_end_of_lane);
93-
94-
const auto ego_width = getCommonParam().vehicle_width;
95-
const auto nearest_object_type = utils::getHighestProbLabel(nearest_object.object.classification);
96-
const auto nearest_object_parameter =
97-
avoidance_parameters_->object_parameters.at(nearest_object_type);
98-
const auto avoid_margin =
99-
nearest_object_parameter.safety_buffer_lateral * nearest_object.distance_factor +
100-
nearest_object_parameter.avoid_margin_lateral + 0.5 * ego_width;
101-
102-
avoidance_helper_->setData(planner_data_);
103-
const auto shift_length = avoidance_helper_->getShiftLength(
104-
nearest_object, utils::avoidance::isOnRight(nearest_object), avoid_margin);
105-
106-
const auto minimum_avoid_distance = avoidance_helper_->getMinAvoidanceDistance(shift_length);
107-
108-
const auto max_offset = std::invoke([&]() -> double {
109-
auto max_offset{0.0};
110-
for (const auto & [type, p] : avoidance_parameters_->object_parameters) {
111-
const auto offset =
112-
2.0 * p.envelope_buffer_margin + p.safety_buffer_lateral + p.avoid_margin_lateral;
113-
max_offset = std::max(max_offset, offset);
114-
}
115-
return max_offset;
116-
});
117-
118-
auto create_point32 = [](const geometry_msgs::msg::Pose & pose) -> geometry_msgs::msg::Point32 {
119-
geometry_msgs::msg::Point32 p;
120-
p.x = static_cast<float>(pose.position.x);
121-
p.y = static_cast<float>(pose.position.y);
122-
p.z = static_cast<float>(pose.position.z);
123-
return p;
124-
};
125-
126-
const auto create_vehicle_polygon =
127-
[&](const vehicle_info_util::VehicleInfo & vehicle_info, const double offset) {
128-
const double & base_to_front = vehicle_info.max_longitudinal_offset_m;
129-
const double & width = vehicle_info.vehicle_width_m;
130-
const double & base_to_rear = vehicle_info.rear_overhang_m;
131-
132-
// if stationary object, extend forward and backward by the half of lon length
133-
const double forward_lon_offset =
134-
base_to_front + std::max(minimum_lane_change_length, minimum_avoid_distance);
135-
const double backward_lon_offset = -base_to_rear;
136-
const double lat_offset = width / 2.0 + offset;
137-
138-
const auto & base_link_pose = getEgoPose();
139-
140-
const auto p1 =
141-
tier4_autoware_utils::calcOffsetPose(base_link_pose, forward_lon_offset, lat_offset, 0.0);
142-
const auto p2 =
143-
tier4_autoware_utils::calcOffsetPose(base_link_pose, forward_lon_offset, -lat_offset, 0.0);
144-
const auto p3 =
145-
tier4_autoware_utils::calcOffsetPose(base_link_pose, backward_lon_offset, -lat_offset, 0.0);
146-
const auto p4 =
147-
tier4_autoware_utils::calcOffsetPose(base_link_pose, backward_lon_offset, lat_offset, 0.0);
148-
geometry_msgs::msg::Polygon polygon;
149-
150-
polygon.points.push_back(create_point32(p1));
151-
polygon.points.push_back(create_point32(p2));
152-
polygon.points.push_back(create_point32(p3));
153-
polygon.points.push_back(create_point32(p4));
154-
155-
return polygon;
156-
};
157-
158-
debug_execution_.effective_area =
159-
create_vehicle_polygon(getCommonParam().vehicle_info, max_offset);
160-
161-
RCLCPP_DEBUG(logger_, "ego pose.x %.3f pose.y %.3f", getEgoPosition().x, getEgoPosition().y);
162-
RCLCPP_DEBUG(
163-
logger_, "effective_area p1.x %.3f, p1.y %.3f",
164-
debug_execution_.effective_area.points.front().x,
165-
debug_execution_.effective_area.points.front().y);
87+
lane_change_debug_.execution_area = createExecutionArea(
88+
getCommonParam().vehicle_info, getEgoPose(),
89+
std::max(minimum_lane_change_length, minimum_avoid_length), calcLateralOffset());
16690

167-
RCLCPP_DEBUG(
168-
logger_,
169-
"nearest_object.longitudinal %.3f, minimum_lane_change_length %.3f, minimum_avoid_distance "
170-
"%.3f",
171-
nearest_object.longitudinal, minimum_lane_change_length, minimum_avoid_distance);
172-
173-
return nearest_object.longitudinal > std::max(minimum_lane_change_length, minimum_avoid_distance);
91+
return nearest_object.longitudinal > std::max(minimum_lane_change_length, minimum_avoid_length);
17492
}
17593

17694
bool AvoidanceByLaneChange::specialExpiredCheck() const
@@ -339,4 +257,48 @@ ObjectData AvoidanceByLaneChange::createObjectData(
339257

340258
return object_data;
341259
}
260+
261+
double AvoidanceByLaneChange::calcMinAvoidanceLength(const ObjectData & nearest_object) const
262+
{
263+
const auto ego_width = getCommonParam().vehicle_width;
264+
const auto nearest_object_type = utils::getHighestProbLabel(nearest_object.object.classification);
265+
const auto nearest_object_parameter =
266+
avoidance_parameters_->object_parameters.at(nearest_object_type);
267+
const auto avoid_margin =
268+
nearest_object_parameter.safety_buffer_lateral * nearest_object.distance_factor +
269+
nearest_object_parameter.avoid_margin_lateral + 0.5 * ego_width;
270+
271+
avoidance_helper_->setData(planner_data_);
272+
const auto shift_length = avoidance_helper_->getShiftLength(
273+
nearest_object, utils::avoidance::isOnRight(nearest_object), avoid_margin);
274+
275+
return avoidance_helper_->getMinAvoidanceDistance(shift_length);
276+
}
277+
278+
double AvoidanceByLaneChange::calcMinimumLaneChangeLength() const
279+
{
280+
const auto current_lanes = getCurrentLanes();
281+
if (current_lanes.empty()) {
282+
RCLCPP_DEBUG(logger_, "no empty lanes");
283+
return std::numeric_limits<double>::infinity();
284+
}
285+
286+
// get minimum lane change distance
287+
const auto shift_intervals =
288+
getRouteHandler()->getLateralIntervalsToPreferredLane(current_lanes.back(), direction_);
289+
return utils::lane_change::calcMinimumLaneChangeLength(
290+
*lane_change_parameters_, shift_intervals,
291+
lane_change_parameters_->backward_length_buffer_for_end_of_lane);
292+
}
293+
294+
double AvoidanceByLaneChange::calcLateralOffset() const
295+
{
296+
auto additional_lat_offset{0.0};
297+
for (const auto & [type, p] : avoidance_parameters_->object_parameters) {
298+
const auto offset =
299+
2.0 * p.envelope_buffer_margin + p.safety_buffer_lateral + p.avoid_margin_lateral;
300+
additional_lat_offset = std::max(additional_lat_offset, offset);
301+
}
302+
return additional_lat_offset;
303+
}
342304
} // namespace behavior_path_planner

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

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include <behavior_path_planner_common/utils/path_safety_checker/path_safety_checker_parameters.hpp>
2121

22+
#include <geometry_msgs/msg/detail/polygon__struct.hpp>
23+
2224
#include <string>
2325

2426
namespace behavior_path_planner::data::lane_change
@@ -31,6 +33,7 @@ struct Debug
3133
CollisionCheckDebugMap collision_check_objects;
3234
CollisionCheckDebugMap collision_check_objects_after_approval;
3335
LaneChangeTargetObjects filtered_objects;
36+
geometry_msgs::msg::Polygon execution_area;
3437
double collision_check_object_debug_lifetime{0.0};
3538

3639
void reset()

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

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "behavior_path_lane_change_module/utils/path.hpp"
2020
#include "behavior_path_planner_common/utils/path_safety_checker/path_safety_checker_parameters.hpp"
2121

22+
#include <geometry_msgs/msg/detail/polygon__struct.hpp>
2223
#include <visualization_msgs/msg/detail/marker_array__struct.hpp>
2324
#include <visualization_msgs/msg/marker_array.hpp>
2425

@@ -40,6 +41,8 @@ MarkerArray showFilteredObjects(
4041
const ExtendedPredictedObjects & current_lane_objects,
4142
const ExtendedPredictedObjects & target_lane_objects,
4243
const ExtendedPredictedObjects & other_lane_objects, const std::string & ns);
44+
MarkerArray createExecutionArea(const geometry_msgs::msg::Polygon & execution_area);
4345
MarkerArray createDebugMarkerArray(const Debug & debug_data);
46+
4447
} // namespace marker_utils::lane_change_markers
4548
#endif // BEHAVIOR_PATH_LANE_CHANGE_MODULE__UTILS__MARKERS_HPP_

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

+10
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,14 @@ lanelet::ConstLanelets generateExpandedLanelets(
221221
*/
222222
rclcpp::Logger getLogger(const std::string & type);
223223
} // namespace behavior_path_planner::utils::lane_change
224+
225+
namespace behavior_path_planner::utils::lane_change::debug
226+
{
227+
geometry_msgs::msg::Point32 create_point32(const geometry_msgs::msg::Pose & pose);
228+
229+
geometry_msgs::msg::Polygon createExecutionArea(
230+
const vehicle_info_util::VehicleInfo & vehicle_info, const Pose & pose,
231+
double additional_lon_offset, double additional_lat_offset);
232+
} // namespace behavior_path_planner::utils::lane_change::debug
233+
224234
#endif // BEHAVIOR_PATH_LANE_CHANGE_MODULE__UTILS__UTILS_HPP_

planning/behavior_path_lane_change_module/src/scene.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "behavior_path_lane_change_module/scene.hpp"
1616

1717
#include "behavior_path_lane_change_module/utils/utils.hpp"
18-
#include "behavior_path_planner_common/marker_utils/utils.hpp"
1918
#include "behavior_path_planner_common/utils/drivable_area_expansion/static_drivable_area.hpp"
2019
#include "behavior_path_planner_common/utils/path_safety_checker/objects_filtering.hpp"
2120
#include "behavior_path_planner_common/utils/path_safety_checker/safety_check.hpp"
@@ -38,7 +37,6 @@
3837
#include <algorithm>
3938
#include <limits>
4039
#include <memory>
41-
#include <string>
4240
#include <utility>
4341
#include <vector>
4442

planning/behavior_path_lane_change_module/src/utils/markers.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ MarkerArray createDebugMarkerArray(const Debug & debug_data)
162162
"ego_and_target_polygon_relation_after_approval"));
163163
}
164164

165+
if (!debug_data.execution_area.points.empty()) {
166+
add(createPolygonMarkerArray(
167+
debug_data.execution_area, "execution_area", 0, 0.16, 1.0, 0.69, 0.1));
168+
}
169+
165170
return debug_marker;
166171
}
167172
} // namespace marker_utils::lane_change_markers

planning/behavior_path_lane_change_module/src/utils/utils.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -1170,3 +1170,42 @@ rclcpp::Logger getLogger(const std::string & type)
11701170
return rclcpp::get_logger("lane_change").get_child(type);
11711171
}
11721172
} // namespace behavior_path_planner::utils::lane_change
1173+
1174+
namespace behavior_path_planner::utils::lane_change::debug
1175+
{
1176+
geometry_msgs::msg::Point32 create_point32(const geometry_msgs::msg::Pose & pose)
1177+
{
1178+
geometry_msgs::msg::Point32 p;
1179+
p.x = static_cast<float>(pose.position.x);
1180+
p.y = static_cast<float>(pose.position.y);
1181+
p.z = static_cast<float>(pose.position.z);
1182+
return p;
1183+
};
1184+
1185+
geometry_msgs::msg::Polygon createExecutionArea(
1186+
const vehicle_info_util::VehicleInfo & vehicle_info, const Pose & pose,
1187+
double additional_lon_offset, double additional_lat_offset)
1188+
{
1189+
const double & base_to_front = vehicle_info.max_longitudinal_offset_m;
1190+
const double & width = vehicle_info.vehicle_width_m;
1191+
const double & base_to_rear = vehicle_info.rear_overhang_m;
1192+
1193+
// if stationary object, extend forward and backward by the half of lon length
1194+
const double forward_lon_offset = base_to_front + additional_lon_offset;
1195+
const double backward_lon_offset = -base_to_rear;
1196+
const double lat_offset = width / 2.0 + additional_lat_offset;
1197+
1198+
const auto p1 = tier4_autoware_utils::calcOffsetPose(pose, forward_lon_offset, lat_offset, 0.0);
1199+
const auto p2 = tier4_autoware_utils::calcOffsetPose(pose, forward_lon_offset, -lat_offset, 0.0);
1200+
const auto p3 = tier4_autoware_utils::calcOffsetPose(pose, backward_lon_offset, -lat_offset, 0.0);
1201+
const auto p4 = tier4_autoware_utils::calcOffsetPose(pose, backward_lon_offset, lat_offset, 0.0);
1202+
geometry_msgs::msg::Polygon polygon;
1203+
1204+
polygon.points.push_back(create_point32(p1));
1205+
polygon.points.push_back(create_point32(p2));
1206+
polygon.points.push_back(create_point32(p3));
1207+
polygon.points.push_back(create_point32(p4));
1208+
1209+
return polygon;
1210+
}
1211+
} // namespace behavior_path_planner::utils::lane_change::debug

0 commit comments

Comments
 (0)