Multi Vehicle Gazebo SITL port configuration

Hey everyone,

I am trying to run a multi vehicle simulation using gazebo garden (gz) without ROS. I want to run these vehicles on a host machine and connect remotely to a machine running a GCS via UDPclient. Currently, I am able to run multiple instances of PX4 with gazebo by starting a new terminal for each instance and running:

PX4_SYS_AUTOSTART=4001 PX4_GZ_MODEL=x500 ./build/px4_sitl_default/bin/px4 -i instance

While this handles port deconfliction, it seems to be broadcasting the MAVlink messages aimlessly. I would like it to only broadcast once connected via UDPclient. I’d also like to be able to specify the ports used. Any help or documentation on this would be greatly appreciated and please let me know if I can clarify any further. Thanks!

Hi @spitkowsky
in SITL the mavlink instances are started by

You can adapt it for your needs!

@Benja thanks! Are the IP addresses set here as well? I’d like to connect the GCS over udpclient with address 0.0.0.0 or similar to not broadcast until receiving a heartbeat.

I think the default 127.0.0.1 is used.
Look here for the documentation of mavlink module

The -t and -c options are probably what you are interested in

Sorry for the confusion, I’m pretty new to PX4 in general. It’s important to be able to spawn the vehicles in a single command (or bash script if needed) as I will be spawning many vehicles. I’d then like to connect on a GCS from another computer, regardless of that computers IP address (on the same network of course). I’m not sure if mavlink commands within an already launched vehicle can accomplish this. Please let me know if you think I am missing something.

Ok, for spawning multiple vehicle you can write a bash script that calls multiple

PX4_SYS_AUTOSTART=4001 PX4_GZ_MODEL=x500 ./build/px4_sitl_default/bin/px4 -i instance

Remember to put a delay between the first spawn command and the second: you want gazebo to be full loaded before spawning the other vehicles otherwise you PX4 SITL startup script will fail to detect the starting gazebo instance and will attempt to start a second one.

Is that so critical? if so, then you have to modify the mavlink startup script (see previous message Multi Vehicle Gazebo SITL port configuration - #2 by Benja).
If you don’t change anything, are you already able to connect from the QGC on the different computer?

Got it, understood about the bash script. I believe the need for this eliminates the possibility of sending individual mavlink commands like -t and -c once the vehicles have spawned though, considering the scale (there may be dozens or hundreds of vehicles).

In regard to the UDPclient requirement, yes it is critical to the application. For a bit more context, I can give an example use case. 100 SITL vehicles will be started from a single machine and then 4 separate machines running a GCS will connect to 25 vehicles each, having been given the udp port to connect to and the ip address of the host machine running the SITL vehicles. This is why the UDPclient requirement exists.

Now, after more experimentation, it does seem like I can connect to QGC (and the other GCS needed for this project) on a different computer. I think the issue was that I was testing with QGC, which automatically listens for MAVlink messages on remote port 14550, so my vehicles were auto connecting without me doing anything. The other GCS does not do this and I can manually connect to each via their UDP port and host IP address. If I do need to edit that remote port 14550, it seems I can do that in the startup script.

Ok! now it makes perfectly sense!

100 drones? WOW

So, is the issue solved?
You disabled the autoconnect feature of QGC and connected manually?

Anyway, adapting the px4-rc.mavlink is a good way to tune your system.

Another approach could be to set up

You could use 4 instences of mavlink router to collect 25 drones each and then interface each interface on a different QGC instance