@@ -351,7 +351,6 @@ void SimplePlannerNode::routeCallback(const route_planning_msgs::msg::Route::Uni
351351 route_topic_diagnostic_->tick (msg->header .stamp );
352352 }
353353 route_ = *msg;
354-
355354 if (!route_init_) {
356355 RCLCPP_INFO (this ->get_logger (), " Received new route message, initialized global variable" );
357356 route_init_ = true ;
@@ -647,12 +646,28 @@ SimplePlannerNode::FollowRoutePlan SimplePlannerNode::buildRoutePlan(const std_m
647646void SimplePlannerNode::appendRoutePoints (const route_planning_msgs::msg::Route& tf_route,
648647 FollowRoutePlan& route_plan,
649648 std::map<uint64_t , uint64_t >& lane_change_indices_map) {
649+ if (tf_route.current_route_element_idx >= tf_route.route_elements .size ()) {
650+ const std::string msg = " Current route element index is outside the received local route" ;
651+ setHealth (diagnostic_msgs::msg::DiagnosticStatus::WARN , msg, health_.key_value_pairs );
652+ RCLCPP_WARN (this ->get_logger (), " %s" , msg.c_str ());
653+ return ;
654+ }
655+
656+ const bool destination_is_present = tf_route.destination_route_element_idx < tf_route.route_elements .size ();
657+ const size_t destination_or_route_end_idx =
658+ destination_is_present ? tf_route.destination_route_element_idx : tf_route.route_elements .size ();
659+ if (destination_or_route_end_idx <= tf_route.current_route_element_idx ) {
660+ const std::string msg = " Received local route contains no remaining route elements" ;
661+ setHealth (diagnostic_msgs::msg::DiagnosticStatus::WARN , msg, health_.key_value_pairs );
662+ RCLCPP_WARN (this ->get_logger (), " %s" , msg.c_str ());
663+ return ;
664+ }
665+
650666 double t_total = 0.0 ;
651- RCLCPP_DEBUG (this ->get_logger (), " Number of remaining route elements: %zu" ,
652- tf_route.destination_route_element_idx - tf_route.current_route_element_idx );
653- health_.key_value_pairs .insert (
654- {" RemainingRouteElements" , std::to_string (tf_route.destination_route_element_idx - tf_route.current_route_element_idx )});
655- for (size_t j = tf_route.current_route_element_idx ; j < tf_route.destination_route_element_idx ; ++j) {
667+ const size_t remaining_route_elements = destination_or_route_end_idx - tf_route.current_route_element_idx ;
668+ RCLCPP_DEBUG (this ->get_logger (), " Number of remaining route elements: %zu" , remaining_route_elements);
669+ health_.key_value_pairs .insert_or_assign (" RemainingRouteElements" , std::to_string (remaining_route_elements));
670+ for (size_t j = tf_route.current_route_element_idx ; j < destination_or_route_end_idx; ++j) {
656671 const auto & route_element = tf_route.route_elements [j];
657672 if (!route_element.is_enriched ) {
658673 RCLCPP_DEBUG (this ->get_logger (), " Route element %zu is not enriched. Skipping." , j);
@@ -664,21 +679,15 @@ void SimplePlannerNode::appendRoutePoints(const route_planning_msgs::msg::Route&
664679 simple_path_point.position =
665680 Eigen::Vector2d (suggested_lane.reference_pose .position .x , suggested_lane.reference_pose .position .y );
666681 simple_path_point.s = route_element.s ;
667- simple_path_point.v = v_ref_;
668- if (v_ref_ < 0.0 ) {
669- simple_path_point.v = suggested_lane.speed_limit / 3.6 ;
670- }
682+ simple_path_point.v = v_ref_ < 0.0 ? suggested_lane.speed_limit / 3.6 : v_ref_;
671683
672684 if (!route_plan.path .points .empty ()) {
673- double v_average = (route_plan.path .points .back ().v + simple_path_point.v ) / 2.0 ;
674- double dt = 0.0 ;
675- if (v_average != 0.0 ) {
676- dt = (simple_path_point.s - route_plan.path .points .back ().s ) / v_average;
677- }
685+ const double v_average = (route_plan.path .points .back ().v + simple_path_point.v ) / 2.0 ;
686+ const double dt = v_average != 0.0 ? (simple_path_point.s - route_plan.path .points .back ().s ) / v_average : 0.0 ;
678687 if (dt <= 0.0 ) {
679- std::string msg = " Negative time difference " + std::to_string (dt) +
680- " between points at s=" + std::to_string (route_plan.path .points .back ().s ) +
681- " and s=" + std::to_string (simple_path_point.s ) + " . Could lead to unexpected behavior." ;
688+ const std::string msg = " Negative time difference " + std::to_string (dt) +
689+ " between points at s=" + std::to_string (route_plan.path .points .back ().s ) +
690+ " and s=" + std::to_string (simple_path_point.s ) + " . Could lead to unexpected behavior." ;
682691 setHealth (diagnostic_msgs::msg::DiagnosticStatus::WARN , msg, health_.key_value_pairs );
683692 RCLCPP_WARN (this ->get_logger (), " %s" , msg.c_str ());
684693 }
@@ -700,8 +709,7 @@ void SimplePlannerNode::appendRoutePoints(const route_planning_msgs::msg::Route&
700709 }
701710
702711 route_plan.path .points .push_back (simple_path_point);
703-
704- if (j == tf_route.destination_route_element_idx - 1 ) {
712+ if (destination_is_present && j + 1 == destination_or_route_end_idx) {
705713 SimplePathPoint destination_point;
706714 destination_point.position = Eigen::Vector2d (tf_route.destination .x , tf_route.destination .y );
707715 destination_point.s = simple_path_point.s + (destination_point.position - simple_path_point.position ).norm ();
@@ -714,6 +722,12 @@ void SimplePlannerNode::appendRoutePoints(const route_planning_msgs::msg::Route&
714722 break ;
715723 }
716724 }
725+
726+ if (!destination_is_present && !route_plan.stop_at_end && t_total < 2.0 * trajectory_horizon_) {
727+ const std::string msg = " Local enriched route ends before the planner horizon; trajectory will end at its last element" ;
728+ setHealth (diagnostic_msgs::msg::DiagnosticStatus::WARN , msg, health_.key_value_pairs );
729+ RCLCPP_WARN (this ->get_logger (), " %s" , msg.c_str ());
730+ }
717731}
718732
719733bool SimplePlannerNode::tryRegisterLaneChange (const route_planning_msgs::msg::Route& tf_route,
0 commit comments