Skip to content

Added CMs MultiThreadedExecutor as an arg 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 28 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 intention currently is to give the user access to the MultiThreadedExecutor so that they can add nodes to it and publish if necessary. A future PR will add a node by default with the hardware_components name

Upon further review, another crucial change is introduced in this PR, we are constructing three structs

  • 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

How was this tested?

Unfortunately the demo examples aren't directly compatible due to the changed API so had to modify them a bit, but was able to add a node to the executor and check

Couple of points to note

  • 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 87.28070% with 29 lines in your changes missing coverage. Please review.

Project coverage is 88.95%. Comparing base (f97a2cb) to head (c4b02f1).

Files with missing lines Patch % Lines
hardware_interface/src/resource_manager.cpp 70.00% 8 Missing and 4 partials ⚠️
...rface_testing/test/test_components/test_sensor.cpp 25.00% 2 Missing and 1 partial ⚠️
...rface_testing/test/test_components/test_system.cpp 25.00% 2 Missing and 1 partial ⚠️
controller_manager/src/controller_manager.cpp 50.00% 2 Missing ⚠️
...hardware_components/test_single_joint_actuator.cpp 0.00% 2 Missing ⚠️
...e_interface/src/mock_components/generic_system.cpp 75.00% 0 Missing and 1 partial ⚠️
...t_hardware_components/test_force_torque_sensor.cpp 50.00% 0 Missing and 1 partial ⚠️
.../test/test_hardware_components/test_imu_sensor.cpp 50.00% 0 Missing and 1 partial ⚠️
...ware_components/test_system_with_command_modes.cpp 50.00% 0 Missing and 1 partial ⚠️
...test_hardware_components/test_two_joint_system.cpp 50.00% 0 Missing and 1 partial ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2323      +/-   ##
==========================================
- Coverage   88.97%   88.95%   -0.02%     
==========================================
  Files         143      145       +2     
  Lines       16608    16664      +56     
  Branches     1429     1432       +3     
==========================================
+ Hits        14777    14824      +47     
- Misses       1275     1281       +6     
- Partials      556      559       +3     
Flag Coverage Δ
unittests 88.95% <87.28%> (-0.02%) ⬇️

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

Files with missing lines Coverage Δ
...er_manager/test/controller_manager_test_common.hpp 89.83% <100.00%> (ø)
...er/test/test_controller_manager_with_namespace.cpp 100.00% <100.00%> (ø)
...t_controllers_chaining_with_controller_manager.cpp 99.25% <100.00%> (+<0.01%) ⬆️
..._interface/include/hardware_interface/actuator.hpp 100.00% <ø> (ø)
.../include/hardware_interface/actuator_interface.hpp 90.96% <100.00%> (ø)
...re_interface/include/hardware_interface/sensor.hpp 100.00% <ø> (ø)
...ce/include/hardware_interface/sensor_interface.hpp 85.00% <100.00%> (ø)
...re_interface/include/hardware_interface/system.hpp 100.00% <ø> (ø)
...ce/include/hardware_interface/system_interface.hpp 84.26% <100.00%> (ø)
...face/types/hardware_component_interface_params.hpp 100.00% <100.00%> (ø)
... and 23 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

@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

Copy link
Contributor

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

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

Please check the pre-commit failures (have you installed it properly?)

@soham2560
Copy link
Contributor Author

Please check the pre-commit failures (have you installed it properly?)

apologies, forgot to rerun pre-commit after the suggested changes

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.

The changes itself LGTM

@soham2560
Copy link
Contributor Author

after some discussion with @saikishor and @bmagyar we have decided to go for a Pimpl approach on this PR, putting in draft till then

@soham2560 soham2560 marked this pull request as draft June 11, 2025 11:20
@soham2560 soham2560 marked this pull request as ready for review June 15, 2025 12:31
@soham2560
Copy link
Contributor Author

@bmagyar @saikishor do let me know how this looks

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.

Thank you for the changes. They are very good

Some nitpicking and other recommended changes

Comment on lines +47 to +58
explicit HardwareComponentInterfaceParams(
const hardware_interface::HardwareInfo & hardware_info_param,
rclcpp::Executor::WeakPtr executor_param)
: hardware_info(hardware_info_param), executor(executor_param)
{
}

explicit HardwareComponentInterfaceParams(hardware_interface::HardwareComponentParams & params)
: hardware_info(params.hardware_info), executor(params.executor)
{
}
};
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if it is better to have no constructors here, because at some point, we might break this one too. Instead, filling in the information individually per element is better. We can always add them back in future

I don't have a strong opinion 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.

Comment on lines +59 to +67
explicit HardwareComponentParams(
const hardware_interface::HardwareInfo & hardware_info_param, rclcpp::Logger logger_param,
rclcpp::Clock::SharedPtr clock_param, rclcpp::Executor::WeakPtr executor_param)
: hardware_info(hardware_info_param),
logger(logger_param),
clock(clock_param),
executor(executor_param)
{
}
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.

Comment on lines +58 to +63
rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_interface,
rclcpp::Executor::SharedPtr executor);

/// Default constructor for the Resource Manager.
explicit ResourceManager(rclcpp::Clock::SharedPtr clock, rclcpp::Logger logger);
explicit ResourceManager(
rclcpp::Clock::SharedPtr clock, rclcpp::Logger logger, rclcpp::Executor::SharedPtr executor);
Copy link
Member

Choose a reason for hiding this comment

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

With the internal structure in place, do we have to extend the other constructors?. For the newer features, they can directly use the newer struct right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing in my mind was that it seems odd to just extend one variant, maybe a seperate constructor not dependent on previous ones would be better what do you think?

Comment on lines +50 to +51
rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface,
rclcpp::Executor::WeakPtr executor);
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. do we have to extend this one too?

Comment on lines 48 to +51
const rclcpp_lifecycle::State & initialize(
const HardwareInfo & system_info, rclcpp::Logger logger,
rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface);
rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface,
rclcpp::Executor::WeakPtr executor);
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

Comment on lines +1468 to +1470
hardware_interface::HardwareComponentParams params(
individual_hardware_info, resource_storage_->rm_logger_, resource_storage_->rm_clock_,
executor_);
Copy link
Member

Choose a reason for hiding this comment

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

May be we should store the params in the class, so we could use it later? This can help us avoid any human errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense, should we do it for all the structs or just this one in your opinion? and I am assuming it should be stored in resource manager publicly?

Comment on lines +1000 to +1002
auto test_executor = std::make_shared<rclcpp::executors::SingleThreadedExecutor>();
auto state = sensor_hw.initialize(
mock_hw_info, node->get_logger(), node->get_node_clock_interface(), test_executor);
Copy link
Member

Choose a reason for hiding this comment

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

If we would have left the old method, we don't have to create all these changes

soham2560 and others added 5 commits June 17, 2025 08:22
…anager_params.hpp

Co-authored-by: Sai Kishor Kothakota <[email protected]>
…anager_params.hpp

Co-authored-by: Sai Kishor Kothakota <[email protected]>
…anager_params.hpp

Co-authored-by: Sai Kishor Kothakota <[email protected]>
…anager_params.hpp

Co-authored-by: Sai Kishor Kothakota <[email protected]>
…omponent_params.hpp

Co-authored-by: Sai Kishor Kothakota <[email protected]>
@@ -158,18 +163,23 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
info_.thread_priority);
async_handler_->start_thread();
}
return on_init(hardware_info);
return on_init(hardware_interface::HardwareComponentInterfaceParams(params));
Copy link
Member

Choose a reason for hiding this comment

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

not sure about it but if we did not mark the constructor explicit, this could be as short as

Suggested change
return on_init(hardware_interface::HardwareComponentInterfaceParams(params));
return on_init(params);

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