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

PlayerClock initial implementation - Player functionally unchanged #689

Merged
merged 11 commits into from Apr 3, 2021

Conversation

emersonknapp
Copy link
Collaborator

@emersonknapp emersonknapp commented Mar 24, 2021

Related Issues

Description

  • Adds new class PlayerClock with now() and sleep_until() with simple rate handling.
  • Adds tests for class
  • Removes time handling from Player in favor of configuring and using PlayerClock

@emersonknapp emersonknapp marked this pull request as ready for review March 25, 2021 00:19
@emersonknapp emersonknapp requested a review from a team as a code owner March 25, 2021 00:19
@emersonknapp emersonknapp requested review from thomas-moulard, piraka9011 and Karsten1987 and removed request for a team and thomas-moulard March 25, 2021 00:19
@emersonknapp emersonknapp force-pushed the emersonknapp/player-clock branch 2 times, most recently from ef47e0e to 06398ad Compare March 25, 2021 01:00
emersonknapp pushed a commit that referenced this pull request Mar 26, 2021
Fixes #99
Design: #675
Depends on #689
Depends on #693 to expose to the CLI

Add a `rosgraph_msgs/Clock` publisher to the `Player` - that uses `PlayerClock::now()` to publish current time.

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
@emersonknapp
Copy link
Collaborator Author

emersonknapp commented Mar 26, 2021

Cross-platform sanity check

Gist: https://gist.githubusercontent.com/emersonknapp/56fa49315468fd07d734740da7975b4a/raw/b85678a7e3040cb2fef7dbccb3e6133c1431ee56/ros2.repos
BUILD args: --packages-up-to rosbag2_transport rosbag2_tests ros2bag rosbag2_py
TEST args: --packages-select rosbag2_transport rosbag2_tests ros2bag rosbag2_py
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/8036

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

Note: rclcpp warnings unrelated and should be fixed by ros2/rclcpp#1608

Copy link
Contributor

@jikawa-az jikawa-az 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 the documentation, diagrams, and test cases!

@emersonknapp emersonknapp requested review from david-prody and removed request for piraka9011 March 30, 2021 21:00
emersonknapp pushed a commit that referenced this pull request Mar 31, 2021
Fixes #99
Design: #675
Depends on #689
Depends on #693 to expose to the CLI

Add a `rosgraph_msgs/Clock` publisher to the `Player` - that uses `PlayerClock::now()` to publish current time.

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
@emersonknapp
Copy link
Collaborator Author

Gist: https://gist.githubusercontent.com/emersonknapp/6fb38f4384ee9db70d518f601711591a/raw/e3aa6275de0ca40c21d1a6860083e814c486933c/ros2.repos
BUILD args: --packages-up-to rosbag2_cpp rosbag2_transport rosbag2_py ros2bag rosbag2_tests rosbag2
TEST args: --packages-select rosbag2_cpp rosbag2_transport rosbag2_py ros2bag rosbag2_tests rosbag2
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/8062

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

Copy link

@david-prody david-prody left a comment

Choose a reason for hiding this comment

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

API looks good. my main question is how scenerio 3 from the design would be set up using this class.

rosbag2_cpp/include/rosbag2_cpp/player_clock.hpp Outdated Show resolved Hide resolved
rosbag2_cpp/test/rosbag2_cpp/test_player_clock.cpp Outdated Show resolved Hide resolved
rosbag2_transport/src/rosbag2_transport/player.cpp Outdated Show resolved Hide resolved
@emersonknapp
Copy link
Collaborator Author

emersonknapp commented Apr 1, 2021

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

Emerson Knapp added 7 commits April 2, 2021 00:59
Create new PlayerClock class with `now()`, `sleep_until()`, and rate handling, with tests.
Removes time handling from `Player` in favor of using this new class.

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
…lper functions to match design

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
…nts to clock setup and move some logic out into helper function

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
…implement - makes it obvious how SimTimeClock will be implemented

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
@emersonknapp
Copy link
Collaborator Author

emersonknapp commented Apr 2, 2021

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

…nings

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
@emersonknapp
Copy link
Collaborator Author

emersonknapp commented Apr 2, 2021

Windows: Build Status (all build warnings resolved - yellow now only for the Cyclone CMake warning)

Copy link
Collaborator

@Karsten1987 Karsten1987 left a comment

Choose a reason for hiding this comment

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

Generally lgtm, but I am finding the typedefs a bit wild. I'd actually stick to their original types if we don't plan on evolving them further into their own structs.

* Remove time point typedefs in favor of using the types directly.
* Use condition_variable for waiting
* Minor formatting updates

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
@emersonknapp
Copy link
Collaborator Author

emersonknapp commented Apr 2, 2021

@Karsten1987 thanks for the feedback - I think it put a nice finishing touch on this diff. Now, fingers crossed for a green result :)

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

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
@emersonknapp
Copy link
Collaborator Author

emersonknapp commented Apr 3, 2021

Fixed float->double conversion warning

Windows: Build Status

^ Green - cmake warning is eclipse-cyclonedds/cyclonedds#741

@emersonknapp emersonknapp merged commit 9ed9102 into master Apr 3, 2021
@delete-merged-branch delete-merged-branch bot deleted the emersonknapp/player-clock branch April 3, 2021 02:42
return reference.steady + std::chrono::nanoseconds(diff_nanos);
}

std::mutex mutex;
Copy link
Contributor

Choose a reason for hiding this comment

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

It is bad practice to use names reserved in C++. It would be more safe if rename variable mutex .
Maybe ref_rate_mutex or time_control_mutex ?


std::mutex mutex;
std::condition_variable cv;
PlayerClock::NowFunction now_fn RCPPUTILS_TSA_GUARDED_BY(mutex);
Copy link
Contributor

Choose a reason for hiding this comment

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

If I am understand correctly we are going to assign now_fn only in constructor. In this case strict requirement to lock mutex is extra and not required.

return std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count();
}

rcutils_time_point_value_t steady_to_ros(std::chrono::steady_clock::time_point steady_time)
Copy link
Contributor

Choose a reason for hiding this comment

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

@emersonknapp It would be nice to add REQUIRES(mutex) attribute to steady_to_ros function.
https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#getting-started
However I am not sure if it possible to do with rclcpp abstraction layer.

}

std::chrono::steady_clock::time_point ros_to_steady(rcutils_time_point_value_t ros_time)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar. It would be nice to add REQUIRES(mutex) attribute to ros_to_steady function.

Kettenhoax pushed a commit to Kettenhoax/rosbag2 that referenced this pull request Apr 9, 2021
…os2#689)

* Initial PlayerClock integration - functionality unchanged

* Create PlayerClock, a pure virtual interface with `now()`, and `sleep_until()` for Player to use to control timing of message playback
* TimeControllerClock implementation of PlayerClock
* Removes time handling from `Player` in favor of using this new class

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
mitsudome-r pushed a commit to mitsudome-r/rosbag2 that referenced this pull request Apr 10, 2021
…os2#689)

* Initial PlayerClock integration - functionality unchanged

* Create PlayerClock, a pure virtual interface with `now()`, and `sleep_until()` for Player to use to control timing of message playback
* TimeControllerClock implementation of PlayerClock
* Removes time handling from `Player` in favor of using this new class

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
hayato-m126 pushed a commit to tier4/rosbag2 that referenced this pull request Apr 22, 2021
* Design for rosbag2 handling of clock/simtime (ros2#675)

* Add a design dock for rosbag2 handling of clock/simtime

Signed-off-by: Emerson Knapp <eknapp@amazon.com>

* PlayerClock initial implementation - Player functionally unchanged (ros2#689)

* Initial PlayerClock integration - functionality unchanged

* Create PlayerClock, a pure virtual interface with `now()`, and `sleep_until()` for Player to use to control timing of message playback
* TimeControllerClock implementation of PlayerClock
* Removes time handling from `Player` in favor of using this new class

Signed-off-by: Emerson Knapp <eknapp@amazon.com>

* /clock publisher in Player (ros2#695)

* Add /clock publishing to Player

Signed-off-by: Emerson Knapp <eknapp@amazon.com>

* fix for foxy abi

Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp>

* fix bug

Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp>

Co-authored-by: Emerson Knapp <537409+emersonknapp@users.noreply.github.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.

None yet

5 participants