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 Clock::sleep_until method #1748

Merged
merged 9 commits into from
Sep 24, 2021

Conversation

emersonknapp
Copy link
Collaborator

@emersonknapp emersonknapp commented Aug 12, 2021

Part of #1730
Related to ros2/rosbag2#694

Add a Clock::sleep_until method. Handle all 3 clock types, and edge cases for shutdown and enabling/disabling ROS time.

Adds test cases for enable/disable ROStime, and rclcpp::shutdown - which needed special interrupts. Tests ROS time via /clock messages, and has basic testing for steady/system times, though those are much simpler cases.

@emersonknapp
Copy link
Collaborator Author

emersonknapp commented Aug 13, 2021

For curiosity while awaiting feedback:

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

Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

overall, i think looks good. some minor comments.

rclcpp/src/rclcpp/clock.cpp Outdated Show resolved Hide resolved
rclcpp/src/rclcpp/clock.cpp Outdated Show resolved Hide resolved
rclcpp/src/rclcpp/clock.cpp Show resolved Hide resolved
rclcpp/test/rclcpp/test_time.cpp Outdated Show resolved Hide resolved
rclcpp/test/rclcpp/test_time.cpp Outdated Show resolved Hide resolved
rclcpp/test/rclcpp/test_time.cpp Outdated Show resolved Hide resolved
@fujitatomoya
Copy link
Collaborator

@emersonknapp
Copy link
Collaborator Author

@fujitatomoya do you have merge access? Or do we also need reviews from one of the maintainers @mabelzhang @wjwwood @ivanpauno

@emersonknapp
Copy link
Collaborator Author

emersonknapp commented Sep 13, 2021

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

@fujitatomoya
Copy link
Collaborator

do we also need reviews from one of the maintainers

👍 we could use the other review. @ivanpauno @clalancette @wjwwood

Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

A few minor things that I think we should fix, but otherwise looks pretty good to me.

rclcpp/test/rclcpp/test_time.cpp Outdated Show resolved Hide resolved
rclcpp/src/rclcpp/clock.cpp Show resolved Hide resolved
rclcpp/src/rclcpp/clock.cpp Show resolved Hide resolved
Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

I've left one nit inline, but it just changing a documentation string.

More concerning is the yellow builds on aarch64; it looks like one of these tests is probably crashing there. Once that is fixed, I'm happy to approve.

rclcpp/include/rclcpp/clock.hpp Outdated Show resolved Hide resolved
Emerson Knapp and others added 8 commits September 23, 2021 15:27
Handle all 3 clock types, and edge cases for shutdown and enabling/disabling ROS time

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
…ond resolution on clang(osx/linux) and windows, unlike nanosecond on Linux+GCC)

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
…est environment on Jenkins

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
…ess now()

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
…nd the test environment on Jenkins"

This reverts commit 4fb7660.

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
… input

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

little sanity check aarch64 Build Status

@emersonknapp
Copy link
Collaborator Author

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

@emersonknapp
Copy link
Collaborator Author

@clalancette are you able to merge this, based on that approval?

@clalancette
Copy link
Contributor

Yeah, I'll go ahead and merge.

@clalancette clalancette merged commit 81df584 into ros2:master Sep 24, 2021
@clalancette
Copy link
Contributor

This is flakey on aarch64: https://ci.ros2.org/job/ci_linux-aarch64/10018/

@emersonknapp
Copy link
Collaborator Author

Yeah that's weird. I'm looking into it, can spin up an ARM instance on EC2

Blast545 added a commit that referenced this pull request Oct 1, 2021
Blast545 added a commit that referenced this pull request Oct 1, 2021
This reverts commit 81df584.

Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
Blast545 added a commit that referenced this pull request Oct 5, 2021
This reverts commit 81df584.

Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
sloretz added a commit that referenced this pull request Nov 3, 2021
sloretz added a commit that referenced this pull request Nov 3, 2021
This reverts commit d04319a.

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
sloretz added a commit that referenced this pull request Nov 5, 2021
* Revert "Revert "Add Clock::sleep_until method (#1748)" (#1793)"

This reverts commit d04319a.

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Context, Shutdown Callback, Condition Var per call

The `Clock` doesn't have enough information to know which Context should
wake it on shutdown, so this adds a Context as an argument to
sleep_until().

Since the context is per call, the shutdown callback is also registered
per call and cannot be stored on impl_.

The condition_variable is also unique per call to reduce spurious
wakeups when multiple threads sleep on the same clock.

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Throw if until has wrong clock type

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* unnecessary newline

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Shorten line

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Fix time jump thresholds and add ROS time test

Use -1 and 1 thresholds because 0 and 0 is supposed to disable the
callbacks

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Shorten line

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* rclcpp::ok() -> context->is_valid()

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* No pre-jump handler instead of noop handler

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* If ros_time_is_active errors, let it throw

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Get time source change from callback to avoid race if ROS time toggled quickly

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Fix threshold and no  pre-jump callback

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Use RCUTILS_MS_TO_NS macro

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Explicit cast for duration to system time

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Throws at the end of docblock

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Add tests for invalid and non-global contexts

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Bi0T1N pushed a commit to Bi0T1N/rclcpp that referenced this pull request Dec 15, 2021
This reverts commit 81df584.

Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
Bi0T1N pushed a commit to Bi0T1N/rclcpp that referenced this pull request Dec 15, 2021
* Revert "Revert "Add Clock::sleep_until method (ros2#1748)" (ros2#1793)"

This reverts commit d04319a.

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Context, Shutdown Callback, Condition Var per call

The `Clock` doesn't have enough information to know which Context should
wake it on shutdown, so this adds a Context as an argument to
sleep_until().

Since the context is per call, the shutdown callback is also registered
per call and cannot be stored on impl_.

The condition_variable is also unique per call to reduce spurious
wakeups when multiple threads sleep on the same clock.

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Throw if until has wrong clock type

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* unnecessary newline

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Shorten line

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Fix time jump thresholds and add ROS time test

Use -1 and 1 thresholds because 0 and 0 is supposed to disable the
callbacks

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Shorten line

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* rclcpp::ok() -> context->is_valid()

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* No pre-jump handler instead of noop handler

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* If ros_time_is_active errors, let it throw

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Get time source change from callback to avoid race if ROS time toggled quickly

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Fix threshold and no  pre-jump callback

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Use RCUTILS_MS_TO_NS macro

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Explicit cast for duration to system time

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Throws at the end of docblock

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Add tests for invalid and non-global contexts

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
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

3 participants