0

我想问一些事情。我想延迟在 parrot AR Drone 2.0 上读取的 navData。你能举例说明如何在我的导航数据读取中添加间隔吗?我需要做什么,如果我想构建实时图表,有人可以提供教程链接吗?

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);
}
});
4

1 回答 1

1

您无法真正更改 navdata 进入的速率。如果您不想处理它,可以忽略 navdata。下面的代码每秒只处理一次 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 库。它专门用于处理具有实时更新的图表和图形。他们的教程使它看起来很容易。下面,我尝试调整他们的教程以显示来自 AR.Drone 的导航数据信息。我还没有测试过,但这可能是一个很好的起点。

首先,在您的 HTML 中,包含 Smoothie 脚本并创建一个画布元素来保存图形:

<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);
于 2017-05-30T18:10:01.233 回答