-
Notifications
You must be signed in to change notification settings - Fork 0
/
imu_graphs.html
136 lines (126 loc) · 3.37 KB
/
imu_graphs.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
<!DOCTYPE html>
<html>
<head>
<script>global=window</script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/flot/0.8.2/jquery.flot.min.js"></script>
<script src='myo.js'></script>
<style>
body{
background-color : #0A0A0A;
color : #84FFF1;
font-family: 'Open Sans', sans-serif;
}
.plot{
width:300px;
height:800px;
display : inline-block;
}
#events{
border : 1px solid #427F78;
font-family: courier;
overflow-y : scroll;
height : 800px;
width: 500px;
}
.event{
margin-bottom: 10px;
}
.event_data{
width: 440px;
font-size: 0.8em;
margin-left: 20px;
opacity: 0.8;
white-space: pre-wrap;
word-wrap: break-word;
}
</style>
</head>
<body>
<title>IMU Graphs - Myo.js</title>
<div style='display:inline-block'>
<div>Gyroscope</div>
<div id='gyroscope' class='plot' ></div>
</div>
<div style='display:inline-block'>
<div>Accelerometer</div>
<div id='accelerometer' class='plot'></div>
</div>
<div style='display:inline-block'>
<div>Orientation</div>
<div id='orientation' class='plot'></div>
</div>
<div style='display:inline-block'>
<div> Events <button id='clear_events'>clear</button></div>
<div id='events'></div>
</div>
</body>
<script>
var myo = Myo.create();
var createGraph = function(elementId, startingData, range, resolution){
var history = _.times(resolution, function(){
return startingData;
});
var graph = {
history : history,
getGraphData : function(){
var result = {};
_.each(this.history, function(data, index){
_.each(data, function(val, axis){
result[axis] = result[axis] || {label : axis, data : []};
result[axis].data.push([val, index])
});
});
return _.values(result);
},
addData : function(data){
this.history.push(data);
this.history = this.history.slice(1);
this.update();
},
update : function(){
this.plot.setData(this.getGraphData());
this.plot.draw()
},
};
graph.plot = $.plot("#" + elementId, graph.getGraphData(), {
series: {shadowSize: 0},
colors: [ '#84FFF1', '#FFF38A', '#FF4B23', '#00797F'],
xaxis: {
min : -range,
max : range
},
yaxis : {
show: false,
min : 0,
max : resolution
},
legend : {
backgroundOpacity : 0,
},
grid : {
borderColor : "#427F78"
}
});
return graph;
}
var gyroGraph = createGraph('gyroscope', {x:0,y:0,z:0}, 600, 100);
var accelerationGraph = createGraph('accelerometer', {x:0,y:0,z:0}, 5, 100);
var orientationGraph = createGraph('orientation', {x:0,y:0,z:0,w:0}, 1, 100);
myo.on('imu', function(data){
gyroGraph.addData(data.gyroscope);
orientationGraph.addData(data.orientation);
accelerationGraph.addData(data.accelerometer);
})
myo.on('*', function(event, data){
if(!_.contains(['imu', 'orientation', 'accelerometer', 'gyroscope', 'position', 'pose', 'rest'], event)){
$('<div class="event">' + event + '<div class="event_data">' + JSON.stringify(data) + '</div></div>')
.prependTo($('#events'));
}
});
$('#clear_events').click(function(){
$('#events').html('');
})
</script>
</html>