-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
77 lines (71 loc) · 2.32 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//Import requirements
var arDrone = require('ar-drone');
var fs = require('fs');
var autonomy = require('ardrone-autonomy');
require('events').EventEmitter.prototype._maxListeners = 100;
//Set variables and drone configuration
var mission = autonomy.createMission();
var pngStream = mission.client().getPngStream();
var frameCounter = 0;
var period = 5000; // Time between each image.
var lastFrameTime = 0;
var baseElevation = 0;
mission.client().config('general:navdata_demo', 'FALSE'); // get back all data the copter can send
mission.client().config('general:navdata_options', 777060865); // turn on GPS
mission.client().config('video:video_channel', 3); //Switch to bottom camera
mission.client().config('control:altitude_max', 30000);
fs.writeFile('navdata.txt', "", function(err) {
if (err) {
console.log("Error creating file" + err);
}
})
//Take and store images and image data.
pngStream
.on('data', function(pngBuffer) {
var now = (new Date()).getTime();
mission.client().on('navdata', function(navdata) {
if (baseElevation == 0) {
baseElevation = navdata.gps.elevation;
}
//console.log(navdata)
if (now - lastFrameTime > period) {
frameCounter++;
lastFrameTime = now;
console.log('Saving frame');
var latitude = navdata.gps.latitude;
var longitude = navdata.gps.longitude;
var elevation = navdata.gps.elevation - baseElevation;
fs.appendFile('navdata.txt',
"latitude = " + latitude + "\n"
+ "longitude = " + longitude + "\n"
+ "elevation = " + elevation + "\n \n",
function(err) {
if (err) {
console.log("Error writing data" + err);
}
});
fs.writeFile('frame' + frameCounter + '.png', pngBuffer, function(err) {
if (err) {
console.log('Error saving PNG: ' + err);
}
});
}
});
});
//Flight sequence
mission.takeoff()
.zero()
.go({x: 1, y: 0, z: 0, yaw: 0})
.go({x: -1, y: 0, z: 1, yaw: 90})
.land();
console.log("Executing");
mission.run(function (err, result) {
if (err) {
console.trace("Oops, something bad happened: %s", err.message);
mission.client().stop();
mission.client().land();
} else {
console.log("Mission success!");
process.exit(0);
}
});