Apollo 11.0
自动驾驶开放平台
close_to_junction_teller.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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 <vector>
20
24
25namespace apollo {
26namespace storytelling {
27namespace {
28
38
40
41bool GetPNCJunction(const PathPoint& point, std::string* pnc_junction_id) {
42 common::PointENU hdmap_point;
43 hdmap_point.set_x(point.x());
44 hdmap_point.set_y(point.y());
45 std::vector<PNCJunctionInfoConstPtr> pnc_junctions;
46 if (HDMapUtil::BaseMap().GetPNCJunctions(hdmap_point, FLAGS_search_radius,
47 &pnc_junctions) == 0) {
48 if (pnc_junctions.size() > 0) {
49 *pnc_junction_id = pnc_junctions.front()->id().id();
50 return true;
51 }
52 }
53 return false;
54}
55
56bool GetJunction(const PathPoint& point, std::string* junction_id) {
57 common::PointENU hdmap_point;
58 hdmap_point.set_x(point.x());
59 hdmap_point.set_y(point.y());
60 std::vector<JunctionInfoConstPtr> junctions;
61 if (HDMapUtil::BaseMap().GetJunctions(hdmap_point, FLAGS_search_radius,
62 &junctions) == 0) {
63 if (junctions.size() > 0) {
64 *junction_id = junctions.front()->id().id();
65 return true;
66 }
67 }
68 return false;
69}
70
71bool GetClearArea(const PathPoint& point, std::string* clear_area_id) {
72 common::PointENU hdmap_point;
73 hdmap_point.set_x(point.x());
74 hdmap_point.set_y(point.y());
75 std::vector<ClearAreaInfoConstPtr> clear_areas;
76 if (HDMapUtil::BaseMap().GetClearAreas(hdmap_point, FLAGS_search_radius,
77 &clear_areas) == 0) {
78 if (clear_areas.size() > 0) {
79 *clear_area_id = clear_areas.front()->id().id();
80 return true;
81 }
82 }
83 return false;
84}
85
86bool GetCrosswalk(const PathPoint& point, std::string* crosswalk_id) {
87 common::PointENU hdmap_point;
88 hdmap_point.set_x(point.x());
89 hdmap_point.set_y(point.y());
90 std::vector<CrosswalkInfoConstPtr> crosswalks;
91 if (HDMapUtil::BaseMap().GetCrosswalks(hdmap_point, FLAGS_search_radius,
92 &crosswalks) == 0) {
93 if (crosswalks.size() > 0) {
94 *crosswalk_id = crosswalks.front()->id().id();
95 return true;
96 }
97 }
98 return false;
99}
100
101bool GetSignal(const PathPoint& point, std::string* signal_id) {
102 common::PointENU hdmap_point;
103 hdmap_point.set_x(point.x());
104 hdmap_point.set_y(point.y());
105 std::vector<SignalInfoConstPtr> signals;
106 if (HDMapUtil::BaseMap().GetSignals(hdmap_point, FLAGS_search_radius,
107 &signals) == 0) {
108 if (signals.size() > 0) {
109 *signal_id = signals.front()->id().id();
110 return true;
111 }
112 }
113 return false;
114}
115
116bool GetStopSign(const PathPoint& point, std::string* stop_sign_id) {
117 common::PointENU hdmap_point;
118 hdmap_point.set_x(point.x());
119 hdmap_point.set_y(point.y());
120 std::vector<StopSignInfoConstPtr> stop_signs;
121 if (HDMapUtil::BaseMap().GetStopSigns(hdmap_point, FLAGS_search_radius,
122 &stop_signs) == 0) {
123 if (stop_signs.size() > 0) {
124 *stop_sign_id = stop_signs.front()->id().id();
125 return true;
126 }
127 }
128 return false;
129}
130
131bool GetYieldSign(const PathPoint& point, std::string* yield_sign_id) {
132 common::PointENU hdmap_point;
133 hdmap_point.set_x(point.x());
134 hdmap_point.set_y(point.y());
135 std::vector<YieldSignInfoConstPtr> yield_signs;
136 if (HDMapUtil::BaseMap().GetYieldSigns(hdmap_point, FLAGS_search_radius,
137 &yield_signs) == 0) {
138 if (yield_signs.size() > 0) {
139 *yield_sign_id = yield_signs.front()->id().id();
140 return true;
141 }
142 }
143 return false;
144}
145
146} // namespace
147
151void CloseToJunctionTeller::GetOverlaps(const ADCTrajectory& adc_trajectory) {
152 static std::string overlapping_junction_id;
153
154 const double s_start = adc_trajectory.trajectory_point(0).path_point().s();
155
156 clear_area_id_.clear();
157 clear_area_distance_ = -1;
158 crosswalk_id_.clear();
159 crosswalk_distance_ = -1;
160 junction_id_.clear();
161 junction_distance_ = -1;
162 pnc_junction_id_.clear();
163 pnc_junction_distance_ = -1;
164 signal_id_.clear();
165 signal_distance_ = -1;
166 stop_sign_id_.clear();
167 stop_sign_distance_ = -1;
168 yield_sign_id_.clear();
169 yield_sign_distance_ = -1;
170 for (const auto& point : adc_trajectory.trajectory_point()) {
171 const auto& path_point = point.path_point();
172 if (path_point.s() > FLAGS_adc_trajectory_search_distance) {
173 break;
174 }
175
176 // clear_area
177 if (clear_area_id_.empty() || clear_area_distance_ < 0) {
178 std::string clear_area_id;
179 if (GetClearArea(path_point, &clear_area_id)) {
180 clear_area_id_ = clear_area_id;
181 clear_area_distance_ = path_point.s() - s_start;
182 }
183 }
184
185 // crosswalk
186 if (crosswalk_id_.empty() || crosswalk_distance_ < 0) {
187 std::string crosswalk_id;
188 if (GetCrosswalk(path_point, &crosswalk_id)) {
189 crosswalk_id_ = crosswalk_id;
190 crosswalk_distance_ = path_point.s() - s_start;
191 }
192 }
193
194 // junction
195 if (junction_id_.empty() || junction_distance_ < 0) {
196 std::string junction_id;
197 if (GetJunction(path_point, &junction_id)) {
198 junction_id_ = junction_id;
199 junction_distance_ = path_point.s() - s_start;
200 }
201 }
202
203 // pnc_junction
204 if (pnc_junction_id_.empty() || pnc_junction_distance_ < 0) {
205 std::string pnc_junction_id;
206 if (GetPNCJunction(path_point, &pnc_junction_id)) {
207 pnc_junction_id_ = pnc_junction_id;
208 pnc_junction_distance_ = path_point.s() - s_start;
209 }
210 }
211
212 // signal
213 if (signal_id_.empty() || signal_distance_ < 0) {
214 std::string signal_id;
215 if (GetSignal(path_point, &signal_id)) {
216 signal_id_ = signal_id;
217 signal_distance_ = path_point.s() - s_start;
218 }
219 }
220
221 // stop_sign
222 if (stop_sign_id_.empty() || stop_sign_distance_ < 0) {
223 std::string stop_sign_id;
224 if (GetStopSign(path_point, &stop_sign_id)) {
225 stop_sign_id_ = stop_sign_id;
226 stop_sign_distance_ = path_point.s() - s_start;
227 }
228 }
229
230 // yield_sign
231 if (yield_sign_id_.empty() || yield_sign_distance_ < 0) {
232 std::string yield_sign_id;
233 if (GetYieldSign(path_point, &yield_sign_id)) {
234 yield_sign_id_ = yield_sign_id;
235 yield_sign_distance_ = path_point.s() - s_start;
236 }
237 }
238 }
239}
240
241void CloseToJunctionTeller::Init(const StorytellingConfig& storytelling_conf) {
242 config_.CopyFrom(storytelling_conf);
243 frame_manager_->CreateOrGetReader<ADCTrajectory>(
245}
246
248 static auto planning_reader =
249 frame_manager_->CreateOrGetReader<ADCTrajectory>(
251 const auto trajectory = planning_reader->GetLatestObserved();
252 if (trajectory == nullptr || trajectory->trajectory_point().empty()) {
253 AERROR << "Planning trajectory not ready.";
254 return;
255 }
256
257 GetOverlaps(*trajectory);
258
259 // CloseToClearArea
260 if (!clear_area_id_.empty() && clear_area_distance_ >= 0) {
261 if (!stories->has_close_to_clear_area()) {
262 AINFO << "Enter CloseToClearArea story";
263 }
264 auto* story = stories->mutable_close_to_clear_area();
265 story->set_id(clear_area_id_);
266 story->set_distance(clear_area_distance_);
267 } else if (stories->has_close_to_clear_area()) {
268 AINFO << "Exit CloseToClearArea story";
269 stories->clear_close_to_clear_area();
270 }
271
272 // CloseToCrosswalk
273 if (!crosswalk_id_.empty() && crosswalk_distance_ >= 0) {
274 if (!stories->has_close_to_crosswalk()) {
275 AINFO << "Enter CloseToCrosswalk story";
276 }
277 auto* story = stories->mutable_close_to_crosswalk();
278 story->set_id(crosswalk_id_);
279 story->set_distance(crosswalk_distance_);
280 } else if (stories->has_close_to_crosswalk()) {
281 AINFO << "Exit CloseToCrosswalk story";
282 stories->clear_close_to_crosswalk();
283 }
284
285 // CloseToJunction
286 if ((!junction_id_.empty() && junction_distance_ >= 0) ||
287 (!pnc_junction_id_.empty() && pnc_junction_distance_ >= 0)) {
288 if (!stories->has_close_to_junction()) {
289 AINFO << "Enter CloseToJunction story";
290 }
291 auto* story = stories->mutable_close_to_junction();
292 if (!pnc_junction_id_.empty() && pnc_junction_distance_ >= 0) {
293 story->set_id(pnc_junction_id_);
294 story->set_type(CloseToJunction::PNC_JUNCTION);
295 story->set_distance(pnc_junction_distance_);
296 } else {
297 story->set_id(junction_id_);
298 story->set_type(CloseToJunction::JUNCTION);
299 story->set_distance(junction_distance_);
300 }
301 } else if (stories->has_close_to_junction()) {
302 AINFO << "Exit CloseToJunction story";
303 stories->clear_close_to_junction();
304 }
305
306 // CloseToSignal
307 if (!signal_id_.empty() && signal_distance_ >= 0) {
308 if (!stories->has_close_to_signal()) {
309 AINFO << "Enter CloseToSignal story";
310 }
311 auto* story = stories->mutable_close_to_signal();
312 story->set_id(signal_id_);
313 story->set_distance(signal_distance_);
314 } else if (stories->has_close_to_signal()) {
315 AINFO << "Exit CloseToSignal story";
316 stories->clear_close_to_signal();
317 }
318
319 // CloseToStopSign
320 if (!stop_sign_id_.empty() && stop_sign_distance_ >= 0) {
321 if (!stories->has_close_to_stop_sign()) {
322 AINFO << "Enter CloseToStopSign story";
323 }
324 auto* story = stories->mutable_close_to_stop_sign();
325 story->set_id(stop_sign_id_);
326 story->set_distance(stop_sign_distance_);
327 } else if (stories->has_close_to_stop_sign()) {
328 AINFO << "Exit CloseToStopSign story";
329 stories->clear_close_to_stop_sign();
330 }
331
332 // CloseToYieldSign
333 if (!yield_sign_id_.empty() && yield_sign_distance_ >= 0) {
334 if (!stories->has_close_to_yield_sign()) {
335 AINFO << "Enter CloseToYieldSign story";
336 }
337 auto* story = stories->mutable_close_to_yield_sign();
338 story->set_id(yield_sign_id_);
339 story->set_distance(yield_sign_distance_);
340 } else if (stories->has_close_to_yield_sign()) {
341 AINFO << "Exit CloseToYieldSign story";
342 stories->clear_close_to_yield_sign();
343 }
344}
345
346} // namespace storytelling
347} // namespace apollo
std::shared_ptr< FrameManager > frame_manager_
Definition base_teller.h:37
void Init(const StorytellingConfig &storytelling_conf) override
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
std::shared_ptr< const PNCJunctionInfo > PNCJunctionInfoConstPtr
std::shared_ptr< const JunctionInfo > JunctionInfoConstPtr
std::shared_ptr< const StopSignInfo > StopSignInfoConstPtr
std::shared_ptr< const ClearAreaInfo > ClearAreaInfoConstPtr
std::shared_ptr< const SignalInfo > SignalInfoConstPtr
std::shared_ptr< const CrosswalkInfo > CrosswalkInfoConstPtr
std::shared_ptr< const YieldSignInfo > YieldSignInfoConstPtr
class register implement
Definition arena_queue.h:37
repeated apollo::common::TrajectoryPoint trajectory_point