Hi All,

I was recently fiddling around the code for a while and decided to create a tutorial out of it so that others may find it useful. If I would have known this knowledge long back, I am sure I would have saved a lot of time since then! I find lot of beginners getting swayed and lack of knowhow on MavLink with respect to APM/PX4. Information on internet is scattered and not much of use!! 

This will be "Step by Step" entertaining, PART - I of the series I plan to write.on:

3691077228?profile=original

What it Covers:

  1. MavLink, starting from scratch. What the hell is it and understand how it works with APM/ PX4
  2. Learn how developers think -> Arducopter communication with Mission Planner and vice-versa.
  3. Get a feel of 'How Stuffs works'.

Too much hype:) Well, this information has been collated from my experience and from internet. I know there is information on the new Wiki, it tells you what, I plan to tell you 'how'! :)

Please let me know if you found it interesting. If there is enough response, I will make another tutorial where I would add more 'Step by step' knowhow!!

Options:

- More on MavLink

- Learning Arducopter source code, Step by Step

- Making swarm (multiple) copters work with your 3DR Telemetry radio! I am working on it.

See attachment for [MAVLink Tutorial for Absolute Dummies (Part –I)]

Edit: Request you to post your queries over the forum directly, as it is not possible for me to address all queries I get by email!

--

Best regards,

Shyam

MAVLINK_FOR_DUMMIESPart1_v.1.1.pdf

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

    • @Diego,

      Thanks for your comments. Second part is still under my plan, will let you know when I make it.

      Time pressure with my regular job ;)

      Regards,

      Shyam

    • Hi I am new here cause I recently buy a pixhawk ;) 
      Your tutoriel is very great :) . If you are ok I want to contribute ( not by adding new content in your tutoriel because as a newbies I can't ... but by translating it in french, because yes I'm french ;) ) 
      I know that it's not a big contribution but it's a begining =). 

      I already translated the first page : I can send you my work to add it in the first page ;) but it could be easier for me if I had the word version of your tutoriel ( to use exactly the same color font and all ... ). I don't know how to use git yet but I am looking on tutoriels ... 

      Regards. 

      Jonathan

    • Hi Jonathan,

      Thanks for your inputs. I am not sure myself, how many people may want to read it in French. But, if you think it will be useful to a large French audience, I will be sure to add your translated version in French to my first page :)

      PM me your email address, I will send you the word version of my tutorial.

      Regards,

      Shyam

  • Im sorry for reposting this since I already asked it under another post. 

    I want to retrieve altitude of ardupilot. When I connect to APM, I can see in telemetry the altitude and if I move ardupilot in my hands, altitude is changing. So my goal is to print altitude. I found out that the float altitude is in mavlink_msg_vfr_hud.h. So far its only printing: "ALTITUDE: 0.0"

    Here is what I have so far:

    #include "/Users/Gabriele/Documents/Arduino/libraries/ArdunioMAVLink/libraries/mavlink/include/mavlink.h" 

    #include <mavlink_msg_vfr_hud.h>

    int system_type = MAV_QUADROTOR;

    int autopilot_type = MAV_AUTOPILOT_GENERIC;

    uint16_t len;

    mavlink_message_t msg; 

    uint8_t buf[MAVLINK_MAX_PACKET_LEN];

    mavlink_status_t status;

    float mavlink_msg_vfr_hud_get_alt;

    char buffer[32];

    void readSerialMavLink();

    void setup() { 

      Serial.begin(115200);

      Serial.println("Booting...");

    }

    void loop() {

    readSerialMavlink();

        delay(1000); 

    }

    void readSerialMavlink() {

      while(Serial.available() > 0) {

       Serial.println("Serial available"); 

              Serial.print("ALTITUTDE: ");

              Serial.println((dtostrf(mavlink_msg_vfr_hud_get_alt,10,2,buffer))); 

              }        

                 }

    • @Murdock,

      I believe, one end of the system is the APM with telemetry which is sending the altitude and you have connected this via USB to your system. The Mission Planner has the code to decode the encoded 'altitude' packet sent from the APM and display 'altitude' for you. This is done in C# in Mission Planner. You must do the same thing at the receiving end as done at the transmitting end (APM).

      From what I see, you have written an arduino code at the receiving end. Can you tell me where you wish to decode the altitude message? Is it another APM attached to your system (PC) or an Arduino Uno. Someone has to be sending the (encoded) packets and someone has to receive them (decode them).

      You are getting there. However, since you have not mentioned detail of your setup it is hard for me to guess where you might be going wrong.

      Regards,

      Shyam

    • Hello Please i am having trouble compiling the mavlink arduino code on the website .. any ideas on how to achieve this?

    • Hey, Shyam!

      Thank you for your reply. My goal is to display everything on my computer right now in Arduino IDE's serial monitor. I connected ArduPilot Mega to my computer via USB. It would be the best if everything would be done in Python and I could print out the altitude in terminal but since I know there is a python library for arduino its not a problem for now. 

      Id really appreciate if you could guide me more precisely with my problem. 

    • @Murdock,

      You must understand that the values (sensor information, GPS position, etc) that are received (via USB or wireless telemetry) from the APM are in an encoded format (encoded by the APM). They cannot be directly displayed on the console (they can, but it will look like junk characters). In other words, logic must be in place at the receiving end (your laptop) where you write the code to decode it.

      Mission Planner already does that, and yes you can do that in Python as well. The logic defined in the APM and Mission planner are almost similar (both do encode and decode, as they pass MavLink messages to each other). You should use Pygen (a generator that generates C, C++ or Python code).

      The mission planner (or APM) use standard XML file(s), e.g. Commons.xml file (in MavLink library), which is used by "MavLink Pygen" to generate the C, C++,C# or Python files. In these files, the logic is auto generated to encode and/or decode. You simply call these functions to do your job (such as decoding the values for the Attitude or Position MavLink headers coming from the APM at the laptop end). In the XML, it defines what is to be done (you should check it out, under Arducopter ->Libraries -> GCS_Mavlink -> (v1.0) folder. 

      Simply write a Python script. Read from the open Serial COM port. Receive the streaming data (MavLink headers, etc) from the APM. Filter out the required headers (are structs). Decode it and voila -> you have what you want!!

      I hope it helps you get started. Also, have you checked this link?

  • Hi,

    Your manual was very helpful for me and my mates in our project beginnings. We are working on kind of GCS using our own map libraries. We implemented already some messages of MAVLink, and for example we are able to show actual GPS position of APM on map.

    We want to implement additional functionality, currently the ARM/DISARM action, which is MAVLINK_MSG_ID_COMMAND_LONG subtype. But we didn't succeeded yet. We create the message, send it to board, but nothing happens after it. When similar message is sent from APMplanner or MissionPlanner the APM(we are using APM2.6 original from 3DR) is armed, and on current Arducopter FW 3.0.1 the rotors start to spin. And after sending DISARM message they stop.

    We want to achieve the same functionality. But it seems like there is needed some special sequence of commands to perform required action or something else that we don't know yet. So I will appreciate any hint where to search or how to debug the communication. We are not sure if the APM received the command, because the MAVLink protocol does not provide such kind of information. If you have any tip how to create something like testing polygon for MAVLink communication it will also help.

    Thanks

    Juraj

    • Hi Juraj,

      Have you tried using qgroundControl first? This might be an alternate to using Mission Planner. You just have to establish connection with the GCS on your computer and it will auto list all the commands coming in from the APM and going to the APM (if you have edited something on your own).

      If I understand correctly, you said "We want to achieve the same functionality". So, it must be already working on APM and GCS, and its just that you are trying to use/ construct your own GCS software?

      From what I understand, the problem isn't on the APM side, rather on the GCS software side you are building. The commands must just flow in. My suggestion would be to debug.write the stream of commands coming in and write it to a text file for you to analyze. Using APM 2.5/ 2.6 etc for MavLink should not matter, because this is something in software and not hardware.

      Regards..

This reply was deleted.