Skip to content

Commit 00628c1

Browse files
jakor97xmfcx
authored andcommitted
feat(autoware_behavior_velocity_run_out_module): check collision with polygon type
Signed-off-by: jkoronczok <jkoronczok@autonomous-systems.pl>
1 parent 9699892 commit 00628c1

File tree

3 files changed

+63
-6
lines changed

3 files changed

+63
-6
lines changed

planning/behavior_velocity_planner/autoware_behavior_velocity_run_out_module/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,5 @@ You can choose whether to use this feature by parameter of `slow_down_limit.enab
244244
### Future extensions / Unimplemented parts
245245

246246
- Calculate obstacle's min velocity and max velocity from covariance
247-
- Detect collisions with polygon object
248247
- Handle the case when the predicted path of obstacles are not straight line
249248
- Currently collision check is calculated based on the assumption that the predicted path of the obstacle is a straight line

planning/behavior_velocity_planner/autoware_behavior_velocity_run_out_module/src/scene.cpp

+55-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <autoware/universe_utils/geometry/geometry.hpp>
2525
#include <autoware/universe_utils/ros/uuid_helper.hpp>
2626

27+
#include <boost/geometry/algorithms/append.hpp>
2728
#include <boost/geometry/algorithms/intersection.hpp>
2829
#include <boost/geometry/algorithms/within.hpp>
2930

@@ -517,7 +518,8 @@ bool RunOutModule::checkCollisionWithShape(
517518
break;
518519

519520
case Shape::POLYGON:
520-
collision_detected = checkCollisionWithPolygon();
521+
collision_detected =
522+
checkCollisionWithPolygon(vehicle_polygon, pose_with_range, shape, collision_points);
521523
break;
522524

523525
default:
@@ -640,11 +642,60 @@ bool RunOutModule::checkCollisionWithBoundingBox(
640642
return true;
641643
}
642644

643-
bool RunOutModule::checkCollisionWithPolygon() const
645+
Polygon2d RunOutModule::createPolygonForRangedPoints(
646+
const PoseWithRange & pose_with_range, const Shape & shape) const
644647
{
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);
646684

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;
648699
}
649700

650701
std::optional<geometry_msgs::msg::Pose> RunOutModule::calcStopPoint(

planning/behavior_velocity_planner/autoware_behavior_velocity_run_out_module/src/scene.hpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,18 @@ class RunOutModule : public SceneModuleInterface
112112
const geometry_msgs::msg::Vector3 & dimension,
113113
std::vector<geometry_msgs::msg::Point> & collision_points) const;
114114

115-
bool checkCollisionWithPolygon() const;
115+
bool checkCollisionWithPolygon(
116+
const Polygon2d & vehicle_polygon,
117+
const PoseWithRange pose_with_range,
118+
const Shape & shape,
119+
std::vector<geometry_msgs::msg::Point> & collision_points) const;
116120

117121
std::vector<geometry_msgs::msg::Point> createBoundingBoxForRangedPoints(
118122
const PoseWithRange & pose_with_range, const float x_offset, const float y_offset) const;
119123

124+
Polygon2d createPolygonForRangedPoints(
125+
const PoseWithRange & pose_with_range, const Shape & shape) const;
126+
120127
std::optional<geometry_msgs::msg::Pose> calcStopPoint(
121128
const std::optional<DynamicObstacle> & dynamic_obstacle, const PathWithLaneId & path,
122129
const geometry_msgs::msg::Pose & current_pose, const float current_vel,

0 commit comments

Comments
 (0)