-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
92 lines (75 loc) · 2.22 KB
/
server.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'use strict';
var wait = require('wait.for')
var Cylon = require('cylon');
var bleno = require('bleno');
var ip = require('ip');
require('wait.for/parallel-tests.js')
Cylon.robot({
name: 'ardrobot',
connections: {
edison: {
adaptor: 'intel-iot'
}
},
devices: {
turnServo: {
driver: 'servo',
pin: 3,
},
driveServo: {
driver: 'servo',
pin: 5,
}
},
//These correspond to the actual api endpoints
commands: function() {
return {
//servo
set_angle: this.setAngle,
set_drive_speed: this.setSpeed,
do_arm: this.arm
};
},
setAngle: function(val) {
if (val != null) {
this.turnServo.angle(this.turnServo.safeAngle(+val));
}
},
setSpeed: function(val) {
if (val != null) {
this.driveServo.angle(this.driveServo.safeAngle(+val));
}
},
arm: function() {
var my = this;
function arm1(param, callback) {
console.log('on -> arming sequence step 1');
my.setSpeed(180);
wait.miliseconds(5000);
};
function arm2(param, callback) {
console.log('on -> arming sequence step 2');
my.setSpeed(0);
wait.miliseconds(5000);
};
function arm3(param, callback) {
console.log('on -> arming sequence step 3');
my.setSpeed(90);
};
function prepareArm() {
console.log('on -> starting arming sequence');
wait.for(arm1);
wait.for(arm2);
wait.for(arm3);
console.log('on -> finished arming sequence');
};
wait.launchFiber(prepareArm);
},
work: function(my) {}
}).start();
Cylon.api(
'http', {
host: ip.address(),
ssl: false,
port: '3000'
});