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 Rate #443

Merged
merged 4 commits into from
Oct 14, 2019
Merged

Add Rate #443

merged 4 commits into from
Oct 14, 2019

Conversation

sloretz
Copy link
Contributor

@sloretz sloretz commented Oct 10, 2019

Resolves #186

This adds a Rate class. It's a tool for running a loop at a constant rate.

Plus:

  • Made context shutdown callbacks use weakref.WeakMethod().
    • Should prevent the callback list from growing infinitely.
  • Added Handle.__bool__().
    • Used to avoid sleeping if the timer was destroyed.

Comparison with ROS 1:

  • ROS 1: rate = rospy.Rate(10); ROS 2 rate = node.create_rate(10).
  • Both raise ROSInterruptException if the client library has been shutdown
  • ROS 1: may raise ROSTimeMovedBackwardsException; ROS 2: uses timer time jump logic.
    • If it went back more than 1 period, Rate sleeps for 1 full period. If it went backwards less than a period, Rate sleeps for the time remaining. If the time source changed, sleeps for the time remaining.
  • ROS 1: Almost always ok to call in a callback; ROS 2: An executor must be serving the timer, so may block if called in a callback in a SingleThreadedExecutor
  • ROS 1: Had Rate.remaining(); ROS 2: not implemented. It should be easy to add if someone needs it.

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
A rate is a synchronous wrapper around a timer.
It raises ROSInterruptException if ROS is shutdown while sleeping.

Signed-off-by: Shane Loretz<sloretz@openrobotics.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
@sloretz sloretz added the in review Waiting for review (Kanban column) label Oct 10, 2019
rclpy/rclpy/timer.py Show resolved Hide resolved
rclpy/rclpy/timer.py Show resolved Hide resolved
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

LGTM

@sloretz
Copy link
Contributor Author

sloretz commented Oct 14, 2019

CI (testing rclpy)

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

@sloretz sloretz merged commit 37c07f6 into master Oct 14, 2019
@wuffle-ros wuffle-ros bot removed the in review Waiting for review (Kanban column) label Oct 14, 2019
@sloretz sloretz deleted the sloretz/rate branch October 14, 2019 20:48
@tfoote tfoote mentioned this pull request Oct 14, 2019
8 tasks
@charlotteheggem
Copy link

Hi, is it possible to make this feature be available for ROS2 dashing?

@jacobperron
Copy link
Member

We typically only backport bug fixes and not features. Though, I don't see much risk in backporting this particular feature and am open to it. @sloretz, what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Time Features in rclpy
3 participants