Controlling APM with MAVLINK protocol

Hi everyone,

I’m new here and I’m planning to start a new project with Ardupilot (Copter). For this project I’m planning to use an APM 2.6 (the Arduino mega based in). I would need to plan a mission (waypoints) through Mavlink protocol (I’ve read a lot about that but I’m slightly confused about how it really works). My idea is to put and Arduino or a Raspberry Pi on board in order to communicate through serial port to the APM 2.6 and send the Mavlink commands in order to plan missions.

Is all of this possible?

I will really appreciate your help.

Thank you in advance,

Sergi

Yes, definitely possible.

MAVLink (https://github.com/mavlink/mavlink) has a number of interfaces to popular programming languages (C, C#, Python, Java, Javascript). So it’d be easiest to start with that interface and build your code on top of that.

Thank you for your answer stephendade,

I’ll take a look to your link. I realised that I forgot to say that I would need to add the waypoints on the flight time. It could be possible too?

Also, has to be enabled in the APM to receive Mavlink commands or is enabled as a default?

Thank you!

Yes, is possible

Enabled by default.

Thank you so much for your answer stephendade.

I’ve been playing a little with the Mavlink protocol and Python, but I’m not able to use it properly. The steps I’ve done are the following.

  • I’ve downloaded the code available on the link stephendade gave me (https://github.com/mavlink/mavlink).
    -I’ve run the mavgenerate.py and I’ve generated a Python code. As far as I know, the Pyhton library to create the Mavlink commands to later send through serial port to the APM.

Now I find the code enormous and I don’t really know how to use it in order to (for example) add a new waypoint.

If there’s something wrong in what I’ve said please feel free to correct me.

I’m really sorry if I’m asking trivial questions.

Thank you for your answers!

If you want to use python, you can look (and steal?) how it is done in dronekit : https://github.com/dronekit/dronekit-python ! Or use it !

Thank you so much khancyr for your reply.

I was planning to use Python as a first introduction to the MAVLink protocol for its simplicity. Later I would like to use C because I want to put onboard some kind of Atmega board (firstly Arduino, later my own). But I’m gonna take a look to dronekit.

Can anybody help me using the MAVLink library above? In Python or in C doesn’t matter.

Thank you all!

Reading the documentation of dronekit I’ve just realised that maybe I’ve misunderstood the whole scenario. The scenario I have in mind is to have onboard an APM 2.8 and a Raspberry or Arduino (depends on if I’m able to master the MAVLink protocol in C or in Python [PLEASE I NEED HELP HERE]), but I don’t want to send the MAVLink commands from a computer on the ground. This second board (Arduino or Raspberry) has to be the one which decides which is the next waypoint and send the MAVlink command to the APM 2.8.

Hi khancyr,

I’ve been reading the dronekit documentation. The API is extremely easy and so useful. Thank you so much for your help.

Otherwise, I would still like to try it in C. Could anybody give me some light in this issue?

Thank you!

There’s an example in C at https://github.com/ArduPilot/mavlink/tree/master/examples/linux