I am experimenting with the accelerometer on my sunspot. I am trying to calculate the velocity by measuring the values of the accelerometer from the axis X and Y but they kind of seem random to me.
What's the proper way to get the values and the orientation/direction of the movement and to calculate its velocity?
This is my code:
while (true) {
try {
offset=Math.sqrt(accel.getAccelX()*accel.getAccelX()+accel.getAccelY()*accel.getAccelY());
if(offset<0.1 && offset>-0.1)
offset=0;
v=(offset+ ((offset-anterior))/2)*0.2; //0.2 is 200millisecs
anterior=offset;
Utils.sleep(200);//5 reads per secound
}}...
UPDATE For example, I move the sunspot in a direction and the variable v(velocity) give me values from negative up to 7ms by random order (not sequencial). If the change the direction of the movement it doesn't give me negative values as I expected.
example:(if I move it to my right)
v =0.4771031167950723
v =0.4771031167950723
v =-0.15903437226502407
v =-0.15903437226502407
v =0.33841556285063856
v =0.33841556285063856
v =0.7397145777969039
Thanks in advance.