Site icon BBBlimp

Mavlink on Beagle Bone Blue

In continuation to Seb’s initial attempt to connect our BBB with the QGroundControl, he actually achieved some super-cool progress – making it think it calls to a real drone!

But let’s start from the beginning – QGroundControl (QGC) is the Graphical User Interface (GUI) application which provides full flight control and mission planning for any MAVLink enabled drone. Its primary goal is ease of use for professional users and developers. All the code is open-source source, so you can contribute and evolve it as you want. and project website is here.

The idea is to use QGC in combination with the Mavlink and use it for our airship navigation.

As the first Seb used the Robot Control library for BBB to send UDP packets to a Mavlink. That’s been achieved through using the rc_mav_send_hearbeat function. We confirmed those with tcpdump accordingly:

$ sudo tcpdump -i any port 14550 udp

20:02:02.222327 wlp5s0 In  IP beaglebone.modem.14550 > mavic.modem.14550: UDP, length 40
	0x0000:  4500 0044 e42b 4000 4011 d387 c0a8 00e6  E..D.+@.@.......
	0x0010:  c0a8 00bf 38d6 38d6 0030 2edf fd1c 0000  ....8.8..0......
	0x0020:  0001 0121 0000 6d26 8cb0 62f6 c8ef 073d  ...!..m&..b....=
	0x0030:  405b 0000 0000 0000 0000 0000 0000 0000  @[..............
	0x0040:  ffff 7078                                ..px
20:02:02.552843 wlp5s0 In  IP beaglebone.modem.14550 > mavic.modem.14550: UDP, length 40
	0x0000:  4500 0044 e435 4000 4011 d37d c0a8 00e6  E..D.5@.@..}....
	0x0010:  c0a8 00bf 38d6 38d6 0030 fba2 fd1c 0000  ....8.8..0......
	0x0020:  0001 0121 0000 6827 8cb0 62f6 c8ef 073d  ...!..h'..b....=
	0x0030:  405b 0000 0000 0000 0000 0000 0000 0000  @[..............
	0x0040:  ffff a8b3                                ....
20:02:02.763607 wlp5s0 In  IP beaglebone.modem.14550 > mavic.modem.14550: UDP, length 40
	0x0000:  4500 0044 e45f 4000 4011 d353 c0a8 00e6  E..D._@.@..S....
	0x0010:  c0a8 00bf 38d6 38d6 0030 dfd2 fd1c 0000  ....8.8..0......
	0x0020:  0001 0121 0000 6228 8cb0 62f6 c8ef 073d  ...!..b(..b....=
	0x0030:  405b 0000 0000 0000 0000 0000 0000 0000  @[..............
	0x0040:  ffff ca82                                ....
20:02:03.027456 wlp5s0 In  IP beaglebone.modem.14550 > mavic.modem.14550: UDP, length 40
	0x0000:  4500 0044 e493 4000 4011 d31f c0a8 00e6  E..D..@.@.......
	0x0010:  c0a8 00bf 38d6 38d6 0030 20c5 fd1c 0000  ....8.8..0......
	0x0020:  0001 0121 0000 5c29 8cb0 62f6 c8ef 073d  ...!..\)..b....=
	0x0030:  405b 0000 0000 0000 0000 0000 0000 0000  @[..............
	0x0040:  ffff 8f8f                                ....
20:02:03.104488 wlp5s0 Out IP mavic.modem.14550 > beaglebone.modem.14550: UDP, length 17
	0x0000:  4500 002d 43d1 4000 4011 73f9 c0a8 00bf  E..-C.@.@.s.....
	0x0010:  c0a8 00e6 38d6 38d6 0019 b0ea fe09 e9ff  ....8.8.........
	0x0020:  be00 0000 0000 0608 c004 0317 eb         .............

In that above Seb actually used existing bindings into the Mavlink library to create a Rust code which he compiled as per previous post and made it to send fake GPS coordinates.

One major problem was that Rust didn’t come with the UDP stream which would inherit from the generic stream and so he needed to reimplement that to see this working. Even more interesting was that this solution was proposed by the ChatGPT.

use std::io::{self, Write};
use std::net::{UdpSocket, SocketAddr};

pub struct UdpStreamWriteWrapper {
    socket: UdpSocket,
    remote_addr: SocketAddr,
}

impl UdpStreamWriteWrapper {
    pub fn new(local_addr: SocketAddr, remote_addr: SocketAddr) -> io::Result<Self> {
        let socket = UdpSocket::bind(local_addr)?;
        Ok(Self { socket, remote_addr })
    }
}

impl Write for UdpStreamWriteWrapper {
    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
        self.socket.send_to(buf, &self.remote_addr).map_err(From::from)
    }

    fn flush(&mut self) -> io::Result<()> {
        // UDP is a datagram protocol, so there's no need to flush.
        Ok(())
    }
}

Result is here – as you can see below in upper left corner, QGC running on Seb’s laptop now thinks that BBB provides some initial data and states “Not Ready”, where it was originally saying “Disconnected”.

There is one more where BBB uses Mavlink protocol to provide some hard-coded GPS coordinates and show them on a map (see the red arrow).

Finally all the code landed in our new blimp_control GitHub repository as per below: https://github.com/bbblimp/blimp_control.

Well done Sebi!

Exit mobile version