基于node.js的ARDrone控制
来源:互联网 发布:入耳式耳机推荐知乎 编辑:程序博客网 时间:2024/05/18 02:43
应用环境
ubuntu12.04 32bit
1. 安装node.js+npmubuntu12.04 32bit
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++,如果没有则安装:
首先确保系统安装来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,解压,
$ 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
$ 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:
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:
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();
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();
});
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 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);
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服务器端编程)
0 0
- 基于node.js的ARDrone控制
- 基于javadrone api实现ARDrone Android控制
- 基于GTK创建ARDrone 2.0控制线程
- 基于PocketSpinxAndroiDemo和javadrone api实现ARDrone语音控制
- 基于Node.js服务器的WebSocket Video
- 基于Node.js的Web框架集合
- 基于Node.js的文件下载服务器
- 基于Node.js的文件下载服务器
- 基于Node.js的Web Socket
- 基于node.js的web程序入门
- 基于Node.js的微服务后台
- 基于node.js的网页抓捕
- 基于node.js的m3u8下载器
- 基于node的uglifyjs压缩JS
- 基于node.js的在线聊天室
- 构建基于Node.js的web应用
- 基于Node.js的后端应用简介
- node.js 路由控制
- HDU-1281 棋盘游戏 二分图匹配匈牙利算法
- tomcat环境变量设置
- C++重写(override)、重载(overload)、重定义(redefine)以及虚函数调用机制【个人总结】
- hive使用mysql作为元数据库时的编码问题
- 测量CT和保护CT的区别
- 基于node.js的ARDrone控制
- hdu 1753 大明A+B
- 从零开始—实践打开咖啡导出的jar程序(以“sushu.jar“为例)
- (JAVA初学)String类中常用方法的简单应用
- JAVA多线程实现的三种方式
- 对Socket CAN的理解(5)——【Socket CAN控制器的初始化过程】
- Linux虚拟机中配置纯源码Lua环境
- 关于技术的问题
- C++中智能指针的设计和使用