I'm working on a project where I must send commands from a smart phone to the APM. I have been reading about MAVlink commands but I am very confused what the purpose of them are. I read here https://code.google.com/p/ardupilot-mega/wiki/MAVLink that the APM uses this set of MAVlink commands. Can I write code to simply build the command and send it to the APM via serial? Or must I use the MAVlink library to build the commands?

Views: 13439

Reply to This

Replies to This Discussion


It takes some time to fully understand MAVLink, that's normal.

You can use the code generator that is in the official MAVLink distribution: http://qgroundcontrol.org/mavlink/pymavlink .It will generate nice C code that has structs for all messages, and can read and write messages to/from a serial or other stream.

You don't have to use that code. You can also write your own. But using the C code from the generator will save you potentially a lot of trouble. It just works..



The wiki article isn't valid for MAVlink 1.0.

The MAVlink library is a code only library, you can grab the source for the APM from the repository. This will be easier. You can then just call the correct functions to make the packets you want to send.

What isn't clear to me yet is the heartbeat timer. There is a requirement for the UAV to send the heartbeat packet periodically. On the GCS you can monitor the heartbeat packet sequence number and determine packet loss statistics, the mode the UAV is in. I'm not clear if this packet needs an ack sent to the UAV.

If the above is true, you will most likely need to create a message loop to process the ACKs that need to be sent on the GCS. If not you will be able to send the correctly formatted sequence of bytes over serial alone.

I'll post more info as I figure it out


I was wondering if you had made any in-roads into this work Bill, Im currently also trying to send mavlink commands to my apm from another arduino over Xbee radios.

Did you manageto find a way to read heartbeat messages to check the link between the apm and seconds arduino board?


Yep, I have it working, it's relative easy once you have understood it. Like what Soren says, use the helper functions and it just works. Each message has an helper that you just give the message struct too and it just packs and encodes it all for you, there's a decode helper as well.

You don't need to send heartbeat messages, but you can on ArduPlane as part of the GCS fail safe.

I've got to sending a spoof mavlink heartbeart packet from my arduino nano over xbee, and i've verified this with QGC however, I want this board to act as a ground station.

Do you know anywhere i can find information on decoding mavlink messages and also sending commands.

Do commands need to be sent in a group like the heartbeat is with mav  type, mode, number etc or can they be sent individually whilst, and does the gcs need to transmit a heartbeat with the apm in order for it to recieve commands such as jump_to?

Thanks, Matt

Hello Matt,

I am not sure if you already got the information you wanted.  Most MAVlink messages are declared on its own file i.e. mavlink_msg_heartbeat.h -- so you can look for encoding, decoding, sending function in those files.



Hi Peter, 

I found this eventually, thank you very much for the heads up 

I've now progressed to been able to send nav commands, but still a little unsure and have posted a topic here. I don't suppose you would mind giving it a glance and see if i am missing anything obvious.

Thanks again,


As they say, enough is enough!

After quite some frustration, I got this thing to build. The same thing that has been talked about in this forum. The sad thing is that all the document out there is quite outdated. I just figured out a way to build this MAVLink library for Arduino Uno.. At this height of frustration, I am going to start writing a book on MAVLink..:-P

Before others break there head, follow these simple steps:

1) No changes in fastserial library required. Go and download both MavLink sample code and ArduStation from here

2) Go to your Arduino Preferences folder ->and paste the libraries folder from ArduStation download.

3) Lay your hands onto the 'ArdunioMAVLink' download and paste it directly under the main Arduino folder (for me it is in C:\users\username\Arduino1.04\..". Remember inside this folder you must have (only) the ArdunioMAVLink.pde or .ino file.

4) Copy the 'mavlink' folder from libraries under ArdunioMAVLink download to the libraries in the same Árduino folder directory.

Now everything should be setup. Open the ArdunioMAVLink.pde file and build. I built it using the Visual Studio plugin but it must build otherwise too.

Thanks again,


Hi shyam, I have been trying to utilize this code but it does not seem to be working. I am currently using the c_uart_interface_example code . Specifically the mavlink_serial.cpp. I am just getting the heartbeat messages:

Received message from serial with ID #0 (sys:1|comp:1):
Received message from serial with ID #0 (sys:1|comp:1):
Received message from serial with ID #253 (sys:1|comp:1):
Received message from serial with ID #253 (sys:1|comp:1):
Received message from serial with ID #0 (sys:1|comp:1):
Received message from serial with ID #0 (sys:1|comp:1):
Received message from serial with ID #0 (sys:1|comp:1):
Received message from serial with ID #0 (sys:1|comp:1):

I think the reason its doing that is because there was no request stream. So included the following line:

mavlink_msg_request_data_stream_pack(127, 0, &message, message.sysid, message.compid, MAV_DATA_STREAM_RAW_SENSORS, 1, 1);

It is still not working. I am new to MAVLink and its difficult to decipher whats going on. Any help is highly appreciated.


Reply to Discussion



Season Two of the Trust Time Trial (T3) Contest 
A list of all T3 contests is here. The current round, the Vertical Horizontal one, is here

© 2018   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service