ros-controls / ros2_control

Generic and simple controls framework for ROS 2
https://control.ros.org
Apache License 2.0
433 stars 272 forks source link

[Feature] Choose different read and write rate for the hardware components #1570

Open saikishor opened 3 weeks ago

saikishor commented 3 weeks ago

Hello!

This PR helps to obtain different read and write update rates rather than having the same update rate as of the controller manager. With these changes, each and every component can run at their own chosen rate and they update the State and Command interfaces according to that rate. This is very useful for system with different communication layers such as EtherCAT, CAN and Serial. Hope this helps the community.

Thank you

codecov[bot] commented 3 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 87.50%. Comparing base (723c869) to head (2540431).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1570 +/- ## ========================================== + Coverage 87.29% 87.50% +0.20% ========================================== Files 108 108 Lines 9793 9947 +154 Branches 886 894 +8 ========================================== + Hits 8549 8704 +155 Misses 925 925 + Partials 319 318 -1 ``` | [Flag](https://app.codecov.io/gh/ros-controls/ros2_control/pull/1570/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/ros-controls/ros2_control/pull/1570/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls) | `87.50% <100.00%> (+0.20%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/ros-controls/ros2_control/pull/1570?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls) | Coverage Δ | | |---|---|---| | [...\_interface/include/hardware\_interface/actuator.hpp](https://app.codecov.io/gh/ros-controls/ros2_control/pull/1570?src=pr&el=tree&filepath=hardware_interface%2Finclude%2Fhardware_interface%2Factuator.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#diff-aGFyZHdhcmVfaW50ZXJmYWNlL2luY2x1ZGUvaGFyZHdhcmVfaW50ZXJmYWNlL2FjdHVhdG9yLmhwcA==) | `100.00% <ø> (ø)` | | | [...re\_interface/include/hardware\_interface/sensor.hpp](https://app.codecov.io/gh/ros-controls/ros2_control/pull/1570?src=pr&el=tree&filepath=hardware_interface%2Finclude%2Fhardware_interface%2Fsensor.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#diff-aGFyZHdhcmVfaW50ZXJmYWNlL2luY2x1ZGUvaGFyZHdhcmVfaW50ZXJmYWNlL3NlbnNvci5ocHA=) | `75.00% <ø> (+8.33%)` | :arrow_up: | | [...re\_interface/include/hardware\_interface/system.hpp](https://app.codecov.io/gh/ros-controls/ros2_control/pull/1570?src=pr&el=tree&filepath=hardware_interface%2Finclude%2Fhardware_interface%2Fsystem.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#diff-aGFyZHdhcmVfaW50ZXJmYWNlL2luY2x1ZGUvaGFyZHdhcmVfaW50ZXJmYWNlL3N5c3RlbS5ocHA=) | `100.00% <ø> (ø)` | | | [hardware\_interface/src/actuator.cpp](https://app.codecov.io/gh/ros-controls/ros2_control/pull/1570?src=pr&el=tree&filepath=hardware_interface%2Fsrc%2Factuator.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#diff-aGFyZHdhcmVfaW50ZXJmYWNlL3NyYy9hY3R1YXRvci5jcHA=) | `76.22% <100.00%> (+1.22%)` | :arrow_up: | | [hardware\_interface/src/component\_parser.cpp](https://app.codecov.io/gh/ros-controls/ros2_control/pull/1570?src=pr&el=tree&filepath=hardware_interface%2Fsrc%2Fcomponent_parser.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#diff-aGFyZHdhcmVfaW50ZXJmYWNlL3NyYy9jb21wb25lbnRfcGFyc2VyLmNwcA==) | `94.35% <100.00%> (+0.22%)` | :arrow_up: | | [hardware\_interface/src/resource\_manager.cpp](https://app.codecov.io/gh/ros-controls/ros2_control/pull/1570?src=pr&el=tree&filepath=hardware_interface%2Fsrc%2Fresource_manager.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#diff-aGFyZHdhcmVfaW50ZXJmYWNlL3NyYy9yZXNvdXJjZV9tYW5hZ2VyLmNwcA==) | `74.66% <100.00%> (+1.02%)` | :arrow_up: | | [hardware\_interface/src/sensor.cpp](https://app.codecov.io/gh/ros-controls/ros2_control/pull/1570?src=pr&el=tree&filepath=hardware_interface%2Fsrc%2Fsensor.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#diff-aGFyZHdhcmVfaW50ZXJmYWNlL3NyYy9zZW5zb3IuY3Bw) | `71.28% <100.00%> (+0.87%)` | :arrow_up: | | [hardware\_interface/src/system.cpp](https://app.codecov.io/gh/ros-controls/ros2_control/pull/1570?src=pr&el=tree&filepath=hardware_interface%2Fsrc%2Fsystem.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#diff-aGFyZHdhcmVfaW50ZXJmYWNlL3NyYy9zeXN0ZW0uY3Bw) | `76.22% <100.00%> (+1.22%)` | :arrow_up: | | [hardware\_interface/test/test\_component\_parser.cpp](https://app.codecov.io/gh/ros-controls/ros2_control/pull/1570?src=pr&el=tree&filepath=hardware_interface%2Ftest%2Ftest_component_parser.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#diff-aGFyZHdhcmVfaW50ZXJmYWNlL3Rlc3QvdGVzdF9jb21wb25lbnRfcGFyc2VyLmNwcA==) | `98.73% <100.00%> (+0.08%)` | :arrow_up: | | [...rface\_testing/test/test\_components/test\_system.cpp](https://app.codecov.io/gh/ros-controls/ros2_control/pull/1570?src=pr&el=tree&filepath=hardware_interface_testing%2Ftest%2Ftest_components%2Ftest_system.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#diff-aGFyZHdhcmVfaW50ZXJmYWNlX3Rlc3RpbmcvdGVzdC90ZXN0X2NvbXBvbmVudHMvdGVzdF9zeXN0ZW0uY3Bw) | `89.58% <100.00%> (+0.22%)` | :arrow_up: | | ... and [1 more](https://app.codecov.io/gh/ros-controls/ros2_control/pull/1570?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls) | |
saikishor commented 3 weeks ago

Great addition 👍

Why not just use update_rate as attribute name (same as for controller_manager or the controllers)

Please update the docs and add also a paragraph to the release notes.

Sure. I forgot about the docs. I'll update it tomorrow at the earliest. Thanks for reminding me.

Well regarding the parameter name, I thought of using different because, we have update_rate for the update callback of the controllers and for the hardware I wanted to use the appropriate one, so I used rw_rate to specify the read/write_rate. How the changes are done, in future we can also have different read and write rates if needed, with just changing the parsing part. I'm open to the discussion on the parameter naming part.

mergify[bot] commented 1 week ago

This pull request is in conflict. Could you fix it @saikishor?

saikishor commented 1 week ago

Resolved conflicts!

mergify[bot] commented 4 days ago

This pull request is in conflict. Could you fix it @saikishor?

saikishor commented 3 days ago

@christophfroehlich I've just fixed the conflicts after your merged PR on deprecating mimic stuff