Ok, so I have an answer - remap!
There is an option inside the launch file to remap one topic to a different name. Here is an example of how I remapped /ardrone/takeoff to /ardrone1/takeoff:
<remap from="/ardrone/takeoff" to="/ardrone1/takeoff"/>
I put this line before the node initialization line: <node ...><="" p="">
Using remap I could now remap all the topics I wanted for the first drone to change "ardrone" to "ardrone1" and for the second drone remap again, but this time to "ardrone2" - thus getting two separate topics for the two drones, namely for /ardrone/takeoff
example we get:
/ardrone1/takeoff
/ardrone2/takeoff
Now I had a problem that I wanted to do this for ~30 topics. As far as I can tell there is no way to just change /ardrone/
with /ardrone1/
and thus with a single remap changing all the topics at once. I looked around and found some github issues mentioning that it is not supported, and in any case I couldn't figure it out. Sadly this meant I had to manually remap the 30 topics (if someone found a better way I would be very happy to see it).
But I do not want to manually edit 30+ topics every time I want to add another drone, its not fun and it looks terrible. So what I ended up doing is have a BASH script that had a for loop for the amount of drones I want and ran the launch file that many times. In order for this to work I now needed to change my launch file and add the following lines:
<arg name="droneip" default="192.168.1.1" />
<arg name="drone_name" default="ardrone"/>
In order to accept in arguments for the drone name and IP.
Then in my remap commands I needed to change ardrone1
with $(arg drone_name)
to look like the following:
<remap from="/ardrone/takeoff" to="/$(arg drone_name)/takeoff"/>
and when initializing my node I need to make the node name change with name="$(arg drone_name)_driver1"
and the ip change args="-ip $(arg droneip)"
so my node initialization looks as follows:
<node name="$(arg drone_name)_driver1" pkg="ardrone_autonomy" type="ardrone_driver" output="screen" args="-ip $(arg droneip)">
My BASH script is short and looks as follows:
#!/bin/bash
for (( i=1; i<=$1; i++))
do
roslaunch launch_multi_drone.launch drone_name:=ardrone$i droneip:=192.168.1.$i &
sleep 15
done
Now everything seems to work.
Hi man,
I am trying to do the same thing for a school project. I am new to ROS and I honestly do not know where to start. Would you be able to share what you did?
Thanks in advance!
For what I did to get the multiple drones working I tried to explain the best I could in the answer below. I will be glad to tell you how I got started in general and recommend some things, but I will need you to post a question so I am not limited on characters and stuff when answering.
Link your post here or tell me the numb er of the post (you can see it in the URL) so that I can find it.
Hi, https://answers.ros.org/question/2953... The question is called "Controlling multiple drones using ROS and the number is 295383. Thank you!!
hi oha ! can yoou please send me your current code in which all the drones follow the same command? because im currently at this initial stage and want to have any sort of code for multi drones to work in swarm...pl send me all the files(codes) including launch file and others too. thx in advance :)
I guide I made with some code can be found here: https://gitlab.com/ohanoch/MSS_Guides... and code I used to implement it can be found here: https://gitlab.com/ohanoch/MSS_drone_...