Skip to content

Commit 85a6d9d

Browse files
committed
fix(avoidance): use nearest overhang point
Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>
1 parent e02dd60 commit 85a6d9d

File tree

7 files changed

+55
-73
lines changed

7 files changed

+55
-73
lines changed

planning/behavior_path_avoidance_by_lane_change_module/src/scene.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ ObjectData AvoidanceByLaneChange::createObjectData(
265265
: Direction::RIGHT;
266266

267267
// Find the footprint point closest to the path, set to object_data.overhang_distance.
268-
object_data.overhang_dist = utils::avoidance::calcEnvelopeOverhangDistance(
269-
object_data, data.reference_path, object_data.overhang_pose.position);
268+
object_data.overhang_points =
269+
utils::avoidance::calcEnvelopeOverhangDistance(object_data, data.reference_path);
270270

271271
// Check whether the the ego should avoid the object.
272272
const auto & vehicle_width = planner_data_->parameters.vehicle_width;

planning/behavior_path_avoidance_module/include/behavior_path_avoidance_module/data_structs.hpp

+6-13
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,8 @@ struct ObjectData // avoidance target
336336
{
337337
ObjectData() = default;
338338

339-
ObjectData(PredictedObject obj, double lat, double lon, double len, double overhang)
340-
: object(std::move(obj)),
341-
to_centerline(lat),
342-
longitudinal(lon),
343-
length(len),
344-
overhang_dist(overhang)
339+
ObjectData(PredictedObject obj, double lat, double lon, double len)
340+
: object(std::move(obj)), to_centerline(lat), longitudinal(lon), length(len)
345341
{
346342
}
347343

@@ -365,9 +361,6 @@ struct ObjectData // avoidance target
365361
// longitudinal length of vehicle, in Frenet coordinate
366362
double length{0.0};
367363

368-
// lateral distance to the closest footprint, in Frenet coordinate
369-
double overhang_dist{0.0};
370-
371364
// lateral shiftable ratio
372365
double shiftable_ratio{0.0};
373366

@@ -392,9 +385,6 @@ struct ObjectData // avoidance target
392385
// the position at the detected moment
393386
Pose init_pose;
394387

395-
// the position of the overhang
396-
Pose overhang_pose;
397-
398388
// envelope polygon
399389
Polygon2d envelope_poly{};
400390

@@ -425,14 +415,17 @@ struct ObjectData // avoidance target
425415
// object direction.
426416
Direction direction{Direction::NONE};
427417

418+
// overhang points (sort by distance)
419+
std::vector<std::pair<double, Point>> overhang_points{};
420+
428421
// unavoidable reason
429422
std::string reason{};
430423

431424
// lateral avoid margin
432425
std::optional<double> avoid_margin{std::nullopt};
433426

434427
// the nearest bound point (use in road shoulder distance calculation)
435-
std::optional<Point> nearest_bound_point{std::nullopt};
428+
std::optional<std::pair<Point, Point>> narrowest_place{std::nullopt};
436429
};
437430
using ObjectDataArray = std::vector<ObjectData>;
438431

planning/behavior_path_avoidance_module/include/behavior_path_avoidance_module/helper.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ class AvoidanceHelper
176176
{
177177
using utils::avoidance::calcShiftLength;
178178

179-
const auto shift_length = calcShiftLength(is_on_right, object.overhang_dist, margin);
179+
const auto shift_length =
180+
calcShiftLength(is_on_right, object.overhang_points.front().first, margin);
180181
return is_on_right ? std::min(shift_length, getLeftShiftBound())
181182
: std::max(shift_length, getRightShiftBound());
182183
}

planning/behavior_path_avoidance_module/include/behavior_path_avoidance_module/utils.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ double lerpShiftLengthOnArc(double arc, const AvoidLine & al);
5656
void fillLongitudinalAndLengthByClosestEnvelopeFootprint(
5757
const PathWithLaneId & path, const Point & ego_pos, ObjectData & obj);
5858

59-
double calcEnvelopeOverhangDistance(
60-
const ObjectData & object_data, const PathWithLaneId & path, Point & overhang_pose);
59+
std::vector<std::pair<double, Point>> calcEnvelopeOverhangDistance(
60+
const ObjectData & object_data, const PathWithLaneId & path);
6161

6262
void setEndData(
6363
AvoidLine & al, const double length, const geometry_msgs::msg::Pose & end, const size_t end_idx,

planning/behavior_path_avoidance_module/src/debug.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ MarkerArray createToDrivableBoundDistance(const ObjectDataArray & objects, std::
113113
MarkerArray msg;
114114

115115
for (const auto & object : objects) {
116-
if (!object.nearest_bound_point.has_value()) {
116+
if (!object.narrowest_place.has_value()) {
117117
continue;
118118
}
119119

@@ -122,8 +122,8 @@ MarkerArray createToDrivableBoundDistance(const ObjectDataArray & objects, std::
122122
"map", rclcpp::Clock{RCL_ROS_TIME}.now(), ns, 0L, Marker::LINE_STRIP,
123123
createMarkerScale(0.1, 0.0, 0.0), createMarkerColor(1.0, 0.0, 0.42, 0.999));
124124

125-
marker.points.push_back(object.overhang_pose.position);
126-
marker.points.push_back(object.nearest_bound_point.value());
125+
marker.points.push_back(object.narrowest_place.value().first);
126+
marker.points.push_back(object.narrowest_place.value().second);
127127
marker.id = uuidToInt32(object.object.object_id);
128128
msg.markers.push_back(marker);
129129
}
@@ -133,7 +133,7 @@ MarkerArray createToDrivableBoundDistance(const ObjectDataArray & objects, std::
133133
"map", rclcpp::Clock{RCL_ROS_TIME}.now(), ns, 0L, Marker::TEXT_VIEW_FACING,
134134
createMarkerScale(0.5, 0.5, 0.5), createMarkerColor(1.0, 1.0, 0.0, 1.0));
135135

136-
marker.pose.position = object.nearest_bound_point.value();
136+
marker.pose.position = object.narrowest_place.value().second;
137137
std::ostringstream string_stream;
138138
string_stream << object.to_road_shoulder_distance << "[m]";
139139
marker.text = string_stream.str();

planning/behavior_path_avoidance_module/src/shift_line_generator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ AvoidOutlines ShiftLineGenerator::generateAvoidOutline(
219219
: -1.0 * feasible_relative_shift_length + current_ego_shift;
220220

221221
const auto infeasible =
222-
std::abs(feasible_shift_length - object.overhang_dist) <
222+
std::abs(feasible_shift_length - object.overhang_points.front().first) <
223223
0.5 * data_->parameters.vehicle_width + object_parameter.safety_buffer_lateral;
224224
if (infeasible) {
225225
RCLCPP_DEBUG(rclcpp::get_logger(""), "feasible shift length is not enough to avoid. ");

planning/behavior_path_avoidance_module/src/utils.cpp

+38-50
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,8 @@ bool isNoNeedAvoidanceBehavior(
819819
return false;
820820
}
821821

822-
const auto shift_length =
823-
calcShiftLength(isOnRight(object), object.overhang_dist, object.avoid_margin.value());
822+
const auto shift_length = calcShiftLength(
823+
isOnRight(object), object.overhang_points.front().first, object.avoid_margin.value());
824824
if (!isShiftNecessary(isOnRight(object), shift_length)) {
825825
object.reason = "NotNeedAvoidance";
826826
return true;
@@ -881,40 +881,41 @@ double getRoadShoulderDistance(
881881
return 0.0;
882882
}
883883

884-
const auto centerline_pose =
885-
lanelet::utils::getClosestCenterPose(object.overhang_lanelet, object_pose.position);
886-
const auto & p1_object = object.overhang_pose.position;
887-
const auto p_tmp =
888-
geometry_msgs::build<Pose>().position(p1_object).orientation(centerline_pose.orientation);
889-
const auto p2_object =
890-
calcOffsetPose(p_tmp, 0.0, (isOnRight(object) ? 100.0 : -100.0), 0.0).position;
884+
std::vector<std::pair<Point, Point>> intersects;
885+
for (const auto & p1 : object.overhang_points) {
886+
const auto centerline_pose =
887+
lanelet::utils::getClosestCenterPose(object.overhang_lanelet, object_pose.position);
888+
const auto p_tmp =
889+
geometry_msgs::build<Pose>().position(p1.second).orientation(centerline_pose.orientation);
890+
const auto p2 = calcOffsetPose(p_tmp, 0.0, (isOnRight(object) ? 100.0 : -100.0), 0.0).position;
891891

892-
// TODO(Satoshi OTA): check if the basic point is on right or left of bound.
893-
const auto bound = isOnRight(object) ? data.left_bound : data.right_bound;
892+
// TODO(Satoshi OTA): check if the basic point is on right or left of bound.
893+
const auto bound = isOnRight(object) ? data.left_bound : data.right_bound;
894894

895-
std::vector<Point> intersects;
896-
for (size_t i = 1; i < bound.size(); i++) {
897-
const auto opt_intersect =
898-
tier4_autoware_utils::intersect(p1_object, p2_object, bound.at(i - 1), bound.at(i));
895+
for (size_t i = 1; i < bound.size(); i++) {
896+
const auto opt_intersect =
897+
tier4_autoware_utils::intersect(p1.second, p2, bound.at(i - 1), bound.at(i));
899898

900-
if (!opt_intersect) {
901-
continue;
902-
}
899+
if (!opt_intersect) {
900+
continue;
901+
}
903902

904-
intersects.push_back(opt_intersect.value());
903+
intersects.emplace_back(p1.second, opt_intersect.value());
904+
}
905905
}
906906

907+
std::sort(intersects.begin(), intersects.end(), [](const auto & a, const auto & b) {
908+
return calcDistance2d(a.first, a.second) < calcDistance2d(b.first, b.second);
909+
});
910+
907911
if (intersects.empty()) {
908912
return 0.0;
909913
}
910914

911-
std::sort(intersects.begin(), intersects.end(), [&p1_object](const auto & a, const auto & b) {
912-
return calcDistance2d(p1_object, a) < calcDistance2d(p1_object, b);
913-
});
914-
915-
object.nearest_bound_point = intersects.front();
915+
object.narrowest_place = intersects.front();
916916

917-
return calcDistance2d(p1_object, object.nearest_bound_point.value());
917+
return calcDistance2d(
918+
object.narrowest_place.value().first, object.narrowest_place.value().second);
918919
}
919920
} // namespace filtering_utils
920921

@@ -1070,34 +1071,22 @@ void fillLongitudinalAndLengthByClosestEnvelopeFootprint(
10701071
return;
10711072
}
10721073

1073-
double calcEnvelopeOverhangDistance(
1074-
const ObjectData & object_data, const PathWithLaneId & path, Point & overhang_pose)
1074+
std::vector<std::pair<double, Point>> calcEnvelopeOverhangDistance(
1075+
const ObjectData & object_data, const PathWithLaneId & path)
10751076
{
1076-
double largest_overhang = isOnRight(object_data) ? -100.0 : 100.0; // large number
1077+
std::vector<std::pair<double, Point>> overhang_points{};
10771078

10781079
for (const auto & p : object_data.envelope_poly.outer()) {
10791080
const auto point = tier4_autoware_utils::createPoint(p.x(), p.y(), 0.0);
10801081
// TODO(someone): search around first position where the ego should avoid the object.
10811082
const auto idx = findNearestIndex(path.points, point);
10821083
const auto lateral = calcLateralDeviation(getPose(path.points.at(idx)), point);
1083-
1084-
const auto & overhang_pose_on_right = [&overhang_pose, &largest_overhang, &point, &lateral]() {
1085-
if (lateral > largest_overhang) {
1086-
overhang_pose = point;
1087-
}
1088-
return std::max(largest_overhang, lateral);
1089-
};
1090-
1091-
const auto & overhang_pose_on_left = [&overhang_pose, &largest_overhang, &point, &lateral]() {
1092-
if (lateral < largest_overhang) {
1093-
overhang_pose = point;
1094-
}
1095-
return std::min(largest_overhang, lateral);
1096-
};
1097-
1098-
largest_overhang = isOnRight(object_data) ? overhang_pose_on_right() : overhang_pose_on_left();
1084+
overhang_points.emplace_back(lateral, point);
10991085
}
1100-
return largest_overhang;
1086+
std::sort(overhang_points.begin(), overhang_points.end(), [&](const auto & a, const auto & b) {
1087+
return isOnRight(object_data) ? b.first < a.first : a.first < b.first;
1088+
});
1089+
return overhang_points;
11011090
}
11021091

11031092
void setEndData(
@@ -1442,10 +1431,10 @@ void fillAvoidanceNecessity(
14421431
0.5 * vehicle_width + object_parameter.safety_buffer_lateral * object_data.distance_factor;
14431432

14441433
const auto check_necessity = [&](const auto hysteresis_factor) {
1445-
return (isOnRight(object_data) &&
1446-
std::abs(object_data.overhang_dist) < safety_margin * hysteresis_factor) ||
1434+
return (isOnRight(object_data) && std::abs(object_data.overhang_points.front().first) <
1435+
safety_margin * hysteresis_factor) ||
14471436
(!isOnRight(object_data) &&
1448-
object_data.overhang_dist < safety_margin * hysteresis_factor);
1437+
object_data.overhang_points.front().first < safety_margin * hysteresis_factor);
14491438
};
14501439

14511440
const auto id = object_data.object.object_id;
@@ -1665,8 +1654,7 @@ void filterTargetObjects(
16651654
}
16661655

16671656
// Find the footprint point closest to the path, set to object_data.overhang_distance.
1668-
o.overhang_dist =
1669-
calcEnvelopeOverhangDistance(o, data.reference_path, o.overhang_pose.position);
1657+
o.overhang_points = utils::avoidance::calcEnvelopeOverhangDistance(o, data.reference_path);
16701658
o.to_road_shoulder_distance = filtering_utils::getRoadShoulderDistance(o, data, planner_data);
16711659
o.avoid_margin = filtering_utils::getAvoidMargin(o, planner_data, parameters);
16721660

0 commit comments

Comments
 (0)