1

When I use this I get an undefined error. latitude is undefined.

var arDrone = require('ar-drone');
var droneClient = arDrone.createClient();
droneClient.config('general:navdata_demo', 'FALSE'); // get back all data the copter can send
droneClient.config('general:navdata_options', 777060865); // turn on GPS

droneClient.on('navdata', function(navdata) {
   console.log(navdata.gps.latitude + ', ' + navdata.gps.longitude);
   // do stuff with the GPS information....
});
droneClient.takeoff(); .....

However if I change 1 line I can get back all gps data.

console.log(navdata.gps);

Why can't I just get back the latitude data specifically?

var arDrone = require('ar-drone');
var droneClient = arDrone.createClient();
droneClient.config('general:navdata_demo', 'FALSE'); // get back all data the copter can send
droneClient.config('general:navdata_options', 777060865); // turn on GPS

droneClient.on('navdata', function(navdata) {
   console.log(navdata.gps);
   // do stuff with the GPS information....
});
droneClient.takeoff(); .....
  • please provide the exact error message. Maybe also the output of `console.log(navdata.gps);` It seems like maybe latitude isn't a property accessible using the dot operator. – Jim U Mar 29 '17 at 20:16
  • C:\data>node gpsLog.js C:\data\gpsLog.js:8 console.log(navdata.gps.latitude + ', ' + navdata.gps.longitude); ^ TypeError: Cannot read property 'latitude' of undefined at Client. (C:\data\gpsLog.js:8:27) at emitOne (events.js:96:13) at Client.emit (events.js:188:7) at Client._handleNavdata (C:\data\node_modules\ar-drone\lib\Client.js:194:8) at emitOne (events.js:96:13) at UdpNavdataStream.emit (events.js:188:7) at UdpNavdataStream._handleMessage (C:\data\node_modules\ar-drone\lib\navdata\UdpNavdataStream.js:73:10) – Kevin Hunkovic Mar 29 '17 at 21:33
  • this code came from another article suggesting it does work. http://stackoverflow.com/questions/24170884/get-gps-data-from-ar-drone-2-0 – Kevin Hunkovic Mar 29 '17 at 21:35
  • I just gave something a try. droneClient.on('navdata', function(navdata) { try {     console.log(navdata.gps.latitude + ', ' + navdata.gps.longitude); } catch(err) {     console.log(err.message); } – Kevin Hunkovic Apr 08 '17 at 22:04

1 Answers1

0

you have to call gps first, use "if(navdata.gps){}, then put the gps property on it. but the result is 0. even using the number to activated the gps. the value of latitude and longitude will be "0".