Hello everyone and thank you in advance for your help!!
I have data collected from a sensor attached on Arduino which have been saved on an SD card as a txt file. Now i’m trying to visualize those values into Processing parsing the text and turning them into floats from Strings creating an array of 6 values seperated by commas for every line of my txt. I am creating an Object (class Body) for every line and I’m adding the location to the acceleration x and y which I have on my txt file. In order to create the path that the person has walked while wearing the accelerometer sensor, I am adding acceleration to location and then trying to find the direction between the locations that change with each loop, since acceleration values change, so I am using the difference between the location vector which has added acceleration to itself and acceleration(Vec2D dif=loc.addSelf(a).sub(a)
When i am creating a point using the x and y of location it’s fine but I’m not sure if i have used the right way to join with lines each new position with the previous one. the code is this (i haven’t yet used the other variables temp, myo and vibr for my vizualization only accx and accy) Please take a look if you want :
import toxi.geom.*;
Body body;
String[] data;
//PeasyCam cam;
int index=0;
void setup()
{
frameRate(3);
size(1200, 1200);
smooth();
data = loadStrings("katerina an thessaloniki paralia 16.30 2_6_2018.TXT");
body= new Body (0, 0, 0.1, -0.01, 0, -0.001);
}
void draw()
{
if (index<data.length)
{
float[] values = float(splitTokens(data[index], ",:/"));
body.update(values[0], values[1], values[2], values[3], values[4], values[5]);
body.display();
}
index++;
}
class Body
{
Vec2D loc, c, a;
Vec2D velocity;
Vec2D acceleration;
Vec2D nrm, scl;
Vec2D pos1, pos2, locNew, dif, nrm1, nrm2, scl1, scl2;
int tot=200;
float step=50;
float temp;
float myo;
float vibr;
float accx;
float accy;
float accz;
float mag;
Body (float temp, float myo, float vibr, float accx, float accy, float accz)
{
this.temp=temp;
this.myo=myo;
this.vibr=vibr;
this.accx = accx;
this.accy = accy;
this.accz= accz;
loc=new Vec2D(50, 50);
}
void update(float temp, float myo, float vibr, float accx, float accy, float accz)
{
this.temp=temp;
this.myo=myo;
this.vibr=vibr;
this.accx = accx;
this.accy = accy;
this.accz= accz;
acceleration= new Vec2D (0, 0);
a=acceleration.addSelf(accx, accy);
mag= acceleration.magnitude();
loc.addSelf(a);
locNew=loc.copy();
dif= loc.addSelf(a).sub(a);
println(a,loc,loc.addSelf(a),dif);
}
void display()
{
strokeWeight(3);
stroke(255);
strokeWeight(5);
point(loc.addSelf(a).x, loc.addSelf(a).y);
stroke(255, 0, 0);
strokeWeight(2);
line(dif.x, dif.y,loc.x, loc.y);
}
}
the .txt file which has to be in the data folder of the script is:
30.00,0.07,0.81,0.351,0.602,0.493
30.00,0.13,0.87,0.429,0.896,0.199
30.00,0.41,1.44,0.896,1.999,0.627
30.00,2.87,0.90,0.418,0.906,0.202
30.00,2.14,1.45,0.950,1.869,0.729
30.00,0.38,1.70,0.063,1.438,-0.006
30.00,1.24,1.16,0.549,1.215,0.079
30.00,0.64,1.10,0.572,1.288,0.500
30.00,1.06,0.98,0.639,1.663,1.279
30.00,0.92,0.97,0.750,1.681,0.938
30.00,0.42,0.70,0.665,1.717,0.959
30.00,0.94,1.15,0.409,1.017,0.119
30.00,0.43,1.80,-0.062,0.685,0.195
30.00,0.54,1.38,0.379,1.062,0.238
30.00,0.89,1.40,0.430,0.864,0.086
30.00,0.66,1.72,0.616,1.840,-0.314
30.00,1.15,0.63,1.201,1.683,0.047
30.00,0.65,1.35,0.326,0.951,0.001
30.00,2.16,0.86,0.452,0.921,0.160
30.00,1.36,0.97,0.102,1.555,0.283
31.00,2.49,1.45,0.378,1.932,-0.100
31.00,1.26,1.95,0.741,-0.109,0.036
31.00,0.29,1.82,1.058,1.572,0.623
31.00,3.64,1.13,0.561,1.045,0.053
31.00,0.53,0.93,0.488,0.881,0.167
31.00,0.96,0.91,0.479,0.885,0.183
31.00,0.12,1.26,0.468,0.882,0.160
31.00,3.03,1.63,0.457,0.890,0.148
31.00,1.02,1.41,0.451,0.896,0.156
31.00,0.57,1.14,0.458,0.893,0.137
31.00,0.60,1.12,0.475,0.875,0.140
31.00,0.53,1.07,0.453,0.893,0.155
31.00,0.23,1.02,0.439,0.906,0.125
31.00,0.46,1.42,0.509,1.024,0.343
31.00,1.30,1.06,0.479,1.062,0.310
31.00,0.85,0.96,0.535,1.005,0.126
31.00,0.70,0.95,0.437,0.887,0.049
31.00,0.69,1.69,0.488,0.890,0.116
31.00,0.38,0.92,-0.463,1.503,-0.063
30.00,1.44,0.81,-0.328,1.334,-0.233
30.00,0.97,3.23,0.462,1.795,0.332
30.00,0.16,1.09,0.374,0.655,-0.561
30.00,0.48,1.49,0.658,1.074,0.285
30.00,1.08,1.12,0.510,1.045,0.190
30.00,0.47,1.02,0.565,0.887,-0.011
31.00,1.29,0.76,1.275,0.896,-1.261
31.00,0.30,1.85,0.479,1.755,0.263
31.00,1.19,0.97,0.239,0.327,-0.025
31.00,0.22,1.49,0.468,0.824,-0.544
31.00,1.37,1.32,1.363,1.560,-0.086
31.00,1.39,1.72,0.584,1.085,0.232
31.00,1.31,0.73,0.257,1.026,-0.044
31.00,0.10,0.89,0.397,0.915,0.144
31.00,1.00,0.97,0.421,0.907,0.181
31.00,0.67,0.73,-0.097,1.033,0.075
31.00,1.98,1.87,0.051,0.775,0.632