Running Gobot on the ARDrone

Most users of it don't know this, but the ARDrone 2.0 runs a BusyBox Linux distro.This means we can execute code on the drone itself, and connect to it over telnet and FTP.

For this example, we'll get an ARDrone to talk to a Digispark plugged into the drone's USB port. Unfortunately, since the ARDrone doesn't have much in the way of resources on-board, we can't compile directly on the drone, but it has an ARM-based processor, so we can easily compile on another Single-Board Linux Computer.

What You'll Need

To get this done you will need:

  • a BeagleBone Black
  • an ARDrone 2.0
  • a Digispark

Your BeagleBone Black will need to be running Ubuntu 13.10 as the default Debian install won't be able to do what we need, and newer versions of the Linux kernel prevent the compiled executable from running on the dron's hardware.

This guide also assumes you're using a UNIX-y OS (Linux or OS X) and you have at least Go version 1.2 installed on your Beaglebone Black. With that in mind, let's get started.

Building the Binary

First, connect to the BeagleBone over SSH, and install the GCC-based Go compiler:

$ sudo apt-get install gccgo libusb-dev

Now install Gobot on the Beaglebone Black:

$ go get -d -u github.com/hybridgroup/gobot/...

For this example, we'll blink the Digispark's built in led every one second:

package main

import (
        "time"

        "github.com/hybridgroup/gobot"
        "github.com/hybridgroup/gobot/platforms/digispark"
        "github.com/hybridgroup/gobot/platforms/gpio"
)

func main() {
        gbot := gobot.NewGobot()

        digisparkAdaptor := digispark.NewDigisparkAdaptor("Digispark")
        led := gpio.NewLedDriver(digisparkAdaptor, "led", "1")

        work := func() {
                gobot.Every(1*time.Second, func() {
                        led.Toggle()
                })
        }

        robot := gobot.NewRobot("blinkBot",
                []gobot.Connection{digisparkAdaptor},
                []gobot.Device{led},
                work,
        )

        gbot.AddRobot(robot)

        gbot.Start()
}

Save this program on your Beaglebone Black as blink.go and then compile the program with:

$ go build -compiler=gccgo -gccgoflags='-static' -o /tmp/blink blink.go

Configuring the ARDrone

On your host computer, connect to your ARDrone's WiFi, and telnet into the drone:

$ telnet 192.168.1.1

Once you're logged into the drone, edit the file /etc/usb.ids:

$ vi /etc/usb.ids

And add the following lines:

1781 digispark
	0c9f digispark
16d0 digispark
	0753 digispark

Next, edit the file /etc/init.d/rcS:

$ vi /etc/init.d/rcS

And replace

echo 2 > /proc/sys/vm/overcommit_memory
# with
echo 1 > /proc/sys/vm/overcommit_memory

Once that's done, restart the drone.

Copy and Run

On your host computer, move to your tmp directory:

$ cd /tmp

And copy the compiled blink binary from your BeagleBone Black to your host computer:

$ scp [email protected]:/tmp/blink .

Connect your computer again to the ARDrone's WiFi and plug the Digispark into the drone's usb port, which should be attached near the battery compartment.

Once that's done, use ftp to move the blink binary from your host computer over to the drone:

$ ftp 192.168.1.1
ftp> put blink

The ftp program will copy the binary to the ~/data/video folder on the drone, so telnet back into it and move to that directory:

$ telnet 192.168.1.1
# cd data/video

Once in that directory, you can set the executible flag on the binary and run it:

# chmod +x blink
# ./blink

At this point your Digispark's LED should be blinking.

Congratulations! You've now got Gobot programs running directly on the ARDrone. From here, the sky's the limit.