Hello everyone,
With Dashing, a new function declare_parameter has been introduced, cf. https://github.com/ros2/rclcpp/blob/master/rclcpp/include/rclcpp/node_interfaces/node_parameters_interface.hpp#L52 and https://github.com/ros2/rclcpp/blob/master/rclcpp/include/rclcpp/node.hpp#L371. I like this idea as it allows to detect mismatches in parameter names between nodes and launch configurations (for example due to typos).
Yet, once a parameter is declared, there seems no possibility to detect whether a value that is equal to the default value has been set explicitly or not. The function get_parameter(name, param) always returns true even if the parameter has not been set but just declared.
In the fmi_adapter package, parameters are created at runtime from a user file (a Functional Mock-up Unit, FMU). Thus, the parameter names depend on a user file which is itself passed via a mandatory parameter fmu_path. In the last days, I ported this package to Dashing and was faced with the issue that I had to declare the parameter names read from the FMU file. Unfortunately, I cannot provide meaningful default values at this stage. The FMU may contain algorithms to compute the default values own its own at a later stage. So, to decide whether the user actually provide a value for a parameter of the FMU or not, I decided to choose NaN as default value and then fall back to the FMU internal mechanism if get_parameter(name).as_double() return this NaN, cf. https://github.com/boschresearch/fmi_adapter_ros2/blob/dev/dashing/fmi_adapter/src/fmi_adapter/FMIAdapter.cpp#L582.
(I also tried the allow_undeclared flag, which did not work for me. Yet, this is also not an option for me as I would like to use the new mechanism due to the reason given in the first paragraph.)
Technically, it should be possible to distinguish whether a value for a parameter has been set or not ā independent of the parameter declaration mechanism. The node_parameters_interface could provide a Boolean function to query for that. Of course, this introduces another level of complexity.
Are other developers faced with the same problem when porting their ROS 2 packages to Dashing? What do you think about the idea to introduce a Boolean function to query whether a parameter value has been set explicitly (even if it is equal to the default) or not?
Looking forward to your feedback!