223 {
224 std::vector<double> center_l;
225 double max_nudge_check_distance;
226 if (reference_line_info.IsChangeLanePath() ||
227 path_boundary->label().find("regular/left") != std::string::npos ||
228 path_boundary->label().find("regular/right") != std::string::npos) {
229 center_l.push_back(
230 (path_boundary->front().l_upper.l + path_boundary->front().l_lower.l) *
231 0.5);
232 max_nudge_check_distance = FLAGS_max_nudge_check_distance_in_lk;
233 } else {
234 center_l.push_back(0.0);
235 max_nudge_check_distance = FLAGS_max_nudge_check_distance_in_lc;
236 }
237
238 *narrowest_width =
239 path_boundary->front().l_upper.l - path_boundary->front().l_lower.l;
240 double mid_l =
241 (path_boundary->front().l_upper.l + path_boundary->front().l_lower.l) / 2;
242 size_t nudge_check_count =
243 size_t(max_nudge_check_distance / FLAGS_path_bounds_decider_resolution);
244 double last_max_nudge_l = center_l.front();
245
246
247 for (size_t i = 1; i < path_boundary->size(); ++i) {
248 double path_boundary_s = path_boundary->at(i).s;
249 auto& left_bound = path_boundary->at(i).l_upper;
250 auto& right_bound = path_boundary->at(i).l_lower;
251 double default_width = right_bound.l - left_bound.l;
252 auto begin_it =
253 center_l.end() - std::min(nudge_check_count, center_l.size());
254 last_max_nudge_l = *std::max_element(
255 begin_it, center_l.end(),
256 [](double a, double b) { return std::fabs(a) < std::fabs(b); });
257 AINFO <<
"last max nudge l: " << last_max_nudge_l;
258 for (size_t j = 0; j < sl_polygon->size(); j++) {
260 AINFO <<
"UpdatePathBoundaryBySLPolygon, ignore obs: "
261 << sl_polygon->at(j).id();
262 continue;
263 }
264 double min_s = sl_polygon->at(j).MinS();
265 double max_s =
266 sl_polygon->at(j).MaxS() + FLAGS_obstacle_lon_end_buffer_park;
267 if (max_s - min_s < FLAGS_path_bounds_decider_resolution) {
268 max_s += FLAGS_path_bounds_decider_resolution;
269 min_s -= FLAGS_path_bounds_decider_resolution;
270 }
271 if (max_s < path_boundary_s) {
272 continue;
273 }
274 if (min_s > path_boundary_s) {
275 break;
276 }
278 sl_polygon->at(j).UpdatePassableInfo(left_bound.l, right_bound.l,
279 adc_obs_edge_buffer);
280
281 double l_lower = sl_polygon->at(j).GetRightBoundaryByS(path_boundary_s);
282 double l_upper = sl_polygon->at(j).GetLeftBoundaryByS(path_boundary_s);
283 PathBoundPoint obs_left_nudge_bound(
284 path_boundary_s, l_upper + adc_obs_edge_buffer, left_bound.l);
285 obs_left_nudge_bound.towing_l = path_boundary->at(i).towing_l;
286 PathBoundPoint obs_right_nudge_bound(path_boundary_s, right_bound.l,
287 l_lower - adc_obs_edge_buffer);
288 obs_right_nudge_bound.towing_l = path_boundary->at(i).towing_l;
289
290
291
292
294 AINFO <<
"last_max_nudge_l: " << last_max_nudge_l
295 << ", obs id: " << sl_polygon->at(j).id()
296 << ", obs l: " << l_lower << ", " << l_upper;
297 double obs_l = (l_lower + l_upper) / 2;
298 if (sl_polygon->at(j).is_passable()[
RIGHT_INDEX]) {
299 if (sl_polygon->at(j).is_passable()[
LEFT_INDEX]) {
300 if (std::fabs(obs_l - mid_l) < 0.4 &&
301 std::fabs(path_boundary_s - init_sl_state.first[0]) < 5.0) {
302 if (init_sl_state.second[0] < obs_l) {
304 AINFO << sl_polygon->at(j).id()
305 << " right nudge with init_sl_state";
306 } else {
308 AINFO << sl_polygon->at(j).id()
309 << " left nudge width init_sl_state";
310 }
311 } else {
312 if (last_max_nudge_l < obs_l) {
314 AINFO << sl_polygon->at(j).id()
315 << " right nudge, according max_nudge_l";
316 } else {
318 AINFO << sl_polygon->at(j).id()
319 << " left nudge, according max_nudge_l";
320 }
321 }
322 } else {
324 AINFO << sl_polygon->at(j).id()
325 << " right nudge, left is not passable";
326 }
327 } else {
329 AINFO << sl_polygon->at(j).id()
330 << " left nudge, right is not passable";
331 }
332 } else {
333 AINFO <<
"last_max_nudge_l: " << last_max_nudge_l
334 << ", obs id: " << sl_polygon->at(j).id()
335 << ", obs l: " << l_lower << ", " << l_upper
336 << ", nudge info: " << sl_polygon->at(j).NudgeInfo();
337 }
339
340 if (obs_right_nudge_bound.l_upper.l < path_boundary->at(i).towing_l) {
341 sl_polygon->at(j).SetOverlapeWithReferCenter(true);
342 sl_polygon->at(j).SetOverlapeSizeWithReference(
343 path_boundary->at(i).towing_l - obs_right_nudge_bound.l_upper.l);
344 }
345 if (!sl_polygon->at(j).is_passable()[
RIGHT_INDEX]) {
346
347 *blocked_id = sl_polygon->at(j).id();
348 AINFO <<
"blocked at " << *blocked_id <<
", s: " << path_boundary_s
349 << ", left bound: " << left_bound.l
350 << ", right bound: " << right_bound.l;
352 break;
353 }
354 if (obs_right_nudge_bound.l_upper.l < left_bound.l) {
355 AINFO <<
"update left_bound: s " << path_boundary_s <<
", l "
356 << left_bound.l << " -> " << obs_right_nudge_bound.l_upper.l;
357 left_bound.l = obs_right_nudge_bound.l_upper.l;
359 left_bound.id = sl_polygon->at(j).id();
360 *narrowest_width =
361 std::min(*narrowest_width, left_bound.l - right_bound.l);
362 }
364
365 if (obs_left_nudge_bound.l_lower.l > path_boundary->at(i).towing_l) {
366 sl_polygon->at(j).SetOverlapeWithReferCenter(true);
367 sl_polygon->at(j).SetOverlapeSizeWithReference(
368 obs_left_nudge_bound.l_lower.l - path_boundary->at(i).towing_l);
369 }
370 if (!sl_polygon->at(j).is_passable()[
LEFT_INDEX]) {
371
372 *blocked_id = sl_polygon->at(j).id();
373 AINFO <<
"blocked at " << *blocked_id <<
", s: " << path_boundary_s
374 << ", left bound: " << left_bound.l
375 << ", right bound: " << right_bound.l;
377 break;
378 }
379 if (obs_left_nudge_bound.l_lower.l > right_bound.l) {
380 AINFO <<
"update right_bound: s " << path_boundary_s <<
", l "
381 << right_bound.l << " -> " << obs_left_nudge_bound.l_lower.l;
382 right_bound.l = obs_left_nudge_bound.l_lower.l;
384 right_bound.id = sl_polygon->at(j).id();
385 *narrowest_width =
386 std::min(*narrowest_width, left_bound.l - right_bound.l);
387 }
388 }
389
390
391
392
393
394
395
396
397
398
399
400 last_max_nudge_l = std::fabs((left_bound.l + right_bound.l) / 2.0 -
401 mid_l) > std::fabs(last_max_nudge_l - mid_l)
402 ? (left_bound.l + right_bound.l) / 2.0
403 : last_max_nudge_l;
404 }
405
406 if (!blocked_id->empty()) {
408 *narrowest_width = default_width;
409 return false;
410 }
411
412
413
414
415 center_l.push_back((left_bound.l + right_bound.l) / 2.0);
416 AINFO <<
"update s: " << path_boundary_s
417 << ", center_l: " << center_l.back();
418 }
419 return true;
420}