var arDrone = require('ar-drone');
var client = new arDrone.createClient();
client.on('navdata', function(d){
if(d.demo){
console.log('Roll:' + d.demo.rotation.roll);
}
});
或此代码?
var arDrone = require('ar-drone');
var droneClient = arDrone.createClient();
droneClient.config('general:navdata_demo', 'TRUE');
droneClient.on('navdata', function(navdata) {
try {
console.log('test:' + navdata.demo.batteryPercentage);
}
catch(err) {
console.log(err.message);
}
});
答案 0 :(得分:0)
您无法真正更改导航数据的速度。如果您不想处理导航数据,则可以忽略导航数据。下面的代码每秒只处理一次navdata:
var lastNavDataMs = 0;
client.on('navdata', function(d) {
var nowMs = new Date().getTime();
if (nowMs - lastNavDataMs > 1000) {
lastNavDataMs = nowMs;
// Process navdata once per second.
if (d.demo){
console.log('pitch:' + d.demo.rotation.roll);
}
}
});
要显示传感器值的实时图表,您可以尝试使用Smoothie Charts库。它专门用于处理具有实时更新的图表和图形。他们的tutorial使它看起来很容易。下面,我尝试调整他们的教程来显示来自AR.Drone的navdata信息。我没有测试过它,但它可能是一个很好的起点。
首先,在HTML中,包含Smoothie脚本并创建一个canvas元素来保存图形:
<script type="text/javascript" src="smoothie.js"></script>
<canvas id="mycanvas" width="400" height="100"></canvas>
代码:
var arDrone = require('ar-drone');
var smoothie = new SmoothieChart();
smoothie.streamTo(document.getElementById("mycanvas"));
// Lines on the chart.
var rollLine = new TimeSeries();
var altitudeLine = new TimeSeries();
var client = new arDrone.createClient();
client.on('navdata', function(d) {
if (d.demo) {
// Add new measurements for roll and altitude.
var time = new Date().getTime();
rollLine.append(time, d.demo.rotation.roll);
altitudeLine.append(time, d.demo.altitudeMeters);
}
});
// Add the lines to our chart.
smoothie.addTimeSeries(rollLine);
smoothie.addTimeSeries(altitudeLine);