Skip to content

Commit

Permalink
Progress bar with nanosecond precision and shorter length
Browse files Browse the repository at this point in the history
Signed-off-by: Nicola Loi <[email protected]>
  • Loading branch information
nicolaloi committed Dec 5, 2024
1 parent 0ef3f26 commit 47dff3d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions rosbag2_transport/src/rosbag2_transport/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1795,10 +1799,12 @@ void PlayerImpl::cout_progress_bar(
const double current_time_secs = RCUTILS_NS_TO_S(static_cast<double>(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<char>(status) << "] \r";
oss << " Bag t: " << std::setw(13) << std::fixed << std::setprecision(9) <<
current_time_secs << " d: " << std::setprecision(9) << progress_secs <<
" [" << static_cast<char>(status) << "] \r";
std::cout << oss.str() << std::flush;
}

Expand Down

0 comments on commit 47dff3d

Please sign in to comment.