Make it possible to use empty lists/arrays as parameter values everywhere
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 805
- Forks
- 564
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 27
Description
Feature request
Make it possible to use empty lists/arrays as parameter values everywhere.
Feature description
The inability to use empty lists/arrays as parameter values on the command line and in YAML files is a surprising edge case in ROS 2. As far as I know, it is already possible to set a parameter value to an empty array with all functions in the rclcpp API that accept parameters, because they know the type of the array. ros2 param set also accepts [] as the parameter value, but silently converts it into a boolean array even though that's not always correct.
It would be nice and a consistency win to be able to use empty lists everywhere a parameter value can be specified.
Implementation considerations
The override parameter values are stored as rclcpp::ParameterValue on the node. Those are converted from rcl_variant_t by rclcpp::parameter_value_from(). Up to that point, empty lists are still accepted: An empty list (and I believe only an empty list) will produce an rcl_variant_t with no variant set.
So, it would be possible to represent an empty list of unknown type given as an override value also at the rclcpp layer. For instance by adding a new variant, including a corresponding new rclcpp::ParameterType called PARAMETER_EMPTY_ARRAY, to rclcpp::ParameterValue.
Would this work in a useful way with all the operations that you can do on parameters? From looking at the code, it appears so to me:
- The
get_parameter()/declare_parameter()functions which returnrclcpp::ParameterValuecould still do so. - The
get_parameter()/declare_parameter()functions which return a concreteTcould return an empty vector for all array-typeTwhen the empty list variant is active. - I think the
set_parameter()function and its siblings should also accept empty list parameters. However, here it will probably be a little tricky to get the interaction with static/dynamic typing right. E.g. if you have set a parameter to a bool array, you don't want to change the type toPARAMETER_EMPTY_ARRAYwhen it is set to an empty list, because that could then produce an array of a different kind withget_parameter(). So once it has a concrete type, it should not be possible to change it back to an empty list type (although it should be possible to change the value to an empty list). Probably the behavior with dynamic typing should be different, so that it is changed to the empty list type. - The parameter service/client could also work with this extended
rclcpp::ParameterValue. TheParameterType.msgmessage would need to be extended withPARAMETER_EMPTY_ARRAY, so that e.g.GetParameters.srvcould report the type accurately. Since the parameter service calls the*_parameter()functions under the hood, I think no further changes would be needed.
Of course the devil's in the details. For instance, I haven't thought through the behavior of a ParameterDescriptor with type PARAMETER_EMPTY_ARRAY yet.
Does this seem (a) like a good idea and (b) feasible to add to rclcpp?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading rclcpp::ParameterValue and parameter_value_from(), then trace how empty overrides move through get_parameter(), declare_parameter(), and set_parameter(). Review ParameterType.msg and GetParameters.srv for the service representation. Done means empty lists work consistently from command-line and YAML inputs without losing concrete array types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, yaml
- Domain
- api, backend-api-design, cli
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100