@@ -218,6 +218,10 @@ std::optional<double> get_first_intersection_arc_length(
218
218
const lanelet::LaneletSequence & lanelet_sequence, const double s_start, const double s_end,
219
219
const double vehicle_length)
220
220
{
221
+ if (lanelet_sequence.empty ()) {
222
+ return std::nullopt;
223
+ }
224
+
221
225
std::optional<double > s_intersection{std::nullopt};
222
226
223
227
const auto s_start_on_bounds = get_arc_length_on_bounds (lanelet_sequence, s_start);
@@ -236,6 +240,10 @@ std::optional<double> get_first_intersection_arc_length(
236
240
lanelet_sequence.rightBound2d ().begin (), lanelet_sequence.rightBound2d ().end ()),
237
241
s_start_on_bounds.right , s_end_on_bounds.right )));
238
242
243
+ if (cropped_centerline.empty () || cropped_left_bound.empty () || cropped_right_bound.empty ()) {
244
+ return std::nullopt;
245
+ }
246
+
239
247
const lanelet::BasicLineString2d start_edge{
240
248
cropped_left_bound.front (), cropped_right_bound.front ()};
241
249
@@ -376,7 +384,7 @@ std::optional<double> get_first_self_intersection_arc_length(
376
384
std::nullopt;
377
385
double s = 0 .;
378
386
379
- for (size_t i = 1 ; i < line_string.size () - 1 ; ++i) {
387
+ for (size_t i = 1 ; i < line_string.size (); ++i) {
380
388
if (first_self_intersection_long && i == first_self_intersection_long->idx + 1 ) {
381
389
return s + first_self_intersection_long->s ;
382
390
}
@@ -395,6 +403,10 @@ std::optional<double> get_first_self_intersection_arc_length(
395
403
PathRange<std::vector<geometry_msgs::msg::Point >> get_path_bounds (
396
404
const lanelet::LaneletSequence & lanelet_sequence, const double s_start, const double s_end)
397
405
{
406
+ if (lanelet_sequence.empty ()) {
407
+ return {};
408
+ }
409
+
398
410
const auto [s_left_start, s_right_start] = get_arc_length_on_bounds (lanelet_sequence, s_start);
399
411
const auto [s_left_end, s_right_end] = get_arc_length_on_bounds (lanelet_sequence, s_end);
400
412
@@ -413,16 +425,41 @@ std::vector<geometry_msgs::msg::Point> crop_line_string(
413
425
const std::vector<geometry_msgs::msg::Point > & line_string, const double s_start,
414
426
const double s_end)
415
427
{
428
+ if (s_start < 0 .) {
429
+ RCLCPP_WARN (
430
+ rclcpp::get_logger (" path_generator" ).get_child (" utils" ).get_child (__func__),
431
+ " Start of crop range is negative, returning input as is" );
432
+ return line_string;
433
+ }
434
+
435
+ if (s_start > s_end) {
436
+ RCLCPP_WARN (
437
+ rclcpp::get_logger (" path_generator" ).get_child (" utils" ).get_child (__func__),
438
+ " Start of crop range is larger than end, returning input as is" );
439
+ return line_string;
440
+ }
441
+
416
442
auto trajectory = autoware::trajectory::Trajectory<geometry_msgs::msg::Point >::Builder ()
417
443
.set_xy_interpolator <trajectory::interpolator::Linear>()
418
444
.build (line_string);
445
+ if (!trajectory) {
446
+ return {};
447
+ }
448
+
419
449
trajectory->crop (s_start, s_end - s_start);
420
450
return trajectory->restore ();
421
451
}
422
452
423
453
PathRange<double > get_arc_length_on_bounds (
424
454
const lanelet::LaneletSequence & lanelet_sequence, const double s_centerline)
425
455
{
456
+ if (s_centerline < 0 .) {
457
+ RCLCPP_WARN (
458
+ rclcpp::get_logger (" path_generator" ).get_child (" utils" ).get_child (__func__),
459
+ " Input arc length is negative, returning 0." );
460
+ return {0 ., 0 .};
461
+ }
462
+
426
463
auto s = 0 .;
427
464
auto s_left = 0 .;
428
465
auto s_right = 0 .;
@@ -459,6 +496,19 @@ PathRange<std::optional<double>> get_arc_length_on_centerline(
459
496
std::optional<double > s_left_centerline = std::nullopt;
460
497
std::optional<double > s_right_centerline = std::nullopt;
461
498
499
+ if (s_left_bound && *s_left_bound < 0 .) {
500
+ RCLCPP_WARN (
501
+ rclcpp::get_logger (" path_generator" ).get_child (" utils" ).get_child (__func__),
502
+ " Input left arc length is negative, returning 0." );
503
+ s_left_centerline = 0 .;
504
+ }
505
+ if (s_right_bound && *s_right_bound < 0 .) {
506
+ RCLCPP_WARN (
507
+ rclcpp::get_logger (" path_generator" ).get_child (" utils" ).get_child (__func__),
508
+ " Input right arc length is negative, returning 0." );
509
+ s_right_centerline = 0 .;
510
+ }
511
+
462
512
auto s = 0 .;
463
513
auto s_left = 0 .;
464
514
auto s_right = 0 .;
0 commit comments