8

I am working on an application to draw in the air with an android phone.

As my phone is moving, thanks to the acceletometer, i retrieve the acceleration on each axis ax, ay, az. What I am interested in is: x,y,z.

From what I read in forums and in some tutorials, integrating the accelaration twice gives huge errors.

So what is the best solution for me to get information on the deplacement of the phone?

Thanks for your help.

user1068400
  • 115
  • 1
  • 6
  • 1
    I know nothing about android programming but AFAIK integrating twice is the only mathematical possible way to figure out the phone's position. – Juan Nov 27 '11 at 22:31
  • What if you just define the starting position as (0, 0, 0) and integrate once to get the velocity, and then add that velocity to vector to the previous position at each accelerometer update to determine a new position? – Mitch Lindgren Nov 27 '11 at 22:40
  • hi! that's what I am trying to do but the accelerometers values are changing so fast that my drawing becomes a real mess! – user1068400 Nov 28 '11 at 22:56
  • how are you even getting halfway reasonable values? due to having to use a high-pass filter to remove the gravity vector my integration results in faster than light speed in a couple minutes when my phone isn't even moving! – Michael Oct 05 '14 at 00:17

2 Answers2

1

Not exactly what you are looking for:

Store orientation to an array - and compare

Tracking orientation works well. Perhaps you can do something similar with the accelerometer data (without any integration).

As you mentioned in your post, integrating the acceleration twice does not work.

Update:

If accuracy is not important at all then the double integral might work for a few seconds but expect very poor results.

However, the gyro mouse is a better choice in my opinion. See between 37:00-38:25 in

Sensor Fusion on Android Devices: A Revolution in Motion Processing.

Community
  • 1
  • 1
Ali
  • 56,466
  • 29
  • 168
  • 265
  • Do you think i could use a gyroscope to record the phone movement? With pitch, roll and yaw? – user1068400 Nov 28 '11 at 22:55
  • **It is impossible to track the phone's movement accurately with the current sensors.** See subsection 6.2.3 Propagation of Errors in [here](http://www.cl.cam.ac.uk//techreports/UCAM-CL-TR-696.pdf). It does not matter whether you the track movement or the orientation, you will need the gyros anyhow, even if it is nicely hidden in the SensorManager. – Ali Nov 29 '11 at 08:04
  • I am student assistant and my semester work is to do this project!!! I am quite stressed now because I am locked on this problem for weeks! Even if the tracking is not accurate, I just (at first) want to make an app which can draw some doodles! Nothing very precise. Do you really think it is impossible? There is an Iphone app with does it! – user1068400 Nov 29 '11 at 08:32
0

Take a look at:

http://www.youtube.com/watch?v=C7JQ7Rpwn2k

http://www.freescale.com/files/sensors/doc/app_note/AN3397.pdf

Also I'm working on a similar project and I don't think you need to double integrate accelertaion and calculate distance moved. Instead use acceleration itself for moving.

But if you insist to use distance, by sampling acceleration(a0,a1,...,an) in short time intervals(t0,t1,...,tn) and suppose your acceleration in this intervals is average of boundaries, you can have something like that;

 Vs=(t1-t0)*(a1+a0)/2 + (t2-t1)*(a2+a1)/2 + ... + (t[n]-t[n-1])(a[n]+a[n-1])/2

 T=t[n]-t[0]

 Xs=Vs*T

It is a little bit different from double intergating. Good luck.

kubudi
  • 658
  • 1
  • 9
  • 20
  • Thanks a lot for your advices. What do you use for your app? I was talking about the distance because I thought it could be the only way to retrieve the user drawing. What do you mean by "use acceleration itself for moving"? How do you do that? – user1068400 Nov 28 '11 at 08:05
  • At first I thought same too. But then I realized this: For example if your acceleration is 1G(10m/s^2) left, you should move your pen 10pixels left untik the accelleration changes. If it is 2G move 20 pixels. I hope you get it? I'll inform you about my project progress. Good luck. I'm working on using device as air pc mouse. – kubudi Nov 28 '11 at 10:34
  • But how do you map the changes to the pixels? For instance, my phone is moving with the acceleration 1G left, how do I draw a line measuring 10 pixels in this direction in my screen? – user1068400 Nov 28 '11 at 13:11
  • @kubudi What you write is the double integral. You cannot get distance from acceleration without the double integral. – Ali Nov 28 '11 at 14:55
  • Once you calculate how many pixels will you draw, rest of is simple drawing. Take a look at: http://developer.android.com/guide/topics/graphics/index.html @Ali it is not double integration, it is sum. As I said It is a little bit different. When you do this, you will be ignore changes at this time intervals. Only samples matters. I hope you get difference. – kubudi Nov 28 '11 at 19:07
  • I use "onSensorChanged" function where i store (ax,ay) each time the sensor changes. However, I get very strange drawings because "ax" can go from 3.65 to -1 very quickly! So if I point the phone toward the right, I will get a line (because the acceleration goes from 1 to 4 for instance) but then when I stop drawing the acceleration comes back to 0 and another line is drawn! You said "move your pen left 10pixels until acceleration changes" but the acceleration changes all the time! Something is drawn on the phone but it is not accurate, I cannot choose what I want to draw! – user1068400 Nov 28 '11 at 20:19
  • When you move your device you give it an acceleration and when it stops an opposite acceleration occurs (take a closer look at my second link.Figure 6.) Can't you just ignore the opposite acceleration until it's stabilized? When I say "until acceleration changes" I guess you thougth it will last for a sec. But it's in nano sec sensivitiy! – kubudi Nov 28 '11 at 22:25