MAVLink protocol

Post Reply
ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

MAVLink protocol

Post by ziss_dm »

Hi,
I was thinking, maybe we should replace existing custom serial protocol with MAVLink: http://qgroundcontrol.org/mavlink/start?
The benefits are:
1) Customizable (code generated by definition)
2) Possibility to connect to the QGround control: http://qgroundcontrol.org/users/start
3) Existing Android App http://code.google.com/p/copter-gcs/
...

Does anybody interested in this? :)

regards,
ziss_dm

pequod
Posts: 6
Joined: Fri May 06, 2011 9:14 am

Re: MAVLink protocol

Post by pequod »

I would appreciate this.
A step towads unifying the GCS. I use qgroundcontol with the Mega Pirate (Arducopter) Code. GPS-Support and map-display.
And its open source working with linux too.
Attachments
HUD mit GPS2.jpg

Lapino
Posts: 84
Joined: Tue Aug 16, 2011 10:01 am

Re: MAVLink protocol

Post by Lapino »

That would be really cool, great idea :)
http://www.youtube.com/watch?v=8PwrCuifj0w

btw, is XBEE supported yet? or is there another (cheaper) communication element for greater distances?

Greetings,

Lapino

capt
Posts: 54
Joined: Wed Jan 19, 2011 10:54 pm

Re: MAVLink protocol

Post by capt »

Some are using these modules on Megapirate code using mavlink in place of the more expensive xbee's

http://www.goodluckbuy.com/apc220-wirel ... erter.html

User avatar
Loosi
Posts: 63
Joined: Sat Aug 20, 2011 8:31 pm
Location: Germany (HSK)
Contact:

Re: MAVLink protocol

Post by Loosi »

Hey!

I just started to play around with mavlink, i think it should be possible to implement it ;) I do my best, but i don´t have much time at the moment.
I will implement it as EXTRA protocol, so the current protocol to talk with multiwiiconf will not be touched.
The problem is that we don´t have enough ports on the ProMini, so i think in the future we have to use a Flyduino or something equal.

Greetings
Daniel

palton
Posts: 48
Joined: Fri Sep 02, 2011 4:06 pm

Re: MAVLink protocol

Post by palton »

APC 220 is really easy to setup compared to Xbee, I got them both and Xbee was a struggle before I got it working. APC 220 took just a few minutes and they where running. And they are affordable as well :=)

User avatar
Loosi
Posts: 63
Joined: Sat Aug 20, 2011 8:31 pm
Location: Germany (HSK)
Contact:

Re: MAVLink protocol

Post by Loosi »

Hey!

What configuration are you using for the apc220? See viewtopic.php?f=6&t=354#p3678 :)

[EDIT:]
Started to implement MavLink this weekend, just playing around a little bit, heartbeat is working, but i think the documentation is very weak, much deadlinks and so on... it will take some time

Greetings
Daniel

User avatar
Loosi
Posts: 63
Joined: Sat Aug 20, 2011 8:31 pm
Location: Germany (HSK)
Contact:

Re: MAVLink protocol

Post by Loosi »

So, learning by doing ;)

I have i beadboard with a ArduinoProMini on it. The Testcode is working for me:

Code: Select all

// Arduino MAVLink test code.

#include <FastSerial.h>
#include "../mavlink/include/mavlink.h"        // Mavlink interface

FastSerialPort0(Serial);

void setup() {
   Serial.begin(57600);
}

void loop() {
   // Define the system type (see mavlink_types.h for list of possible types)
   int system_type = MAV_QUADROTOR;
   int autopilot_type = MAV_AUTOPILOT_GENERIC;
   
   // Initialize the required buffers
   mavlink_message_t msg;
   uint8_t buf[MAVLINK_MAX_PACKET_LEN];
   
   // Pack the message
   // mavlink_message_heartbeat_pack(system id, component id, message container, system type, MAV_AUTOPILOT_GENERIC)
   mavlink_msg_heartbeat_pack(123, 234, &msg, system_type, autopilot_type);
   
   // Copy the message to send buffer
   uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
   
   // Send the message (.write sends as bytes)
   Serial.write(buf, len);
   comm_receive();
}

void comm_receive() {
   mavlink_message_t msg;
   mavlink_status_t status;
   
   //receive data over serial
   while(Serial.available() > 0) {
      uint8_t c = Serial.read();
      
      //try to get a new message
      if(mavlink_parse_char(MAVLINK_COMM_0, c, &msg, &status)) {
         // Handle message
          switch(msg.msgid) {
                 case MAVLINK_MSG_ID_SET_MODE: {
                    // set mode
                 }
                 break;
                 case MAVLINK_MSG_ID_ACTION:
               // EXECUTE ACTION
            break;
            default:
               //Do nothing
            break;
         }
      }
     
      // And get the next one
   }
delay(500);
}



, but when i add the lines

Code: Select all

        //try to set some values
        int xacc = 10;
        int yacc = 11;
        int zacc = 12;
        int xgyro = 100;
        int ygyro = 101;
        int zgyro = 102;
        int xmag = 200;
        int ymag = 201;
        int zmag = 202;
        mavlink_msg_raw_imu_pack(100, 200, &msg, 0, xacc, yacc, zacc, xgyro, ygyro, zgyro, xmag, ymag, zmag);
        uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
        // Send the message (.write sends as bytes)
        Serial.write(buf, len);


then the complete code looks like this:

Code: Select all

// Arduino MAVLink test code.

#include <FastSerial.h>
#include "../mavlink/include/mavlink.h"        // Mavlink interface

FastSerialPort0(Serial);

void setup() {
   Serial.begin(57600);
}

void loop() {
   // Define the system type (see mavlink_types.h for list of possible types)
   int system_type = MAV_QUADROTOR;
   int autopilot_type = MAV_AUTOPILOT_GENERIC;
   
   // Initialize the required buffers
   mavlink_message_t msg;
   uint8_t buf[MAVLINK_MAX_PACKET_LEN];
   
   // Pack the message
   // mavlink_message_heartbeat_pack(system id, component id, message container, system type, MAV_AUTOPILOT_GENERIC)
   mavlink_msg_heartbeat_pack(123, 234, &msg, system_type, autopilot_type);
   
   // Copy the message to send buffer
   uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
   
   // Send the message (.write sends as bytes)
   Serial.write(buf, len);

         //try to set some values
        int xacc = 10;
        int yacc = 11;
        int zacc = 12;
        int xgyro = 100;
        int ygyro = 101;
        int zgyro = 102;
        int xmag = 200;
        int ymag = 201;
        int zmag = 202;
        mavlink_msg_raw_imu_pack(100, 200, &msg, 0, xacc, yacc, zacc, xgyro, ygyro, zgyro, xmag, ymag, zmag);
        uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
        // Send the message (.write sends as bytes)
        Serial.write(buf, len);
       
          comm_receive();
}

void comm_receive() {
   mavlink_message_t msg;
   mavlink_status_t status;
   
   //receive data over serial
   while(Serial.available() > 0) {
      uint8_t c = Serial.read();
      
      //try to get a new message
      if(mavlink_parse_char(MAVLINK_COMM_0, c, &msg, &status)) {
         // Handle message
          switch(msg.msgid) {
                 case MAVLINK_MSG_ID_SET_MODE: {
                    // set mode
                 }
                 break;
                 case MAVLINK_MSG_ID_ACTION:
               // EXECUTE ACTION
            break;
            default:
               //Do nothing
            break;
         }
      }
     
      // And get the next one
   }
delay(500);
}



i get the error:

Code: Select all

ArduinoMAVLink.cpp: In function 'void loop()':
ArduinoMAVLink:43: error: redeclaration of 'uint16_t len'
ArduinoMAVLink:25: error: 'uint16_t len' previously declared here


i am new to arduino and did all programming before with bascom, a basic like programming language ;) can someone explain me how to solve the mistake? i know that i declare the uint16_t len twice, but i dont know how to solve...

PatrikE
Posts: 1976
Joined: Tue Apr 12, 2011 6:35 pm
Location: Sweden
Contact:

Re: MAVLink protocol

Post by PatrikE »

As it says...

Code: Select all

 error: redeclaration of 'uint16_t len'


You have declared uint16_t len Two times in loop()

Remove uint16_t at the second place.
Leaving it like this.

Code: Select all

len = mavlink_msg_to_send_buffer(buf, &msg); 

User avatar
kos
Posts: 286
Joined: Thu Feb 16, 2012 4:51 am
Location: Fr

Re: MAVLink protocol

Post by kos »

mwi gyro reading with mavlink and qgroundcontrol

:geek:
Attachments
mwi-mavlink.png

User avatar
kos
Posts: 286
Joined: Thu Feb 16, 2012 4:51 am
Location: Fr

Re: MAVLink protocol

Post by kos »

i have setup a little project to send and forward mwi data over MAVLink protocol , here are the source :

http://code.google.com/p/mwi-gc/



for the moment : read raw imu ,attitude, rc data , etc ... display HUD and roll/pitch angle over video feed , etc , etc .. readonly

a short test video viewtopic.php?f=9&t=1610

juanquy
Posts: 30
Joined: Sat Jan 05, 2013 9:58 pm

Re: MAVLink protocol

Post by juanquy »

HI:
I can compile your code on Linux?
if yes please provide me how to , tools and lib I need it to do it
thanks
jc

User avatar
treym
Posts: 258
Joined: Sat Jul 21, 2012 12:28 am

Re: MAVLink protocol

Post by treym »

sorry for the late response

the project moved to github

the code now work with latest multiwii 2.3 .. minimal support

you also have an example.c

if you need to build for linux :

git clone https://github.com/treymarc/multiwii-mavlink-gc.git
cd multiwii-mavlink-gc
make
./src/udp/mwgc --help



Image

User avatar
treym
Posts: 258
Joined: Sat Jul 21, 2012 12:28 am

Re: MAVLink protocol

Post by treym »

juanquy wrote:HI:
I can compile your code on Linux?


you dont need anything special , no extra lib, both windows or linux , just type "make"


https://github.com/treymarc/multiwii-mavlink-gc/wiki

koenkooi
Posts: 13
Joined: Sat Apr 19, 2014 8:31 am

MAVLink protocol

Post by koenkooi »

It works great on OSX as well.

LexxSbg
Posts: 3
Joined: Tue Jun 28, 2016 11:53 am

MAVLink protocol

Post by LexxSbg »

Hi trey,

at first I should say I am a beginner at the topic multicopter :D and then to my task I should controle a Flexbot (MultWii 2.2) with MAVLink and I hope that I can use your program.

Unfortunately, I just failing when compiling the makefile. :?
I use a computer with windows 10 - 64 bit, install MinGW and added the Path to the enviromentvariable but I get allwas an Error wenn I would compile the makefile (see picture).

Could you or someone else help me? :roll: :D

Thanks and best regards Alex
Attachments
Error.JPG

gregd72002
Posts: 103
Joined: Fri Dec 12, 2014 5:16 pm

Re: MAVLink protocol

Post by gregd72002 »

LexxSbg, Here is something that might be of interest to you: https://github.com/rpicopter/mw-mavlink
Though it requires an extra SoC to be carried.

It implements mavlink and works with QGroundControl (though no WayPoint navigation yet).

LexxSbg
Posts: 3
Joined: Tue Jun 28, 2016 11:53 am

Re: MAVLink protocol

Post by LexxSbg »

Hi gregd72002,

thanks for your answer! But wenn i understand this git-link correctly than I need to attach a raspberry pi ( wich is connect with the flighcontrol about USART) on the drone for this solution or? The Flexbot is only a microdrone and can`t handle that.

trogalko
Posts: 5
Joined: Thu Aug 28, 2014 8:50 am

Re: MAVLink protocol

Post by trogalko »

Hi,
I'm quite lost here in order how to setup the Multiwii to use mavlink.
Is connection like MW FC ->Receiver --------------------------------------Transmitter->PC ?
Is Rx and Tx responsible to implement mavlink? and MW FC simply send data via MSP to Rx?
Tx then send mavlink data to PC and display it using Treymarc's mavlink implementation, is that right?

I'm really interesting to use Ultimate Lrs with Multiwii , here is the link : http://www.rcgroups.com/forums/showthread.php?t=2037442
Unfortunatelly, it only support mavlink right now, no frsky.
Thank You.

gregd72002
Posts: 103
Joined: Fri Dec 12, 2014 5:16 pm

Re: MAVLink protocol

Post by gregd72002 »

hi trogalko,

MultiWii (MW) does not implement MAVLink but something that is called MSP. MSP is different to MAVLink and would require translation.

I've worked on such translation program previously (https://github.com/rpicopter/mw-mavlink) but this require an auxiliary SOC like Odroid/Beaglebone/RPi.

So your communication would look like:

MultiWii<-----[msp]------->SOC<------[mavlink]-------->PC

trogalko
Posts: 5
Joined: Thu Aug 28, 2014 8:50 am

Re: MAVLink protocol

Post by trogalko »

gregd72002 wrote:hi trogalko,

MultiWii (MW) does not implement MAVLink but something that is called MSP. MSP is different to MAVLink and would require translation.

I've worked on such translation program previously (https://github.com/rpicopter/mw-mavlink) but this require an auxiliary SOC like Odroid/Beaglebone/RPi.

So your communication would look like:

MultiWii<-----[msp]------->SOC<------[mavlink]-------->PC


Thanks gregd72002, if only I had rpi zero ( only 9 gram) compared to rpi a (31 gram). So in order to translate msp to mavlink, I would require two uart(s) port on rpi or similar (banana/orange pi), one build-in, another one using usb to ttl right?
Well, this seem interesting to try.

gregd72002
Posts: 103
Joined: Fri Dec 12, 2014 5:16 pm

Re: MAVLink protocol

Post by gregd72002 »

RPi Zero, this is what I'm using on my 250 copter and Odroid on my 550 copter.

You would need indeed 2 serial ports if you want to use LRS:
RPi<->MW
RPi<->LRS

I'm actually waiting for my OrangeRX LRS to arrive as I intend to do exactly what you are trying to do.
RPi has only single serial port so to get second one I will be using:
- USB to TTL converter (http://www.ebay.co.uk/itm/261888018066) - should be easy to desolder the usb plug to save space
- or SPI/I2C to TTL converter (SC16IS750)

Post Reply