-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathflydrone.js
60 lines (56 loc) · 1.36 KB
/
flydrone.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();
const readline = require('readline');
readline.emitKeypressEvents(process.stdin);
process.stdin.setRawMode(true);
process.stdin.on('keypress', (str, key) => {
// key.name='k';
if (key.name === 'w')
{
client.takeoff();
console.log('drone is taking off.....');
}
else if (key.name === 's')
{
client.land();
console.log('drone is landing....');
}
else if (key.name === 'a')
{
client.up(0.2);
client.after(2000, function() {
this.stop(0.2);
})
console.log('drone is moving up....');
}
else if (key.name === 'd') {
client.down(0.2);
client.after(2000, function() {
this.stop(0.2);
})
console.log('drone is coming down....');
}
else if (key.name === 'l'){
client.left(0.2);
client.after(2000, function() {
this.stop(0.2);
})
console.log('drone is going left...');
}
else if (key.name === 'r') {
client.right(0.2);
client.after(2000, function() {
this.stop(0.2);
})
console.log('drone is going right...');
}
else {
console.log(`You pressed the "${str}" key`);
console.log('Try again!!')
console.log();
process.exit();
console.log(key);
console.log();
}
})
console.log('Press any key...');