How to set up a modular launch file to launch a variable number of robots and nodes?
Hi there!
Together with a colleague I'm trying to set up a system which will be able to launch a variable number of robots and robot types with their accompanying nodes.
We have several types of robots in Gazebo, e.g. the Clearpath Ridgeback or the Husarion ROSbot 2.0. Each robot with it's accompanying nodes will be launched inside it's own namespace: For Ridgeback this will be rdg##, for ROSbot this will be rbt##, where ## is replaced with the ID, such as 01 or 13.
An example robot ID's in a fleet could be: rgd01, rgd02, rdg05, rbt01, rbt11
But the list of robot ID's in the fleet can be kind of combinations really.
What we have working right now is a launch file structure which can launch a fixed number of Ridgeback robots (3) with the required nodes in their respective namespaces.
We've looked into using the parameter server and using rosparam inside launch files to look at a parameter containing a list of the desired robots ID's we which to launch, but hit a roadblock in trying to read from the parameter server inside a launch file (You can write server parameters, but not read server parameters?). Which made us doubt it this was the right approach.
Thus my question is; How should we approach setting up a system which is capable of launching a variable number or robots and robot types inside their own namespaces?
-Patrick
roslaunch
does not support this directly. There is no loop construct. Perhaps recursion could be used, but I haven't tried whether it'll work.All parameters are stored on the parameter server before anything else is started (ie: nodes), so there are essentially two phases: store configuration on parameter server, then start nodes. There is no "read from parameter server" phase in between.
Hmm ok, so the only variable input which can be given to a launch file is as an argument in the roslaunch command.
Say we get a param inside the launch file which contains the list [rdg01,rdg02,rbt05], then the next issue is, how do we iterate over this list, retrieve the namespace of each robot and set that as an arg for later usage in the namespace tag, especially since the number of items in the list varies. Any ideas?
You also mentioned recursion, which I assume would be including the launchfile itself with an include tag. This tag should imo be wrapped in a conditional which checks if the desired depth is reached to prevent infinite self launching. Which brings up the question of how to deal with counters in conditionals inside XML.. I'll look into this, but any knowledge shared is appreciated.
Yes.
Of course.
Not "XML", but in
roslaunch
XML. Androslaunch
supports passing arguments toinclude
d.launch
files, which in turn can use Python expressions inarg
s. So it might be possible to pass a counterarg
to aninclude
d.launch
, have that.launch
subtract 1, pass thearg
on to another and instantiate whatever it wants with the value of the counter it was passed in its "layer" of recursion.But again: I've not tested this, so there could be something which makes this "not work".
And we're of course really zooming in on implementation ...(more)
I've managed to set up the basic recursion as a test. I must say it feels a bit finicky because I couldn't use < <= operators inside the eval. I had to resort to using:
Where the recursion_depth starts at 1 and is increment with each include. The robot_number is derived from the roslaunch argument (string):
Using the following eval:
But it seems working with a test; As a test it sets up a range of variables, each in their own namespaces (rdg01, rdg02, etc..). Which are derived from the string robotlist_string.
Shall I post the solution code as an answer (limited amount of characters here), allowing further improvements there using comments?
After some time: #q229489 is essentially a duplicate I believe.