-
Notifications
You must be signed in to change notification settings - Fork 418
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
Clarify rate names and introduce SteadyRate #1373
base: rolling
Are you sure you want to change the base?
Conversation
788e7c7
to
e36afba
Compare
Yeah, this is exactly what I think. For the most part, I think people's expectation is that when they use the We did have a bit of a discussion about this in another ticket: #1248 . |
I agree on that the default for An overview of clock sources for
If wonder if |
Honestly, I might rename
I personally wouldn't do this, especially if we rename |
- WallRate now is based on system_clock instead of steady_clock - SteadyRate is introduced for steady_clock - Rate becomes an alias for WallRate for now (maybe should become based on ROS time in case `use_sime_time` is enabled?) WallRate in ROS1 was based on WallTime, which was based wall time (including time jumps and slew), so this would be changing back to that. Signed-off-by: Martijn Buijs <martijn.buijs@gmail.com>
Signed-off-by: Martijn Buijs <martijn.buijs@gmail.com>
e36afba
to
a0ee1c1
Compare
Signed-off-by: Martijn Buijs <martijn.buijs@gmail.com>
b82e877
to
7ae0e7a
Compare
As far as I see, the easiest way to make Compared to I have not created unit tests for this class yet, as I'm not sure on what is the best approach on updating the |
} | ||
|
||
virtual bool | ||
sleep() |
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 passing
Similarly 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() }
Maybe sleep_remainder
or sleep_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 the rclcpp::Rate
by adding the references (and objects???) of rclcpp::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:
using Rate = GenericRate<RCL_SYSTEM_TIME>;
using WallRate = GenericRate<RCL_STEADY_TIME>;
using ROSRate = GenericRate<RCL_ROS_TIME>;
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 inside sleep()
implementation it will check whether the given clock
corresponds to a class template <Type>
and use clock->sleep_for(time_to_sleep)
API call to sleep.
O2. In the GenericRate
constrictor, create an internal rclcpp::Clock(Type)
object of the templated type and then store it in GenericRate
privates: clock_ = rclcpp::Clock::make_shared(Type);
. Then using clock_->sleep_for()
inside the sleep()
. This will free sleep()
call from extra checks and developers from one more pointer to the clock in API. But it also will make a new rclcpp::Clock
object inside rclcpp::GenericRate
. Which as I understand, is not the intention, if we want to rclcpp::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.
Not sure if this is the best place to start a discussion, but this PR might result in some discussion anyway.
rclcpp::WallRate
has been based onstd::chrono::steady_clock
.ros::WallRate
is based onros::WallTime
, which ends up usingclock_gettime(CLOCK_REALTIME, [..])
to get time, which returns the wall time (including time jumps and slew).To me the name
WallRate
is misleading, since it's not actually using the wall time, but a clock that is typically not related to wall time at all. On top of that, it has different semantics than what it used to be in ROS1.My suggestion is to change the names of the specific Rate like this:
WallRate
should usesystem_clock
instead ofsteady_clock
, to be consistent with the ROS1 behavior.SteadyRate
is introduced forsteady_clock
.WallRate
, to not change it's behavior, i.e. make it usesystem_clock
.Personally I see only very limited use for a
Rate
based onsystem_clock
, so I would fine havingRate
be an alias forSteadyRate
instead.On another note: maybe it should become based on ROS time in case
use_sime_time
is enabled?