Wiki

Clone wiki

Autonomous4jGA / PiConfiguration

Configuring a Raspberry Pi as the Drone's Positronic Brain

Change Log

12 July 2014 | Mark Heckler | Initial capture

Assessment

Fully functional.

Description

Here are the steps I followed to configure a Raspberry Pi to serve as a network client (to connect to the AR.Drone 2.0) and a wifi router with DHCP server (to accept connections from a development machine). These steps are captured from memory, so updates/adjustments will likely be required as we discover (hopefully minor) omissions.

Configuration Details

Bill of Materials

Instructions

ONCE-AGAIN DISCLAIMER: Revisions likely as inadvertent omissions/errors are discovered. :)


  1. Install Raspbian to SD card. The best way to do this is to download the latest version of Raspbian and install it (instructions vary by your dev workstation’s OS).
  2. Plug SD card, ethernet cable, keyboard, and HDMI cable (connected to TV/monitor) into Pi.
  3. Plug in power cable and watch Pi boot.
  4. Expand filesystem, enable SSH, change Pi timezone, change Pi name (I used pidrone), change password if desired, over clock to High (950MHz) - NOT TO TURBO!, and "update this tool”.
  5. Reboot as requested and log into Pi. Type ifconfig -a to examine network settings.
  6. Issue sudo shutdown -h now to shutdown the Pi.
  7. Once it has fully shut down, unplug the power cable and plug in one of the Edimax wifi adapters. Plug in the power to boot the Pi.
  8. Use the Adafruit guide (good, but unusually for Adafruit, problematic; we’ll adjust later) to configure the Pi as a Wireless Access Point (HTML version; PDF guide here). IMPORTANT: Skip the section to “Configure Network Address Translation”, as we won’t be using this to pass packets straight through from dev workstation to drone, only to connect from dev workstation to the Pi. The program we run on the Pi will communicate with the drone.
  9. You may not have to complete the section entitled “Update hostapd”. This is necessary for use of Adafruit’s adapters, which are very similar to the Edimax adapters, and I did complete this step. But the first time through, I’d recommend skipping that step and testing to see if it is necessary. Why add steps and trouble if not absolutely necessary? :D
  10. Perform the steps in the “Finishing up!” section. Additional steps are required to make this consistently work, but this forms the foundation.
  11. Configure the key files below as appropriate. Notes included as well.

Key File Contents

/etc/hostapd/hostapd.conf

interface=wlan0
driver=rtl871xdrv
ssid=Positronic
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=Raspberry
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

The hostapd.conf file should have been configured while following the Adafruit instructions referenced above.

/etc/network/interfaces

auto lo
iface lo inet loopback

iface eth0 inet static
address 192.168.1.149
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

#auto wlan0
allow hotplug wlan0
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
gateway 192.168.42.1

#auto wlan1
allow hotplug wlan1
iface wlan1 inet dhcp
wireless-essid ardrone2_mkheck

The interfaces file configures wlan0 for the WAP functionality (static IP), while the wlan1 interface acts as a DHCP client to the drone’s onboard WAP. Note that if the drone isn’t powered up when the Pi boots (or if there is a problem connecting), you may have to issue the following commands to get it to connect (& then verify connection):

sudo su (to log in as su - easier to do this once vs. sudo’ing every command)
ifdown —force wlan1
ifup wlan1
ifconfig -a (to verify connections - but give the previous command several seconds to connect)
/etc/default/ifplugd

INTERFACES="eth0"
HOTPLUG_INTERFACES="eth0"
ARGS="-q -f -u0 -d10 -w -I"
SUSPEND_ACTION=stop"

This is absolutely critical to maintaining multiple simultaneous network connections across interfaces. The first two lines are what must be changed from the default ifplugd file; removing the wireless interfaces from ifplugd control allows us to manage them ourselves and keep two wlann connections alive.

/etc/rc.local

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

ifup wlan0
/etc/init.d/isc-dhcp-server start
ifup wlan1

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

exit 0

You must add the ifup and isc-dhcp-server start directives to “manually" initialize the wireless network connections upon booting the Pi.

Note that if the drone’s WAP isn’t on/accepting network connections when you boot the Pi, you’ll need to issue a sequence of commands to connect once the drone is available (documented above).

Summary

Revisions to this document are expected as errors/omissions discovered, but this should be the essence of configuring our drone’s "Positronic brain”. Happy hacking! :D

Updated