-
Notifications
You must be signed in to change notification settings - Fork 427
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
ROSRate to be useless without chain to clock pointer #2307
Comments
Yicks, good to point that out I like solution 3 from an end user API perspective. Messing with time sources should not be required for standard application code to benefit from ROS time -- any method that would require that would break my soul. Instead of just deleting it, we could shape it elsewhere. For instance: |
+1 for solution 3 |
Okay, I got it. The idea with making the analogue of |
I will go ahead to close this in favor of #2326 |
In #2123 there was added new interface: optional pointer to the
rclcpp::Clock
inRate
class, which could make it to operate with any type of clock; and derivativeWallRate
andROSRate
classes operating with clocks ofRCL_STEADY_TIME
andRCL_ROS_TIME
types respectively.However, without of having back the pointer to the
clock
created insideROSRate
class, the rate became to be useless having no respect to ROS simulated time and publishing to the/clock
topic. Indeed, the subscription to/clock
is being implemented inrclcpp::TimeSource
class that correcting all attached clocks each time when new message from clock topic is arrived. Thus, to makeROSRate
to operate in the same way asRate
with given custom clocks, we need to return backrclcpp::Clock
pointer fromROSRate
and then do something with it (e.g. attach the given clock to theTimeSource
operating with selected node whereuse_sim_time
parameter applied).Bug report
Required Info:
Steps to reproduce issue
Steps to reproduce:
$ source test_ws/install/setup.bash
and run launch-script, that will bring-up testing node along with Gazebo simulation:
Default outputs for 2Hz rate are
0.5
seconds per each duration (measured in real and ROS time):1000
-> to500
Expected behavior
When using
custom_rate
with custom clock:rclcpp::Clock::SharedPtr clock = std::make_shared<rclcpp::Clock>(RCL_ROS_TIME); rclcpp::Rate::SharedPtr custom_rate = std::make_shared<rclcpp::Rate>(2.0, clock);
... attached to the
TimeSource
that subscribing to the/clock
:rclcpp::TimeSource time_source(shared_from_this()); time_source.attachClock(clock);
... and operating through the node where "use_sim_time" parameter is being targeted
... the timing will be as expected:
<- CORRECT: duration in ROS clock between two ticks shouldn't be changed, while real time slowed down twice
Actual behavior
When using just ROSRate (uncomment
ros_rate
and comment backcustom_rate
lines in asrc/test_node.cpp
):rclcpp::ROSRate::SharedPtr ros_rate = std::make_shared<rclcpp::ROSRate>(2.0);
...with default initialized clock, ROSRate won't respect simulation time:
<- INCORRECT: duration in ROS shouldn't be changed
Implementation considerations
There are three different solutions I'd see from this point of view:
Solution 1
Add new
rclcpp::Clock::SharedPtr Rate::getClock()
method to theRate
(orRateBase
) in order to give developer an ability to getclock_
back and later manually attach it in the target code by usingrclcpp::TimeSource time_source(node); time_source.attachClock(clock);
... or similar construction
Solution 2
Add node pointer optional parameter to the
ROSRate
constructor and do the sameTimeSource(node)->attachClock(clock)
chain inside ROSRate, that will hide unnecessary operations from end-developers. However, this might break the overall API logic: why do we need bothClock
andNode
pointers, if I could get the the clock from node by addressingnode->get_clock()
method? If so, theROSRate
in this case will not be different from just callingRate
with custom clock argument.So, therefore moving to the
Solution 3
Completely remove
ROSRate
fromrate.hpp
. If someone wants to use ROS-respective rate in his node, it could be a Rate with clock pointer already attached to this node:and thus,
ROSRate
is unnecessary in this case.From my point of view, I'd prefer Solution1 or Solution3, but anyway, this should be discus-sable before the fix to be applied.
The text was updated successfully, but these errors were encountered: