Apollo 11.0
自动驾驶开放平台
open_space_fallback_util.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2024 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
22
23namespace apollo {
24namespace planning {
25
30
32 const TrajGearPair& trajectory_gear_pair,
33 const std::vector<std::vector<Box2d>>&
34 predicted_bounding_rectangles,
35 const std::vector<Obstacle*>& static_obstacles, int* current_index,
36 int* first_collision_index, bool& is_collision_with_static_obstacle,
37 bool& is_collision_with_dynamic_obstacle, const double& collilsion_time_buffer) {
38 // prediction time resolution: FLAGS_trajectory_time_resolution
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 // is collision with static obstacles
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 // is collision with dynamic obstacles
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 // remove points in previous trajectory
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}
97
99 const Vec2d ego_pos,
100 const std::vector<const Obstacle*>& obstacles,
101 std::vector<std::vector<common::math::Box2d>>&
102 predicted_bounding_rectangles,
103 const double& time_period,
104 const double& build_range) {
105 predicted_bounding_rectangles.clear();
106 double relative_time = 0.0;
107 while (relative_time < time_period) {
108 std::vector<Box2d> predicted_env;
109 std::vector<Obstacle*> static_obstacles_env;
110 for (const Obstacle* obstacle : obstacles) {
111 if (!obstacle->IsVirtual() && !obstacle->IsStatic()) {
112 TrajectoryPoint point = obstacle->GetPointAtTime(relative_time);
113 if (ego_pos.DistanceTo(Vec2d(point.path_point().x(), point.path_point().y())) > build_range) {
114 continue;
115 }
116 Box2d box = obstacle->GetBoundingBox(point);
117 predicted_env.push_back(std::move(box));
118 }
119 }
120 predicted_bounding_rectangles.emplace_back(std::move(predicted_env));
121 relative_time += FLAGS_trajectory_time_resolution;
122 }
123}
124
126 const Vec2d ego_pos,
127 const std::vector<const Obstacle*>& obstacles,
128 std::vector<Obstacle*>& static_obstacles,
129 const double& build_range) {
130 static_obstacles.clear();
131 for (const Obstacle* obstacle : obstacles) {
132 if (!obstacle->IsVirtual() && obstacle->IsStatic() &&
133 obstacle->Perception().width() > 0.2 &&
134 obstacle->Perception().length() > 0.2 &&
135 obstacle->PerceptionPolygon().DistanceTo(ego_pos) <= build_range) {
136 static_obstacles.push_back(const_cast<Obstacle*>(obstacle));
137 }
138 }
139}
140
141} // apollo
142} // planning
143
Rectangular (undirected) bounding box in 2-D.
Definition box2d.h:52
The class of polygon in 2-D.
Definition polygon2d.h:42
bool HasOverlap(const LineSegment2d &line_segment) const
Check if a line segment has overlap with this polygon.
Definition polygon2d.cc:377
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
double DistanceTo(const Vec2d &other) const
Returns the distance to the given vector
Definition vec2d.cc:47
This is the class that associates an Obstacle with its path properties.
Definition obstacle.h:62
static bool IsCollisionFreeTrajectory(const TrajGearPair &trajectory_gear_pair, const std::vector< std::vector< common::math::Box2d > > &predicted_bounding_rectangles, const std::vector< Obstacle * > &static_obstacles, int *current_index, int *first_collision_index, bool &is_collision_with_static_obstacle, bool &is_collision_with_dynamic_obstacle, const double &collilsion_time_buffer)
static void BuildPredictedEnvironment(const common::math::Vec2d ego_pos, const std::vector< const Obstacle * > &obstacles, std::vector< std::vector< common::math::Box2d > > &predicted_bounding_rectangles, const double &time_period, const double &build_range)
static void BuildStaticObstacleEnvironment(const common::math::Vec2d ego_pos, const std::vector< const Obstacle * > &obstacles, std::vector< Obstacle * > &static_obstacles, const double &build_range)
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AINFO
Definition log.h:42
std::pair< DiscretizedTrajectory, canbus::Chassis::GearPosition > TrajGearPair
class register implement
Definition arena_queue.h:37