I’m trying to forward MAVLink messages via UDP from one QGC instance (MAV Sys ID 254) to another QGC instance (MAV Sys ID 255) running on a separate PC that’s connected to the same LAN.
I have done the following in the source QGC (MAV Sys ID 254):
Q > Application Settings > MAVLink:
Selected “Enable MAVLink forwarding”
I tried selecting and deselecting “Only accept MAVs with the same protocol version”
Set Host name: 192.168.1.107.14445 (ip addr of destination QGC (MAV Sys ID 255))
Restarted source QGC (MAV Sys ID 254), after making the above change to Host name
Q > Application Settings > General:
AutoConnect to the following devices: Deselected “UDP” (also tried with this selected)
Q > Application Settings > Comm Links:
Added a Link: Type UDP, Server Address: 192.168.1.107:14550
I tried with and without connecting the above comm link
A possible clue:
Q > Analysis Tools > MAVLink Inspector:
In both QGC instances the System for the other QGC appears in the drop-down list near the top-right of the screen
When the System for the other GCS is selected, the Heartbeat message from that other QGC appears and increments as expect, so clearly the two QGCs are communicating
Here’s the only thing I found on MAVLink forwarding in the documentation (or anywhere else):
Enable MAVLink forwarding: Enable QGroundControl to forward MAVLink messages from connected vehicles to another UDP endpoint (Default: False). Note that this forwarding is one-way: from QGC to the specified host. Any MAVLink messages that are received from the specified host will be ignored.
Should I be able to build mavlink-router for Windows (e.g., using Visual Studio)?
I assume that using MAVSDK would involve writing a program that (for example) would connect directly to the flight controller via a serial link, and then forward messages to multiple GCSs via UDP. Does that sound right?
I briefly read the MAVSDK information you pointed to, and I noticed the following statement:
“For TCP connections, only the client connection is currently implemented”.
Does that result in any limitations on the communication between the GCSs and control flight controllers? In particular, it’s my understanding that mission plans and parameters are transmitted via TCP.
I would of course prefer to use the MAVLink forwarding capability that is built into QGC, if it serves the purpose, and is reliable. It appeared to be working correctly at one point, but I haven’t been able to get it to work again, although I don’t know of anything that changed. Are there some conditions that would prevent MAVLink forwarding, but allow the heartbeat messages to get through? Or is there a reliability issue with the GCS MAVLink forwarding function?
I was able to get MAVLink forwarding to work by setting up the connections in MAVSDK with forwarding ON, as suggested by JulianOes (above).
Thanks for the suggestion!
For me (a MAVSDK novice), it required quite a few hours of guessing and experimenting. So, I think it would be good to include an example of how to do this in the “MAVSDK\examples” folder, since I expect that it’s a fairly common requirement. I’d be happy to provide my example, but someone may want to clean it up a bit, since I’m very new to MAVSDK. I tried to upload it here, but it apparently won’t accept zip files or source files, so let me know if anyone wants it.
Yes, I understand that it might not be straightforward using just the docs. If you could make a pull request contributing an example of how to set it up, that would be amazing!
I just discovered that the method I’m using to forward MAVLink messages between multiple autopilots and GCS’s is causing QGC to get each message from the autopilot twice.
In particular, I’m using the method specified at the following location “To forward bi-directional from UDP to serial and serial to UDP”:
Q > Application Settings > Comm Links: Nothing is connected
Q > Application Settings > General > AutoConnect to the following devices: UDP and Pixhawk are both unchecked
pix32 V6 connected to the same PC via a serial link (pix32 V6 UDP port connected to PC UDP port using an FTDI to UDP cable)
Procedure:
Start QGC
Connect AP to the USB port and wait for it to boot
Start my MAVlink forwarding program
QGC connects to the AP after few seconds.
Go to Q > Analyze Tools > MAVLink Inspector: Messages are updating at 2x the normal rate (e.g., HEARTBEAT is received at 2 Hz)
Go to Q > Analyze Tools > MAVLink Console: nsh> prompt is displayed twice each time is pressed
Let me know if you need more details.
For reference, when I connect QGC directly to the serial port, I don’t get duplicate messages from the AP (using Q > Comm Links > Serial Port COM5, Baud Rate 115200)
I meant to say FTDI to USB cable, but actually I’m just using a USB cable to connect the AP USB port to the a PC USB port. Sorry about that misinformation.
I’d be happy to provide the code. What’s the best way to do that? Should I just paste it here, or is there a better way?
Also, let me know if you have any suggestions for things to try.
When I add a connection to a 2nd PC running QGC (on the same LAN as the 1st PC), that 2nd QGC only gets one copy of the MAVLink messages from the FC (which is connected by USB to the 1st PC).
Also, when I connect a (2nd) FC to the 2nd PC (also via USB), I get duplicate messages from that FC on the 2nd QGC, but the 1st QGC only gets one copy of each message.
In other words, I suppose you could say the problem is symmetrical.
Here is the command line input for each PC (updated code is below):
Could it be that QGC also connects directly to the serial port? On Linux that’s not possible. If one application - in this case mavsdk - uses the port, it is busy and QGC won’t connect to it. My hunch is that Windows can still connect to it anyway.
Thanks Julian. It wasn’t connecting to the serial port twice, but it was connecting twice to the QGC instance running on the local PC, so your theory pointed me in the right direction.
Specifically, it was connecting to the local QGC using the IP address I specified, and also connecting to it automatically using 127.0.0.1:14550
Nice, glad you could fix it. So just to understand, mavsdk created two UDP connections? I don’t understand why it would do that exactly? The default QGC connections listen on local UDP port 14550, and mavsdk would send UDP traffic there using udp://127.0.0.1:14550, or using any of the network adapters’ IPs. So what am I missing?