Skip to content

Add Rate#443

Merged
sloretz merged 4 commits intomasterfrom
sloretz/rate
Oct 14, 2019
Merged

Add Rate#443
sloretz merged 4 commits intomasterfrom
sloretz/rate

Conversation

@sloretz
Copy link
Copy Markdown
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>
@ghost ghost added the needs review label Oct 10, 2019
@sloretz sloretz added the in review Waiting for review (Kanban column) label Oct 10, 2019
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Copy link
Copy Markdown
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
Copy Markdown
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
@ghost ghost 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
Copy Markdown

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

@jacobperron
Copy link
Copy Markdown
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