The api and documentation for publisher/subscriber and service/client is great. Pretty straight forward. Simple. Makes sense. Love it.
On the other hand the parameters is not so clean. In the beginner section of the documentation there are a few code smells:
- have to pass the string “my_parameter” into multiple functions (declare_parameter, get_parameter)
- this->get_parameter().get_parameter_value().get…how many times do i need to type “get” to get this thing
- we’re calling this whole get chain from a timer_callback…seems odd? why not a callback that’s called when it changes? or even better why not just have a value that updates when it should?
And again in the intermediate documentation:
- still passing strings around (declare_parameter, add_parameter_callback)
- have to hold on to these “cb_handle” objects (one per parameter??)
- the handler doesn’t even know the “type” of the parameter I just declared?
I’ve played around a very little bit with the parameter stuff on my own and one thing that I found a little disturbing is from the command line I can say “ros2 param set node variable value” which is great but there’s no guarantee that anyone was listening on the other end. If the implementer of the node says “eh I’ll declare these parameters but figure out how to use them later”…no way I’d know the difference as a user of that node.
Anyway. I’m not a great programmer by any means (so the following may simply be impossible) but as an end user it feels like the api should be more like:
int & my_int_param = this->declare_parameter("my_int_name", default_int_value, optional_int_callback);
// my_int_param is just a reference to an int that is updated behind the scenes when it should be
// if I care I could pass in a callback that gets called when the thing is about to be changed and modify/verify/reject the change
// that's it. now I use my_int_param throughout my node and I'm done
I did a little more digging and found this: https://github.com/ros2/rcl_interfaces/blob/rolling/rcl_interfaces/msg/ParameterValue.msg
which is also mildly terrifying. I (clearly) don’t know how this stuff works at all but the message format makes me think that every time I send a parameter it’s as if I’m sending a message containing a bunch of extra junk??
Anyway. I’m sure there are a lot of good reasons it is the way it is. I’d like to understand better if anyone knows. Does the api I proposed seem plausible? Is this the right place to bring this up? If not where should I?