-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
64 lines (55 loc) · 1.33 KB
/
api.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
module.exports = function(client) {
var api = {};
api.takeoff = function() {
if(client) {
client.takeoff();
console.log("Drone is taking off");
}
else console.log("Client is null");
};
api.land = function() {
if(client) {
//client.stop();
client.land();
console.log("Drone is landing");
}
else console.log("Client is null");
};
api.moveForwardBy = function(distance, speed) {
var ms = this.distanceToMs(distance, speed);
client.front(speed);
client.after(ms, function(){
client.stop();
});
console.log("Move for "+ms+"ms");
};
api.rotateBy = function(angle, speed) {
var ms = this.degreesToMs(angle, speed);
if(angle > 0) {
client.clockwise(speed);
client.after(ms, function(){
client.stop();
});
console.log("Rotated cw by "+angle+" in "+ms+"ms");
} else if(angle < 0) {
client.counterClockwise(speed)
client.after(ms, function(){
client.stop();
});
console.log("Rotated ccw by "+angle+" in "+ms+"ms");
} else console.log("Bad rotation args: "+angle+"; "+speed);
};
api.stopAll = function() {
client.stop();
};
api.distanceToMs = function(distance, speed) {
return distance*speed*50;
};
api.degreesToMs = function(angle, speed) {
return Math.abs(angle*speed*10);
};
api.parsePath = function(pathData) {
return pathData;
};
return api;
};