37 {
38
39 const auto& vehicle_config =
40 common::VehicleConfigHelper::Instance()->GetConfig();
41 double ego_length = vehicle_config.vehicle_param().length();
42 double ego_width = vehicle_config.vehicle_param().width();
43 auto trajectory_pb = trajectory_gear_pair.first;
44 const int point_size = trajectory_pb.NumOfPoints();
45 AINFO <<
"trajectory_pb.NumOfPoints: [" << point_size <<
"]";
46 *current_index = trajectory_pb.QueryLowerBoundPoint(0.0);
47
48 for (int i = *current_index; i < point_size; ++i) {
49 const auto& trajectory_point = trajectory_pb.TrajectoryPointAt(i);
50 double ego_theta = trajectory_point.path_point().theta();
51 Box2d ego_box(
52 {trajectory_point.path_point().x(), trajectory_point.path_point().y()},
53 ego_theta, ego_length, ego_width);
54 double shift_distance =
55 ego_length / 2.0 - vehicle_config.vehicle_param().back_edge_to_center();
56 Vec2d shift_vec{shift_distance * std::cos(ego_theta),
57 shift_distance * std::sin(ego_theta)};
58 ego_box.Shift(shift_vec);
59
60
61 Polygon2d ego_polygon = Polygon2d(ego_box);
62 for (const Obstacle* obstacle : static_obstacles) {
63 Polygon2d obstacle_polygon = obstacle->PerceptionPolygon();
64 if (ego_polygon.HasOverlap(obstacle_polygon)) {
65 AINFO <<
"HasOverlapWithStaticObstacle" << obstacle->Id()
66 << "first_collision_index_of_static_obstacle: [" << i << "]";
67 *first_collision_index = i;
68 is_collision_with_static_obstacle = true;
69 return false;
70 }
71 }
72
73
74 int predicted_time_horizon = predicted_bounding_rectangles.size();
75 for (int j = 0; j < predicted_time_horizon; j++) {
76 for (const auto& obstacle_box : predicted_bounding_rectangles[j]) {
77 if (ego_box.HasOverlap(obstacle_box)) {
78 ADEBUG <<
"HasOverlap(obstacle_box) [" << i <<
"]";
79
80 if (std::abs(trajectory_point.relative_time() -
81 static_cast<double>(j) *
82 FLAGS_trajectory_time_resolution) <
83 collilsion_time_buffer &&
84 trajectory_point.relative_time() > 0.0) {
85 ADEBUG <<
"first_collision_index: [" << i <<
"]";
86 *first_collision_index = i;
87 is_collision_with_dynamic_obstacle = true;
88 return false;
89 }
90 }
91 }
92 }
93 }
94
95 return true;
96}