221 {
222 std::vector<double> center_l;
223 double max_nudge_check_distance;
224 if (reference_line_info.IsChangeLanePath() ||
225 path_boundary->label().find("regular/left") != std::string::npos ||
226 path_boundary->label().find("regular/right") != std::string::npos) {
227 center_l.push_back(
228 (path_boundary->front().l_upper.l + path_boundary->front().l_lower.l) *
229 0.5);
230 max_nudge_check_distance =
231 std::max(FLAGS_max_nudge_check_distance_in_lk,
233 } else {
234 center_l.push_back(0.0);
235 max_nudge_check_distance =
236 std::max(FLAGS_max_nudge_check_distance_in_lc,
238 }
239
240 *narrowest_width =
241 path_boundary->front().l_upper.l - path_boundary->front().l_lower.l;
242 double mid_l =
243 (path_boundary->front().l_upper.l + path_boundary->front().l_lower.l) / 2;
244 size_t nudge_check_count =
245 size_t(max_nudge_check_distance / FLAGS_path_bounds_decider_resolution);
246 double last_max_nudge_l = center_l.front();
247
248 const double adc_end_s = reference_line_info.AdcSlBoundary().end_s() + 1.0;
249 const double adc_start_s = reference_line_info.AdcSlBoundary().start_s();
250 const double adc_end_l = reference_line_info.AdcSlBoundary().end_l();
251
252 for (size_t i = 1; i < path_boundary->size(); ++i) {
253 double path_boundary_s = path_boundary->at(i).s;
254 auto& left_bound = path_boundary->at(i).l_upper;
255 auto& right_bound = path_boundary->at(i).l_lower;
256 double default_width = right_bound.l - left_bound.l;
257 auto begin_it =
258 center_l.end() - std::min(nudge_check_count, center_l.size());
259 last_max_nudge_l = *std::max_element(
260 begin_it, center_l.end(),
261 [](double a, double b) { return std::fabs(a) < std::fabs(b); });
262 AINFO <<
"last max nudge l: " << last_max_nudge_l;
263 bool is_left_width = false;
265 reference_line_info, path_boundary_s, &is_left_width);
266 double left_half_width, right_half_width;
267 if (is_left_width) {
268 left_half_width = eq_width + FLAGS_obstacle_lat_buffer;
269 right_half_width =
271 FLAGS_obstacle_lat_buffer;
272 } else {
273 left_half_width =
275 FLAGS_obstacle_lat_buffer;
276 right_half_width = eq_width + FLAGS_obstacle_lat_buffer;
277 }
278
279 for (size_t j = 0; j < sl_polygon->size(); j++) {
281 AINFO <<
"UpdatePathBoundaryBySLPolygon, ignore obs: "
282 << sl_polygon->at(j).id();
283 continue;
284 }
285 double min_s = sl_polygon->at(j).MinS();
286 double max_s =
287 sl_polygon->at(j).MaxS() + FLAGS_obstacle_lon_end_buffer_park;
288 if (max_s - min_s < FLAGS_path_bounds_decider_resolution) {
289 max_s += FLAGS_path_bounds_decider_resolution;
290 min_s -= FLAGS_path_bounds_decider_resolution;
291 }
292 if (max_s < path_boundary_s) {
293 continue;
294 }
295 if (min_s > path_boundary_s) {
296 break;
297 }
298
299 sl_polygon->at(j).UpdatePassableInfo(left_bound.l, right_bound.l,
300 right_half_width, left_half_width,
301 path_boundary_s);
302
303 double l_lower = sl_polygon->at(j).GetRightBoundaryByS(path_boundary_s);
304 double l_upper = sl_polygon->at(j).GetLeftBoundaryByS(path_boundary_s);
305 PathBoundPoint obs_left_nudge_bound(
306 path_boundary_s, l_upper + right_half_width, left_bound.l);
307 obs_left_nudge_bound.towing_l = path_boundary->at(i).towing_l;
308 PathBoundPoint obs_right_nudge_bound(path_boundary_s, right_bound.l,
309 l_lower - left_half_width);
310 obs_right_nudge_bound.towing_l = path_boundary->at(i).towing_l;
311
312
313
314
316 AINFO <<
"last_max_nudge_l: " << last_max_nudge_l
317 << ", obs id: " << sl_polygon->at(j).id()
318 << ", obs l: " << l_lower << ", " << l_upper;
319 double obs_l = (l_lower + l_upper) / 2;
320 if (sl_polygon->at(j).is_passable()[
RIGHT_INDEX]) {
321 if (sl_polygon->at(j).is_passable()[
LEFT_INDEX]) {
322 if (std::fabs(obs_l - mid_l) < 0.4 &&
323 std::fabs(path_boundary_s - init_sl_state.first[0]) < 5.0) {
324 if (init_sl_state.second[0] < obs_l) {
326 AINFO << sl_polygon->at(j).id()
327 << " right nudge with init_sl_state";
328 } else {
330 AINFO << sl_polygon->at(j).id()
331 << " left nudge width init_sl_state";
332 }
333 } else if (path_boundary_s - adc_start_s > 0 &&
334 path_boundary_s - adc_end_s < 0) {
335
336 if (adc_end_l < obs_l) {
338 AINFO << sl_polygon->at(j).id()
339 << " right nudge with init_sl_state";
340 } else {
342 AINFO << sl_polygon->at(j).id()
343 << " left nudge width init_sl_state";
344 }
345 } else {
346 if (last_max_nudge_l < obs_l) {
348 AINFO << sl_polygon->at(j).id()
349 << " right nudge, according max_nudge_l";
350 } else {
352 AINFO << sl_polygon->at(j).id()
353 << " left nudge, according max_nudge_l";
354 }
355 }
356 } else {
358 AINFO << sl_polygon->at(j).id()
359 << " right nudge, left is not passable";
360 }
361 } else {
363 AINFO << sl_polygon->at(j).id()
364 << " left nudge, right is not passable";
365 }
366 } else {
367 AINFO <<
"last_max_nudge_l: " << last_max_nudge_l
368 << ", obs id: " << sl_polygon->at(j).id()
369 << ", obs l: " << l_lower << ", " << l_upper
370 << ", nudge info: " << sl_polygon->at(j).NudgeInfo();
371 }
373
374 if (obs_right_nudge_bound.l_upper.l < path_boundary->at(i).towing_l) {
375 sl_polygon->at(j).SetOverlapeWithReferCenter(true);
376 sl_polygon->at(j).SetOverlapeSizeWithReference(
377 path_boundary->at(i).towing_l - obs_right_nudge_bound.l_upper.l);
378 }
379 if (!sl_polygon->at(j).is_passable()[
RIGHT_INDEX]) {
380
381 *blocked_id = sl_polygon->at(j).id();
382 AINFO <<
"blocked at " << *blocked_id <<
", s: " << path_boundary_s
383 << ", left bound: " << left_bound.l
384 << ", right bound: " << right_bound.l;
386 break;
387 }
388 if (obs_right_nudge_bound.l_upper.l < left_bound.l) {
389 AINFO <<
"update left_bound: s " << path_boundary_s <<
", l "
390 << left_bound.l << " -> " << obs_right_nudge_bound.l_upper.l;
391 left_bound.l = obs_right_nudge_bound.l_upper.l;
393 left_bound.id = sl_polygon->at(j).id();
394 *narrowest_width =
395 std::min(*narrowest_width, left_bound.l - right_bound.l);
396 }
398
399 if (obs_left_nudge_bound.l_lower.l > path_boundary->at(i).towing_l) {
400 sl_polygon->at(j).SetOverlapeWithReferCenter(true);
401 sl_polygon->at(j).SetOverlapeSizeWithReference(
402 obs_left_nudge_bound.l_lower.l - path_boundary->at(i).towing_l);
403 }
404 if (!sl_polygon->at(j).is_passable()[
LEFT_INDEX]) {
405
406 *blocked_id = sl_polygon->at(j).id();
407 AINFO <<
"blocked at " << *blocked_id <<
", s: " << path_boundary_s
408 << ", left bound: " << left_bound.l
409 << ", right bound: " << right_bound.l;
411 break;
412 }
413 if (obs_left_nudge_bound.l_lower.l > right_bound.l) {
414 AINFO <<
"update right_bound: s " << path_boundary_s <<
", l "
415 << right_bound.l << " -> " << obs_left_nudge_bound.l_lower.l;
416 right_bound.l = obs_left_nudge_bound.l_lower.l;
418 right_bound.id = sl_polygon->at(j).id();
419 *narrowest_width =
420 std::min(*narrowest_width, left_bound.l - right_bound.l);
421 }
422 }
423
424
425
426
427
428
429
430
431
432
433
434 last_max_nudge_l = std::fabs((left_bound.l + right_bound.l) / 2.0 -
435 mid_l) > std::fabs(last_max_nudge_l - mid_l)
436 ? (left_bound.l + right_bound.l) / 2.0
437 : last_max_nudge_l;
438 }
439
440 if (!blocked_id->empty()) {
442 *narrowest_width = default_width;
443 return false;
444 }
445
446
447
448
449 center_l.push_back((left_bound.l + right_bound.l) / 2.0);
450 AINFO <<
"update s: " << path_boundary_s
451 << ", center_l: " << center_l.back();
452 }
453 return true;
454}
double CalculateEquivalentEgoWidth(const ReferenceLineInfo &reference_line_info, double s, bool *is_left)