-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·686 lines (529 loc) · 17.8 KB
/
index.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
<html>
<head>
<meta charset="utf-8">
<style>
html,
body {
width: 100%;
padding: 0;
/*background: #10161d url('dot_grid.png');*/
font-family: 'blender_prothin';
font-size: 12px;
color: #58bccc;
line-height: 20px;
}
#container_emg {
margin: 0 0px 0 0px;
}
#container_imu {
margin: 0 0px 0 0px;
}
#container_imu_rows {
margin: 0 0px 0 0px;
}
#container_machineLearning {
margin: 0 0px 0 0px;
}
#container_machineLearning_controls {
margin: 0 0px 0 0px;
}
#container_synth {
margin: 0 10px 0 20px;
}
#container_synth_rows {
margin: 0 20px 0 20px;
}
#gyroGraph {
height: 70px;
width: 450px;
}
#accelGraph {
height: 70px;
width: 450px;
}
#orientationGraph {
height: 85px;
width: 450px;
}
.button_emg {
height: 30px;
margin: 10 10 10 10;
}
.button_imu {
height: 45px;
width: 45px;
margin: 10 10 10 10;
}
.graph_emg {
/*display: inline-block;*/
height: 50px;
width: 100px;
padding: 0 0 0 0;
}
.graph_composite_emg {
/*display: inline-block;*/
height: 400px;
width: 150px;
}
.inline-fields {
display: inline-block;
}
.element_synth {
margin: 5 5 5 5;
}
.slider_synth_param {
width: 90px;
}
#randomData {
display: inline-block;
height: 250px;
width: 500px;
margin: 10px 0 0 50px;
}
</style>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<!--style="background: Thistle"-->
<div id="container_emg" style="background: Thistle" class="col-12">
<div class="row">
<h2>EMG</h2>
</div>
<div class="row">
<div id="container_emg_rows" class="col-md-6">
<div class="row emgRow">
<div id="pod0" class="graph_emg col-md-10"></div>
<button id="ch1" type="button" class="btn btn-outline-primary btn-sm button_emg" data-toggle="button" onclick="btn_onClick(this);">Ch 1</button>
</div>
<div class="row emgRow">
<div id="pod1" class="graph_emg col-md-10"></div>
<button id="ch2" type="button" class="btn btn-outline-primary btn-sm button_emg " data-toggle="button" onclick="btn_onClick(this);">Ch 2</button>
</div>
<div class="row emgRow">
<div id="pod2" class="graph_emg col-md-10"></div>
<button id="ch3" type="button" class="btn btn-outline-primary btn-sm button_emg" data-toggle="button" onclick="btn_onClick(this);">Ch 3</button>
</div>
<div class="row emgRow">
<div id="pod3" class="graph_emg col-md-10"></div>
<button id="ch4" type="button" class="btn btn-outline-primary btn-sm button_emg" data-toggle="button" onclick="btn_onClick(this);">Ch 4</button>
</div>
<div class="row emgRow">
<div id="pod4" class="graph_emg col-md-10"></div>
<button id="ch5" type="button" class="btn btn-outline-primary btn-sm button_emg" data-toggle="button" onclick="btn_onClick(this);">Ch 5</button>
</div>
<div class="row emgRow">
<div id="pod5" class="graph_emg col-md-10"></div>
<button id="ch6" type="button" class="btn btn-outline-primary btn-sm button_emg" data-toggle="button" onclick="btn_onClick(this);">Ch 6</button>
</div>
<div class="row emgRow">
<div id="pod6" class="graph_emg col-md-10"></div>
<button id="ch7" type="button" class="btn btn-outline-primary btn-sm button_emg" data-toggle="button" onclick="btn_onClick(this);">Ch 7</button>
</div>
<div class="row emgRow">
<div id="pod7" class="graph_emg col-md-10"></div>
<button id="ch8" type="button" class="btn btn-outline-primary btn-sm button_emg" data-toggle="button" onclick="btn_onClick(this);">Ch 8</button>
</div>
</div>
<div id="emgComposite" class="graph_composite_emg col-md-6"></div>
</div>
</div>
</div>
<br>
<div class="row">
<!--style="background: PaleGreen"-->
<div id="container_imu" style="background: PaleGreen" class="col-6">
<div class="row">
<h2>IMU</h2>
</div>
<div class="row">
<div id="container_imu_rows" class="col-12">
<div class="row">
<div id="gyroGraph" class="col-md-10"></div>
<button id="gyro" type="button" class="btn btn-outline-primary btn-sm button_imu" data-toggle="button" onclick="btn_onClick(this);">Gyro</button>
</div>
<div class="row">
<div id="accelGraph" class="col-md-10"></div>
<button id="accel" type="button" class="btn btn-outline-primary btn-sm button_imu" data-toggle="button" onclick="btn_onClick(this);">Accel</button>
</div>
<div class="row">
<div id="orientationGraph" class="col-md-10 "></div>
<button id="ori" type="button" class="btn btn-outline-primary btn-sm button_imu active" data-toggle="button" onclick="btn_onClick(this);">Ori</button>
</div>
</div>
</div>
</div>
<!--style="background: lightblue"-->
<div id="container_machineLearning" style="background: lightblue" class="col-6">
<div class="row">
<h2>Machine Learning</h2>
</div>
<br>
<div class="row">
<div id="trainingData" class="container_machineLearning_controls">
[0.0000, 0.0000, 0.0000, 00000, 00000 ,0000 , 0000 ,0000, 000, 000, 00000 ,0000 ,0000, 00000, 0000]
</div>
</div>
<br>
<div class="row">
<div class="container_machineLearning_controls">
<button class="btn btn-outline-primary btn-lg" data-toggle="button" aria-pressed="false" onclick="togRecord()">Record</button>
<button class="btn btn-outline-primary btn-lg" onclick="train()">Train</button>
<button class="btn btn-outline-primary btn-lg" data-toggle="button" aria-pressed="false" onclick="togRun()">Run</button>
</div>
</div>
</div>
<!--<div class="randomDataGraph col-md-6 " id="randomData "></div>-->
<!--style="background: Salmon" -->
<div id="container_synth" style="background: Salmon" class="col-3">
<div class="row">
<h2>Synth</h2>
</div>
<div class="row">
<div id="container_synth_rows">
<div class="row">
<button class="btn btn-outline-danger btn-lg col-6" onclick="randomize()">Randomize</button>
<button data-toggle="button" class="btn btn-outline-danger btn-lg active col-6" aria-pressed="true" onclick="togMute()">Mute</button>
</div>
<div class="row">
<div class="controls col-6" id="modParams">
<div class="row">
<h5 class="element_synth">Modulator</h5>
</div>
<div class="row">
<div style="text-align: left;" class="element_synth" for="mdSlider ">Frequency</div>
<input id="mfSlider" name="mfSlider" min="1" max="4096" step="0.5" value="4.1" type="range" autocomplete="off" class="element_synth slider_synth_param inline-fields" oninput="mfOutput.value=mfSlider.value">
<output id="mfOutput" class="element_synth inline-fields">4.1</output>
</div>
<div class="row">
<div class="element_synth inline-fields" style="margin: 5 25 5 5; text-align: left;" for="mdSlider">Depth</div>
<input id="mdSlider" name="mdSlider" class="element_synth slider_synth_param inline-fields" min="0" max="1" step="0.01" value="0.2" type="range" autocomplete="off" oninput="mdOutput.value=mdSlider.value">
<output id="mdOutput" class="element_synth inline-fields">0.2</output>
</div>
</div>
<div class="controls col-6" id="filParams">
<div class="row">
<h5 class="element_synth">Filter</h5>
</div>
<div class="row">
<div style="text-align: left;" class="element_synth inline-fields" for="cfSlider ">Center Frequency</div>
<input id="cfSlider" name="cfSlider" min="256" max="4096" step="0.5" value="512.0" type="range" autocomplete="off" class="element_synth slider_synth_param inline-fields" oninput="cfOutput.value=cfSlider.value">
<output id="cfOutput" class="inline-fields">512</output>
</div>
<div class="row">
<div style="text-align: left;" class="element_synth inline-fields" for="qSlider">Resonance</div>
<input id="qSlider" name="qSlider" class="element_synth slider_synth_param inline-fields" min="0" max="40" step="0.5" value="2" type="range" autocomplete="off" oninput="qOutput.value=qSlider.value">
<output id="qOutput" class="element_synth inline-fields">2</output>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<!-- jQuery (v1.12.4 necessary for Bootstrap"s JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
var jQuery_1_12_4 = $.noConflict(true);
</script>
<script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.min.js"></script>
<script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.selection.js"></script>
<script language="javascript" type="text/javascript" src="https://www.doc.gold.ac.uk/eavi/rapidmix/RapidLib.js"></script>
<script>
//alert("Record mouse positions associated with filter parameters.");
/////////////////////////////////////////MAXI
var myMod = 0;
var myFreq = 256;
function makeNoise(rOut) {
myFreq = 256 + (1024 * rOut);
}
var maxiAudio = new maximJs.maxiAudio();
var myWave = new maximJs.maxiOsc();
var myLFO01 = new maximJs.maxiOsc();
var myFilter = new maximJs.maxiFilter();
maxiAudio.init();
var mfSlider = document.getElementById("mfSlider");
var mdSlider = document.getElementById("mdSlider");
var cfSlider = document.getElementById("cfSlider");
var qSlider = document.getElementById("qSlider");
var mfOutput = document.getElementById("mfOutput");
var mdOutput = document.getElementById("mdOutput");
var qOutput = document.getElementById("qOutput");
var cfOutput = document.getElementById("cfOutput");
var muted = true;
function togMute() {
muted = !muted;
if (muted) {
this.maxiAudio = null;
console.warn("Sound muted");
} else {
console.log("Sound playing");
}
}
maxiAudio.play = function() {
var LFO01 = ((myLFO01.sinewave(parseFloat(mfSlider.value)) + 1.0) / 2.0) * (mdSlider.value) + (1 - mdSlider.value);
var oscOutput = myWave.pulse(83, LFO01);
var cFreq = parseFloat(cfSlider.value);
var res = parseFloat(qSlider.value);
var myFilteredOutput = myFilter.lores(oscOutput, cFreq, res);
this.output = muted ? 0.0 : myFilteredOutput;
};
////////////////////////////////////GET DATA
var data = [],
totalPoints = 300;
var res = [];
function getRandomData() {
if (data.length > 0)
data = data.slice(1);
// Do a random walk
while (data.length < totalPoints) {
var prev = data.length > 0 ? data[data.length - 1] : 50,
y = prev + Math.random() * 10 - 5;
if (y < 0) {
y = 0;
} else if (y > 100) {
y = 100;
}
data.push(y);
}
res = [];
// Zip the generated y values with the x values
for (var i = 0; i < data.length; ++i) {
res.push([i, data[i]]);
}
return res;
}
var compositeData;
function getCompositeData() {
for (var z = 0; z < compositeData.length; ++z) {
var obj = compositeData[z];
var data = obj.data;
if (data.length > 0)
data = data.slice(1);
res = [];
while (data.length < totalPoints) {
var prev = data.length > 0 ? data[data.length - 1] : 50,
y = prev + Math.random() * 10 - 5;
if (y < 0) {
y = 0;
} else if (y > 100) {
y = 100;
}
data.push(y);
}
// Zip the generated y values with the x values
for (var i = 0; i < data.length; ++i) {
res.push([i, data[i]]);
}
compositeData[z].data = res;
// cfinalRes.push(["label : ".concat(z), "data :" res]);
}
return compositeData;
}
var graphDataOrientation;
function getCurrentQuaternion() {
var quat_x = graphDataOrientation.x;
var quat_y = graphDataOrientation.y;
var quat_z = graphDataOrientation.z;
var quat_w = graphDataOrientation.w;
return [quat_x[quat_x.length - 1], quat_y[quat_y.length - 1], quat_z[quat_z.length - 1], quat_w[quat_w.length - 1]];
}
var updateInterval = 10;
var realTimeUpdate = true;
// $("#updateInterval").val(updateInterval).change(function() {
// var v = $(this).val();
// if (v && !isNaN(+v)) {
// updateInterval = +v;
// if (updateInterval < 1) {
// updateInterval = 1;
// } else if (updateInterval > 2000) {
// updateInterval = 2000;
// }
// $(this).val("" + updateInterval);
// }
// });
// var plot = $.plot("#randomData", [getRandomData()], {
// colors: ["#04fbec", "#ebf1be", "#c14b2a", "#8aceb5"],
// series: {
// shadowSize: 0 // Drawing is faster without shadows
// },
// yaxis: {
// min: 0,
// max: 100
// },
// xaxis: {
// show: true
// },
// selection: {
// mode: "x"
// }
// });
////////////////////////////////////TIMER
var myTimer;
var trainingData = document.getElementById("trainingData");
function setCurrentTrainingSample() {
var rapidInput = getCurrentQuaternion();
var rapidOutput = [(mfSlider.value), (mdSlider.value), (cfSlider.value), (qSlider.value)];
myTrainingSet.push({
input: rapidInput,
output: rapidOutput
});
}
function update() {
// console.log("Not updating");
if (realTimeUpdate) {
// plot.setData([getRandomData()]);
// // Since the axes don"t change, we don"t need to call plot.setupGrid()
// // plot.setupGrid();
// plot.draw();
// myTimer = setTimeout(update, updateInterval);
} else {
console.log("Not updating");
}
myTimer = setTimeout(update, updateInterval);
if (recordState) {
setCurrentTrainingSample();
trainingData.innerHTML = myTrainingSet[myTrainingSet.length - 1].input;
}
if (runState) {
var rapidInput = getCurrentQuaternion();
process(rapidInput);
}
}
update();
/////////////SUBSCRIBE EVENTS
// Subscribe the event Keydown to check
window.addEventListener("keydown", this.check, false);
function check(e) {
//console.log(e.keyCode);
// console.log(rawData);
switch (e.keyCode) {
case 90: //z
togRealtimeUpdate();
break;
case 88: //x
togRecord();
break;
case 86: //v
togRun();
break;
case 67: //c
train();
break;
default:
// minyOutput = e.keyCode - 48;
}
}
function btn_onClick(element) {
var displayText = "I am ".concat(element.id);
switch (element.id) {
case "ch1":
alert(displayText);
break;
case "ch2":
alert(displayText);
break;
case "ch3":
alert(displayText);
break;
case "ch4":
alert(displayText);
break;
case "ch5":
alert(displayText);
break;
case "ch6":
alert(displayText);
break;
case "ch7":
alert(displayText);
break;
case "ch8":
alert(displayText);
break;
case "gyro":
alert(displayText);
break;
case "accel":
alert(displayText);
break;
case "ori":
alert(displayText);
break;
default:
alert(displayText);
}
}
/////////////STATES
var recordState;
function togRecord() {
recordState = !recordState;
if (recordState) {
console.warn("recording!");
} else {
console.log("stopped recording");
}
}
function togRealtimeUpdate() {
realTimeUpdate = !realTimeUpdate;
if (realTimeUpdate) {
console.warn("RealTime Updating");
update();
} else {
clearTimeout(myTimer);
console.log("No RealTime");
}
}
var runState;
function togRun() {
runState = !runState;
console.log("running");
}
function randomize() {
mfSlider.value = 4096 * Math.random();
mdSlider.value = 1.0 * Math.random();
cfSlider.value = 4096 * Math.random();
qSlider.value = 40 * Math.random();
updateOutputs();
}
////////////////////////////////////RAPID API
// Create an instance of the library
var rapidMix = window.RapidLib();
// Create a classification object
var myRegression = new rapidMix.Regression();
// Training - myTraining set will be filled with training examples,
// such as sensor data paired with outputs
var myTrainingSet = [];
var trained = false;
function train() {
console.log("regression trained: ", myRegression.train(myTrainingSet));
trained = true;
}
//Run the models
var regressionOutput = new rapidMix.VectorDouble();
function process(input) {
regressionOutput = myRegression.process(input);
mfSlider.value = regressionOutput[0];
mdSlider.value = regressionOutput[1];
cfSlider.value = regressionOutput[2];
qSlider.value = regressionOutput[3];
updateOutputs();
}
function updateOutputs() {
mfOutput.value = mfSlider.value;
mdOutput.value = mdSlider.value;
cfOutput.value = cfSlider.value;
qOutput.value = qSlider.value;
}
</script>
<script language="javascript" src="https://www.doc.gold.ac.uk/~fbern010/RAPID-Myo/myo.js"></script>
<script language="javascript" src="https://www.doc.gold.ac.uk/~fbern010/RAPID-Myo/emgGraphs.js"></script>
<script language="javascript" src="https://www.doc.gold.ac.uk/~fbern010/RAPID-Myo/deviceGraphs.js"></script>
</html>