14
14
15
15
#include " scene.hpp"
16
16
17
+ #include " behavior_velocity_crosswalk_module/util.hpp"
17
18
#include " path_utils.hpp"
18
19
19
20
#include < behavior_velocity_planner_common/utilization/trajectory_utils.hpp>
20
21
#include < behavior_velocity_planner_common/utilization/util.hpp>
22
+ #include < motion_utils/distance/distance.hpp>
23
+ #include < motion_utils/trajectory/trajectory.hpp>
24
+ #include < tier4_autoware_utils/geometry/geometry.hpp>
25
+
26
+ #include < boost/geometry/algorithms/intersection.hpp>
27
+ #include < boost/geometry/algorithms/within.hpp>
28
+
29
+ #include < lanelet2_core/geometry/Point.h>
30
+ #include < lanelet2_core/geometry/Polygon.h>
21
31
22
32
#include < algorithm>
23
33
#include < limits>
@@ -105,8 +115,14 @@ bool RunOutModule::modifyPathVelocity(
105
115
elapsed_obstacle_creation.count () / 1000.0 );
106
116
107
117
// detect collision with dynamic obstacles using velocity planning of ego
118
+ const auto crosswalk_lanelets = planner_param_.run_out .suppress_on_crosswalk
119
+ ? getCrosswalksOnPath (
120
+ planner_data_->current_odometry ->pose , *path,
121
+ planner_data_->route_handler_ ->getLaneletMapPtr (),
122
+ planner_data_->route_handler_ ->getOverallGraphPtr ())
123
+ : std::vector<lanelet::ConstLanelet>();
108
124
const auto dynamic_obstacle =
109
- detectCollision (partition_excluded_obstacles, extended_smoothed_path);
125
+ detectCollision (partition_excluded_obstacles, extended_smoothed_path, crosswalk_lanelets );
110
126
111
127
// record time for collision check
112
128
const auto t_collision_check = std::chrono::system_clock::now ();
@@ -150,7 +166,8 @@ bool RunOutModule::modifyPathVelocity(
150
166
}
151
167
152
168
boost::optional<DynamicObstacle> RunOutModule::detectCollision (
153
- const std::vector<DynamicObstacle> & dynamic_obstacles, const PathWithLaneId & path)
169
+ const std::vector<DynamicObstacle> & dynamic_obstacles, const PathWithLaneId & path,
170
+ const std::vector<lanelet::ConstLanelet> & crosswalk_lanelets)
154
171
{
155
172
if (path.points .size () < 2 ) {
156
173
RCLCPP_WARN_STREAM (logger_, " path doesn't have enough points." );
@@ -184,7 +201,7 @@ boost::optional<DynamicObstacle> RunOutModule::detectCollision(
184
201
debug_ptr_->pushTravelTimeTexts (travel_time, p2.pose , /* lateral_offset */ 3.0 );
185
202
186
203
auto obstacles_collision =
187
- checkCollisionWithObstacles (dynamic_obstacles, vehicle_poly, travel_time);
204
+ checkCollisionWithObstacles (dynamic_obstacles, vehicle_poly, travel_time, crosswalk_lanelets );
188
205
if (obstacles_collision.empty ()) {
189
206
continue ;
190
207
}
@@ -304,7 +321,8 @@ std::vector<geometry_msgs::msg::Point> RunOutModule::createVehiclePolygon(
304
321
305
322
std::vector<DynamicObstacle> RunOutModule::checkCollisionWithObstacles (
306
323
const std::vector<DynamicObstacle> & dynamic_obstacles,
307
- std::vector<geometry_msgs::msg::Point > poly, const float travel_time) const
324
+ std::vector<geometry_msgs::msg::Point > poly, const float travel_time,
325
+ const std::vector<lanelet::ConstLanelet> & crosswalk_lanelets) const
308
326
{
309
327
const auto bg_poly_vehicle = run_out_utils::createBoostPolyFromMsg (poly);
310
328
@@ -333,8 +351,8 @@ std::vector<DynamicObstacle> RunOutModule::checkCollisionWithObstacles(
333
351
*predicted_obstacle_pose_min_vel, *predicted_obstacle_pose_max_vel};
334
352
335
353
std::vector<geometry_msgs::msg::Point > collision_points;
336
- const bool collision_detected =
337
- checkCollisionWithShape ( bg_poly_vehicle, pose_with_range, obstacle.shape , collision_points);
354
+ const bool collision_detected = checkCollisionWithShape (
355
+ bg_poly_vehicle, pose_with_range, obstacle.shape , crosswalk_lanelets , collision_points);
338
356
339
357
if (!collision_detected) {
340
358
continue ;
@@ -393,6 +411,7 @@ boost::optional<geometry_msgs::msg::Pose> RunOutModule::calcPredictedObstaclePos
393
411
394
412
bool RunOutModule::checkCollisionWithShape (
395
413
const Polygon2d & vehicle_polygon, const PoseWithRange pose_with_range, const Shape & shape,
414
+ const std::vector<lanelet::ConstLanelet> & crosswalk_lanelets,
396
415
std::vector<geometry_msgs::msg::Point > & collision_points) const
397
416
{
398
417
bool collision_detected = false ;
@@ -415,6 +434,23 @@ bool RunOutModule::checkCollisionWithShape(
415
434
break ;
416
435
}
417
436
437
+ if (!collision_points.empty ()) {
438
+ for (const auto & crosswalk : crosswalk_lanelets) {
439
+ const auto poly = crosswalk.polygon2d ().basicPolygon ();
440
+ for (auto it = collision_points.begin (); it != collision_points.end ();) {
441
+ if (boost::geometry::within (lanelet::BasicPoint2d (it->x , it->y ), poly)) {
442
+ it = collision_points.erase (it);
443
+ } else {
444
+ ++it;
445
+ }
446
+ }
447
+ if (collision_points.empty ()) {
448
+ break ;
449
+ }
450
+ }
451
+ collision_detected = !collision_points.empty ();
452
+ }
453
+
418
454
return collision_detected;
419
455
}
420
456
0 commit comments