Skip to content

Commit 15b8260

Browse files
authored
Publish clock after delay is over and disable delay on next loops (#1861)
* publish clock after the delay is over Signed-off-by: Nicola Loi <[email protected]> * Disable delay period in subsequent loops (ros2 bag play) Signed-off-by: Nicola Loi <[email protected]> * Reset clock publisher timer outisde playback loop Signed-off-by: Nicola Loi <[email protected]> * review Signed-off-by: Nicola Loi <[email protected]> --------- Signed-off-by: Nicola Loi <[email protected]>
1 parent c8feaea commit 15b8260

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

Diff for: ros2bag/ros2bag/verb/play.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ def add_arguments(self, parser, cli_name): # noqa: D102
103103
)
104104
parser.add_argument(
105105
'-d', '--delay', type=positive_float, default=0.0,
106-
help='Sleep duration before play (each loop), in seconds. Negative durations invalid.')
106+
help='Sleep duration before play (loops are not affected), in seconds.'
107+
'Negative durations invalid.')
107108
parser.add_argument(
108109
'--playback-duration', type=float, default=-1.0,
109110
help='Playback duration, in seconds. Negative durations mark an infinite playback. '

Diff for: rosbag2_transport/include/rosbag2_transport/play_options.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct PlayOptions
8383
// a /clock update to be published. If list is empty, all topics will act as a trigger
8484
std::vector<std::string> clock_trigger_topics = {};
8585

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

8989
// Determines the maximum duration of the playback. Negative durations will make the playback to

Diff for: rosbag2_transport/src/rosbag2_transport/player.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -524,19 +524,22 @@ bool PlayerImpl::play()
524524
playback_thread_ = std::thread(
525525
[&, delay]() {
526526
try {
527+
if (delay > rclcpp::Duration(0, 0)) {
528+
RCLCPP_INFO_STREAM(owner_->get_logger(), "Sleep " << delay.nanoseconds() << " ns");
529+
std::chrono::nanoseconds delay_duration(delay.nanoseconds());
530+
std::this_thread::sleep_for(delay_duration);
531+
}
527532
do {
528-
if (delay > rclcpp::Duration(0, 0)) {
529-
RCLCPP_INFO_STREAM(owner_->get_logger(), "Sleep " << delay.nanoseconds() << " ns");
530-
std::chrono::nanoseconds delay_duration(delay.nanoseconds());
531-
std::this_thread::sleep_for(delay_duration);
532-
}
533533
{
534534
std::lock_guard<std::mutex> lk(reader_mutex_);
535535
for (const auto & [reader, _] : readers_with_options_) {
536536
reader->seek(starting_time_);
537537
}
538538
clock_->jump(starting_time_);
539539
}
540+
if (clock_publish_timer_ != nullptr) {
541+
clock_publish_timer_->reset();
542+
}
540543
load_storage_content_ = true;
541544
storage_loading_future_ = std::async(
542545
std::launch::async, [this]() {
@@ -1165,7 +1168,7 @@ void PlayerImpl::prepare_publishers()
11651168
clock_publish_timer_ = owner_->create_wall_timer(
11661169
publish_period, [this]() {
11671170
publish_clock_update();
1168-
});
1171+
}, nullptr, false);
11691172
}
11701173

11711174
if (play_options_.clock_publish_on_topic_publish) {

0 commit comments

Comments
 (0)