Multi Vehicle SITL using non-local GCS without MAVProxy

I would like to know how or if there is any documentation on a multi vehicle sim without MAVProxy. I would like to connect to a non-local GCS (QGC for the sake of argument) via a UDP connection with:

sim_vehicle.py --no-mavproxy -A "–serial0=udpclient::

I can change the udp port for each vehicle but I get an error stating the following:

bind port 5762 for 2
bind failed on port 5762 - Address already in use

Any help here would be much appreciated!

I use:

sim_vehicle.py --vehicle=Copter --count=2 --no-mavproxy --auto-sysid

Note that each vehicle will output on a different port - TCP 5760 for Vehicle 1, TCP 5780 for Vehicle 2, etc.

This works great, thank you! Is there a way to handle udp ports automatically as well? So for each vehicle the gcs ip would be the same but their udp ports would incrmement.

Additionally, is there a way to configure these vehicles for udp client with ip address 0.0.0.0? The goal is to run multiple vehicles on one machine and connect via udp client from another machine running the GCS with the given udp ports and host machine ip address.

sim_vehicle.py --vehicle=Copter --count=2 --no-mavproxy --auto-sysid --udp

Now uses UDP ports. UDP 5760 for Vehicle 1, UDP 5780 for Vehicle 2, etc.

Got it, thanks! Since my GCS is on another machine and I’d like to use udp client, I was trying some like:

sim_vehicle.py --no-mavproxy -v ArduCopter --instance=0 -A "--serial0=udpclient:*gcs ip*:*udp port*"

And then in a separate terminal:

sim_vehicle.py --no-mavproxy -v ArduCopter --instance=1 -A "--serial0=udpclient:*gcs ip*:*different udp port*"

For my application, it does not actually matter if the vehicles’ system ids are different, as I am differentiating between vehicles via udp port, not sys_id. In fact, I would prefer for each vehicles’ sys_id to be the same if that’s possible. However, I am struggling to connect to the vehicles via udpclient which would use ip address 0.0.0.0.

Is there any way to give specify this ip address either through spawning multiple vehicles via --count or by spawning each in its own terminal?

Yes. sim_vehicle.py --udp option is udpclient, but only in the 127.0.0.1 address.

You can either:

Got it. I have been editing sim_vehicle.py --udp option and/or using the -A "--serial0=udpclient:**ip**:**udp**" command. This question may be outside the scope of Ardupilot and more into networking, but I believe giving the ip address of 0.0.0.0 would allow a GCS to connect via UDP client using the host IP and the given udp port. However, the only way I can connect is by using regular UDP and specifying the host ip address, which is not what is necessary for my application. If anyone knows how to get the UDP client to work by specifying the HOST IP on the GCS, I’d really appreciate it!

I think I may better understand my question at this point. My understanding may be off but I believe the SITL is in udpclient mode and the GCS is in UDP server mode. Therefor the GCS is listening on a port and the SITL is specifying an IP address and the port. Once the GCS sees something on that port, it connects and starts sending MAVlink messages back. I want the reverse of this, so that the SITL is listening on a port and then when the GCS specifies an IP address and the port, the SITL will see that and start sending the MAVlink messages back. My GCS is configured this way, but Ardupilot is not. Is it possible to configure this in MAVLink_routing.cpp or something similar?

Correct.

You’ll need to add support for udpserver in SITL. See ardupilot/libraries/AP_HAL_SITL/UARTDriver.cpp at master · ArduPilot/ardupilot · GitHub, where the current udpclient is defined.