Not positive I have the terminology right, but the idea is that I have a ROS 1 node that can have multiple "layers" of namespaces for some of the parameters. So the parameter list is something like:
/perception_node/map_size /perception_node/sensor_1/max_range /perception_node/sensor_2/max_range It doesn't have to be set up this way, the key here is that there are multiple "sensor" objects that have the same parameter names, but can have different values. And the sensor names themselves should ideally be configurable from the launch file or a YAML file.
I'm able to get it up and running so that it all initializes correctly, I can have a sensor struct like this:
struct Sensor { string sensor_name; // < This gets set in the constructor float max_range; void configure(ros::NodeHandle & nodeHandle) { max_range = nodeHandle.param(sensor_name + "/max_range"); } }; And that works, but I'd really like to use dynamic reconfigure with this setup too. I've used dynamic reconfigure before on other projects, so I know the basics of creating a ".cfg" file and everything.
But dynamic reconfigure doesn't seem to like parameter names with "/" symbols in them, at least when I tried the following it failed to compile:
gen = ParameterGenerator() gen.add("sensor_1/max_range", float_t ...etc.... My initial idea was that since the ".cfg" file is (I think) really a python file, I could do something clever here and read the sensor names from a configuration file rather than hard coding it like in the above example.
I also tried using groups, but it looks like you're not allowed to use the same parameter name more than once even if you do this:
sensor_1_params = gen.addGroup("sensor_1") sensor_1_params.add("max_range", float_t ...etc... sensor_2_params = gen.addGroup("sensor_2") sensor_2_params.add("max_range", float_t ...etc... #Nope! This fails to compile too The only thing I can think of right now is to get rid of the slashes, so that the parameters are called something like "sensor_1_max_range" and "sensor_2_max_range" and so on. The issue being that it would make the config callback kind of ugly, because on the C++ side I'd have to do something like:
if (sensor_name == "sensor_1") { max_range = config.sensor_1_max_range; } else if (sensor_name == "sensor_2") { max_range = config.sensor_2_max_range; } // And many more lines... I also feel like this kind of defeats the purpose of having the sensor names in a configuration file, because now any time we want to add or remove sensors we need to edit the configuration file AND the C++ code.
So, I guess I'm wondering is it possible to actually do something like what I want? Have people had to deal with this before? Or am I better off restructuring things?