-
Notifications
You must be signed in to change notification settings - Fork 315
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
Use monotonic clock for triggering read-update-write cycles + fix for overruns #2046
base: master
Are you sure you want to change the base?
Use monotonic clock for triggering read-update-write cycles + fix for overruns #2046
Conversation
…instead of system/ros clock
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.
Thanks for this fix. LGTM as far as I can tell.
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.
oh
Terminate called after throwing an instance of 'std::runtime_error'
what(): can't compare times with different time sources
on it |
@christophfroehlich I changed my approach to the original one, as this way we have the tests running with the Monotonic clock, and any changes to the code can be early tested with the existing test. If not, we will have to test the changes every time on the real robot |
I tested this fix on TIAGo PRo that is running at 1khz, and it works perfectly. |
…Steady clock time
cecf3c3
@bmagyar as you raised the point of possible discrepancies of time in the controllers. I've added a test to make sure that the controllers always receive the ROS time instead of the steady clock time |
@saikishor i have a question, is it not possible anymore to pass the desired clock type e.g. |
@mamueluth Yes, you are right. We can also approach it that way. Indeed, that was my first approach to the problem. Look here: 5b4cb98 With the above approach of setting the CM's deafult clock with Steady clock, the time that we are going to pass to the https://github.com/ros2/rclcpp/blob/605251bd71da0427ab2cdca26a9e737ca93e73d9/rclcpp/src/rclcpp/time.cpp#L114-L121 For instance, this part of code in diff_drive_controller will be affected and in someother places: There could be many other controllers that this might be affected. I wanted to avoid that for the controllers. If we want to have it functional, then we will need a separate clock anyway. I think it is better to have a separate monotic steady clock rather than a separate ROS clock. This way all messages that we publish and receive from the controller_manager or any further integrations we do, can use the ROS clock and we can use the new steady clock only for the RT loop operations. What do you think? |
Yes, absolutely I had a similar issue with some controllers about the different time sources. I think i got what you try to avoid by creating a seperate clock for the real-time loop, but I did not quite catch why we need a separate clock. An idea I just had what about we pass the clock type of the ControllerManager to the controller? We could do this here:
Right before the controller is initialized. Do you think this would then solve the comparison of different time sources since a controller should still have its own clock, but they use the same clock type? |
@mamueluth Not really, because the clock received from the messages in ROS layer is in ROS time and when you set the steady clock to the controller as well, then you cannot compare the time at any instance. The problem is the steady clock doesn't follow the same format of the system clock, so we will have issues. To give more context, the following is output from the steady clock (monotonic) and system clock printing their nanoseconds (
I couldn't use the node options, also for the fact that that option doesn't exist in Humble and moreover, if we want the CM to be able to publish topics like this #2006, we would definitely need another clock. |
Ah ok now i got it, thanks for the clarification!:) |
@saikishor Thanks for the deep dive here and the great work! LGTM |
Thank you for the discussion. Discussions always bring new points of view. |
For real-time applications and for certain hardware monotonic clock is pretty much needed and in certain occasions, it is also needed for the safety. This PR addressed this by having a monotonic clock for non simulation cases.
Apart from that, there is a bug in the CM statistics in the first loop, but then apart from that, when there is a controller that takes longer in the loop, this causes an overrun in the system. In order to fix it, I've added an overrun check and adjust the time properly to trigger the loops.
Earlier, the triggered overruns are the cause for such fast loops, resulting in high periodicity reports
Tested on real hardware TIAGo at 1kHz
Makes #2042 obselete
closes #2042