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

Publish clock after delay is over and disable delay on next loops #1861

Merged
merged 5 commits into from
Dec 7, 2024
Merged
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
3 changes: 2 additions & 1 deletion ros2bag/ros2bag/verb/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def add_arguments(self, parser, cli_name): # noqa: D102
)
parser.add_argument(
'-d', '--delay', type=positive_float, default=0.0,
help='Sleep duration before play (each loop), in seconds. Negative durations invalid.')
help='Sleep duration before play (loops are not affected), in seconds.'
'Negative durations invalid.')
parser.add_argument(
'--playback-duration', type=float, default=-1.0,
help='Playback duration, in seconds. Negative durations mark an infinite playback. '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct PlayOptions
// a /clock update to be published. If list is empty, all topics will act as a trigger
std::vector<std::string> clock_trigger_topics = {};

// Sleep before play. Negative durations invalid. Will delay at the beginning of each loop.
// Sleep before play. Negative durations invalid. Loops are not affected.
rclcpp::Duration delay = rclcpp::Duration(0, 0);

// Determines the maximum duration of the playback. Negative durations will make the playback to
Expand Down
15 changes: 9 additions & 6 deletions rosbag2_transport/src/rosbag2_transport/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,19 +524,22 @@ bool PlayerImpl::play()
playback_thread_ = std::thread(
[&, delay]() {
try {
if (delay > rclcpp::Duration(0, 0)) {
RCLCPP_INFO_STREAM(owner_->get_logger(), "Sleep " << delay.nanoseconds() << " ns");
std::chrono::nanoseconds delay_duration(delay.nanoseconds());
std::this_thread::sleep_for(delay_duration);
}
do {
if (delay > rclcpp::Duration(0, 0)) {
RCLCPP_INFO_STREAM(owner_->get_logger(), "Sleep " << delay.nanoseconds() << " ns");
std::chrono::nanoseconds delay_duration(delay.nanoseconds());
std::this_thread::sleep_for(delay_duration);
}
{
std::lock_guard<std::mutex> lk(reader_mutex_);
for (const auto & [reader, _] : readers_with_options_) {
reader->seek(starting_time_);
}
clock_->jump(starting_time_);
}
if (clock_publish_timer_ != nullptr) {
clock_publish_timer_->reset();
}
load_storage_content_ = true;
storage_loading_future_ = std::async(
std::launch::async, [this]() {
Expand Down Expand Up @@ -1165,7 +1168,7 @@ void PlayerImpl::prepare_publishers()
clock_publish_timer_ = owner_->create_wall_timer(
publish_period, [this]() {
publish_clock_update();
});
}, nullptr, false);
}

if (play_options_.clock_publish_on_topic_publish) {
Expand Down
Loading