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 sleep function that respects ROS time #617

Closed
sloretz opened this issue Sep 3, 2020 · 1 comment · Fixed by #858 or #864
Closed

Add sleep function that respects ROS time #617

sloretz opened this issue Sep 3, 2020 · 1 comment · Fixed by #858 or #864
Assignees
Labels
enhancement New feature or request

Comments

@sloretz
Copy link
Contributor

sloretz commented Sep 3, 2020

Feature request

Feature description

This is a request for a function that sleeps the current thread while respecting ROS time.

Implementation considerations

There's some discussion about where a method like this should live in ros2/rclcpp#1248.
Historically this method has lived as rospy.sleep() and rospy.Rate.sleep()

Sleeping should respect the clock being used. I think this could be implemented by waiting on a threading.Event that's woken by a time jump callback. Steady clock and system clocks don't have time jump callbacks, so the event would expire on the timeout being reached.

I'm assuming this would be a sleep_for(duration) rather than a sleep_until(time). The latter is tricky when using system time because right now we don't have time jump callbacks for when system time changes.

Sleeping on ROS clocks would only be as accurate as the frequency of published time messages on the /clock topic. More frequent publishing has a drawback that it will wake the time jump callback more frequently before the sleep period has elapsed.

Related to ros2/rclcpp#1730

@clalancette clalancette assigned sloretz and unassigned sloretz Sep 17, 2020
@wjwwood wjwwood added enhancement New feature or request help wanted Extra attention is needed labels Mar 29, 2021
@sloretz
Copy link
Contributor Author

sloretz commented Nov 30, 2021

This is tricky in python, as there doesn't appear to be a way to specify sleeping on a system clock or a steady clock in Python.

The pause library tries to solve this problem. It sleeps for half the time, gets the current time off the clock to see if it's time to wake up, then repeats until the time is up. That's not perfect as a time jump greater than half the time remaining would go unnoticed.

Maybe a ClockAwareEvent class like threading.Event could be implemented in the rclpy pybind11 bindings and used by Clock? Internally it would use C++'s condition_variable class to get this functionality.

@jacobperron jacobperron removed their assignment Dec 2, 2021
@sloretz sloretz self-assigned this Dec 6, 2021
@sloretz sloretz removed the help wanted Extra attention is needed label Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants