@@ -357,7 +357,7 @@ void PerceptionReplayerCommon::publish_topics_at_timestamp(
357357 }
358358
359359 if (param_.replay_route ) {
360- publish_route_at_timestamp (bag_timestamp);
360+ publish_route_at_timestamp (bag_timestamp, current_timestamp );
361361 }
362362}
363363
@@ -410,7 +410,8 @@ void PerceptionReplayerCommon::publish_reference_images_at_timestamp(
410410 }
411411}
412412
413- void PerceptionReplayerCommon::publish_route_at_timestamp (const rclcpp::Time & bag_timestamp)
413+ void PerceptionReplayerCommon::publish_route_at_timestamp (
414+ const rclcpp::Time & bag_timestamp, const rclcpp::Time & current_timestamp)
414415{
415416 // Helper: find the index of the last message at or before bag_timestamp.
416417 // Returns nullopt if there is no such message.
@@ -436,17 +437,33 @@ void PerceptionReplayerCommon::publish_route_at_timestamp(const rclcpp::Time & b
436437 if (!rosbag_route_data_.empty ()) {
437438 const auto idx = find_last_before (rosbag_route_data_, bag_timestamp);
438439 if (idx.has_value () && last_published_route_idx_ != idx.value ()) {
439- route_pub_->publish (rosbag_route_data_[idx.value ()].second );
440+ auto route_msg = rosbag_route_data_[idx.value ()].second ;
441+ route_msg.header .stamp = current_timestamp;
442+ route_pub_->publish (route_msg);
440443 last_published_route_idx_ = idx.value ();
441444 }
442445 }
443446
444- // route state
447+ // route state: publish when bag index changes, or re-publish every 5s (replay time)
445448 if (!rosbag_route_state_data_.empty ()) {
446449 const auto idx = find_last_before (rosbag_route_state_data_, bag_timestamp);
447- if (idx.has_value () && last_published_route_state_idx_ != idx.value ()) {
448- route_state_pub_->publish (rosbag_route_state_data_[idx.value ()].second );
449- last_published_route_state_idx_ = idx.value ();
450+ if (idx.has_value ()) {
451+ const bool index_changed =
452+ !last_published_route_state_idx_.has_value () ||
453+ last_published_route_state_idx_.value () != idx.value ();
454+ constexpr double k_route_state_republish_period_sec = 10.0 ;
455+ const bool period_elapsed =
456+ !last_route_state_publish_replay_time_.has_value () ||
457+ (current_timestamp - last_route_state_publish_replay_time_.value ()).seconds () >=
458+ k_route_state_republish_period_sec;
459+
460+ if (index_changed || period_elapsed) {
461+ auto route_state_msg = rosbag_route_state_data_[idx.value ()].second ;
462+ route_state_msg.stamp = current_timestamp;
463+ route_state_pub_->publish (route_state_msg);
464+ last_published_route_state_idx_ = idx.value ();
465+ last_route_state_publish_replay_time_ = current_timestamp;
466+ }
450467 }
451468 }
452469}
0 commit comments