Skip to content

Add Rate - #443

Merged
sloretz merged 4 commits into
masterfrom
sloretz/rate
Oct 14, 2019
Merged

sloretz merged 4 commits into
masterfrom
sloretz/rate

Conversation

@sloretz

@sloretz sloretz commented Oct 10, 2019

Copy link
Copy Markdown
Contributor

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 <[email protected]>
A rate is a synchronous wrapper around a timer.
It raises ROSInterruptException if ROS is shutdown while sleeping.

Signed-off-by: Shane Loretz<[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
@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
Comment thread rclpy/rclpy/timer.py Resolved
Comment thread rclpy/rclpy/timer.py Resolved

@jacobperron jacobperron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sloretz

sloretz commented Oct 14, 2019

Copy link
Copy Markdown
Contributor Author

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 done
@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