Thursday, September 29, 2016

Setting up a Drone Programming Environment using DroneKit on Ubuntu 16.04

This guide describes how to setup an environment for programming drones using DroneKit. The main requirement is an Ubuntu 16.04 box. Using this environment will allow testing of code before they are run on an actual drone. To run the code on a drone, simply update the connection parameters.

The procedure will require four terminals which will be used for different purposes. In the steps that follow, SRG-Bots is the working directory.

Terminal Zero - Used for installing the required packages 

$cd ~/Downloads
$wget  http://firmware.eu.ardupilot.org/Tools/APMPlanner/apm_planner2_2.0.23_ubuntu_xenial64.deb
$sudo dpkg -i apmplanner*.deb
$sudo apt-get -f install
$sudo dpkg -i apmplanner*.deb
$sudo apt-get install python-pip
$pip install virtualenv
$mkdir SRG-Bots
$cd SRG-Bots
$virtualenv dronekit_env
$source dronekit_env/bin/activate
$pip install dronekit dronekit-sitl mavproxy

 
Terminal One -  and running the simulator

$cd SRG-Bots
$source dronekit_env/bin/activate
$dronekit-sitl copter

Terminal Two - Used to allow multiple connections on the drone

$cd SRG-Bots
$source dronekit_env/bin/activate 
$mavproxy.py --master tcp:127.0.0.1:5760 --sitl 127.0.0.1:5501 --out 127.0.0.1:14550 --out 127.0.0.1:14551

Terminal Three - Used to run APM Planner


$apmplanner2

Go to the menu, then select Communications -> Add Link -> UDP. Set the UDP Port field to 14550. Connection to the copter will be established.

Terminal Four - Used to run programs

$cd SRG-Bots
$source dronekit_env/bin/activate
$wget https://github.com/dronekit/dronekit-python/raw/master/examples/simple_goto/simple_goto.py
$python simple_goto.py --connect "udp:127.0.0.1:14551"

You can observe the behavior of the drone on the APM Planner as the code gets executed.