|
21 | 21 | #include "behavior_path_planner_common/utils/utils.hpp"
|
22 | 22 | #include "lanelet2_extension/utility/message_conversion.hpp"
|
23 | 23 |
|
| 24 | +#include <behavior_path_avoidance_module/data_structs.hpp> |
| 25 | +#include <behavior_path_lane_change_module/utils/utils.hpp> |
24 | 26 | #include <lanelet2_extension/utility/utilities.hpp>
|
25 | 27 | #include <rclcpp/logging.hpp>
|
26 | 28 | #include <tier4_autoware_utils/geometry/geometry.hpp>
|
|
32 | 34 | #include <boost/geometry/algorithms/centroid.hpp>
|
33 | 35 | #include <boost/geometry/strategies/cartesian/centroid_bashein_detmer.hpp>
|
34 | 36 |
|
35 |
| -#include <cstddef> |
| 37 | +#include <limits> |
36 | 38 | #include <utility>
|
37 | 39 |
|
38 | 40 | namespace behavior_path_planner
|
39 | 41 | {
|
| 42 | +using behavior_path_planner::utils::lane_change::debug::createExecutionArea; |
| 43 | + |
40 | 44 | AvoidanceByLaneChange::AvoidanceByLaneChange(
|
41 | 45 | const std::shared_ptr<LaneChangeParameters> & parameters,
|
42 | 46 | std::shared_ptr<AvoidanceByLCParameters> avoidance_parameters)
|
@@ -76,101 +80,15 @@ bool AvoidanceByLaneChange::specialRequiredCheck() const
|
76 | 80 | return false;
|
77 | 81 | }
|
78 | 82 |
|
79 |
| - const auto current_lanes = getCurrentLanes(); |
80 |
| - if (current_lanes.empty()) { |
81 |
| - RCLCPP_DEBUG(logger_, "no empty lanes"); |
82 |
| - return false; |
83 |
| - } |
84 |
| - |
85 | 83 | 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(); |
86 | 86 |
|
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()); |
166 | 90 |
|
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); |
174 | 92 | }
|
175 | 93 |
|
176 | 94 | bool AvoidanceByLaneChange::specialExpiredCheck() const
|
@@ -339,4 +257,48 @@ ObjectData AvoidanceByLaneChange::createObjectData(
|
339 | 257 |
|
340 | 258 | return object_data;
|
341 | 259 | }
|
| 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 | +} |
342 | 304 | } // namespace behavior_path_planner
|
0 commit comments