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

Add delay option #789

Merged
merged 11 commits into from
Jul 6, 2021
Merged

Add delay option #789

merged 11 commits into from
Jul 6, 2021

Conversation

kosuke55
Copy link
Contributor

Hi, thank you for your work.
In this PR I added --delay option related to #786.
If we run for the following, the rosbag will play after a 5 second sleep.

ros2 bag play <rosbag2 file> -d 5

It also works with --loop like

ros2 bag play <rosbag2 file> -d 5 -l

@kosuke55 kosuke55 requested a review from a team as a code owner June 23, 2021 14:19
@kosuke55 kosuke55 requested review from Karsten1987 and zmichaels11 and removed request for a team June 23, 2021 14:19
Copy link
Contributor

@zmichaels11 zmichaels11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR!

I left a couple comments/suggestions.

@@ -215,6 +215,13 @@ void Player::play()
is_in_play_ = true;
try {
do {
float delay =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move delay out of the loop? I don't think it can change between iterations.

I'd also suggest raising a warning or exception when delay is an invalid value. That way the user knows when they enter an invalid value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it out of the loop. And raising warning and set to 0 if dealy value is invalid. 0b4687f

@@ -43,6 +43,8 @@ TEST_F(RosBag2PlayTestFixture, play_bag_file_twice) {
const size_t read_ahead_queue_size = 1000;
const float rate = 1.0;
const bool loop_playback = false;
double clock_publish_frequency = 0.0;
const float delay = 1.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also test for an invalid delay value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added tests for delay in dfee76a.

@danthony06
Copy link

I know at one point there was a plan to implement node lifecycles for rosbag. Is this still the case, because this seems like a case where it would fit in really well.

@kosuke55
Copy link
Contributor Author

@zmichaels11
Thaks for your review. I modified so please check them.

@@ -116,6 +119,7 @@ def main(self, *, args): # noqa: D102
play_options.loop = args.loop
play_options.topic_remapping_options = topic_remapping
play_options.clock_publish_frequency = args.clock
play_options.delay=args.delay
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter is failing on this line - it will help you to run the tests locally before putting up for review!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thaks for your review and advice. I modified it and checked that test_flake8.py paased. 1c0cbff

@emersonknapp
Copy link
Collaborator

I know at one point there was a plan to implement node lifecycles for rosbag. Is this still the case, because this seems like a case where it would fit in really well.

There isn't an active effort going on - I don't personally have a concrete idea what this would look like. We could take that discussion to another issue if we want to pick it up. With some quick diagrams or something showing what we would want.

@emersonknapp
Copy link
Collaborator

Looking very close - you will need to sign your commits for the DCO check to pass. You can do that with git rebase master --signoff

@kosuke55
Copy link
Contributor Author

@emersonknapp
Oh, sorry and thaks. I did that.

@emersonknapp
Copy link
Collaborator

Gist: https://gist.githubusercontent.com/emersonknapp/df22ce71e23066faa49f1ad4b777faee/raw/e66eb02dae79a8dbe4184fb2c6bf28be493f1741/ros2.repos
BUILD args: --packages-up-to ros2bag rosbag2_py rosbag2_transport rosbag2 rosbag2_tests
TEST args: --packages-select ros2bag rosbag2_py rosbag2_transport rosbag2 rosbag2_tests
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/8646

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@emersonknapp
Copy link
Collaborator

The Windows runners are very slow - and so timing-based tests don't always work the way you would expect there. Is there any deterministic way to check on this test, without depending on actual timing? (worst case, we could just expand the error margin to accommodate these slow runners)

@kosuke55
Copy link
Contributor Author

kosuke55 commented Jul 1, 2021

@emersonknapp
hmm, I can't think of any other way than using the actual time.
This test was made with reference to other parts. Other tests have a fairly large margin .

ASSERT_THAT(replay_time, Gt(0.5 * message_time_difference));
ASSERT_THAT(replay_time, Lt(message_time_difference));

I don't think there are many cases where we actually want to delay by 0.x seconds, so how about simply increasing the margin (1.0, etc.)?

@kosuke55
Copy link
Contributor Author

kosuke55 commented Jul 1, 2021

And this test is included in the rate test, but it's better to separate them.

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
auto reader = std::make_unique<rosbag2_cpp::Reader>(std::move(prepared_mock_reader));
auto player = std::make_shared<rosbag2_transport::Player>(
std::move(
reader), storage_options_, play_options_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick. It would be better if

    std::move(
        reader), storage_options_, play_options_);

would be on one line

    std::move(reader), storage_options_, play_options_);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I modified all same part in 75eca9f.

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
@emersonknapp
Copy link
Collaborator

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@kosuke55
Copy link
Contributor Author

kosuke55 commented Jul 5, 2021

@emersonknapp
Is there anything else I need to fix in this code? If not, I would like to send a same PR for the galactic branch as well.

@emersonknapp emersonknapp merged commit bd665cb into ros2:master Jul 6, 2021
@emersonknapp
Copy link
Collaborator

No - nothing left. I just didn't look at it over the holiday weekend. Please feel free to open a Galactic backport PR

kosuke55 added a commit to kosuke55/rosbag2 that referenced this pull request Jul 7, 2021
* Add delay option

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
@wep21 wep21 deleted the feature/delay branch July 7, 2021 17:33
emersonknapp pushed a commit that referenced this pull request Jul 8, 2021
Backport #789 to galactic

* Add delay option

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants