/
loopanimations.js
60 lines (55 loc) · 1.67 KB
/
loopanimations.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
var arDrone = require('ar-drone');
var client = arDrone.createClient();
client.config('general:navdata_demo', 'TRUE');
client.takeoff();
/*
Fly the quadcopter within a range of 1 to 3 meters. Correct its altitude
if it moves outside of that range.
*/
client.on('navdata', function(navdata) {
if (!navdata.demo) {return; }
if (navdata.demo.altitudeMeters > 2) {
console.log('maxed out, going down', navdata.demo.altitudeMeters);
client.down(0.5);
client.after(1000, function() {
client.stop();
});
} else if (navdata.demo.altitudeMeters < 1) {
console.log('going up', navdata.demo.altitudeMeters);
client.up(0.5);
client.after(1000, function() {
client.stop();
});
} else {
console.log('level: ', navdata.demo.altitudeMeters);
client.after(250, function() {
client.stop();
});
}
// console.log(navdata);
});
/*
After two seconds, loop through all the animations (some of these rock)
*/
client.after(2000, function() {
// this.up(0.4);
// client.after(3000, function() { client.stop(); });
var animations = [
'phiM30Deg', 'phi30Deg', 'thetaM30Deg', 'theta30Deg', 'theta20degYaw200deg',
'theta20degYawM200deg', 'turnaround', 'turnaroundGodown',
'yawShake', 'yawDance', 'phiDance', 'thetaDance', 'vzDance',
'wave', 'phiThetaMixed',
'doublePhiThetaMixed', 'flipAhead', 'flipBehind', 'flipLeft', 'flipRight'
];
animations.forEach(function(anim) {
//I think the .after time needs to match the animate time or else it cuts it short?
client.after(2000, function() {
console.log(anim);
client.animate(anim, 2000);
});
});
client.after(3000, function() {
this.stop();
this.land();
});
});