Minimal MAVLink Example Code

QGroundControl is an open-source "ground control station" for uncrewed aerial vehicles. It's an all-in-one center for display of live-streaming inbound UDP video, attractive display of vehicle telemetry, and manual joystick remote control. It communicates with the vehicle controller using the open MAVLink protocol.

I <3 quaternions

I find MAVLink attractive for simple embedded systems since libraries for C are readily avaiable and easy to use on the microcontroller end. Though it's specialized for autonomous aerial vehicle control, QGroundControl has been adapted to a lot of other contexts, and seemed like a good option for remote human-piloted teleoperation of other types of robot.

I got it working, but had a hard time finding clear documentation or a minimal example of the specific messages required to establish a MAVLink "connection" between a vehicle and QGroundControl without using a complicated autopilot framework. For many applications, one of the off-the-shelf autopilot solutions like Ardupilot or PX4 is an appropriate choice.

But if the robot's dynamics and controls are too far outside those of a normal air, water, or ground vehicle, it makes less sense to try to shoehorn it into one of the existing autopilot frameworks. Instead, you'll want to add MAVLink to your firmware as needed. I worked through the negotiation of all the messages QGroundControl negotiates with a vehicle.

Given how hard it is to find a bare-bones example like this, I decided to develop a standalone non-proprietary version to share. So I wrote a simple Arduino sketch that will connect to QGroundControl:

Once the connection is made, if virtual joysticks are enabled in QGroundControl or a physical game controller is connected, the embedded code will loop back the control messages. I wanted to provide an example that does not require any external hardware besides the target microcontroller, and the built-in virtual joysticks in QGC enable this.

Site generator

Manual control message loopback demonstration