|
24 | 24 | #include <autoware/universe_utils/geometry/geometry.hpp>
|
25 | 25 | #include <autoware/universe_utils/ros/uuid_helper.hpp>
|
26 | 26 |
|
| 27 | +#include <boost/geometry/algorithms/append.hpp> |
27 | 28 | #include <boost/geometry/algorithms/intersection.hpp>
|
28 | 29 | #include <boost/geometry/algorithms/within.hpp>
|
29 | 30 |
|
@@ -517,7 +518,8 @@ bool RunOutModule::checkCollisionWithShape(
|
517 | 518 | break;
|
518 | 519 |
|
519 | 520 | case Shape::POLYGON:
|
520 |
| - collision_detected = checkCollisionWithPolygon(); |
| 521 | + collision_detected = |
| 522 | + checkCollisionWithPolygon(vehicle_polygon, pose_with_range, shape, collision_points); |
521 | 523 | break;
|
522 | 524 |
|
523 | 525 | default:
|
@@ -640,11 +642,60 @@ bool RunOutModule::checkCollisionWithBoundingBox(
|
640 | 642 | return true;
|
641 | 643 | }
|
642 | 644 |
|
643 |
| -bool RunOutModule::checkCollisionWithPolygon() const |
| 645 | +Polygon2d RunOutModule::createPolygonForRangedPoints( |
| 646 | + const PoseWithRange & pose_with_range, const Shape & shape) const |
644 | 647 | {
|
645 |
| - RCLCPP_WARN_STREAM(logger_, "detection for POLYGON type is not implemented yet."); |
| 648 | + // Convert the obstacle's pose to a min and max polygon |
| 649 | + const auto pose_min_polygon = |
| 650 | + autoware::universe_utils::toPolygon2d(pose_with_range.pose_min, shape); |
| 651 | + const auto pose_max_polygon = |
| 652 | + autoware::universe_utils::toPolygon2d(pose_with_range.pose_max, shape); |
| 653 | + |
| 654 | + // Compute the convex hull of the min and max polygons |
| 655 | + auto ranged_polygon = pose_min_polygon; |
| 656 | + bg::append(ranged_polygon.outer(), pose_max_polygon.outer()); |
| 657 | + Polygon2d convex_polygon; |
| 658 | + bg::convex_hull(ranged_polygon, convex_polygon); |
| 659 | + |
| 660 | + return convex_polygon; |
| 661 | +} |
| 662 | + |
| 663 | +bool RunOutModule::checkCollisionWithPolygon( |
| 664 | + const Polygon2d & vehicle_polygon, const PoseWithRange pose_with_range, const Shape & shape, |
| 665 | + std::vector<geometry_msgs::msg::Point> & collision_points) const |
| 666 | +{ |
| 667 | + const auto bg_ranged_polygon = createPolygonForRangedPoints(pose_with_range, shape); |
| 668 | + |
| 669 | + if (bg_ranged_polygon.outer().empty()) { |
| 670 | + RCLCPP_WARN_STREAM_THROTTLE(logger_, *clock_, 1000, "failed to check collision with polygon"); |
| 671 | + return false; |
| 672 | + } |
| 673 | + |
| 674 | + std::vector<geometry_msgs::msg::Point> ranged_polygon; |
| 675 | + for (const auto & point : bg_ranged_polygon.outer()) { |
| 676 | + const auto p_msg = autoware::universe_utils::createPoint( |
| 677 | + point.x(), point.y(), pose_with_range.pose_min.position.z); |
| 678 | + ranged_polygon.emplace_back(p_msg); |
| 679 | + } |
| 680 | + |
| 681 | + // Check for collision between the vehicle and the obstacle polygon |
| 682 | + std::vector<Point2d> collision_points_bg; |
| 683 | + bg::intersection(vehicle_polygon, bg_ranged_polygon, collision_points_bg); |
646 | 684 |
|
647 |
| - return false; |
| 685 | + debug_ptr_->pushPredictedObstaclePolygons(ranged_polygon); |
| 686 | + |
| 687 | + // No collision detected |
| 688 | + if (collision_points_bg.empty()) { |
| 689 | + return false; |
| 690 | + } |
| 691 | + |
| 692 | + // Collision detected |
| 693 | + for (const auto & p : collision_points_bg) { |
| 694 | + const auto p_msg = |
| 695 | + autoware::universe_utils::createPoint(p.x(), p.y(), pose_with_range.pose_min.position.z); |
| 696 | + collision_points.emplace_back(p_msg); |
| 697 | + } |
| 698 | + return true; |
648 | 699 | }
|
649 | 700 |
|
650 | 701 | std::optional<geometry_msgs::msg::Pose> RunOutModule::calcStopPoint(
|
|
0 commit comments