Giter VIP home page Giter VIP logo

go-mavlink's Introduction

#go-mavlink

Go implementation of the MAVLink protocol. You can make your drone fly with Go.

MAVLink or Micro Air Vehicle Link is a protocol for communicating with small unmanned vehicle.
It's designed as a header-only message marshaling library.
MAVLink was first released early 2009 by Lorenz Meier under LGPL license.

This implementation is mainly inspired by the C version (see on GitHub).

Only tested under Unix

#Usage

Here two quick examples to understand how to deal with it but first, look at the MavPacket definition.

###MavPacket definition :

type Message interface {
        ID() uint8
        Size() uint8
}

type MavHeader struct {
        FrameStart     uint8
        PayloadLength  uint8
        PacketSequence uint8
        SystemID       uint8
        ComponentID    uint8
        MessageID      uint8
}

type MavPacket struct {
        Header   MavHeader
        Msg      Message
        Checksum uint16
}

You got all the message definitions in message.go.

##UDP communication (receiving example)

package main

import (
	"bufio"
	"fmt"
	mav "github.com/Sabmit/go-mavlink"
	"log"
	"net"
)

func main() {
	laddr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:14550")
	conn, _ := net.ListenUDP("udp", laddr) // check errors

	parser := mav.GetMavParser()
        reader := bufio.NewReader(conn)

        for {
    	    c, _ := reader.ReadByte() // check errors

            packet, err := parser(c)
            if err != nil {
           	log.Fatalf("Parser error: ", err)
            } else if packet != nil {
        	fmt.Println("Packet received :", packet.Bytes())
    	    }
	}
}

The C server is available here, you can also test it by hand...

$ echo -ne "\xfe\x09\x0\x01\xC8\x00\x0\x0\x0\x0\x0\x0\x0\x0\x0\x5A\x3E" | nc -u 127.0.0.1 14550

##Serial communication (Sending example)

import (
	"github.com/tarm/goserial"
	mav "github.com/Sabmit/go-mavlink"
       "log"
)

func main() {
	port := &serial.Config{Name: "/dev/ttyUSB0", Baud: 57600}
        s, _ := serial.OpenPort(port) // check errors

	message := new(mav.RequestDataStream)
        message.ReqMessageRate = 20

        err := mav.Send(s, 1, 200, message)
        if err != nil {
		log.Fatalf("Error while sending the packet:", err)
	}
}

##More The operation is simple : get the MavParser and then, parse each received byte untill you get a non-nil pointer pointing to the full MavPacket.

Please read main_udp.go if you want the full code examples.

#TO-DO

  • For now, only the received packet has its own checksum computed on the go
  • Verify if all properties of each message is in its own place (see Mavlink generator)
  • Create some tests for future devlopment...

#See

#Authors

ungerik sabmit

go-mavlink's People

Contributors

ungerik avatar sabmit avatar romout avatar

Stargazers

Samuel Stauffer avatar  avatar Clément MORISSARD avatar Dimitri Cabete Jorge avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.