Karelics / param_configuration

The tools to make ROS 2 parameter configuration easier
Apache License 2.0
41 stars 1 forks source link

Modifying final param structure during runtime #12

Open kushal2507 opened 1 day ago

kushal2507 commented 1 day ago

I am currently using this repo to manage different parameters for different locations where my robot needs to run. The final param file that is generated contains environment specific params which are used by my ros2 nodes to navigate through a setting eg., door_height, corridor_width etc. I have defined the PARAM_CONFIG_DIR and PARAM_DEVICE_DIR as ENV variables in my bashrc. Currently, I keep changing the PARAM_DEVICE_DIR specific to every new location and new robot and it works seamlessly. The params are currently being loaded through the launch file during startup. However, I now have a situation where one robot needs to traverse through 2 different locations after startup. I cannot create different params under the same node for different locations as that would defeat the clean way of managing my params, which are currently separated for every location in a separate repo (as suggested in the README)

How can I use this package in such a situation? Have you dealt with such a situation before?

Thanks!

tanelikor commented 14 hours ago

Hi Kushal,

Separating the device-level configs by the locations or working environments of the robots is an interesting use case for this package, and something that we haven't considered before. The original idea behind this package was to allow varying configurations of the (at least mostly) same software for different robots with varying capabilities. It was always assumed that if the robot was deployed to a new site that required different parameters, one would just update the parameters of that robot. However, storing the parameters also by the environment makes sense and is a nice idea.

When it comes to the runtime configuration of the nodes, I'm afraid this package does not provide a ready-made solution. The package is meant to be used only for launch-time configuration, so changing the parameters of the nodes with it in runtime requires some extra work. But, assuming that I understand your setup correctly, I think you could achieve this with the steps below or something similar. How difficult this will be likely depends on what your nodes that need configuring are like at the moment.

Idea:

  1. Make the parameters of the nodes (that you need to re-configure) runtime-configurable, i.e. either always read the parameters with node.get_parameter whenever you use them or add parameter callbacks for updating any stored values when the parameters are updated. Depending on what the nodes are doing, you might also want to make them lifecycle nodes so that you can stop their operation before changing the parameters, and then re-activate them after.
  2. Write some configurator node that updates the PARAM_DEVICE_DIR environment variable and uses this configuration package to get updated parameters when needed, and then sends the new parameters to the nodes that need them via the set parameter service. Note that to use this package for the parameter resolving, this node likely has to be written in Python. Depending on what your nodes do, you may also want to add some extra logic here (remembering where the robot is to localize it correctly etc). Using this package inside a node like this is not the designed way of using it, but it should work.
  3. Whenever you need to change the settings of the nodes, you then stop the robot, deactivate/cleanup the nodes that need new parameters, call the configurator node to get and send the updated parameters to the nodes, and then re-activate the nodes with the new parameters.

Other solutions like performing launches as sub-processes from other nodes should also work (and wouldn't require the runtime configurability of the nodes), but I believe the suggestion above should be a cleaner solution if you can make it work. There may also be other solutions that I'm not thinking of right now.

I hope this helps, and definitely let us know if you have further questions or problems regarding the use of this package!