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

A method to get node options to setup the controller node #api-breaking #1169

Merged
merged 10 commits into from
Jan 31, 2024

Conversation

saikishor
Copy link
Member

This PR adds a new API get_node_options method that other controllers will be able to override, this would make it easy for other controllers to be able to setup their own custom node options

@saikishor saikishor changed the title Class method to obtain node options to setup the controller node A method to get node options to setup the controller node Nov 15, 2023
Copy link

codecov bot commented Nov 15, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (51ff9ce) 48.02% compared to head (4d63bcd) 48.00%.
Report is 4 commits behind head on master.

❗ Current head 4d63bcd differs from pull request most recent head a0c1341. Consider uploading reports for the commit a0c1341 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1169      +/-   ##
==========================================
- Coverage   48.02%   48.00%   -0.03%     
==========================================
  Files          41       41              
  Lines        3525     3529       +4     
  Branches     1912     1915       +3     
==========================================
+ Hits         1693     1694       +1     
  Misses        442      442              
- Partials     1390     1393       +3     
Flag Coverage Δ
unittests 48.00% <40.00%> (-0.03%) ⬇️

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

Files Coverage Δ
...roller_interface/src/controller_interface_base.cpp 48.14% <100.00%> (ø)
...controller_interface/controller_interface_base.hpp 37.50% <50.00%> (+4.16%) ⬆️
controller_manager/src/controller_manager.cpp 39.12% <0.00%> (-0.07%) ⬇️

Copy link
Contributor

mergify bot commented Nov 20, 2023

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

@saikishor saikishor force-pushed the controller_node_options_method branch from 7934dde to 0636984 Compare November 20, 2023 19:04
@saikishor
Copy link
Member Author

@bmagyar @destogl @christophfroehlich As we are breaking the API, do you think this PR make sense to go into rolling?. I'm asking because most of the time, you tend to override the init method to just replace the NodeOptions and with this PR it would be much simpler. I also have a branch with the changes to the ros2_controllers tests : ros-controls/ros2_controllers#840.

What's your opinion on this PR?

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.

I would never have needed to overwrite NodeOptions (or at least never thought of a solution using this), but the changes look simple and clean for me.
I just ask for some API documentation, which is published here.

@saikishor
Copy link
Member Author

I just ask for some API documentation, which is published here.

@christophfroehlich Thanks for the reminder, I've just added some documentation to the newly added API method

@saikishor
Copy link
Member Author

saikishor commented Nov 20, 2023

I would never have needed to overwrite NodeOptions (or at least never thought of a solution using this), but the changes look simple and clean for me.

The motivation behind it is, if someone wants to override the NodeOptions to have allow_undeclared_parameters, right now they have to override this init function to be able to do it. Moreover, the controller manager while initializing the controllers with the load_controller service, doesn't pass this argument at all, so, for me it didn't make sense to be a part of the controller init method

if (
controller.c->init(
controller.info.name, robot_description_, get_update_rate(), get_namespace()) ==
controller_interface::return_type::ERROR)

@saikishor saikishor force-pushed the controller_node_options_method branch from 9b45446 to feb6dcf Compare November 20, 2023 20:51
Copy link
Contributor

mergify bot commented Nov 24, 2023

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

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.

Should we add any explicit hint that this method can/should be overridden?

@saikishor
Copy link
Member Author

Should we add any explicit hint that this method can/should be overridden?

Sure, why not. I can add it to the documentation of the method.

Thank you

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.

Just one thing to clarify in the test change.

One more thing. What do you think if we named the method define_node_options or define_custom_node_options, rather then get_node_options. The last one sounds more like getter, not sure if name "invites" people to override it when reading it. @christophfroehlich @bmagyar what do you think too?

Comment on lines -34 to -41
controller_interface::return_type TestControllerFailedInit::init(
const std::string & /* controller_name */, const std::string & /* urdf */,
unsigned int /*cm_update_rate*/, const std::string & /*node_namespace*/,
const rclcpp::NodeOptions & /*node_options*/)
{
return controller_interface::return_type::ERROR;
}

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we still keep this test?

What I understand, you are here not moving the node options only, but changing how init is provoking error in this case. It could be that I am missing a detail or something.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally, you don't need to have this as the same behavior will be achieved as the main init method in the base class will call the get_node_options method

Comment on lines 116 to 118
virtual return_type init(
const std::string & controller_name, const std::string & urdf, unsigned int cm_update_rate,
const std::string & node_namespace = "",
const rclcpp::NodeOptions & node_options = rclcpp::NodeOptions().enable_logger_service(true));
const std::string & node_namespace = "");
Copy link
Member Author

@saikishor saikishor Jan 16, 2024

Choose a reason for hiding this comment

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

@bmagyar @destogl @christophfroehlich
I need some feedback from you guys. Do you think it makes sense to package these arguments into a structure so that next time we like to add or remove entities we won't be breaking any API (Similar to PImpl implementation)?

Moreover, this PR only provides a method for the user to override the node_options of this particular controller. As per the PR: #1293, the CM will need to get these node options from the newly added method and modify them with the arguments of the params-file and then somehow feed it back to the init method to initialize the LifeCycleNode.

  • We can still keep this node_options parameter in the init method, but we will have to remove the default argument and also mark it as final so it won't be overridden
  • We can package them all together into a single struct (PImpl approach) and then mark this init method as final, then we can do the logic without many issues.

One of the above should be fine. Any more ideas are welcome.

@christophfroehlich
Copy link
Contributor

One more thing. What do you think if we named the method define_node_options or define_custom_node_options, rather then get_node_options. The last one sounds more like getter, not sure if name "invites" people to override it when reading it. @christophfroehlich @bmagyar what do you think too?

I asked already for a more explicit API description that this can be overridden, but renaming is a good idea! I'd go for define_custom_node_options

@saikishor
Copy link
Member Author

@destogl @christophfroehlich @bmagyar I've applied the suggestion proposed by you guys, and then modified a few things to have it ready for the other PR that fixes the parameters: #1293

Let me know your opinion

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.

LGTM, minor text changes only

Copy link
Contributor

mergify bot commented Jan 23, 2024

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

@saikishor saikishor force-pushed the controller_node_options_method branch from 4d63bcd to a0c1341 Compare January 23, 2024 14:37
@bmagyar bmagyar changed the title A method to get node options to setup the controller node A method to get node options to setup the controller node #api-breaking Jan 31, 2024
@bmagyar bmagyar merged commit db11077 into ros-controls:master Jan 31, 2024
14 of 15 checks passed
mateusmenezes95 added a commit to mateusmenezes95/ros2_controllers that referenced this pull request Aug 4, 2024
christophfroehlich pushed a commit to ros-controls/ros2_controllers that referenced this pull request Aug 5, 2024
@saikishor saikishor deleted the controller_node_options_method branch August 17, 2024 08:27
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