A look at the Parrot AR Drone quadcopter and how to make it fly autonomously and perform tricks - all using the Fantom programming language!
Parrot AR Drone
If you've not used an AR Drone before, I'll explain the control mechanism.
The drone itself has an on-board microprocessor and runs Linux Busy Box. It uses this to read its various sensors and send output to its 4 motors. It also contains Wifi hardware.
When you turn the drone on it sets itself up as a Wifi hot spot, to which your computer connects.
The drone, and your computer, use standard TCP and UDP protocols to send and receive data. In particular, your computer sends configuration and movement commands and the drone sends back video feeds and navigation data.
Parrot SDK
On our computer we're going to be running a Fantom program, and we're going to use the Parrot Drone SDK library to send flying commands to the drone.
The drone SDK library is produced by Alien-Factory and is one of the many libraries freely available on the Eggbox pod repository.
A quick glance at the API shows that most functionality is centred on the Drone
class. While I can't deny there are lots of slots on the Drone
class note there are 9 methods of moving the drone and 9 event handlers. So once you take these into account the Drone
class becomes quite manageable.
Also note the VideoStreamer
class that we'll be using to download video from the drone. VideoStreamer
requires the popular FFMEG utility to convert the raw data from the drone to an easily playable MP4 file.
FFMEG is also freely available. Just head to the website, click download, and choose one of the pre-made builds. Once extacted you'll notice it's just one big executable file (~40Mb).
To install Parrot Drone SDK 2 with Fantom Pod Manager, cut'n'paste the following into a cmd prompt, terminal or shell:
fpm install afParrotSdk2
Or to install Parrot Drone SDK 2 with the Fantom Repository Manager ( fanr ), cut'n'paste the following:
fanr install -r http://eggbox.fantomfactory.org/fanr/ afParrotSdk2
Parrot Program
As for the drone program itself we're just going to use the Simple Example bundled with the SDK documentation. So just cut'n'paste that into a new file called SimpleExample.fan
.
using afParrotSdk2 using concurrent::Actor class SimpleExample { Void main() { drone := Drone().connect drone.clearEmergency() drone.flatTrim()// set some outdoor configurationdrone.config.useOutdoorProfile = true drone.config.useOutdoorShell = true// record the action to an MP4 filedrone.config.session("Simple Example") drone.config.session.videoCamera = VideoCamera.horizontal drone.config.session.videoResolution = VideoResolution._720p VideoStreamer.toMp4File(`simpleExample.mp4`).attachToLiveStream(drone)// let's fly!!!drone.takeOff drone.animateFlight(FlightAnimation.flipBackward) Actor.sleep(2sec) drone.land drone.disconnect } }
The first part creates a new instance of the Drone class and initialises it for take off. The clearEmergency()
puts the drone into a normal state, and flatTrim()
tells it to calibrate while it's lying flat on the ground.
drone := Drone().connect drone.clearEmergency() drone.flatTrim()
Then we give the drone some information about its environment. I usually use the indoor shell, because it has some really BIG Bumpers and I crash my drone... a lot!
// set some outdoor configurationdrone.config.useOutdoorProfile = true drone.config.useOutdoorShell = false
The next bit activates the drone's front camera and record the video to an MP4 file.
// record the action to an MP4 filedrone.config.session("Simple Example") drone.config.session.videoCamera = VideoCamera.horizontal drone.config.session.videoResolution = VideoResolution._720p VideoStreamer.toMp4File(`simpleExample.mp4`).attachToLiveStream(drone)
Then we have the actual flight plan. We're going to take off, do a backwards flip, hover for a bit, and then land.
// let's fly!!!drone.takeOff drone.animateFlight(FlightAnimation.flipBackward) Actor.sleep(2sec) drone.land
Easy!
But note that for accurate and precision flying you need to have kept good care of your drone. This includes cleaning and balancing your rotors, and replacing any key mechanical parts with high performance variants. There are loads of videos on YouTube showing you how to do this, for example:
- AR Drone 2.0 Bearings Upgrade
- AR.Drone 2.0 Fix for Warped Propellors
- AR Drone 2.0 How to Balance Propellers
Now, I crash my drone quite a lot, so it's never in the best condition! As you'll see in the video, this makes my drone rather, um, unstable!
Anyway, without further a do, lets heat up the drone, connect to its Wifi, and let's fly!
That was the Parrot AR Drone, performing an autonomous flip, controlled by Fantom!
Have Fun!
Note that 2 drones died in the making of this video. :(
Versions
The following versions were used in the making of this article:
Also See
Edits
- 19 May 2017 - Original article.