From 47dff3d1bfa4ccfb18354084c28993f96763ae5f Mon Sep 17 00:00:00 2001 From: Nicola Loi Date: Thu, 5 Dec 2024 22:06:34 +0000 Subject: [PATCH] Progress bar with nanosecond precision and shorter length Signed-off-by: Nicola Loi --- rosbag2_transport/src/rosbag2_transport/player.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rosbag2_transport/src/rosbag2_transport/player.cpp b/rosbag2_transport/src/rosbag2_transport/player.cpp index fc2ecb42a..17f093190 100644 --- a/rosbag2_transport/src/rosbag2_transport/player.cpp +++ b/rosbag2_transport/src/rosbag2_transport/player.cpp @@ -579,6 +579,8 @@ bool PlayerImpl::play() } RCLCPP_INFO_STREAM(owner_->get_logger(), "Playback until timestamp: " << play_until_timestamp_); + RCLCPP_INFO_STREAM(owner_->get_logger(), "Duration of the rosbag: " << std::fixed << + std::setprecision(9) << duration_secs_ << " s"); // May need to join the previous thread if we are calling play() a second time if (playback_thread_.joinable()) { @@ -1742,8 +1744,10 @@ void PlayerImpl::print_progress_bar_help_str() const help_str = oss.str(); } RCLCPP_INFO_STREAM(owner_->get_logger(), help_str); - std::string help_str2 = "Progress bar [?]: [R]unning, [P]aused, [B]urst, [D]elayed"; + std::string help_str2 = "Progress bar t: time, d: duration"; RCLCPP_INFO_STREAM(owner_->get_logger(), help_str2); + std::string help_str3 = "Progress bar [?]: [R]unning, [P]aused, [B]urst, [D]elayed"; + RCLCPP_INFO_STREAM(owner_->get_logger(), help_str3); } else { help_str = "Progress bar disabled"; RCLCPP_INFO_STREAM(owner_->get_logger(), help_str); @@ -1795,10 +1799,12 @@ void PlayerImpl::cout_progress_bar( const double current_time_secs = RCUTILS_NS_TO_S(static_cast(timestamp)); const double progress_secs = current_time_secs - starting_time_secs_; // Print progress bar ending with carriage return '/r' so it will be overwritten by next print + // Spaces before '\r' are to clear any previous progress bar in case the new one is shorter, + // which can happen when the playback starts a new loop. std::ostringstream oss; - oss << " Bag Time " << std::setw(13) << std::fixed << std::setprecision(6) << - current_time_secs << " Duration " << std::setprecision(3) << progress_secs << - "/" << duration_secs_ << " [" << static_cast(status) << "] \r"; + oss << " Bag t: " << std::setw(13) << std::fixed << std::setprecision(9) << + current_time_secs << " d: " << std::setprecision(9) << progress_secs << + " [" << static_cast(status) << "] \r"; std::cout << oss.str() << std::flush; }