-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccelerationVizPlayground.pde
245 lines (206 loc) · 6.96 KB
/
accelerationVizPlayground.pde
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
import oscP5.*;
import netP5.*;
import java.util.Collections;
import java.util.Comparator;
OscP5 oscP5;
OscMessage myMessage;
OscP5 multicastOsc;
ArrayList<ArrayList<AccelerationSample>> dataList;
ArrayList<Integer> dataId;
MyLock myLock;
ArrayList<AccelerationSample> inputBuffer;
ArrayList<AccelerationSample> lastInput;
float plottedMs = 15000.0;
float accMult = 2.0;
void setup() {
size(1200, 800,P3D);
frameRate(30);
// The following is needed for Macs to get the Multicast
System.setProperty("java.net.preferIPv4Stack" , "true");
myLock = new MyLock();
inputBuffer = new ArrayList<AccelerationSample>();
dataList = new ArrayList<ArrayList<AccelerationSample>>();
dataId = new ArrayList<Integer>();
oscP5 = new OscP5(this, 7018);
initializeReceiving();
}
void draw() {
background(0);
colorMode(HSB, 100);
strokeWeight(2);
int tSize = 32;
textSize(tSize);
text("X", 10, (height * 0.0) + tSize);
text("Y", 10, (height * 0.25) + tSize);
text("Z", 10, (height * 0.5) + tSize);
text("abs", 10, (height * 0.75) + tSize);
/*myLock.lock();
// Checking if the data comes from a known id or new one
// WTF is data list
for (int i = 0; i < inputBuffer.size(); i++)
{
AccelerationSample sample = inputBuffer.get(i);
boolean found = false;
for (int listInd = 0; listInd < dataList.size(); listInd++)
{
if (dataId.get(listInd) == sample.id)
{
found = true;
ArrayList<AccelerationSample> data = dataList.get(listInd);
data.add(sample);
}
}
if (!found)
{
ArrayList<AccelerationSample> data = new ArrayList<AccelerationSample>();
data.add(sample);
dataId.add(sample.id);
dataList.add(data);
}
}
inputBuffer.clear();
myLock.unlock();*/
myLock.lock();
// Sorting all data lists
for (int listInd = 0; listInd < dataList.size(); listInd++)
{
println("sorting");
ArrayList<AccelerationSample> data = dataList.get(listInd);
Collections.sort(data, new Comparator<AccelerationSample>() {
public int compare(AccelerationSample acc1, AccelerationSample acc2)
{
return (int)(acc1.time - acc2.time);
}
});
}
// Finding the max timestamp
long maxTime = 0;
for (int listInd = 0; listInd < dataList.size(); listInd++)
{
ArrayList<AccelerationSample> data = dataList.get(listInd);
if (data.size() > 1 && maxTime < data.get(data.size()-1).time)
{
maxTime = data.get(data.size()-1).time;
}
}
// Removing old data => ???
for (int listInd = 0; listInd < dataList.size(); listInd++)
{
println("removing");
ArrayList<AccelerationSample> data = dataList.get(listInd);
if (data.size() > 1)
{
for (int i = data.size()-1; i >= 0; i--)
{
if (data.get(i).time < maxTime - (long)plottedMs)
{
data.remove(i);
}
}
}
}
// Plotting the data
for (int listInd = 0; listInd < dataList.size(); listInd++)
{
println("plotting");
ArrayList<AccelerationSample> data = dataList.get(listInd);
if (data.size() > 1)
{
stroke((15*listInd) % 100, 100, 100);
long xStart = maxTime - (maxTime % 5000) + 5000;
for (int i = 1; i < data.size(); i++)
{
AccelerationSample acc0 = data.get(i-1);
AccelerationSample acc1 = data.get(i);
if (acc1.time - acc0.time < 1000)
{
line(width - ((xStart - acc0.time) / plottedMs * width),
(acc0.x * accMult) + (height * 0.125),
width - ((xStart - acc1.time) / plottedMs * width),
(acc1.x * accMult) + (height * 0.125));
line(width - ((xStart - acc0.time) / plottedMs * width),
(acc0.intx * accMult) + (height * 0.375),
width - ((xStart - acc1.time) / plottedMs * width),
(acc1.intx * accMult) + (height * 0.375));
line(width - ((xStart - acc0.time) / plottedMs * width),
(acc0.MAx * accMult) + (height * 0.625),
width - ((xStart - acc1.time) / plottedMs * width),
(acc1.MAx * accMult) + (height * 0.625));
/*line(width - ((xStart - acc0.time) / plottedMs * width),
(acc0.y * accMult) + (height * 0.375),
width - ((xStart - acc1.time) / plottedMs * width),
(acc1.y * accMult) + (height * 0.375));
line(width - ((xStart - acc0.time) / plottedMs * width),
(acc0.z * accMult) + (height * 0.625),
width - ((xStart - acc1.time) / plottedMs * width),
(acc1.z * accMult) + (height * 0.625));*/
float abs0 = (float)Math.sqrt((acc0.x * acc0.x) + (acc0.y * acc0.y) + (acc0.z * acc0.z));
float abs1 = (float)Math.sqrt((acc1.x * acc1.x) + (acc1.y * acc1.y) + (acc1.z * acc1.z));
line(width - ((xStart - acc0.time) / plottedMs * width),
((-abs0 + 10.0) * accMult) + (height * 0.875),
width - ((xStart - acc1.time) / plottedMs * width),
((-abs1 + 10.0) * accMult) + (height * 0.875));
}
}
}
}
myLock.unlock();
}
/*
RECEIVING MESSAGES
*/
void initializeReceiving()
{
println("initializeReceiving");
multicastOsc = new OscP5(this, "239.98.98.1", 10333, OscP5.MULTICAST);
}
/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage message)
{
println("oscEvent");
if (message.checkAddrPattern("/fsensync/acc") == true)
{
println("message right");
int appId = message.get(0).intValue();
String tags = message.get(1).stringValue();
int packetNumber = message.get(2).intValue();
int timeStamp = message.get(3).intValue();
float x = message.get(4).floatValue();
float y = message.get(5).floatValue();
float z = message.get(6).floatValue();
myLock.lock();
println("message right, locked");
boolean found = false;
for (int listInd = 0; listInd < dataList.size(); listInd++)
{
println("message received, looping");
if (dataId.get(listInd) == appId)
{
print("jestem tu");
found = true;
float MAx = 0.7*x + lastInput.get(listInd).MAx * 0.3;
float intx = lastInput.get(listInd).intx;
print(MAx, ",", intx);
AccelerationSample sample = new AccelerationSample(x, y, z, MAx, intx, appId, timeStamp);
ArrayList<AccelerationSample> data = dataList.get(listInd);
data.add(sample);
//lastInput.set(listInd, sample);
}
}
if (!found)
{
AccelerationSample sample = new AccelerationSample(x, y, z, x, x, appId, timeStamp);
ArrayList<AccelerationSample> data = new ArrayList<AccelerationSample>();
data.add(sample);
lastInput.add(sample);
dataId.add(appId);
dataList.add(data);
}
myLock.unlock();
return;
}
{
println("got other message: " + message.addrPattern());
return;
}
}