基于node.js的ARDrone控制

应用环境
ubuntu12.04 32bit 
 
1. 安装node.js+npm
          Node.js是一个基于google v8+javascript的服务端编程框架。但是Node.js又不是js应用,应该说是js的运行平台。它采用事件驱动、异步编程,为网络服务而设。 
          Node.js的性能不错,按照创始人Ryan Dahl的说法,性能是Node.js考虑的重要因素,选择c++和v8而不是ruby或者其他的虚拟机也是基于性能的目的。Node.js在设计上也是比较大胆,它以单进程、单线程模式运行,事件驱动机制是Node.js通过内部单线程高效率地维护事件循环队列来实现的,没有多线程的资源占用和上下文切换,这意味着面对大规模的http请求,Node.js凭借事件驱动搞定一切。 
安装步骤
          首先确保系统安装来python,gcc,g++,如果没有则安装: 
$ sudo apt-get install python 
$ sudo apt-get install build-essential 
$ sudo apt-get install gcc 
$ sudo apt-get install g++ 
          从nodeJS官网 http://nodejs.org/ 下载最新源代码包:node-v0.10.26.tar.gz, 解压,
$ tar -zxf node-v0.10.26.tar.gz 
$ cd node-v0.10.26
默认安装,
$ ./configure 
$ make 
$ sudo make install 
或选择目录方式安装:,
$ ./configure –prefix=/usr/node 
$ make -j 5 #5=CPU核数+1 
$ sudo make install 
安装结束,可以用下面的命令检查安装的版本: 
$ node --version 
v0.10.26 
         在node.js早一些的版本,是不带npm(node包管理器)的,npm需要另外安装,但我安装的 v0.10.26直接自带npm,所以就不用安装了,检查npm是否已安装,
$ npm --version
1.4.3

2. 安装node-ar-drone
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
使用npm安装的包,会放在执行npm命令的 当前 目录下面的node_modules文件夹中(另外,根目录下貌似多了一个空文件夹tmp)。

3. 编写ARDrone node app
         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 droneStateand demo data.

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

Once you have manged 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.

参考:
http://www.cnblogs.com/hwpayg/archive/2012/11/04/2753404.html(Ubuntu下node.js安装)
http://www.cnblogs.com/seanlv/archive/2011/11/22/2258716.html(Windows下node.js安装)
https://github.com/felixge/node-ar-drone(node-ar-drone源码地址,包括安装和使用说明)
http://nodecopter.com/hack#connect-to-access-point(一个 node-ar-drone的使用例子
https://github.com/eschnou/ardrone-autonomy(一个基于node-ar-drone的更高级的库,及其使用说明)

http://www.cnblogs.com/dolphinX/p/3474568.html(node.js说明和一些例子,编写容易功能强大)
http://www.ibm.com/developerworks/cn/web/1107_chengfu_nodejs/(node.js服务器端编程)





 

你可能感兴趣的:(JavaScript,node.js,ArDrone)