Apollo 10.0
自动驾驶开放平台
sl_polygon.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
22
23#include <limits>
24#include <string>
25#include <utility>
26
29
30namespace apollo {
31namespace planning {
32
34
36 const std::vector<SLPoint>& boundary, const double s) {
37 ACHECK(!boundary.empty());
38 if (s <= boundary.front().s()) {
39 return boundary.front().l();
40 } else if (s >= boundary.back().s()) {
41 return boundary.back().l();
42 }
43 SLPoint sl_point;
44 sl_point.set_s(s);
45 sl_point.set_l(0.0);
46 auto cmp = [](const SLPoint& sl_point, const double s) {
47 return sl_point.s() < s;
48 };
49 auto iter = std::lower_bound(boundary.begin(), boundary.end(), s, cmp);
50 auto last_iter = *(iter - 1);
51 return last_iter.l() + (s - last_iter.s()) * (iter->l() - last_iter.l()) /
52 (iter->s() - last_iter.s());
53}
54void SLPolygon::PrintToLog(std::string prefix) const {
55 PrintCurves print_curve;
56 std::string key = id_ + prefix + "_sl_boundary";
57 for (int i = 0; i < sl_boundary_.boundary_point_size(); i++) {
58 print_curve.AddPoint(key, sl_boundary_.boundary_point(i).s(),
59 sl_boundary_.boundary_point(i).l());
60 }
61 print_curve.PrintToLog();
62}
63
65 PrintCurves print_curve;
66 std::string key = id_ + "_BlockSLPolygons";
67 for (int i = 0; i < sl_boundary_.boundary_point_size(); i++) {
68 print_curve.AddPoint(key, sl_boundary_.boundary_point(i).s(),
69 sl_boundary_.boundary_point(i).l());
70 }
71 print_curve.PrintToLog();
72}
73
74SLPolygon::SLPolygon(SLBoundary sl_boundary, std::string id,
75 PerceptionObstacle::Type type, bool print_log)
76 : sl_boundary_(sl_boundary), id_(id), obstacle_type_(type) {
77 int min_s_index = -1;
78 int max_s_index = -1;
79 int min_l_index = -1;
80 int max_l_index = -1;
81 double min_s = std::numeric_limits<double>::max();
82 double min_l = std::numeric_limits<double>::max();
83 double max_s = std::numeric_limits<double>::lowest();
84 double max_l = std::numeric_limits<double>::lowest();
85 for (int i = 0; i < sl_boundary.boundary_point_size(); i++) {
86 const auto& sl_point = sl_boundary.boundary_point(i);
87 if (sl_point.s() < min_s) {
88 min_s = sl_point.s();
89 min_s_index = i;
90 }
91 if (sl_point.s() > max_s) {
92 max_s = sl_point.s();
93 max_s_index = i;
94 }
95 if (sl_point.l() < min_l) {
96 min_l = sl_point.l();
97 min_l_index = i;
98 }
99 if (sl_point.l() > max_l) {
100 max_l = sl_point.l();
101 max_l_index = i;
102 }
103 }
104 min_s_point_ = sl_boundary.boundary_point(min_s_index);
105 min_l_point_ = sl_boundary.boundary_point(min_l_index);
106 max_s_point_ = sl_boundary.boundary_point(max_s_index);
107 max_l_point_ = sl_boundary.boundary_point(max_l_index);
108 // AINFO << "min_s_point_" << min_s_point_.s() << "," << min_s_point_.l();
109 // AINFO << "min_l_point_" << min_l_point_.s() << "," << min_l_point_.l();
110 // AINFO << "max_s_point_" << max_s_point_.s() << "," << max_s_point_.l();
111 // AINFO << "max_l_point_" << max_l_point_.s() << "," << max_l_point_.l();
112 int t = min_s_index;
113 SLPoint sl_point;
114 while (t != max_s_index) {
115 sl_point.set_s(sl_boundary.boundary_point(t).s());
116 sl_point.set_l(sl_boundary.boundary_point(t).l());
117 right_boundary_.push_back(sl_point);
118 t = (t + 1) % sl_boundary.boundary_point_size();
119 }
120 sl_point.set_s(sl_boundary.boundary_point(t).s());
121 sl_point.set_l(sl_boundary.boundary_point(t).l());
122 right_boundary_.push_back(sl_point);
123 if (right_boundary_.front().s() > right_boundary_.back().s()) {
124 std::reverse(right_boundary_.begin(), right_boundary_.end());
125 }
126
127 t = max_s_index;
128 while (t != min_s_index) {
129 sl_point.set_s(sl_boundary.boundary_point(t).s());
130 sl_point.set_l(sl_boundary.boundary_point(t).l());
131 left_boundary_.push_back(sl_point);
132 t = (t + 1) % sl_boundary.boundary_point_size();
133 }
134 sl_point.set_s(sl_boundary.boundary_point(t).s());
135 sl_point.set_l(sl_boundary.boundary_point(t).l());
136 left_boundary_.push_back(sl_point);
137 if (left_boundary_.front().s() > left_boundary_.back().s()) {
138 std::reverse(left_boundary_.begin(), left_boundary_.end());
139 }
140 double mid_s = (sl_boundary.boundary_point(min_s_index).s() +
141 sl_boundary.boundary_point(max_s_index).s()) /
142 2.0;
143
144 if (GetInterpolatedLFromBoundary(left_boundary_, mid_s) <
145 GetInterpolatedLFromBoundary(right_boundary_, mid_s)) {
146 std::swap(left_boundary_, right_boundary_);
147 }
148
149 if (print_log) {
150 PrintCurves print_curve;
151 for (auto pt : right_boundary_) {
152 print_curve.AddPoint("right_boundary", pt.s(), pt.l());
153 }
154 for (auto pt : left_boundary_) {
155 print_curve.AddPoint("left_boundary", pt.s(), pt.l());
156 }
157 print_curve.PrintToLog();
158 }
159}
160
162 const std::vector<SLPoint>& boundary, double s) {
163 if (s <= boundary.front().s()) {
164 return boundary.front().l();
165 }
166 if (s >= boundary.back().s()) {
167 return boundary.back().l();
168 }
169 auto iter = std::lower_bound(
170 boundary.begin(), boundary.end(), s,
171 [](const SLPoint& sl_point, const double s) { return sl_point.s() < s; });
172 auto last_iter = std::prev(iter);
173 double ret = last_iter->l() + (s - last_iter->s()) *
174 (iter->l() - last_iter->l()) /
175 (iter->s() - last_iter->s());
176 return ret;
177}
178
179void SLPolygon::UpdatePassableInfo(double left_bound, double right_bound,
180 double buffer) {
181 if (!is_passable_[0] && !is_passable_[1]) {
182 return;
183 }
184 is_passable_[0] = left_bound > max_l_point_.l() + buffer;
185 is_passable_[1] = right_bound < min_l_point_.l() - buffer;
186}
187
188double SLPolygon::MinRadiusStopDistance(double check_l) {
189 if (min_radius_stop_distance_ > 0) {
190 return min_radius_stop_distance_;
191 }
192 static constexpr double stop_distance_buffer = 0.4;
193 double min_turn_radius = VehicleConfigHelper::MinSafeTurnRadius();
194 AINFO << "min_turn_radius: " << min_turn_radius;
195
196 const auto& adc_param =
197 VehicleConfigHelper::Instance()->GetConfig().vehicle_param();
198 double lateral_diff = 0.0;
199 double expand_adc_half_width =
200 adc_param.width() / 2.0 + FLAGS_nonstatic_obstacle_nudge_l_buffer;
201 min_turn_radius += expand_adc_half_width;
202 AINFO << "expand min_turn_radius: " << min_turn_radius;
203 if (nudge_type_ == NudgeType::LEFT_NUDGE) {
204 lateral_diff = expand_adc_half_width - check_l + max_l_point_.l();
205 } else if (nudge_type_ == NudgeType::RIGHT_NUDGE) {
206 lateral_diff = expand_adc_half_width + check_l - min_l_point_.l();
207 }
208 lateral_diff = std::max(0.0, lateral_diff);
209 const double kEpison = 1e-5;
210 lateral_diff = std::min(lateral_diff, min_turn_radius - kEpison);
211 AINFO << "obs: " << id_ << ", lateral_diff: " << lateral_diff;
212 double min_radius_stop_distance_ =
213 std::sqrt(std::fabs(min_turn_radius * min_turn_radius -
214 (min_turn_radius - lateral_diff) *
215 (min_turn_radius - lateral_diff))) +
216 stop_distance_buffer;
217 double turn_heading =
218 std::atan2(min_radius_stop_distance_, min_turn_radius - lateral_diff);
219
220 min_radius_stop_distance_ +=
221 adc_param.front_edge_to_center() * std::cos(turn_heading);
222 min_radius_stop_distance_ =
223 std::min(min_radius_stop_distance_, FLAGS_max_stop_distance_obstacle);
224 min_radius_stop_distance_ =
225 std::max(min_radius_stop_distance_, FLAGS_min_stop_distance_obstacle);
226 AINFO << "obs: " << id_
227 << ", min_radius_stop_distance: " << min_radius_stop_distance_;
228 return min_radius_stop_distance_;
229}
230
231} // namespace planning
232} // namespace apollo
@Brief This is a helper class that can load vehicle configurations.
static double MinSafeTurnRadius()
Get the safe turning radius when the vehicle is turning with maximum steering angle.
void AddPoint(std::string key, double x, double y)
add point to curve key
void PrintToLog(std::string prefix="") const
Definition sl_polygon.cc:54
static double GetInterpolatedLFromBoundary(const std::vector< SLPoint > &boundary, const double s)
Definition sl_polygon.cc:35
double MinRadiusStopDistance(double check_l)
static double GetInterpolatedSFromBoundary(const std::vector< SLPoint > &boundary, double s)
void UpdatePassableInfo(double left_bound, double right_bound, double buffer)
Planning module main class.
#define ACHECK(cond)
Definition log.h:80
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37
repeated apollo::common::SLPoint boundary_point