-
Notifications
You must be signed in to change notification settings - Fork 252
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
base: rolling
Are you sure you want to change the base?
Conversation
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.
lgtm with green CI.
@MichaelOrlov could you have 2nd 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.
@nicolaloi Thanks for the PR. Overall looks good among one undefined behavior / race introducing with the
if (!play_options_.start_paused) {
clock_->resume();
}
in Play method.
if (!play_options_.start_paused) { | ||
clock_->resume(); | ||
} |
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.
I can predict that after some time someone will complain and raise a new issue that when using a player with --loop
and --start-paused
delay
options and sending the pause service call request to the player somewhere at the end of the playback the request is ignored and player still will continue to playback from the beginning.
And we will have a hard time to debug this race condition, because of this resume
call.
cc: @fujitatomoya @hayato-m126
Ah yes, the clock will resume automatically at the next loop regardless of user requests. Then to not overcomplicate things, I would suggest removing the "pause clock until delay is over" feature from this PR, and keeping the "publish clock after the delay is over" feature only, which is the actual fix for issue #1858. Pausing the clock is not required to fix this specific issue since anyway the I was pausing the clock as a comprehensive "inner" change for the |
5576c77
to
0323e46
Compare
Signed-off-by: Nicola Loi <[email protected]>
0323e46
to
5f7da84
Compare
Removing
to keep the "pause clock until delay is over" feature only, but if it is not okay I can reintegrate and try to fix this "pause clock until delay is over" feature in this PR too. Extra change: now before sleeping for the delay period, the |
i prefer this approach, one thing at a time. and easier to backport to downstream distros. and the question here is that clock needs to be paused in delay duration? i am not quite sure about what state |
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 Thanks for addressing the comments from the review.
It looks good to me in the current form. However, I would move the delay out of the playback loop. IMO, there is no value in making a delay in the loop after we have finished the playback round.
Delay needs for the purporse to be able to wait for other nodes (subscribers and other dependend nodes in the pipeline) to start and be discoverable. When we have run the first playback round all other nodes still up un running. Thereofre, there is no need to make a delay on a consequent rounds of replay.
Okay, I will incorporate the change to the delay loop behavior in this PR. Need to invoke |
Signed-off-by: Nicola Loi <[email protected]>
Signed-off-by: Nicola Loi <[email protected]>
64bd7a4
to
cecd120
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 Thanks for the updates.
I think now it would be safe to init clock in pause mode in constructor and resume it after the delay. i.e.
clock_ = std::make_unique<rosbag2_cpp::TimeControllerClock>(
starting_time_, std::chrono::steady_clock::now,
std::chrono::milliseconds{100},
play_options_.start_paused || play_options_.delay > rclcpp::Duration(0, 0));
Also may I ask you in future do a separate commit after a round of review instead of push force the branch with the the same changed commit?
We are squashing all commits before merging to the target branch after review anyway automatically. However, the separate commits allow to keep history of changes during review.
{ | ||
std::lock_guard<std::mutex> lk(reader_mutex_); | ||
clock_->jump(starting_time_); | ||
} |
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.
We have already do clock_->jump(..)
just a few lines down. On line 502.
This one is redundant and should be removed IMO.
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.
I copied the jump before the loop because in this commit it needs to be called before starting the clock_publisher_timer
to avoid publishing a non-monotonic clock. But yes if I revert to pausing the clock until the delay is over, then it is not needed.
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.
@MichaelOrlov I think there could be issues with pausing the clock and resuming it after the delay. If the user commands a direct "pause" of the clock (via keyboard control or service) during the delay period, the clock will resume automatically after the delay regardless of the user's intent (#1861 (comment)). Another linked issue is if I remove the clock_->jump
call before starting clock_publisher_timer
, and the user resumes the clock during the delay period; then when the delay ends and the clock_publisher_timer
starts, the clock publisher could publish "future" timestamps before going back to the starting_time_
timestamp with the clock_->jump
call inside the loop.
clock_publish_timer
is now initialized withautostart = false
, so it doesn't immediately start publishing the/clock
topic. It is "activated" later withclock_publish_timer->reset()
at the beginning of the playback thread, ensuring that the (optional) user-defined delay period has passedAdditionally, the
clock_
now starts in a paused state if a delay time is specified by the user. It resumes after the delay period has ended.