Apollo 11.0
自动驾驶开放平台
path_assessment_decider_util.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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
18
19#include <algorithm>
20#include <utility>
21
24
25namespace apollo {
26namespace planning {
27
31
33 const ReferenceLineInfo& reference_line_info, const PathData& path_data) {
34 // Basic sanity checks.
35 if (path_data.Empty()) {
36 AERROR << path_data.path_label() << ": path data is empty.";
37 return false;
38 }
39 // Check if the path is greatly off the reference line.
40 if (IsGreatlyOffReferenceLine(path_data)) {
41 AERROR << path_data.path_label() << ": ADC is greatly off reference line.";
42 return false;
43 }
44 // Check if the path is greatly off the road.
45 if (IsGreatlyOffRoad(reference_line_info, path_data)) {
46 AERROR << path_data.path_label() << ": ADC is greatly off road.";
47 return false;
48 }
49 // Check if there is any collision.
50 // if (IsCollidingWithStaticObstacles(reference_line_info, path_data)) {
51 // AINFO << path_data.path_label() << ": ADC has collision.";
52 // return false;
53 // }
54
55 if (IsStopOnReverseNeighborLane(reference_line_info, path_data)) {
56 AERROR << path_data.path_label() << ": stop at reverse neighbor lane";
57 return false;
58 }
59
60 return true;
61}
62
64 const PathData& path_data) {
65 static constexpr double kOffReferenceLineThreshold = 20.0;
66 const auto& frenet_path = path_data.frenet_frame_path();
67 for (const auto& frenet_path_point : frenet_path) {
68 if (std::fabs(frenet_path_point.l()) > kOffReferenceLineThreshold) {
69 AINFO << "Greatly off reference line at s = " << frenet_path_point.s()
70 << ", with l = " << frenet_path_point.l();
71 return true;
72 }
73 }
74 return false;
75}
76
78 const ReferenceLineInfo& reference_line_info, const PathData& path_data) {
79 static constexpr double kOffRoadThreshold = 10.0;
80 const auto& frenet_path = path_data.frenet_frame_path();
81 for (const auto& frenet_path_point : frenet_path) {
82 double road_left_width = 0.0;
83 double road_right_width = 0.0;
84 if (reference_line_info.reference_line().GetRoadWidth(
85 frenet_path_point.s(), &road_left_width, &road_right_width)) {
86 if (frenet_path_point.l() > road_left_width + kOffRoadThreshold ||
87 frenet_path_point.l() < -road_right_width - kOffRoadThreshold) {
88 AINFO << "Greatly off-road at s = " << frenet_path_point.s()
89 << ", with l = " << frenet_path_point.l();
90 return true;
91 }
92 }
93 }
94 return false;
95}
96
98 const ReferenceLineInfo& reference_line_info, const PathData& path_data) {
99 // Get all obstacles and convert them into frenet-frame polygons.
100 std::vector<const Obstacle*> obstacles;
101 const auto& indexed_obstacles =
102 reference_line_info.path_decision().obstacles();
103 const auto& vehicle_param =
105 double front_edge_to_center = vehicle_param.front_edge_to_center();
106 double back_edge_to_center = vehicle_param.back_edge_to_center();
107 double path_point_lateral_buffer =
108 std::max(vehicle_param.width() / 2.0, vehicle_param.length() / 2.0);
109 for (const auto* obstacle : indexed_obstacles.Items()) {
110 // Filter out unrelated obstacles.
112 continue;
113 }
114 // Ignore too small obstacles.
115 const auto& obstacle_sl = obstacle->PerceptionSLBoundary();
116 if ((obstacle_sl.end_s() - obstacle_sl.start_s()) *
117 (obstacle_sl.end_l() - obstacle_sl.start_l()) <
119 continue;
120 }
121 obstacles.push_back(obstacle);
122 }
123 // Go through all the four corner points at every path pt, check collision.
124 const auto& frenet_path = path_data.frenet_frame_path();
125 for (size_t i = 0; i < path_data.discretized_path().size(); ++i) {
126 // Skip the point after end point.
127 if (path_data.frenet_frame_path().back().s() -
128 path_data.frenet_frame_path()[i].s() <
129 (FLAGS_num_extra_tail_bound_point + 1) *
130 FLAGS_path_bounds_decider_resolution +
131 vehicle_param.length()) {
132 break;
133 }
134 double path_point_start_s = frenet_path[i].s() - back_edge_to_center;
135 double path_point_end_s = frenet_path[i].s() + front_edge_to_center;
136 double path_point_start_l = frenet_path[i].l() - path_point_lateral_buffer;
137 double path_point_end_l = frenet_path[i].l() + path_point_lateral_buffer;
138 // Check the points near the obstacles
139 for (const auto* obstacle : obstacles) {
140 const auto& obstacle_sl = obstacle->PerceptionSLBoundary();
141 // Filter the path points by s range.
142 if (obstacle_sl.start_s() > path_point_end_s ||
143 obstacle_sl.end_s() < path_point_start_s) {
144 continue;
145 }
146 if (obstacle_sl.start_l() > path_point_end_l ||
147 obstacle_sl.end_l() < path_point_start_l) {
148 continue;
149 }
150 const auto& path_point = path_data.discretized_path()[i];
151 const auto& vehicle_box =
152 common::VehicleConfigHelper::Instance()->GetBoundingBox(path_point);
153 const std::vector<Vec2d>& ABCDpoints = vehicle_box.GetAllCorners();
154 const common::math::Polygon2d& obstacle_polygon =
155 obstacle->PerceptionPolygon();
156 for (const auto& corner_point : ABCDpoints) {
157 if (obstacle_polygon.IsPointIn(corner_point)) {
158 AERROR << "ADC is colliding with obstacle at path s = "
159 << path_point.s() << ", with obstacle " << obstacle->Id();
160 return true;
161 }
162 }
163 }
164 }
165 return false;
166}
167
169 const ReferenceLineInfo& reference_line_info, const PathData& path_data) {
170 if (path_data.path_label().find("left") == std::string::npos &&
171 path_data.path_label().find("right") == std::string::npos) {
172 return false;
173 }
174
175 std::vector<common::SLPoint> all_stop_point_sl =
176 reference_line_info.GetAllStopDecisionSLPoint();
177 if (all_stop_point_sl.empty()) {
178 return false;
179 }
180
181 double check_s = 0.0;
182 // filter out sidepass stop fence
183 static constexpr double kLookForwardBuffer = 5.0;
184 const double adc_end_s = reference_line_info.AdcSlBoundary().end_s();
185 for (const auto& stop_point_sl : all_stop_point_sl) {
186 if (stop_point_sl.s() - adc_end_s < kLookForwardBuffer) {
187 continue;
188 }
189 check_s = stop_point_sl.s();
190 break;
191 }
192 if (check_s <= 0.0) {
193 return false;
194 }
195
196 double lane_left_width = 0.0;
197 double lane_right_width = 0.0;
198 if (!reference_line_info.reference_line().GetLaneWidth(
199 check_s, &lane_left_width, &lane_right_width)) {
200 return false;
201 }
202
203 static constexpr double kSDelta = 0.3;
204 common::SLPoint path_point_sl;
205 for (const auto& frenet_path_point : path_data.frenet_frame_path()) {
206 if (std::fabs(frenet_path_point.s() - check_s) < kSDelta) {
207 path_point_sl.set_s(frenet_path_point.s());
208 path_point_sl.set_l(frenet_path_point.l());
209 }
210 }
211 ADEBUG << "path_point_sl[" << path_point_sl.s() << ", " << path_point_sl.l()
212 << "] lane_left_width[" << lane_left_width << "] lane_right_width["
213 << lane_right_width << "]";
214
215 hdmap::Id neighbor_lane_id;
216 double neighbor_lane_width = 0.0;
217 if (path_data.path_label().find("left") != std::string::npos &&
218 path_point_sl.l() > lane_left_width) {
219 if (reference_line_info.GetNeighborLaneInfo(
221 &neighbor_lane_id, &neighbor_lane_width)) {
222 AINFO << "stop path point at LeftForward neighbor lane["
223 << neighbor_lane_id.id() << "]";
224 return false;
225 } else {
226 AINFO << "stop path point at LeftReverse neighbor lane";
227 return true;
228 }
229 } else if (path_data.path_label().find("right") != std::string::npos &&
230 path_point_sl.l() < -lane_right_width) {
231 if (reference_line_info.GetNeighborLaneInfo(
233 &neighbor_lane_id, &neighbor_lane_width)) {
234 AINFO << "stop path point at RightForward neighbor lane["
235 << neighbor_lane_id.id() << "]";
236 return false;
237 } else {
238 AINFO << "stop path point at RightReverse neighbor lane";
239 return true;
240 }
241 }
242 return false;
243}
244
246 const PathData& path_data, const PathData::PathPointType type,
247 std::vector<PathPointDecision>* const path_point_decision) {
248 // Sanity checks.
249 CHECK_NOTNULL(path_point_decision);
250 path_point_decision->clear();
251
252 // Go through every path point in path data, and initialize a
253 // corresponding path point decision.
254 for (const auto& frenet_path_point : path_data.frenet_frame_path()) {
255 path_point_decision->emplace_back(frenet_path_point.s(), type,
256 std::numeric_limits<double>::max());
257 }
258}
259
261 PathData* const path_data) {
262 // Don't trim self-lane path or fallback path.
263 if (path_data->path_label().find("fallback") != std::string::npos ||
264 path_data->path_label().find("self") != std::string::npos) {
265 return;
266 }
267
268 // Trim.
269 AINFO << "Trimming " << path_data->path_label();
270 auto frenet_path = path_data->frenet_frame_path();
271 auto path_point_decision = path_data->path_point_decision_guide();
272 while (!path_point_decision.empty() &&
273 std::get<1>(path_point_decision.back()) !=
275 if (std::get<1>(path_point_decision.back()) ==
277 AINFO << "Trimming out forward lane point";
278 } else if (std::get<1>(path_point_decision.back()) ==
280 AINFO << "Trimming out reverse lane point";
281 } else {
282 AINFO << "Trimming unknown lane point";
283 }
284 frenet_path.pop_back();
285 path_point_decision.pop_back();
286 }
287 path_data->SetFrenetPath(std::move(frenet_path));
288 path_data->SetPathPointDecisionGuide(std::move(path_point_decision));
289 AINFO << "After TrimTailingOutLanePoints: FrenetPath size: "
290 << path_data->frenet_frame_path().size();
291}
292
293} // namespace planning
294} // namespace apollo
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
Rectangular (undirected) bounding box in 2-D.
Definition box2d.h:52
The class of polygon in 2-D.
Definition polygon2d.h:42
bool IsPointIn(const Vec2d &point) const
Check if a point is within the polygon.
Definition polygon2d.cc:130
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
static bool IsGreatlyOffReferenceLine(const PathData &path_data)
static void InitPathPointDecision(const PathData &path_data, const PathData::PathPointType type, std::vector< PathPointDecision > *const path_point_decision)
Init path_point_decision as type
static bool IsGreatlyOffRoad(const ReferenceLineInfo &reference_line_info, const PathData &path_data)
static bool IsCollidingWithStaticObstacles(const ReferenceLineInfo &reference_line_info, const PathData &path_data)
static void TrimTailingOutLanePoints(PathData *const path_data)
Trim the points at tail of path which away from lane
static bool IsStopOnReverseNeighborLane(const ReferenceLineInfo &reference_line_info, const PathData &path_data)
static bool IsValidRegularPath(const ReferenceLineInfo &reference_line_info, const PathData &path_data)
Check if the generated path is valid
static bool IsWithinPathDeciderScopeObstacle(const Obstacle &obstacle)
Is obstacle should be considered in path decision
const std::string & path_label() const
Definition path_data.cc:264
const FrenetFramePath & frenet_frame_path() const
Definition path_data.cc:94
bool SetPathPointDecisionGuide(std::vector< std::tuple< double, PathPointType, double > > path_point_decision_guide)
Definition path_data.cc:73
const DiscretizedPath & discretized_path() const
Definition path_data.cc:90
const std::vector< std::tuple< double, PathPointType, double > > & path_point_decision_guide() const
Definition path_data.cc:99
bool SetFrenetPath(FrenetFramePath frenet_path)
Definition path_data.cc:58
const IndexedList< std::string, Obstacle > & obstacles() const
ReferenceLineInfo holds all data for one reference line.
bool GetNeighborLaneInfo(const ReferenceLineInfo::LaneType lane_type, const double s, hdmap::Id *ptr_lane_id, double *ptr_lane_width) const
const ReferenceLine & reference_line() const
std::vector< common::SLPoint > GetAllStopDecisionSLPoint() const
const SLBoundary & AdcSlBoundary() const
bool GetRoadWidth(const double s, double *const road_left_width, double *const road_right_width) const
bool GetLaneWidth(const double s, double *const lane_left_width, double *const lane_right_width) const
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37
optional VehicleParam vehicle_param
optional string id
Definition map_id.proto:7