Skip to content
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

Add new get_value API for Handles and Interfaces #1976

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

Conversation

saikishor
Copy link
Member

@saikishor saikishor commented Jan 2, 2025

Related to ros-controls/ros2_controllers#1442 and ros-controls/ros2_controllers#1443

There are still some deprecated warnings in the following ros2_control packages:

transmission_interface: Once this PR is merged. I will perform the changes here : #1845
hardware components: This needs to be handled in a different PR.

I'll take care of both

Copy link

codecov bot commented Jan 2, 2025

Codecov Report

Attention: Patch coverage is 87.69231% with 16 lines in your changes missing coverage. Please review.

Project coverage is 89.36%. Comparing base (f8c03cc) to head (45d8e71).

Files with missing lines Patch % Lines
...de/hardware_interface/loaned_command_interface.hpp 41.66% 6 Missing and 1 partial ⚠️
...lude/hardware_interface/loaned_state_interface.hpp 41.66% 6 Missing and 1 partial ⚠️
...re_interface/include/hardware_interface/handle.hpp 66.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1976      +/-   ##
==========================================
+ Coverage   89.35%   89.36%   +0.01%     
==========================================
  Files         130      130              
  Lines       14576    14570       -6     
  Branches     1258     1254       -4     
==========================================
- Hits        13024    13021       -3     
+ Misses       1088     1086       -2     
+ Partials      464      463       -1     
Flag Coverage Δ
unittests 89.36% <87.69%> (+0.01%) ⬆️

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

Files with missing lines Coverage Δ
...nclude/semantic_components/force_torque_sensor.hpp 97.95% <100.00%> (ø)
...terface/include/semantic_components/imu_sensor.hpp 97.77% <100.00%> (+0.10%) ⬆️
...erface/include/semantic_components/pose_sensor.hpp 96.55% <100.00%> (ø)
...mantic_components/semantic_component_interface.hpp 90.90% <100.00%> (ø)
...rface/test/test_chainable_controller_interface.cpp 100.00% <100.00%> (ø)
...chainable_controller/test_chainable_controller.cpp 88.37% <100.00%> (+0.27%) ⬆️
...r_manager/test/test_controller/test_controller.cpp 88.73% <100.00%> (ø)
...t_controllers_chaining_with_controller_manager.cpp 99.25% <100.00%> (+0.02%) ⬆️
...rface/test/mock_components/test_generic_system.cpp 99.72% <ø> (-0.04%) ⬇️
...dware_interface/test/test_component_interfaces.cpp 96.49% <100.00%> (+0.15%) ⬆️
... and 7 more

... and 2 files with indirect coverage changes

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.

Thanks for pushing this forward.

I was thinking of something shorter than 2xget+2xvalue in get().get_value<double>().value(), but still have no better suggestion.

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.

One thing: Could you please update the release_notes and also add something to the migration notes? We have only a section about the hardware_components there.

@saikishor
Copy link
Member Author

One thing: Could you please update the release_notes and also add something to the migration notes? We have only a section about the hardware_components there.

Sure I'll do that

Copy link
Member

@destogl destogl left a comment

Choose a reason for hiding this comment

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

It is not beautiful, but probably we don't have a better way to do this…

Maybe we think of a simpler API in the future. At least we are good with the types.

Maybe the approach from ROS 2 parameters using method get_value_as_double() is better compared to get_value<double>().value()?

@bmagyar what do you think?

hardware_interface/include/hardware_interface/handle.hpp Outdated Show resolved Hide resolved
}

template <typename T>
[[nodiscard]] bool get_value(T & value) const
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need this format of get_value? Are we using this somewhere of do you have specific use-case where this has advantages over std::optional<T> get_value()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right now, we are not using it in ros2_control repositories, but this exists from many releases both in rolling nd jazzy. So, at least not to break API of people that might use it, I haven't removed it here

++get_value_statistics_.timeout_counter;
return std::nullopt;
}

template <typename T>
[[nodiscard]] bool get_value(T & value, unsigned int max_tries = 10) const
Copy link
Member

Choose a reason for hiding this comment

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

Also this version, do we need it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Same here as well

@saikishor
Copy link
Member Author

Maybe the approach from ROS 2 parameters using method get_value_as_double() is better compared to get_value<double>().value()?

If we use optional, we cannot avoid using .has_value() and .value() even with the new method as the ROS2 parameters. That's a bit downside.

I have used .value() directly here as we know most of these tests work synchronously, so we always have value, but in the ROS2 Controllers etc, we will need to have the .get_value() as usual into a variable and check if it has value and if it does have value, then replace other instances of the variable in the code with .value()

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.

3 participants