Skip to content

Commit 77de25e

Browse files
committed
fix(intersection_occlusion): estimate dynamic occlusion source with triangle (autowarefoundation#6585)
Signed-off-by: Mamoru Sobue <mamoru.sobue@tier4.jp>
1 parent 00336c2 commit 77de25e

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

planning/behavior_velocity_intersection_module/src/debug.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,22 @@ visualization_msgs::msg::MarkerArray IntersectionModule::createDebugMarkerArray(
389389
&debug_marker_array, now);
390390
}
391391

392+
if (debug_data_.nearest_occlusion_triangle) {
393+
const auto [p1, p2, p3] = debug_data_.nearest_occlusion_triangle.value();
394+
const auto color = debug_data_.static_occlusion ? green : red;
395+
geometry_msgs::msg::Polygon poly;
396+
poly.points.push_back(
397+
geometry_msgs::build<geometry_msgs::msg::Point32>().x(p1.x).y(p1.y).z(p1.z));
398+
poly.points.push_back(
399+
geometry_msgs::build<geometry_msgs::msg::Point32>().x(p2.x).y(p2.y).z(p2.z));
400+
poly.points.push_back(
401+
geometry_msgs::build<geometry_msgs::msg::Point32>().x(p3.x).y(p3.y).z(p3.z));
402+
appendMarkerArray(
403+
debug::createPolygonMarkerArray(
404+
poly, "nearest_occlusion_triangle", lane_id_, now, 0.3, 0.0, 0.0, std::get<0>(color),
405+
std::get<1>(color), std::get<2>(color)),
406+
&debug_marker_array, now);
407+
}
392408
if (debug_data_.traffic_light_observation) {
393409
const auto GREEN = autoware_perception_msgs::msg::TrafficSignalElement::GREEN;
394410
const auto YELLOW = autoware_perception_msgs::msg::TrafficSignalElement::AMBER;

planning/behavior_velocity_intersection_module/src/scene_intersection.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ class IntersectionModule : public SceneModuleInterface
235235
std::vector<geometry_msgs::msg::Polygon> occlusion_polygons;
236236
std::optional<std::pair<geometry_msgs::msg::Point, geometry_msgs::msg::Point>>
237237
nearest_occlusion_projection{std::nullopt};
238+
std::optional<
239+
std::tuple<geometry_msgs::msg::Point, geometry_msgs::msg::Point, geometry_msgs::msg::Point>>
240+
nearest_occlusion_triangle{std::nullopt};
241+
bool static_occlusion{false};
238242
std::optional<double> static_occlusion_with_traffic_light_timeout{std::nullopt};
239243

240244
std::optional<std::tuple<geometry_msgs::msg::Pose, lanelet::ConstPoint3d, lanelet::Id, uint8_t>>

planning/behavior_velocity_intersection_module/src/scene_intersection_occlusion.cpp

+31-7
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,14 @@ IntersectionModule::OcclusionType IntersectionModule::detectOcclusion(
331331
}
332332
return nearest;
333333
};
334-
struct NearestOcclusionPoint
334+
struct NearestOcclusionInterval
335335
{
336336
int64 division_index{0};
337337
int64 point_index{0};
338338
double dist{0.0};
339339
geometry_msgs::msg::Point point;
340340
geometry_msgs::msg::Point projection;
341+
geometry_msgs::msg::Point visible_end;
341342
} nearest_occlusion_point;
342343
double min_dist = std::numeric_limits<double>::infinity();
343344
for (unsigned division_index = 0; division_index < lane_divisions.size(); ++division_index) {
@@ -367,6 +368,8 @@ IntersectionModule::OcclusionType IntersectionModule::detectOcclusion(
367368
continue;
368369
}
369370
double acc_dist = 0.0;
371+
bool found_min_dist_for_this_division = false;
372+
bool is_prev_occluded = false;
370373
auto acc_dist_it = projection_it;
371374
for (auto point_it = projection_it; point_it != division.end(); point_it++) {
372375
const double dist =
@@ -383,11 +386,24 @@ IntersectionModule::OcclusionType IntersectionModule::detectOcclusion(
383386
if (acc_dist < min_dist) {
384387
min_dist = acc_dist;
385388
nearest_occlusion_point = {
386-
division_index, std::distance(division.begin(), point_it), acc_dist,
389+
division_index,
390+
std::distance(division.begin(), point_it),
391+
acc_dist,
387392
tier4_autoware_utils::createPoint(point_it->x(), point_it->y(), origin.z),
388-
tier4_autoware_utils::createPoint(projection_it->x(), projection_it->y(), origin.z)};
393+
tier4_autoware_utils::createPoint(projection_it->x(), projection_it->y(), origin.z),
394+
tier4_autoware_utils::createPoint(
395+
projection_it->x(), projection_it->y(),
396+
origin.z) /* initialize with projection point at first*/};
397+
found_min_dist_for_this_division = true;
398+
} else if (found_min_dist_for_this_division && is_prev_occluded) {
399+
// although this cell is not "nearest" cell, we have found the "nearest" cell on this
400+
// division previously in this iteration, and the iterated cells are still OCCLUDED since
401+
// then
402+
nearest_occlusion_point.visible_end =
403+
tier4_autoware_utils::createPoint(point_it->x(), point_it->y(), origin.z);
389404
}
390405
}
406+
is_prev_occluded = (pixel == OCCLUDED);
391407
}
392408
}
393409

@@ -397,16 +413,24 @@ IntersectionModule::OcclusionType IntersectionModule::detectOcclusion(
397413

398414
debug_data_.nearest_occlusion_projection =
399415
std::make_pair(nearest_occlusion_point.point, nearest_occlusion_point.projection);
400-
LineString2d ego_occlusion_line;
401-
ego_occlusion_line.emplace_back(current_pose.position.x, current_pose.position.y);
402-
ego_occlusion_line.emplace_back(nearest_occlusion_point.point.x, nearest_occlusion_point.point.y);
416+
debug_data_.nearest_occlusion_triangle = std::make_tuple(
417+
current_pose.position, nearest_occlusion_point.point, nearest_occlusion_point.visible_end);
418+
Polygon2d ego_occlusion_triangle;
419+
ego_occlusion_triangle.outer().emplace_back(current_pose.position.x, current_pose.position.y);
420+
ego_occlusion_triangle.outer().emplace_back(
421+
nearest_occlusion_point.point.x, nearest_occlusion_point.point.y);
422+
ego_occlusion_triangle.outer().emplace_back(
423+
nearest_occlusion_point.visible_end.x, nearest_occlusion_point.visible_end.y);
424+
bg::correct(ego_occlusion_triangle);
403425
for (const auto & attention_object_info : object_info_manager_.allObjects()) {
404426
const auto obj_poly =
405427
tier4_autoware_utils::toPolygon2d(attention_object_info->predicted_object());
406-
if (bg::intersects(obj_poly, ego_occlusion_line)) {
428+
if (bg::intersects(obj_poly, ego_occlusion_triangle)) {
429+
debug_data_.static_occlusion = false;
407430
return DynamicallyOccluded{min_dist};
408431
}
409432
}
433+
debug_data_.static_occlusion = true;
410434
return StaticallyOccluded{min_dist};
411435
}
412436
} // namespace behavior_velocity_planner

0 commit comments

Comments
 (0)