Skip to content

Shift to Struct based Method and Constructors, with Executor passed from CM to on_init() #2323

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

Open
wants to merge 49 commits into
base: master
Choose a base branch
from

Conversation

soham2560
Copy link
Contributor

@soham2560 soham2560 commented Jun 9, 2025

Brief

This addition is the first step towards solving #2141 (also #1732 in some way).
The concept is simple, we are creating a Struct pathway of sorts all the way from the CM to the on_init() call in the hardware component. This enables future additions without too harsh API/ABI breaks.

An example to show this currently is to give the user access to the MultiThreadedExecutor so that they can add nodes to it and publish if necessary by propogating the executor_ from CM all the way to on_init() (refer ab8d08c). A future PR will add a node by default with the hardware_components name

Three Structs have been added to help in the above

  • HardwareComponentInterfaceParams
    • To be passed in on_init() and parsed by user to get all relevant data (hardware_info and executor at this point)
  • HardwareComponentParams
    • To be used for all other initialisation, loading calls up till resource manager
  • ResourceManagerParams
    • To construct Resource Manager

Important Note

This means over time we will have to deprecate and remove the non struct based methods

Side Notes

  • This does mean we have to update the ros2_control_demos with the updated API
  • It is expected the user will lock and use the executor as needed
  • documentation is yet to be added, in particular about notifying the user to not abuse the executor (since they can use the cancel() call internally and cripple the services etc for the CM basically )

Copy link

codecov bot commented Jun 9, 2025

Codecov Report

Attention: Patch coverage is 83.08824% with 23 lines in your changes missing coverage. Please review.

Project coverage is 88.95%. Comparing base (4d3362d) to head (6d42540).

Files with missing lines Patch % Lines
hardware_interface/src/resource_manager.cpp 78.87% 11 Missing and 4 partials ⚠️
controller_manager/src/controller_manager.cpp 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2323      +/-   ##
==========================================
- Coverage   88.96%   88.95%   -0.02%     
==========================================
  Files         144      147       +3     
  Lines       16634    16706      +72     
  Branches     1436     1433       -3     
==========================================
+ Hits        14799    14861      +62     
- Misses       1277     1287      +10     
  Partials      558      558              
Flag Coverage Δ
unittests 88.95% <83.08%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
..._interface/include/hardware_interface/actuator.hpp 100.00% <ø> (ø)
.../include/hardware_interface/actuator_interface.hpp 91.30% <100.00%> (+0.34%) ⬆️
...re_interface/include/hardware_interface/sensor.hpp 100.00% <ø> (ø)
...ce/include/hardware_interface/sensor_interface.hpp 85.98% <100.00%> (+0.98%) ⬆️
...re_interface/include/hardware_interface/system.hpp 100.00% <ø> (ø)
...ce/include/hardware_interface/system_interface.hpp 84.80% <100.00%> (+0.53%) ⬆️
...face/types/hardware_component_interface_params.hpp 100.00% <100.00%> (ø)
...ware_interface/types/hardware_component_params.hpp 100.00% <100.00%> (ø)
...rdware_interface/types/resource_manager_params.hpp 100.00% <100.00%> (ø)
hardware_interface/src/actuator.cpp 80.61% <100.00%> (+0.61%) ⬆️
... and 4 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@soham2560 soham2560 marked this pull request as ready for review June 9, 2025 10:50
Copy link
Member

@saikishor saikishor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A partial review here

I think as this is an API breaking change, we should open the corresponding PRs in the packages like gz_ros2_control and also webots_ros2_control probably? We can discuss this part when we finish the final review of this PR

@soham2560
Copy link
Contributor Author

soham2560 commented Jun 9, 2025

we should open the corresponding PRs in the packages like gz_ros2_control

@saikishor have added PR at ros-controls/gz_ros2_control#606

soham2560 and others added 6 commits June 9, 2025 18:55
…ce.hpp

Co-authored-by: Sai Kishor Kothakota <saisastra3@gmail.com>
….hpp

Co-authored-by: Sai Kishor Kothakota <saisastra3@gmail.com>
….hpp

Co-authored-by: Sai Kishor Kothakota <saisastra3@gmail.com>
…ce.hpp

Co-authored-by: Sai Kishor Kothakota <saisastra3@gmail.com>
….hpp

Co-authored-by: Sai Kishor Kothakota <saisastra3@gmail.com>
….hpp

Co-authored-by: Sai Kishor Kothakota <saisastra3@gmail.com>
@saikishor
Copy link
Member

we should open the corresponding PRs in the packages like gz_ros2_control

@saikishor have added PR at ros-controls/gz_ros2_control#606

Awesome. Sorry I missed that one

@soham2560 soham2560 changed the title Added CMs MultiThreadedExecutor as an arg to on_init() Pimpl Approach based Struct Based Methods, with Executor passed from CM to on_init() Jun 21, 2025
@soham2560 soham2560 changed the title Pimpl Approach based Struct Based Methods, with Executor passed from CM to on_init() Shift to Struct based Method and Constructors, with Executor passed from CM to on_init() Jun 21, 2025
@soham2560 soham2560 requested review from saikishor and bmagyar June 21, 2025 18:49
@bmagyar
Copy link
Member

bmagyar commented Jun 22, 2025

Good renamings!

Copy link
Member

@saikishor saikishor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review

Comment on lines 198 to 203
virtual CallbackReturn on_init(const HardwareInfo & hardware_info)
{
info_ = hardware_info;
hardware_interface::HardwareComponentInterfaceParams params;
params.hardware_info = hardware_info;
return on_init(params);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, we should do the opposite, As this is an overridable method, for the backward compatibility, we need to call this one from the params one. Later once, it is deprecated we can move the logic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh didn't think that would be okay, but if yes then I will make a note in pr description to change that later on

refer 0137417

Comment on lines 163 to 168
hardware_interface::HardwareComponentInterfaceParams params;
params.hardware_info = hardware_info;
return on_init(params);
};

/// Initialization of the hardware interface from data parsed from the robot's URDF.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refer 0137417

Comment on lines 204 to 206
hardware_interface::HardwareComponentInterfaceParams params;
params.hardware_info = hardware_info;
return on_init(params);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refer 0137417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants