Skip to content

Add Clock::sleep_until method - #1748

Merged
clalancette merged 9 commits into
ros2:masterfrom
aws-ros-dev:emersonknapp/clock-sleep-until
Sep 24, 2021
Merged

clalancette merged 9 commits into
ros2:masterfrom
aws-ros-dev:emersonknapp/clock-sleep-until

Conversation

@emersonknapp

@emersonknapp emersonknapp commented Aug 12, 2021 •

Copy link
Copy Markdown
Collaborator

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

emersonknapp commented Aug 13, 2021 •

Copy link
Copy Markdown
Collaborator Author

For curiosity while awaiting feedback:

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

@fujitatomoya fujitatomoya left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread rclcpp/src/rclcpp/clock.cpp Resolved
Comment thread rclcpp/src/rclcpp/clock.cpp Resolved
Comment thread rclcpp/src/rclcpp/clock.cpp Resolved
Comment thread rclcpp/test/rclcpp/test_time.cpp Resolved
Comment thread rclcpp/test/rclcpp/test_time.cpp Resolved
Comment thread rclcpp/test/rclcpp/test_time.cpp Resolved
@emersonknapp
emersonknapp force-pushed the emersonknapp/clock-sleep-until branch from e980175 to b3b53f2 Compare August 26, 2021 21:22
@fujitatomoya

Copy link
Copy Markdown
Collaborator

@emersonknapp

Copy link
Copy Markdown
Collaborator Author

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

@emersonknapp

emersonknapp commented Sep 13, 2021 •

Copy link
Copy Markdown
Collaborator Author
  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@fujitatomoya

Copy link
Copy Markdown
Collaborator

do we also need reviews from one of the maintainers

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

@emersonknapp
emersonknapp force-pushed the emersonknapp/clock-sleep-until branch from 02beba9 to f0cd10e Compare September 13, 2021 21:33

@clalancette clalancette left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread rclcpp/test/rclcpp/test_time.cpp Resolved
Comment thread rclcpp/src/rclcpp/clock.cpp Resolved
Comment thread rclcpp/src/rclcpp/clock.cpp Resolved
@emersonknapp
emersonknapp force-pushed the emersonknapp/clock-sleep-until branch from f0cd10e to 489e51d Compare September 16, 2021 23:57

@clalancette clalancette left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread rclcpp/include/rclcpp/clock.hpp 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 <[email protected]>
…ond resolution on clang(osx/linux) and windows, unlike nanosecond on Linux+GCC)

Signed-off-by: Emerson Knapp <[email protected]>
…est environment on Jenkins

Signed-off-by: Emerson Knapp <[email protected]>
…nd the test environment on Jenkins"

This reverts commit 4fb7660.

Signed-off-by: Emerson Knapp <[email protected]>
Signed-off-by: Emerson Knapp <[email protected]>
Signed-off-by: Emerson Knapp <[email protected]>
@emersonknapp
emersonknapp force-pushed the emersonknapp/clock-sleep-until branch from 489e51d to 9529ef8 Compare September 23, 2021 22:32
@emersonknapp
emersonknapp force-pushed the emersonknapp/clock-sleep-until branch from 9529ef8 to c6ab0a8 Compare September 23, 2021 22:35
@emersonknapp

Copy link
Copy Markdown
Collaborator Author

little sanity check aarch64 Build Status

@emersonknapp

Copy link
Copy Markdown
Collaborator Author
  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@emersonknapp

Copy link
Copy Markdown
Collaborator Author

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

@clalancette

Copy link
Copy Markdown
Contributor

Yeah, I'll go ahead and merge.

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

Copy link
Copy Markdown
Contributor

@emersonknapp

Copy link
Copy Markdown
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 <[email protected]>
Blast545 added a commit that referenced this pull request Oct 5, 2021
This reverts commit 81df584.

Signed-off-by: Jorge Perez <[email protected]>
sloretz added a commit that referenced this pull request Nov 3, 2021
sloretz added a commit that referenced this pull request Nov 3, 2021
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 <[email protected]>

* 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 <[email protected]>

* Throw if until has wrong clock type

Signed-off-by: Shane Loretz <[email protected]>

* unnecessary newline

Signed-off-by: Shane Loretz <[email protected]>

* Shorten line

Signed-off-by: Shane Loretz <[email protected]>

* 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 <[email protected]>

* Shorten line

Signed-off-by: Shane Loretz <[email protected]>

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

Signed-off-by: Shane Loretz <[email protected]>

* No pre-jump handler instead of noop handler

Signed-off-by: Shane Loretz <[email protected]>

* If ros_time_is_active errors, let it throw

Signed-off-by: Shane Loretz <[email protected]>

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

Signed-off-by: Shane Loretz <[email protected]>

* Fix threshold and no  pre-jump callback

Signed-off-by: Shane Loretz <[email protected]>

* Use RCUTILS_MS_TO_NS macro

Signed-off-by: Shane Loretz <[email protected]>

* Explicit cast for duration to system time

Signed-off-by: Shane Loretz <[email protected]>

* Throws at the end of docblock

Signed-off-by: Shane Loretz <[email protected]>

* Add tests for invalid and non-global contexts

Signed-off-by: Shane Loretz <[email protected]>
Bi0T1N pushed a commit to Bi0T1N/rclcpp that referenced this pull request Dec 15, 2021
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 <[email protected]>

* 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 <[email protected]>

* Throw if until has wrong clock type

Signed-off-by: Shane Loretz <[email protected]>

* unnecessary newline

Signed-off-by: Shane Loretz <[email protected]>

* Shorten line

Signed-off-by: Shane Loretz <[email protected]>

* 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 <[email protected]>

* Shorten line

Signed-off-by: Shane Loretz <[email protected]>

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

Signed-off-by: Shane Loretz <[email protected]>

* No pre-jump handler instead of noop handler

Signed-off-by: Shane Loretz <[email protected]>

* If ros_time_is_active errors, let it throw

Signed-off-by: Shane Loretz <[email protected]>

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

Signed-off-by: Shane Loretz <[email protected]>

* Fix threshold and no  pre-jump callback

Signed-off-by: Shane Loretz <[email protected]>

* Use RCUTILS_MS_TO_NS macro

Signed-off-by: Shane Loretz <[email protected]>

* Explicit cast for duration to system time

Signed-off-by: Shane Loretz <[email protected]>

* Throws at the end of docblock

Signed-off-by: Shane Loretz <[email protected]>

* Add tests for invalid and non-global contexts

Signed-off-by: Shane Loretz <[email protected]>
bartalor pushed a commit to bartalor/rclcpp that referenced this pull request Jul 15, 2026
* Add Clock::sleep_until method

Handle all 3 clock types, and edge cases for shutdown and enabling/disabling ROS time

Signed-off-by: Emerson Knapp <[email protected]>
bartalor pushed a commit to bartalor/rclcpp that referenced this pull request Jul 15, 2026
bartalor pushed a commit to bartalor/rclcpp that referenced this pull request Jul 15, 2026
* Revert "Revert "Add Clock::sleep_until method (ros2#1748)" (ros2#1793)"

This reverts commit a13ab6a.

Signed-off-by: Shane Loretz <[email protected]>

* 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 <[email protected]>

* Throw if until has wrong clock type

Signed-off-by: Shane Loretz <[email protected]>

* unnecessary newline

Signed-off-by: Shane Loretz <[email protected]>

* Shorten line

Signed-off-by: Shane Loretz <[email protected]>

* 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 <[email protected]>

* Shorten line

Signed-off-by: Shane Loretz <[email protected]>

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

Signed-off-by: Shane Loretz <[email protected]>

* No pre-jump handler instead of noop handler

Signed-off-by: Shane Loretz <[email protected]>

* If ros_time_is_active errors, let it throw

Signed-off-by: Shane Loretz <[email protected]>

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

Signed-off-by: Shane Loretz <[email protected]>

* Fix threshold and no  pre-jump callback

Signed-off-by: Shane Loretz <[email protected]>

* Use RCUTILS_MS_TO_NS macro

Signed-off-by: Shane Loretz <[email protected]>

* Explicit cast for duration to system time

Signed-off-by: Shane Loretz <[email protected]>

* Throws at the end of docblock

Signed-off-by: Shane Loretz <[email protected]>

* Add tests for invalid and non-global contexts

Signed-off-by: Shane Loretz <[email protected]>
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.

3 participants