-
Notifications
You must be signed in to change notification settings - Fork 448
Clarify rate names and introduce SteadyRate #1373
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
Draft
mbuijs
wants to merge
3
commits into
ros2:rolling
Choose a base branch
from
mbuijs:using_rate_names
base: rolling
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a fundamental concern/worry is that we're conflating two concepts here.
The rate object is a data storage which has an interval period and the last start time.
The clock on the other hand is the thing that has a concept of time passing and keeps track of that.
If you call XXXX.sleep() it has to be the thing that has a concept of time passing. Now we've gotten used to the ROS 1 Rate object being able to reach under the hood and grab the Node singleton and from that get the clock status and disambiguate sim time vs wall time and then give you an answer. This implementation uses the original temporary rclcpp::sleep_for which was added before we had sim time and will not use that.
However we've separated out these many layers so we now actually have a separate clock concept. And we could require that you construct a Rate object with the clock as proposed above. But that's tying together a much heaver concept which requires a time source and a lot more initialization. Whereas the Rate object is basically a little bit of data that doesn't need extra infrastructure.
This can also be seen in Duration where we have not ported forward the
sleep
method that was previously defined in roscpp. And this parallels how chrono implements it. There's no Sleep defined on the "duration" object. https://en.cppreference.com/w/cpp/chrono/duration You call sleep_for on the duration because the Duration doesn't have a concept of time passingSimilarly for the Rate concept. You're going to call sleep_for(x) where x = start + period - now The Rate object doesn't need to know or handle time in the background etc.
You can have and store Rate objects in messages and they stay valid without them additionally forcing association and maintenance of the clock object. Similarly different clocks could service a specific Rate object.
To keep things isolated I would rather propose a Rate.sleep(Clock::ptr clock) Which will do the sleep and you pass it the appropriate clock when you want to sleep using it. This would be a shorthand for users to
if clock.sleep(Rate.get_remainder()) { Rate.reset() }
Maybesleep_remainder
orsleep_cycle
It would be valuable to enable the Rates to be templated on the Clock type to check that Rate is compatible with Clock so you don't end up sleeping from different timelines (Steady, Wall, ROS)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tfoote, we also have the same need in Nav2 to use
rclcpp::Rate
respectful to ROS-time. If I undestood correctly, the main reason of the above - is to not overcomplicate therclcpp::Rate
by adding the references (and objects???) ofrclcpp::Clock
there?We could template the
rclcpp::GenericRate
by<rcl_clock_type_t Type>
instead of<class Clock = std::chrono::clock>
. Depending on it, templates' instantiations will be as follows:Here I see 2 options of API solutions:
O1. Update
GenericRate::sleep(Clock::SharedPtr clock)
call to accept the pointer to RCLCPP Clock as input argument. Then insidesleep()
implementation it will check whether the givenclock
corresponds to a class template<Type>
and useclock->sleep_for(time_to_sleep)
API call to sleep.O2. In the
GenericRate
constrictor, create an internalrclcpp::Clock(Type)
object of the templated type and then store it inGenericRate
privates:clock_ = rclcpp::Clock::make_shared(Type);
. Then usingclock_->sleep_for()
inside thesleep()
. This will freesleep()
call from extra checks and developers from one more pointer to the clock in API. But it also will make a newrclcpp::Clock
object insiderclcpp::GenericRate
. Which as I understand, is not the intention, if we want torclcpp::GenericRate
to be a lightweight structure. However, from my perspective, this option is pretty straight-forward to end-developers who will use this API.Which way is better to prefer?
I may not see the whole picture, so please correct it if something missed or we could go another way.