Skip to content
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

Open
wants to merge 17 commits into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/design/rosbag2_record_replay_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ Added or changed parameters:

Rename from `--exclude`. Exclude topics and services containing provided regular expression.

- `--progress-bar [ProgressBarFrequency]`

Print a progress bar of the playback player at a specific frequency in Hz. Negative values mark an update for every published message, while a zero value disables the progress bar. Default to a positive low value.

`-e REGEX, --regex REGEX` affects both topics and services.

## Implementation Staging
Expand Down
20 changes: 20 additions & 0 deletions ros2bag/ros2bag/verb/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ def add_arguments(self, parser, cli_name): # noqa: D102
'--log-level', type=str, default='info',
choices=['debug', 'info', 'warn', 'error', 'fatal'],
help='Logging level.')
parser.add_argument(
'--progress-bar', type=float, default=3.0,
help='Print a progress bar of the playback player at a specific frequency in Hz. '
'Default is %(default)d. '
'Negative values mark an update for every published message, while '
' a zero value disables the progress bar.',
metavar='PROGRESS_BAR_FREQUENCY')
parser.add_argument(
'--progress-bar-separation-lines', type=check_not_negative_int, default=2,
help='Number of lines to separate the progress bar from the rest of the '
'playback player output. Negative values are invalid. Default is %(default)d. '
'This option makes sense only if the progress bar is enabled. '
'Large values are useful if external log messages from other nodes are shorter '
'than the progress bar string and are printed at a rate higher than the '
'progress bar update rate. In these cases, a larger value will avoid '
'the external log message to be mixed with the progress bar string.',
metavar='SEPARATION_LINES')

def get_playback_until_from_arg_group(self, playback_until_sec, playback_until_nsec) -> int:
nano_scale = 1000 * 1000 * 1000
Expand Down Expand Up @@ -292,6 +309,9 @@ def main(self, *, args): # noqa: D102
'sent': MessageOrder.SENT_TIMESTAMP,
}.get(args.message_order)

play_options.progress_bar_update_rate = args.progress_bar
play_options.progress_bar_separation_lines = args.progress_bar_separation_lines

player = Player(args.log_level)
try:
player.play(storage_options, play_options)
Expand Down
2 changes: 2 additions & 0 deletions rosbag2_py/rosbag2_py/_transport.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class PlayOptions:
node_prefix: str
playback_duration: float
playback_until_timestamp: int
progress_bar_separation_lines: int
progress_bar_update_rate: float
publish_service_requests: bool
rate: float
read_ahead_queue_size: int
Expand Down
2 changes: 2 additions & 0 deletions rosbag2_py/src/rosbag2_py/_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ PYBIND11_MODULE(_transport, m) {
"playback_until_timestamp",
&PlayOptions::getPlaybackUntilTimestamp,
&PlayOptions::setPlaybackUntilTimestamp)
.def_readwrite("progress_bar_update_rate", &PlayOptions::progress_bar_update_rate)
.def_readwrite("progress_bar_separation_lines", &PlayOptions::progress_bar_separation_lines)
.def_readwrite("wait_acked_timeout", &PlayOptions::wait_acked_timeout)
.def_readwrite("disable_loan_message", &PlayOptions::disable_loan_message)
.def_readwrite("publish_service_requests", &PlayOptions::publish_service_requests)
Expand Down
7 changes: 7 additions & 0 deletions rosbag2_transport/include/rosbag2_transport/play_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ struct PlayOptions
// replayed messages may not be correctly ordered. A possible solution could be to increase the
// read_ahead_queue_size value to buffer (and order) more messages.
MessageOrder message_order = MessageOrder::RECEIVED_TIMESTAMP;

// Rate in Hz at which to print progress bar.
double progress_bar_update_rate = 3.0;

// Number of separation lines to print in between the playback output
// and the progress bar.
int progress_bar_separation_lines = 3;
};

} // namespace rosbag2_transport
Expand Down
9 changes: 9 additions & 0 deletions rosbag2_transport/src/rosbag2_transport/play_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ Node convert<rosbag2_transport::PlayOptions>::encode(

node["disable_loan_message"] = play_options.disable_loan_message;

node["progress_bar_update_rate"] = play_options.progress_bar_update_rate;
node["progress_bar_separation_lines"] = play_options.progress_bar_separation_lines;

return node;
}

Expand Down Expand Up @@ -114,6 +117,12 @@ bool convert<rosbag2_transport::PlayOptions>::decode(

optional_assign<bool>(node, "disable_loan_message", play_options.disable_loan_message);

optional_assign<double>(
node, "progress_bar_update_rate", play_options.progress_bar_update_rate);

optional_assign<int>(
node, "progress_bar_separation_lines", play_options.progress_bar_separation_lines);

return true;
}

Expand Down
Loading
Loading