• Stars
    star
    1,755
  • Rank 26,530 (Top 0.6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 12 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A node.js client for controlling Parrot AR Drone 2.0 quad-copters.

ar-drone

Build Status

An implementation of the networking protocols used by the Parrot AR Drone 2.0. It appears that 1.0 drones are also compatible.

Install via Github to get the latest version:

npm install git://github.com/felixge/node-ar-drone.git

Or, if you're fine with missing some cutting edge stuff, go for npm:

npm install ar-drone

Introduction

The AR Drone is an affordable, yet surprisingly capable quadcopter. The drone itself runs a proprietary firmware that can be controlled via WiFi using the official FreeFlight mobile app (available for iOS and Android).

Unlike the firmware, the client protocol is open, and Parrot publishes an SDK (signup required to download) including a good amount of documentation and C code. Their target audience seems to be mobile developers who can use this SDK to create games and other apps for people to have more fun with their drones.

However, the protocol can also be used to receive video and sensor data, enabling developers to write autonomous programs for the upcoming robot revolution.

Status

This module is still under heavy development, so please don't be surprised if you find some functionality missing or undocumented.

However, the documented parts are tested and should work well for most parts.

Client

This module exposes a high level Client API that tries to support all drone features, while making them easy to use.

The best way to get started is to create a repl.js file like this:

var arDrone = require('ar-drone');
var client  = arDrone.createClient();
client.createRepl();

Using this REPL, you should be able to have some fun:

$ node repl.js
// Make the drone takeoff
drone> takeoff()
true
// Wait for the drone to takeoff
drone> clockwise(0.5)
0.5
// Let the drone spin for a while
drone> land()
true
// Wait for the drone to land

Now you could write an autonomous program that does the same:

var arDrone = require('ar-drone');
var client  = arDrone.createClient();

client.takeoff();

client
  .after(5000, function() {
    this.clockwise(0.5);
  })
  .after(3000, function() {
    this.stop();
    this.land();
  });

Ok, but what if you want to make your drone to interact with something? Well, you could start by looking at the sensor data:

client.on('navdata', console.log);

Not all of this is handled by the Client library yet, but you should at the very least be able to receive droneState and demo data.

A good initial challenge might be to try flying to a certain altitude based on the navdata.demo.altitudeMeters property.

Once you have managed this, you may want to try looking at the camera image. Here is a simple way to get this as PngBuffers (requires a recent ffmpeg version to be found in your $PATH):

var pngStream = client.getPngStream();
pngStream.on('data', console.log);

Your first challenge might be to expose these png images as a node http web server. Once you have done that, you should try feeding them into the opencv module.

Client API

arDrone.createClient([options])

Returns a new Client object. options include:

  • ip: The IP of the drone. Defaults to '192.168.1.1'.
  • frameRate: The frame rate of the PngEncoder. Defaults to 5.
  • imageSize: The image size produced by PngEncoder. Defaults to null.

client.createREPL()

Launches an interactive interface with all client methods available in the active scope. Additionally client resolves to the client instance itself.

client.getPngStream()

Returns a PngEncoder object that emits individual png image buffers as 'data' events. Multiple calls to this method returns the same object. Connection lifecycle (e.g. reconnect on error) is managed by the client.

client.getVideoStream()

Returns a TcpVideoStream object that emits raw tcp packets as 'data' events. Multiple calls to this method returns the same object. Connection lifecycle (e.g. reconnect on error) is managed by the client.

client.takeoff(callback)

Sets the internal fly state to true, callback is invoked after the drone reports that it is hovering.

client.land(callback)

Sets the internal fly state to false, callback is invoked after the drone reports it has landed.

client.up(speed) / client.down(speed)

Makes the drone gain or reduce altitude. speed can be a value from 0 to 1.

client.clockwise(speed) / client.counterClockwise(speed)

Causes the drone to spin. speed can be a value from 0 to 1.

client.front(speed) / client.back(speed)

Controls the pitch, which a horizontal movement using the camera as a reference point. speed can be a value from 0 to 1.

client.left(speed) / client.right(speed)

Controls the roll, which is a horizontal movement using the camera as a reference point. speed can be a value from 0 to 1.

client.stop()

Sets all drone movement commands to 0, making it effectively hover in place.

client.calibrate(device)

Asks the drone to calibrate a device. Although the AR.Drone firmware only supports one device that can be calibrated. This function also includes ftrim.

The Magnetometer

Device: 0

The magnetometer can only be calibrated while the drone is flying, and the calibration routine causes the drone to yaw in place a full 360 degrees.

FTRIM

Device: 1

FTRIM essentially resets the Yaw, Pitch, and Roll to 0. Be very cautious of using this function and only calibrate while on flat surface. Never use while flying.

client.config(key, value, callback)

Sends a config command to the drone. You will need to download the drone SDK to find a full list of commands in the ARDrone_Developer_Guide.pdf.

For example, this command can be used to instruct the drone to send all navdata.

client.config('general:navdata_demo', 'FALSE');

callback is invoked after the drone acknowledges the config request or if a timeout occurs.

Alternatively, you can pass an options object containing the following:

  • key: The config key to set.
  • value: The config value to set.
  • timeout: The time, in milliseconds, to wait for an ACK from the drone.

For example:

var callback = function(err) { if (err) console.log(err); };
client.config({ key: 'general:navdata_demo', value: 'FALSE', timeout: 1000 }, callback);

client.animate(animation, duration)

Performs a pre-programmed flight sequence for a given duration (in ms). animation can be one of the following:

['phiM30Deg', 'phi30Deg', 'thetaM30Deg', 'theta30Deg', 'theta20degYaw200deg',
'theta20degYawM200deg', 'turnaround', 'turnaroundGodown', 'yawShake',
'yawDance', 'phiDance', 'thetaDance', 'vzDance', 'wave', 'phiThetaMixed',
'doublePhiThetaMixed', 'flipAhead', 'flipBehind', 'flipLeft', 'flipRight']

Example:

client.animate('flipLeft', 1000);

Please note that the drone will need a good amount of altitude and headroom to perform a flip. So be careful!

client.animateLeds(animation, hz, duration)

Performs a pre-programmed led sequence at given hz frequency and duration (in sec!). animation can be one of the following:

['blinkGreenRed', 'blinkGreen', 'blinkRed', 'blinkOrange', 'snakeGreenRed',
'fire', 'standard', 'red', 'green', 'redSnake', 'blank', 'rightMissile',
'leftMissile', 'doubleMissile', 'frontLeftGreenOthersRed',
'frontRightGreenOthersRed', 'rearRightGreenOthersRed',
'rearLeftGreenOthersRed', 'leftGreenRightRed', 'leftRedRightGreen',
'blinkStandard']

Example:

client.animateLeds('blinkRed', 5, 2)

client.disableEmergency()

Causes the emergency REF bit to be set to 1 until navdata.droneState.emergencyLanding is 0. This recovers a drone that has flipped over and is showing red lights to be flyable again and show green lights. It is also done implicitly when creating a new high level client.

Events

A client will emit landed, hovering, flying, landing, batteryChange, and altitudeChange events as long as demo navdata is enabled.

To enable demo navdata use

client.config('general:navdata_demo', 'FALSE');

See documentation for navadata object

UdpControl

This is a low level API. If you prefer something simpler, check out the Client docs.

The drone is controlled by sending UDP packets on port 5556. Because UDP does not guarantee message ordering or delivery, clients must repeatedly send their instructions and include an incrementing sequence number with each command.

For example, the command used for takeoff/landing (REF), with a sequence number of 1, and a parameter of 512 (takeoff) looks like this:

AT*REF=1,512\r

To ease the creation and sending of these packets, this module exposes an UdpControl class handling this task. For example, the following program will cause your drone to takeoff and hover in place.

var arDrone = require('ar-drone');
var control = arDrone.createUdpControl();

setInterval(function() {
  // The emergency: true option recovers your drone from emergency mode that can
  // be caused by flipping it upside down or the drone crashing into something.
  // In a real program you probably only want to send emergency: true for one
  // second in the beginning, otherwise your drone may attempt to takeoff again
  // after a crash.
  control.ref({fly: true, emergency: true});
  // This command makes sure your drone hovers in place and does not drift.
  control.pcmd();
  // This causes the actual udp message to be send (multiple commands are
  // combined into one message)
  control.flush();
}, 30);

Now that you are airborne, you can fly around by passing an argument to the pcmd() method:

control.pcmd({
  front: 0.5, // fly forward with 50% speed
  up: 0.3, // and also fly up with 30% speed
});

That's it! A full list of all pcmd() options can be found in the API docs below.

With what you have learned so far, you could create a simple program like this:

var arDrone = require('ar-drone');
var control = arDrone.createUdpControl();
var start   = Date.now();

var ref  = {};
var pcmd = {};

console.log('Recovering from emergency mode if there was one ...');
ref.emergency = true;
setTimeout(function() {
  console.log('Takeoff ...');

  ref.emergency = false;
  ref.fly       = true;

}, 1000);

setTimeout(function() {
  console.log('Turning clockwise ...');

  pcmd.clockwise = 0.5;
}, 6000);

setTimeout(function() {
  console.log('Landing ...');

  ref.fly = false;
  pcmd = {};
}, 8000);


setInterval(function() {
  control.ref(ref);
  control.pcmd(pcmd);
  control.flush();
}, 30);

UdpControl API

arDrone.createUdpControl([options]) / new arDrone.UdpControl([options])

Creates a new UdpControl instance where options can include:

  • ip: The drone IP address, defaults to '192.168.1.1'.
  • port: The port to use, defaults to 5556.

udpControl.raw(command, [arg1, arg2, ...])

Enqueues a raw AT* command. This is useful if you want full control.

For example, a takeoff instructions be send like this:

udpControl.raw('REF', (1 << 9));

udpControl.ref([options])

Enqueues a AT*REF command, options are:

  • fly: Set this to true for takeoff / staying in air, or false to initiate landing / stay on the ground. Defaults to false.
  • emergency: Set this to true to set the emergency bit, or false to not set it. Details on this can be found in the official SDK Guide. Defaults to false.

udpControl.pcmd([options])

Enqueues a AT*PCMD (progressive) command, options are:

  • front or back: Fly towards or away from front camera direction.
  • left or/ right: Fly towards the left or right of the front camera.
  • up or down: Gain or reduce altitude.
  • clockwise or counterClockwise: Rotate around the center axis.

The values for each option are the speed to use for the operation and can range from 0 to 1. You can also use negative values like {front: -0.5}, which is the same as {back: 0.5}.

udpControl.flush()

Sends all enqueued commands as an UDP packet to the drone.

Video

@TODO Document the low level video API.

Navdata

@TODO Document the low level navdata API.

Environment variables

  • DEFAULT_DRONE_IP

Camera access

You can access the head camera and the bottom camera, you just have to change the config:

// access the head camera
client.config('video:video_channel', 0);

// access the bottom camera
client.config('video:video_channel', 3);

More Repositories

1

node-style-guide

A guide for styling your node.js / JavaScript code. Fork & adjust to your taste.
JavaScript
4,950
star
2

fgprof

๐Ÿš€ fgprof is a sampling Go profiler that allows you to analyze On-CPU as well as Off-CPU (e.g. I/O) time together.
Go
2,469
star
3

node-dateformat

A node.js package for Steven Levithan's excellent dateFormat() function.
JavaScript
1,297
star
4

node-memory-leak-tutorial

A tutorial for debugging memory leaks in node
JavaScript
909
star
5

httpsnoop

Package httpsnoop provides an easy way to capture http related metrics (i.e. response time, bytes written, and http status code) from your application's http.Handlers.
Go
891
star
6

fgtrace

fgtrace is an experimental profiler/tracer that is capturing wallclock timelines for each goroutine. It's very similar to the Chrome profiler.
Go
878
star
7

faster-than-c

Talk outline: Faster than C? Parsing binary data in JavaScript.
JavaScript
836
star
8

node-dirty

A tiny & fast key value store with append-only disk log. Ideal for apps with < 1 million records.
JavaScript
625
star
9

node-stack-trace

Get v8 stack traces as an array of CallSite objects.
JavaScript
449
star
10

nodeguide.com

My unofficial and opinionated guide to node.js.
CSS
371
star
11

node-couchdb

A new CouchDB module following node.js idioms
JavaScript
364
star
12

sqlbench

sqlbench measures and compares the execution time of one or more SQL queries.
Go
361
star
13

node-sandboxed-module

A sandboxed node.js module loader that lets you inject dependencies into your modules.
JavaScript
344
star
14

node-require-all

An easy way to require all files within a directory.
JavaScript
300
star
15

tcpkeepalive

Go package tcpkeepalive implements additional TCP keepalive control beyond what is currently offered by the net pkg.
Go
238
star
16

node-paperboy

A node.js module for delivering static files.
JavaScript
234
star
17

godrone

GoDrone is a free software alternative firmware for the Parrot AR Drone 2.0.
Go
204
star
18

node-romulus

Building static empires with node.js.
JavaScript
157
star
19

node-gently

A node.js module that helps with stubbing and behavior verification.
JavaScript
142
star
20

node-combined-stream

A stream that emits multiple other streams one after another.
JavaScript
142
star
21

cakephp-authsome

Auth for people who hate the Auth component
PHP
123
star
22

pprofutils

Go
122
star
23

node-growing-file

A readable file stream for files that are growing.
JavaScript
106
star
24

node-graphite

A node.js client for graphite.
JavaScript
105
star
25

node-cross-compiler

Simplified cross compiling for node.js using vagrant.
Shell
105
star
26

pidctrl

A PID controller implementation in Golang.
Go
96
star
27

node-m3u

A node.js module for creating m3u / m3u8 files.
JavaScript
89
star
28

debuggable-scraps

MIT licensed code without warranty ; )
PHP
79
star
29

traceutils

Code for decoding and encoding runtime/trace files as well as useful functionality implemented on top.
Go
62
star
30

node-delayed-stream

Buffers events from a stream until you are ready to handle them.
JavaScript
56
star
31

go-redis

A redis implementation written in Go.
Go
53
star
32

nodelog

A node.js irc bot that logs a channel
JavaScript
49
star
33

flame-explain

A PostgreSQL EXPLAIN ANALYZE visualizer with advanced quirk correction algorithms.
TypeScript
46
star
34

node-stream-cache

A simple way to cache and replay readable streams.
JavaScript
45
star
35

node-utest

The minimal unit testing library.
JavaScript
42
star
36

go-cpu-utilization

Go
39
star
37

go-xxd

The history of this repo demonstrates how to take a slow xxd implementation in Go, and make it faster than the native version on OSX/Linux.
Go
38
star
38

vim-nodejs-errorformat

Vim Script
36
star
39

tweets

C
35
star
40

go-ardrone

Parrot AR Drone 2.0 drivers and protocols written in Go.
Go
33
star
41

dotfiles

My setup. Pick what you like.
Lua
31
star
42

node-buffy

A module to read / write binary data and streams.
JavaScript
31
star
43

node-urun

The minimal test runner.
JavaScript
31
star
44

node-multipart-parser

A fast and streaming multipart parser.
JavaScript
30
star
45

node-require-like

Generates require functions that act as if they were operating in a given path.
JavaScript
29
star
46

benchmore

Go
28
star
47

node-nix

Node.js bindings for non-portable *nix functions
JavaScript
28
star
48

node-fake

Test one thing at a time, fake the rest.
JavaScript
28
star
49

node-bash

Utilities for using bash from node.js.
JavaScript
25
star
50

gounwind

Experimental go stack unwinding using frame pointers.
Go
25
star
51

node-microtest

Unit testing done right.
JavaScript
23
star
52

pgmigrate

pgmigrate implements a minimalistic migration library for postgres.
Go
22
star
53

node-comment

Proof of concept - Long polling message queue with CouchDB for persistence.
JavaScript
21
star
54

node-ugly

A hack so unbelievably ugly, yet so hard to resist
JavaScript
20
star
55

advent-2021

Advent of Go Profiling 2021.
Go
19
star
56

open-source-contribution-guide

A guide for anybody interested in contribution to my open source projects.
18
star
57

go-patch-overlay

WIP
Go
17
star
58

node-channel

A general purpose comet server written in node.js
JavaScript
16
star
59

node-active-x-obfuscator

A module to (safely) obfuscate all occurrences of the string 'ActiveX' inside any JavaScript code.
JavaScript
16
star
60

gotraceanalyzer

Command gotraceanalyzer turns golang tracebacks into useful summaries.
Go
14
star
61

go-observability-bench

Measure the overheads of various observability tools, especially profilers.
Jupyter Notebook
14
star
62

rebel-resize

Dynamic image resizing server written during my web rebels 2012 live coding.
JavaScript
13
star
63

node-fast-or-slow

Are your tests fast or slow? A pragmatic testing framework.
JavaScript
13
star
64

cl

Quickly clone git repositories into a nested folders like GOPATH.
Go
13
star
65

node-lazy-socket

A stateless socket that always lets you write().
JavaScript
13
star
66

raleigh-workshop-08

Code repository for the Raleigh, NC CakePHP workshop
PHP
12
star
67

node-deferred

Dojo deferreds as a nodejs module - Work in Progress
JavaScript
12
star
68

node-oop

Simple & light-weight oop.
JavaScript
11
star
69

node-win-iap

Verifies windows store receipts.
JavaScript
10
star
70

goardronefirmware

Open source firmware for the Parrot AR Drone 2.0 written in Go.
Go
10
star
71

node-far

https://github.com/felixge/node-far
JavaScript
10
star
72

node-convert-example

Node.js image resizing demo. One version with and one version without in-memory caching.
10
star
73

couchdb-benchmarks

some benchmark scripts for testing CouchDB performance
PHP
10
star
74

node-socketio-benchmark

A WebSocket / LongPolling simulation to estimate users / core
JavaScript
9
star
75

gpac

Mirror of https://gpac.svn.sourceforge.net/svnroot/gpac/trunk/gpac + my patches
C
9
star
76

node-passthrough-stream

An example of a passthrough stream for node.js
JavaScript
9
star
77

node-http-recorder

A little tool to record and replay http requests.
JavaScript
9
star
78

node-cluster-isolatable

Isolate workers so they only handle one request at a time. Useful for file uploads.
JavaScript
8
star
79

nodecopter-ssh-tunnel

Bash scripts for controlling an AR Drone over the internet via ssh tunneling.
Shell
8
star
80

makefs

WIP - come back later.
Go
8
star
81

node-unicode-sanitize

JavaScript
8
star
82

felixge.de

My site and blog.
HTML
7
star
83

dump

A code dump of things not worth putting into their own repo.
Go
7
star
84

ooti

A kickass test suite for node.js
JavaScript
6
star
85

go-cgo-finalizer

Demonstrates using runtime.SetFinalizer to free cgo memory allocations.
Go
6
star
86

focus-app

Helps you focus by hiding all your windows except the ones you are currently working in.
Objective-C
6
star
87

gopg

Go
5
star
88

isalphanumeric

A small arm64 SIMD adventure for gophers.
Go
5
star
89

dd-trace-go-demo

A simple application to show how to use dd-trace-go's tracer and profiler.
Go
5
star
90

profiler-simulator

Go
5
star
91

talks

Source and slides for my presentations.
PLpgSQL
5
star
92

node-redis-pool

A simple node.js redis pool.
JavaScript
5
star
93

countermap

Go
5
star
94

pprof-breakdown

Go
5
star
95

proftest

proftest is a C application for testing the quality of different operating system APIs for profiling.
C
5
star
96

s3.sh

Bash functions for Amazon S3. (Not complete, just scratching my itch)
Shell
5
star
97

can

Nothing to see here yet.
Go
4
star
98

js-robocom

A robocom inspired programming game for JavaScript
JavaScript
4
star
99

log

nothing to see here yet
Go
4
star
100

dd-prof-upload

Go
4
star