ROS2 - Multi-robot launch files with variable parameters
Hello,
I am currently working on a multi-robot simulation package and I would like to spawn multiple robots with different parameters using launch files.
In general, I have a few ideas to implement this, but don't know if it is even possible to implement them currently.
1.Use a .yaml file to specify the scenario, so for example
robot1:
name: robot0
x_pose: 0.0
y_pose: 0.0
robot2:
name: robot1
x_pose: 1.0
y_pose: 1.0
You would then need to load this in the launch file and for each entry you create a corresponding action in the launch description.
2.Specify the number of robots as an os environment variable or as argv in the command line and accessing it in the launch file. However I think this is not modular enough for larger simulations.
3.Access the launch configuration of the launch file (for example "LaunchConfiguration('robot_number')") and create a array with an entry for each robot:
for num in range(int(robot_number.perform(LaunchContext()))):
robots.append({'name': 'robot'+str(num), 'namespace': 'robot'+str(num), 'x_pose': num*-1.0, 'y_pose': 0.0, 'z_pose': 0.01},)
However, when I tried to implement the third approach, it was not possible to access the LaunchConfiguration when there is no default value set. Additionally, if you call this launch file with a different number of robots, the default value is still used, as the LaunchContext is local.
4.It could be possible to combine the ideas, so that you access a LaunchConfiguration to get the number of robots and then modify a template .yaml file with a $namespace$ parameter, which gets replaced by a script in the launch file. This temporary parameter file could then be forwarded to the other launch files to spawn the robots and start the navigation nodes (inspired by the RewrittenYaml script of Nav2).
My questions would be:
- Is it somehow possible to access the non-default LaunchConfiguration value in a launch file?
- Is it possible to access a .yaml file in a launch file and add actions for each listed robot?
Best Regards
Harun Teper