-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRobot.js
More file actions
86 lines (72 loc) · 1.93 KB
/
Copy pathRobot.js
File metadata and controls
86 lines (72 loc) · 1.93 KB
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
var PythonShell = require('python-shell');
var Cylon = require('cylon');
var ATTENTION_NUMBERS = 3;
var mapping_devices = require('./arduino_devices.js');
Cylon.robot({
connections: {
neurosky: {
adaptor: "neurosky",
port: '/dev/cu.MindWaveMobile-SerialPo'
},
arduino: {
adaptor: 'firmata',
port: '/dev/tty.usbmodem1411'
}
},
devices: {
headset: { driver: "neurosky", connection: 'neurosky'},
relay_1: {
driver: 'relay',
pin: 6,
type: 'open',
connection: 'arduino'
},
relay_2: {
driver: 'relay',
pin: 7,
type: 'open',
connection: 'arduino'
}
},
work: function(my) {
var attention_data = 0;
var meditation_data = 0;
var attention_counter = 0;
var device_return = null;
var pyshell = new PythonShell('python/markerdetect.py');
every((1).second(), function() {
if (attention_data > 80) {
attention_counter++;
}
// if (meditation_data > 10) {
// attention_counter = 0;
// }
console.log('attention_data: ' + attention_data);
// console.log('meditation_data: ' + meditation_data);
console.log('attention_counter: ' + attention_counter);
console.log('===================');
if (attention_counter >= ATTENTION_NUMBERS) {
if (device_return != null) {
console.log(device_return);
var device = mapping_devices[device_return];
device.action(my[device.name])
attention_counter = 0;
}
}
});
my.headset.on("attention", function(data) {
attention_data = data;
});
// my.headset.on("meditation", function(data) {
// meditation_data = data;
// });
pyshell.on('message', function (message) {
console.log(message);
device_return = message;
});
pyshell.end(function (err) {
if (err) throw err;
console.log('finished');
});
}
}).start();