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 play-for functionality #960

Merged
merged 9 commits into from
Jun 2, 2022
Merged

Conversation

gbiggs
Copy link
Member

@gbiggs gbiggs commented Feb 15, 2022

This PR adds the ability to play for a specified number of seconds.

This work was co-authored by @agalbachicar.

@gbiggs gbiggs marked this pull request as ready for review February 15, 2022 12:46
@gbiggs gbiggs requested a review from a team as a code owner February 15, 2022 12:46
Copy link
Contributor

@MichaelOrlov MichaelOrlov left a comment

Choose a reason for hiding this comment

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

@gbiggs Thank you for your contribution.
I like the idea with adding possibility to play recorded bag file until some specified timestamp.
Although it would be nice to add one more parameter to be able to start playback after some timestamp.

I have some comments to the design.
In particular the way how duration for playback passing to the player. It's passing as separate parameter to the constructor and other method of the class. Which is kind of going against our generic design which is follow the rule that all parameters should be passed via PlayOptions data structure.
Also duration parameter uses std::optional<rcutils_duration_value_t> type with optional wrapper from C++17. While we are currently formally supporting compilation C++17 code we are trying to avoid new C++17 primitives in Rosbag2 at least.
Especially in this particular case it will be better to use rclcpp::Duration data type, and use some constant with negative value for indicating None value.
We have done recently similar feature for delaying playback for some amount of time. Please refer to the #789 and #843. Where we are using rclcpp::Duration for delay value.
Also I think it will be reasonable to define command line parameter to be as floating point value to be able more precisely specify timestamp until which need to playback. Please refer to the example of how it was done for delay parameter in https://github.com/ros2/rosbag2/pull/843/files

Another comment for the API in PlayFor.srv service it would be nice to define it more generic as "Play.srv" and provide two parameters start_time and duration

I also have concern about the way how unit tests written with usage of the newly added spin_subscriptions_for(duration);.
In particular tests TEST_F(RosBag2PlayForTestFixture, play_for_none_are_played_due_to_duration) and TEST_F(RosBag2PlayForTestFixture, play_for_less_than_the_total_duration) are going to be very flaky.
Since relying on the real time delay in tests is non deterministic approach which is always leading to the flakiness on the heavy loaded machines in CI.
Also please use subscription_manager, PublicationManager and wait_for_matched methods to avoid lost messages and flakiness in unit tests.

ros2bag/ros2bag/verb/play.py Outdated Show resolved Hide resolved
rosbag2_transport/CMakeLists.txt Outdated Show resolved Hide resolved
rosbag2_transport/src/rosbag2_transport/player.cpp Outdated Show resolved Hide resolved
rosbag2_transport/src/rosbag2_transport/player.cpp Outdated Show resolved Hide resolved
rosbag2_transport/src/rosbag2_transport/player.cpp Outdated Show resolved Hide resolved
rosbag2_transport/test/rosbag2_transport/test_play_for.cpp Outdated Show resolved Hide resolved
rosbag2_transport/test/rosbag2_transport/test_play_for.cpp Outdated Show resolved Hide resolved
@gbiggs
Copy link
Member Author

gbiggs commented Mar 16, 2022

@MichaelOrlov: @agalbachicar has addressed your comments. Can you please re-review?

@MichaelOrlov
Copy link
Contributor

@gbiggs I am a bit confused. As far as I can see you add new command line parameter --playback_duration which is hosted inside playback_options and has type rclcpp::Duration which is very good 👍
However the old parameter -duration still there.
Did you forget to remove it?

Copy link
Contributor

@MichaelOrlov MichaelOrlov left a comment

Choose a reason for hiding this comment

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

@gbiggs Thank you for your effort. I think It's get very close to be good to go.
Please see my comments.

rosbag2_interfaces/srv/Play.srv Outdated Show resolved Hide resolved
rosbag2_interfaces/srv/PlayFor.srv Outdated Show resolved Hide resolved
rosbag2_py/src/rosbag2_py/_transport.cpp Outdated Show resolved Hide resolved
rosbag2_py/src/rosbag2_py/_transport.cpp Outdated Show resolved Hide resolved
rosbag2_transport/src/rosbag2_transport/player.cpp Outdated Show resolved Hide resolved
rosbag2_transport/src/rosbag2_transport/player.cpp Outdated Show resolved Hide resolved
rosbag2_transport/src/rosbag2_transport/player.cpp Outdated Show resolved Hide resolved
rosbag2_transport/test/rosbag2_transport/test_play_for.cpp Outdated Show resolved Hide resolved
rosbag2_transport/test/rosbag2_transport/test_play_for.cpp Outdated Show resolved Hide resolved
gbiggs pushed a commit to gbiggs/rosbag2 that referenced this pull request Mar 17, 2022
* Removes duration parameter. A leftover after switching to playback_duration.

* Fixes comment.

* Solves format in rosbag2_py -> _transport.cpp

* Applies style suggestions.

* Changes play() to return a boolean indicating whether the request could be fulfilled.

* Removes extra unnecessary code.
Copy link
Contributor

@MichaelOrlov MichaelOrlov left a comment

Choose a reason for hiding this comment

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

@gbiggs I have only one nitpick for the implementation, in checking atomic variable.

Although I have a concern in regards to the tests execution time.
I've tried to run newly added tests locally on my machine and it turns out that running time for newly added test_play_for test suite taking around 1 minute. Most of the newly added tests running in 10 sec.
This is too much. Need to redesign tests to run them faster.

I already reworked one last test play_should_return_false_when_interrupted to be deterministic and run faster. See my comments in line.
Please take a look on the idea and rework other tests.

rosbag2_transport/src/rosbag2_transport/player.cpp Outdated Show resolved Hide resolved
rosbag2_transport/test/rosbag2_transport/test_play_for.cpp Outdated Show resolved Hide resolved
rosbag2_transport/test/rosbag2_transport/test_play_for.cpp Outdated Show resolved Hide resolved
gbiggs pushed a commit to gbiggs/rosbag2 that referenced this pull request Mar 22, 2022
* Adresses reviewer's comments.

* Improve test time by adding an optional argument to SubscriptionManager::spin_subscriptions()

- Reduces test_play_for execution time from 50s to 6s approximately.
@agalbachicar
Copy link
Contributor

@MichaelOrlov I see an error in the last build here. Where can I see the build configuration to try to reproduce it and determine whether it is because of this PR or a preexisting problem?

@MichaelOrlov
Copy link
Contributor

@agalbachicar I don't quite understand what build configuration you are talking about.
Form the first glance I have a suspicious that tests failures relates to your changes in spin_subscriptions()

@MichaelOrlov
Copy link
Contributor

After a more detailed look in the code I think that your changes in spin_subscription doesn't relate to the tests failures.
It looks like failures on the CI baseline.

Copy link
Contributor

@MichaelOrlov MichaelOrlov left a comment

Choose a reason for hiding this comment

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

@agalbachicar @gbiggs It was to tedious making a lot of comments and propose changes on code review.
I prepared all proposed changes on separate branch gbiggs#17

I had a concern that after last changes tests still rely on the assumption that subscription waiting for N messages however in tests valid expectation that it will be published less then N` messages or nothing. And waiting time reduced to the 1 second.
Such assumption tend to make tests false negative or flaky due to the possible delays on CI.

Please consider to merge my changes on your branch as result of the code review.

@gbiggs
Copy link
Member Author

gbiggs commented Mar 28, 2022

@MichaelOrlov Thank you for making those improvements. I have incorporated them into the PR's branch.

Copy link
Contributor

@MichaelOrlov MichaelOrlov left a comment

Choose a reason for hiding this comment

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

@gbiggs Approving now.
However need to fix DCO and run CI pipeline.

gbiggs pushed a commit to gbiggs/rosbag2 that referenced this pull request Mar 30, 2022
* Removes duration parameter. A leftover after switching to playback_duration.

* Fixes comment.

* Solves format in rosbag2_py -> _transport.cpp

* Applies style suggestions.

* Changes play() to return a boolean indicating whether the request could be fulfilled.

* Removes extra unnecessary code.

Signed-off-by: Geoffrey Biggs <gbiggs@killbots.net>
gbiggs pushed a commit to gbiggs/rosbag2 that referenced this pull request Mar 30, 2022
* Adresses reviewer's comments.

* Improve test time by adding an optional argument to SubscriptionManager::spin_subscriptions()

- Reduces test_play_for execution time from 50s to 6s approximately.

Signed-off-by: Geoffrey Biggs <gbiggs@killbots.net>
@gbiggs
Copy link
Member Author

gbiggs commented Mar 30, 2022

CI (build --packages-up-to rosbag2, test --packages-select ros2bag rosbag2_py rosbag2_transport):

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

@gbiggs
Copy link
Member Author

gbiggs commented Mar 30, 2022

The Windows CI errors appear to be infrastructure failures, so I'm going to try again:

Build Status

@MichaelOrlov
Copy link
Contributor

@clalancette We have CI failure on Windows which is unrelated to the changes and kind of relates to the infrastructure.
It seems that it's common for all builds on CI for windows target.
Do you have any clue what it is and when or how it could be fixed?

@clalancette
Copy link
Contributor

Hm, I don't know. It is failing to install the RTI connext binaries, but as far as I can tell that happened successfully in the nightlies: https://ci.ros2.org/view/nightly/job/nightly_win_rel/2256 . I'll try it one more time, and if that doesn't work I'll loop in some other people.

Build Status

@gbiggs
Copy link
Member Author

gbiggs commented Apr 12, 2022

@clalancette Any updates on the CI situation?

@clalancette
Copy link
Contributor

@clalancette Any updates on the CI situation?

Oh, that latest build I ran looks like it did the right thing. From an infrastructure issue, it looks like things are working. Any remaining issues will have something to do with this PR.

Some of the warnings in that latest build have already been fixed, but I'm not sure all of them have been. I'd say it's worthwhile doing another run to see how things look now, I'll kick it off:

Build Status

@gbiggs
Copy link
Member Author

gbiggs commented Apr 12, 2022

The error in the CI is not in the tests, which are all passing. It's an error finding a particular source file, C:\ci\ws\src\ros2\rosbag2\rosbag2_transport\src\rosbag2_transport\qos.cpp.

The CI failure doesn't appear to be related to this PR, although I'm not sure why it's happening. That source file exists in the repository, both in master and in the PR's branch.

@clalancette
Copy link
Contributor

The error in the CI is not in the tests, which are all passing. It's an error finding a particular source file, C:\ci\ws\src\ros2\rosbag2\rosbag2_transport\src\rosbag2_transport\qos.cpp.

Geoff and I talked, and I think the problem is that that qos.cpp is being compiled as part of one of the tests again: https://github.com/ros2/rosbag2/pull/960/files#diff-81a326226779dbc5abab3808861f8664841bdafaed9ff22ebf59ae30b6233219R108-R113 . But that shouldn't be necessary, since that file should be getting pulled in as part of the rosbag2_transport library. So my suggestion is to remove that and try CI again.

@gbiggs
Copy link
Member Author

gbiggs commented Apr 14, 2022

I've pushed the change and fired off a CI run.

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

@gbiggs
Copy link
Member Author

gbiggs commented Apr 17, 2022

CI looks good. We can merge this when the freeze ends.

@MichaelOrlov
Copy link
Contributor

@clalancette @gbiggs Can we already rebase and merge this PR?
When new feature freeze will end up?

gbiggs pushed a commit to gbiggs/rosbag2 that referenced this pull request May 11, 2022
* Removes duration parameter. A leftover after switching to playback_duration.

* Fixes comment.

* Solves format in rosbag2_py -> _transport.cpp

* Applies style suggestions.

* Changes play() to return a boolean indicating whether the request could be fulfilled.

* Removes extra unnecessary code.

Signed-off-by: Geoffrey Biggs <gbiggs@killbots.net>
gbiggs pushed a commit to gbiggs/rosbag2 that referenced this pull request May 11, 2022
* Adresses reviewer's comments.

* Improve test time by adding an optional argument to SubscriptionManager::spin_subscriptions()

- Reduces test_play_for execution time from 50s to 6s approximately.

Signed-off-by: Geoffrey Biggs <gbiggs@killbots.net>
@gbiggs
Copy link
Member Author

gbiggs commented May 11, 2022

I've rebased the PR to master. Here's another round of CI for that.

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

@MichaelOrlov
Copy link
Contributor

@gbiggs Build fail with error:

--- stderr: rosbag2_transport
20:57:20 In file included from �[K/home/jenkins-agent/workspace/ci_linux/ws/src/ros2/rosbag2/rosbag2_transport/src/rosbag2_transport/player.cpp�[K:
20:57:20 �[K/home/jenkins-agent/workspace/ci_linux/ws/src/ros2/rosbag2/rosbag2_transport/include/rosbag2_transport/player.hpp:245:��[Kerro��[KPlay�[K’ is not a member o�[Krosbag2_interfaces::�[K’; did you mea�[KP�[K’?
20:57:20   245 |   rclcpp::Service<rosbag2_interfaces::srv::�[KPlay�[K>::SharedPtr srv_play_for_;
20:57:20       |                                            �[K^~~~�[K
20:57:20       |                                            �[KP�[K
20:57:20 �[K/home/jenkins-agent/workspace/ci_linux/ws/src/ros2/rosbag2/rosbag2_transport/include/rosbag2_transport/player.hpp:245:��[Kerro�[Ktemplate argument 1 is invalid
20:57:20   245 |   rclcpp::Service<rosbag2_interfaces::srv::PlayFor��[K::SharedPtr srv_play_for_;

It seems something wrong with code after rebase.

gbiggs and others added 8 commits June 1, 2022 07:58
Signed-off-by: Geoffrey Biggs <gbiggs@killbots.net>
Signed-off-by: Geoffrey Biggs <gbiggs@killbots.net>
…/960/files (#14)

* Add play-for functionality

Signed-off-by: Geoffrey Biggs <gbiggs@killbots.net>

* Add play-for to the CLI

Signed-off-by: Geoffrey Biggs <gbiggs@killbots.net>

* Adds playback_duration to PlayOptions.

* Changes from PlayFor to Play srv message and changes start_offset and playback_duration.

* Restores play_for tests.

* Removes extra SubscriptionManager methods.

* Solves comment about extra sent message.

* Reorders code and comment.

* Removes the SKIP_TEST flag.

Co-authored-by: Geoffrey Biggs <gbiggs@killbots.net>
Signed-off-by: Geoffrey Biggs <gbiggs@killbots.net>
* Removes duration parameter. A leftover after switching to playback_duration.

* Fixes comment.

* Solves format in rosbag2_py -> _transport.cpp

* Applies style suggestions.

* Changes play() to return a boolean indicating whether the request could be fulfilled.

* Removes extra unnecessary code.

Signed-off-by: Geoffrey Biggs <gbiggs@killbots.net>
* Adresses reviewer's comments.

* Improve test time by adding an optional argument to SubscriptionManager::spin_subscriptions()

- Reduces test_play_for execution time from 50s to 6s approximately.

Signed-off-by: Geoffrey Biggs <gbiggs@killbots.net>
* Redesigned tests to be more deterministic and running faster
* Fixed bug in `play_for()` flow when replaying in loop or multiple
times from the same player instance.

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>
Signed-off-by: Geoffrey Biggs <gbiggs@killbots.net>
Signed-off-by: Geoffrey Biggs <gbiggs@killbots.net>
Signed-off-by: Geoffrey Biggs <gbiggs@killbots.net>
@gbiggs
Copy link
Member Author

gbiggs commented Jun 1, 2022

It looks like the rebase resurrected some code that had been deleted, which is what led to the errors. I've corrected them. Here's some CI.

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

@MichaelOrlov
Copy link
Contributor

@gbiggs We forgot to handle the play_until_time scenario for play_next API.

Will need to add the same

 if (play_until_time >= starting_time_ && message_ptr->time_stamp > play_until_time) {
      break;
    }

Inside play_next.
Also it will need to move this part https://github.com/ros2/rosbag2/pull/960/files#diff-547fe4e718fdbdb2aa48c572ef5fa0706144c8e90e47890c50199f7d3834ae80R210-R213 to the constructor and make play_until_time as member variable.

Do you prefer to fix it in current PR or create a follow up PR after merging this one?

Signed-off-by: Geoffrey Biggs <gbiggs@killbots.net>
@gbiggs
Copy link
Member Author

gbiggs commented Jun 2, 2022

I think it's easier and faster to just correct the behaviour now, so I've done so.

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

@MichaelOrlov
Copy link
Contributor

@gbiggs Thanks for promptly addressing findings.
CI is green, merging then.

@MichaelOrlov MichaelOrlov merged commit ccafe85 into ros2:master Jun 2, 2022
@gbiggs gbiggs deleted the gbiggs/play_for branch June 2, 2022 22:38
@ros-discourse
Copy link

This pull request has been mentioned on ROS Discourse. There might be relevant details there:

https://discourse.ros.org/t/ros-2-tsc-meeting-minutes-8-18-2022/27050/1

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