Skip to content

Commit 047696c

Browse files
authored
fix(path_generator): deal with unintended input (#336)
* prevent segfault Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * fix self-intersection search range Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * define behavior for unintended input Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * prevent segfault Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * check builder output instead of input size Signed-off-by: mitukou1109 <mitukou1109@gmail.com> --------- Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
1 parent 22bcb40 commit 047696c

File tree

1 file changed

+51
-1
lines changed
  • planning/autoware_path_generator/src

1 file changed

+51
-1
lines changed

planning/autoware_path_generator/src/utils.cpp

+51-1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ std::optional<double> get_first_intersection_arc_length(
218218
const lanelet::LaneletSequence & lanelet_sequence, const double s_start, const double s_end,
219219
const double vehicle_length)
220220
{
221+
if (lanelet_sequence.empty()) {
222+
return std::nullopt;
223+
}
224+
221225
std::optional<double> s_intersection{std::nullopt};
222226

223227
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(
236240
lanelet_sequence.rightBound2d().begin(), lanelet_sequence.rightBound2d().end()),
237241
s_start_on_bounds.right, s_end_on_bounds.right)));
238242

243+
if (cropped_centerline.empty() || cropped_left_bound.empty() || cropped_right_bound.empty()) {
244+
return std::nullopt;
245+
}
246+
239247
const lanelet::BasicLineString2d start_edge{
240248
cropped_left_bound.front(), cropped_right_bound.front()};
241249

@@ -376,7 +384,7 @@ std::optional<double> get_first_self_intersection_arc_length(
376384
std::nullopt;
377385
double s = 0.;
378386

379-
for (size_t i = 1; i < line_string.size() - 1; ++i) {
387+
for (size_t i = 1; i < line_string.size(); ++i) {
380388
if (first_self_intersection_long && i == first_self_intersection_long->idx + 1) {
381389
return s + first_self_intersection_long->s;
382390
}
@@ -395,6 +403,10 @@ std::optional<double> get_first_self_intersection_arc_length(
395403
PathRange<std::vector<geometry_msgs::msg::Point>> get_path_bounds(
396404
const lanelet::LaneletSequence & lanelet_sequence, const double s_start, const double s_end)
397405
{
406+
if (lanelet_sequence.empty()) {
407+
return {};
408+
}
409+
398410
const auto [s_left_start, s_right_start] = get_arc_length_on_bounds(lanelet_sequence, s_start);
399411
const auto [s_left_end, s_right_end] = get_arc_length_on_bounds(lanelet_sequence, s_end);
400412

@@ -413,16 +425,41 @@ std::vector<geometry_msgs::msg::Point> crop_line_string(
413425
const std::vector<geometry_msgs::msg::Point> & line_string, const double s_start,
414426
const double s_end)
415427
{
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+
416442
auto trajectory = autoware::trajectory::Trajectory<geometry_msgs::msg::Point>::Builder()
417443
.set_xy_interpolator<trajectory::interpolator::Linear>()
418444
.build(line_string);
445+
if (!trajectory) {
446+
return {};
447+
}
448+
419449
trajectory->crop(s_start, s_end - s_start);
420450
return trajectory->restore();
421451
}
422452

423453
PathRange<double> get_arc_length_on_bounds(
424454
const lanelet::LaneletSequence & lanelet_sequence, const double s_centerline)
425455
{
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+
426463
auto s = 0.;
427464
auto s_left = 0.;
428465
auto s_right = 0.;
@@ -459,6 +496,19 @@ PathRange<std::optional<double>> get_arc_length_on_centerline(
459496
std::optional<double> s_left_centerline = std::nullopt;
460497
std::optional<double> s_right_centerline = std::nullopt;
461498

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+
462512
auto s = 0.;
463513
auto s_left = 0.;
464514
auto s_right = 0.;

0 commit comments

Comments
 (0)