Closed ghost closed 10 years ago
It seems you are not having any demo data at all and my guess is because you have set navdata_demo to false. I typically write it this way (not sure about strings vs booleans).
drone1.config('general:navdata_demo', 'TRUE');
If this does not work, please log the complete result in 'd' and paste it.
I try with drone1.config('general:navdata_demo', 'TRUE');
and drone1.config('general:navdata_demo', true);
and it returns the same TypeError: Cannot read property 'altitude' of undefined
.
But if I put console.log(d.demo);
or console.log(d);
it prints the values correctly:
I try with other values like demo.batteryPercentage or visionDetect.nbDetected and it doesn't work ('undefined').
Thanks. Jon
So, what do you actually receive in 'd' ? Can you try your code and share the result? Just put everything in a gist (https://gist.github.com/) ans share the link. Thanks!
drone1.on('navdata', function (d) {
console.log(d);
});
There my code and the result: https://gist.github.com/jonlarra1/9913095
Thanks.
So, it is all there, d.demo.altitude. What is wrong?
Note that it may happen, especially at the initial connection, that the demo data isn't there yet. So, it is good to check if demo is defined before looking for altitude. But since you logged it, it is there.
Yes, but my cuestion is why I can print, for example, d.droneState.flying
without error but when I print or take like variable d.demo.altitude
or d.visionDetect.nbDetect
returns an error :
/home/gic/multi.js:20
console.log(d.demo.altitude);
^
TypeError: Cannot read property 'altitude' of undefined
at Client.<anonymous> (/home/gic/multi.js:20:20)
at Client.EventEmitter.emit (events.js:95:17)
at Client._handleNavdata (/home/gic/node_modules/ar-drone/lib/Client.js:120:8)
at UdpNavdataStream.EventEmitter.emit (events.js:95:17)
at UdpNavdataStream._handleMessage (/home/gic/node_modules/ar-drone/lib/navdata/UdpNavdataStream.js:73:10)
at Socket.EventEmitter.emit (events.js:98:17)
at UDP.onMessage (dgram.js:423:8)
Sorry if I am explaining bad
Well, that error means that demo isn't there (Cannot read property of undefined). Is it the same code?
Yes is the same code (https://gist.github.com/jonlarra1/9913095). I can't print d.demo.altitude
but I can d.demo
, I don't understand :(
Anyone know why this happens? Is possible that Demo navdata is wrong actived?
Maybe try changing that gist so it reads
drone1.on('navdata', function(d) {
console.log(d);
if (d.demo) {
console.log("DEMO:");
console.log(d.demo);
if (d.demo.altitude) {
console.log("ALT");
console.log(d.demo.altitude);
}
}
});
Does it print out d.demo.altitude every time? If it works, then you need to figure out what's different between that example and your code.
It works. Thanks!
For the benefit of searchers etc, what was the problem?
The problem was that I didn't added :
if (d.demo) { console.log(d.demo.altitude) }
If I put only console.log(d.demo.altitude)
it returned a error saying it couldn't read altitude.
Closing as this has been resolved.
Great thread! solved a problem i was having for a while
Hello: I am new with the node-ar-node and I am trying to use the altitude section within the navdata to read what the current height of the drone is (I move the drone by hand). But I don't get anything back. What is wrong?
And returns :
Have I to change something in
/lib/navdata/parseNavdata.js
?Thank you