-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Progress-bar for ros2 bag play #1836
base: rolling
Are you sure you want to change the base?
Progress-bar for ros2 bag play #1836
Conversation
Signed-off-by: Nicola Loi <[email protected]>
video-example.mp4(at 2.6-2.7 seconds of bag duration, the progress bar is slightly updating while in paused state because I was clicking the left arrow for the play next keyboard control) Since [INFO] [1729028986.845909253] [rosbag2_player]: Pausing play.
Bag Time 1718553782.525239 Duration 1.272325/6.974378 [P] while this longer version of the progress bar doesn't work properly without extra line clearing (in this case, it's easy to clear the line since the logs come from rosbag2_player., but for "external" logs, this becomes more difficult): [INFO] [1729028986.845909253] [rosbag2_player]: Pausing play.us:Running]
Bag Time 1718553782.525239 Duration 1.272325/6.974378 [status:Paused] @MichaelOrlov looking forward to your feedback, for now I have made a test MVP code to check the feasibility of the feature. |
Signed-off-by: Nicola Loi <[email protected]>
d503e5f
to
2cb732d
Compare
Signed-off-by: Nicola Loi <[email protected]>
b815f9e
to
4ba1a8c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolaloi Thank you for your contribution.
I have a few concerns about the design and implementation.
First, we need to limit the frequency with which we will print in std::cout
. The best way to do this is to create a local variable, aka size_t progress_bar_update_freq_
(in Hz).
e.g. 1 Hz = once per/sec, 2 Hz = twice per second, 3 = three times per second etc..
Then, check the delay between the last call in the print_status(..)
. If the delay is more than the threshold, print; otherwise, skip.
We also need to move the check for the if (disable_progress_bar_)
inside print_status(..)
to make the logic cleaner and in one place.
Calling double current_time_secs = RCUTILS_NS_TO_S(static_cast<double>(clock_->now()));
each time in the print_status(..)
is very inefficient and expensive since we are locking mutex inside and transorming current time to the ROS time. We actually know the current ROS time at which we are playing. This is a timestamp from the message. I would suggest passing it to the print function as a parameter.
i.e., add tiemstamp parameter to the print_status(..)
function and use message_ptr->recv_timestamp
as a source of timestamp.
I found the implementation of the print_status(..)
function a bit messy.
That is a quintessence of the modern C++17 with templates and old style plain C code.
Need to avoid using C code. Please use C++ alternatives. I am not sure if we really need to flush buffer each time. Flush is an expensive operation since this is a blocking system call. Need to avoid it if possible.
IMO templating print_status(..)
function is overengineering and make code less readable and less understandable. The cleaner solution would be if using enum class values for different modes. In this case all extra wrappers like check_and_print_status()
will not be needed. We will be able to call print_status(PrintStatus::Paused)
directly from where we needed it.
@MichaelOrlov thanks for the comments.
Should the progress bar be disabled by default, or enabled by default with a default low update frequency? |
253256a
to
44fa94a
Compare
Signed-off-by: Nicola Loi <[email protected]>
Signed-off-by: Nicola Loi <[email protected]>
44fa94a
to
43fa0f8
Compare
I have made changes as discussed. Linked modifications: I have modified the
|
@nicolaloi I have not had a chance yet to look deeply into the code after your latest changes. However, I have a few comments.
|
Ok, I'll set the default rate to 3 Hz. For 2nd and 3rd points, there is no longer the |
Signed-off-by: Nicola Loi <[email protected]>
eb9ea35
to
9cdf5ad
Compare
I have realized the newly added variables |
Signed-off-by: Nicola Loi <[email protected]>
Signed-off-by: Nicola Loi <[email protected]>
@MichaelOrlov So, to avoid synchronization issues without using mutexes, etc to not increase overhead, the variable Regarding how to print the current timestamp: when a message is published, the Extras:
|
Signed-off-by: Nicola Loi <[email protected]>
Signed-off-by: Nicola Loi <[email protected]>
Signed-off-by: Nicola Loi <[email protected]>
@nicolaloi Could you please rebase your branch and address conflicts one more time? |
Signed-off-by: Nicola Loi <[email protected]>
Signed-off-by: Nicola Loi <[email protected]>
@xqms thanks for the suggestions. Adding extra lines is indeed a good idea to mitigate the problem. External user's log messages shorter than the progress bar string can still be smashed, but the extra lines give more safety margin.
Due to this, I have added an extra option, video_example.mp4From the video, you can see that with 3 external log messages (with one being a short message), you could encounter some issues with 2,1, and 0 separation lines. General rule: if between two progress bar updates you are expecting N external log messages and at least one is shorter than the progress bar strings, then you should set at least N However, if the external log messages are longer than the progress bar strings, or there will be less than "default separation lines" (2) external log messages between two progress bar updates, then everything is ok by default. Moreover, this is an issue only if the user has his own log messages on the same output of the playback player and the progress bar is enabled. @MichaelOrlov I have also added the separator line ( |
Signed-off-by: Nicola Loi <[email protected]>
friendly ping |
@nicolaloi Sorry for the delay with the review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @nicolaloi. Thanks for your contributions.
The code needs to be refactored to adhere to the single responsibility principle.
The progress bar is a good candidate to be a separate self-contained class and software component with its own properties and behavior which should be covered by unit tests.
I've made such refactoring as well as many other fixes as I think make sense for progress bar implementation.
Please review and feel free to cherry-pick my changes in a separate draft PR here https://github.com/ros2/rosbag2/pull/1902/files/c4a723136795a54ce09865655fb32ce8a597d9f6..42e5134e76c2eed227e3797a660ec9340c9f2a77.
Please note that c4a7231 commit is all your commits from this PR squashed in one and rebased on top of latest master and the rest are mine.
Also please implement the missing unit test for the progress bar mentioned as TODO here 42e5134. The progress bar now can output to a provided std::ostringstream
during construction. That should simplify writing unit tests to be able to deterministically verify output from it.
Yes at the very beginning, the progress bar was a separate class (not a pointer to implementation though) but then I integrated it in the player class in commit 4ba1a8c. Regarding the tests, I was waiting for a definite "progress bar style". |
* Add test_xmllint.py to python packages. This ensures we'll detect any invalid XML in e.g. the package.xml Signed-off-by: Chris Lalancette <[email protected]> * Add in test_depend on ament_xmllint. Signed-off-by: Chris Lalancette <[email protected]> --------- Signed-off-by: Chris Lalancette <[email protected]>
…os2#1881) Signed-off-by: Michael Orlov <[email protected]>
Signed-off-by: Yadunund <[email protected]>
…1888) Signed-off-by: Michael Orlov <[email protected]>
…#1894) * Invert start discovery condition Repeated calls to start_discovery should not start additional topics discovery tasks without stop_discovery calls Signed-off-by: Øystein Sture <[email protected]> * Rename stop_discovery to discovery_running and change logic accordingly Signed-off-by: Øystein Sture <[email protected]> --------- Signed-off-by: Øystein Sture <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
- Rationale: We will update progress bar with check rate from main playback loop even in burst mode. Signed-off-by: Michael Orlov <[email protected]>
- Rationale: To adhere single responsibility principle Signed-off-by: Michael Orlov <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
- Also added appropriate Doxygen comments for public API Signed-off-by: Michael Orlov <[email protected]>
- Rationale: To be able to redirect progress bar output to the std::ostringstream in unit tests. Signed-off-by: Michael Orlov <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
- The progress_bar_update_period_ms_ equal to 0 means update always. - Also use integer arithmetic for the sake of performance. Signed-off-by: Michael Orlov <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
Signed-off-by: Nicola Loi <[email protected]>
Signed-off-by: Nicola Loi <[email protected]>
|
Closes #1762: Adds a progress bar for
ros2 bag play
, showing the bag time and duration, similar to what is seen in ROS1.In ROS1, the progress bar was easy to handle because the
rosbag play
command didn't print additional output during playback. However, in ROS2, many logs can be printed during playback (e.g., keyboard control logs).The progress bar is printed and continuously updated on the last line of the playback output. I have tested this initial implementation with keyboard controls (play, pause, play next, set rate), Ctrl+C, throwing an exception, and the flags
--log-level debug
,--delay X
, and--start-offset X
.To try it, use the new
--progress-bar
flag when playing a bag.