PickNikRobotics / generate_parameter_library

Declarative ROS 2 Parameters
BSD 3-Clause "New" or "Revised" License
247 stars 45 forks source link

Parameters and gmock #130

Closed christophfroehlich closed 1 year ago

christophfroehlich commented 1 year ago

I added not_empty<> to https://github.com/ros-controls/ros2_controllers/pull/703, but got error messages that the command_interface parameter cannot be empty: https://github.com/ros-controls/ros2_controllers/actions/runs/5555108925/jobs/10145808720?pr=703

In the readme of this repo, it is suggested to use size_gt, but that gives the same result https://github.com/PickNikRobotics/generate_parameter_library/blob/a242eaeb9d48fc08c019f5d615eef6bfd85e1c96/README.md?plain=1#L225-L236

How does this library work together with gmock, and why does the parameter-test fail but the test itself is fine without not_empty<>?

tylerjw commented 1 year ago

Wait, where does this work?

I think the reason for the errors wit both not_empty and size_gt is that a parameter is not set before you try to initialize, and there is no default, so it defaults to a size of 0 which fails validation. You'll need to select the parameter on the node before creating the ParamListener. You could mock the param listener if you wanted to with gmock if you created a wrapper for it and implemented your own version of the wrapper.

christophfroehlich commented 1 year ago

Ok, I think I realized now that subset_of<> validator, as well as the custom ones, do not throw errors if the parameters are not set.

But actually, they are set before calling the init()/on_init() methods, where the ParamListener is created.

https://github.com/ros-controls/ros2_controllers/blob/8436ed549becce0b694dfe23cfa053436f2b6d42/joint_trajectory_controller/test/test_trajectory_controller_utils.hpp#L157-L174 https://github.com/ros-controls/ros2_control/blob/aea4efee3744a14290cdd37da2b71e1fa031fde9/controller_interface/src/controller_interface_base.cpp#L45 What is missing to satisfy ParamListener?

christophfroehlich commented 1 year ago

No, I'm wrong. The fields of params_ will be set, not the ROS parameters used for ParamListener. Why aren't they overridden by ParamListener then? Parameters are set only after the init() call, this might be the problem here: https://github.com/ros-controls/ros2_controllers/blob/8436ed549becce0b694dfe23cfa053436f2b6d42/joint_trajectory_controller/test/test_trajectory_controller_utils.hpp#L173

christophfroehlich commented 1 year ago

And because the node is created inside the init() method of the ControllerInterfaceBase, there is no chance to set the parameters before the ParamListener.

Thanks for pointing me in this direction