gobot.io/x/gobot/v2@v2.1.0/platforms/mavlink/README.md (about) 1 # Mavlink 2 3 For information on the MAVlink communication protocol click [here](http://qgroundcontrol.org/mavlink/start). 4 5 This package supports Mavlink over serial (such as a 6 [SiK modem](http://ardupilot.org/copter/docs/common-sik-telemetry-radio.html)) 7 and Mavlink over UDP (such as via 8 [mavproxy](https://github.com/ArduPilot/MAVProxy)). Serial is useful 9 for point to point links, and UDP is useful for where you have 10 multiple simultaneous clients such as the robot and 11 [QGroundControl](http://qgroundcontrol.com/). 12 13 As at 2018-04, this package supports Mavlink 1.0 only. If the robot 14 doesn't receiving data then check that the other devices are 15 configured to send version 1.0 frames. 16 17 ## How to Install 18 19 ``` 20 go get -d -u gobot.io/x/gobot/v2/... 21 22 ``` 23 24 ## How to Use 25 26 ```go 27 package main 28 29 import ( 30 "fmt" 31 32 "gobot.io/x/gobot/v2" 33 "gobot.io/x/gobot/v2/platforms/mavlink" 34 common "gobot.io/x/gobot/v2/platforms/mavlink/common" 35 ) 36 37 func main() { 38 adaptor := mavlink.NewAdaptor("/dev/ttyACM0") 39 iris := mavlink.NewDriver(adaptor) 40 41 work := func() { 42 iris.Once(iris.Event("packet"), func(data interface{}) { 43 packet := data.(*common.MAVLinkPacket) 44 45 dataStream := common.NewRequestDataStream(100, 46 packet.SystemID, 47 packet.ComponentID, 48 4, 49 1, 50 ) 51 iris.SendPacket(common.CraftMAVLinkPacket(packet.SystemID, 52 packet.ComponentID, 53 dataStream, 54 )) 55 }) 56 57 iris.On(iris.Event("message"), func(data interface{}) { 58 if data.(common.MAVLinkMessage).Id() == 30 { 59 message := data.(*common.Attitude) 60 fmt.Println("Attitude") 61 fmt.Println("TIME_BOOT_MS", message.TIME_BOOT_MS) 62 fmt.Println("ROLL", message.ROLL) 63 fmt.Println("PITCH", message.PITCH) 64 fmt.Println("YAW", message.YAW) 65 fmt.Println("ROLLSPEED", message.ROLLSPEED) 66 fmt.Println("PITCHSPEED", message.PITCHSPEED) 67 fmt.Println("YAWSPEED", message.YAWSPEED) 68 fmt.Println("") 69 } 70 }) 71 } 72 73 robot := gobot.NewRobot("mavBot", 74 []gobot.Connection{adaptor}, 75 []gobot.Device{iris}, 76 work, 77 ) 78 79 robot.Start() 80 } 81 ``` 82 83 ## How to use: UDP 84 85 ``` go 86 adaptor := mavlink.NewUDPAdaptor(":14550") 87 ``` 88 89 To test, install Mavproxy and set it up to listen on serial and repeat 90 over UDP: 91 92 `$ mavproxy.py --out=udpbcast:192.168.0.255:14550` 93 94 Change the address to the broadcast address of your subnet.