www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Yerst on July 18, 2013, 09:35:08 pm

Title: Linear Accelerometer has inaccurate values
Post by: Yerst on July 18, 2013, 09:35:08 pm
Hey!
I have a object infront of my camera that is controlled by the linear accelerometer.
Unfortunaly, the object trembles always, even if i hold my phone completely still and this really hurts my eyes.
Does anyone know how to remove this trembling?
I tried rounding the values given by the sensor, but then it trembles when switching between for example 0.09 and 0.1...
Title: Re: Linear Accelerometer has inaccurate values
Post by: EgonOlsen on July 18, 2013, 11:38:25 pm
Maybe use some damping or a threshold?
Title: Re: Linear Accelerometer has inaccurate values
Post by: Yerst on July 18, 2013, 11:44:39 pm
That's what i need, but i don't know how to implement it.
It is maybe just one or two lines to do it, but i don't get it to work.
Maybe i just think to complicated.
Title: Re: Linear Accelerometer has inaccurate values
Post by: ned flanders on July 19, 2013, 08:34:21 pm
Along similar lines, sounds like you might benefit from that "sensor fusion" stuff all the cool kids are talking about.

I've yet to find any APIs for it yet, but I stumbled across some code somewhere that looks promising.

Anyway, here's a link in case you haven't come across this yet:

http://www.youtube.com/watch?v=C7JQ7Rpwn2k
Title: Re: Linear Accelerometer has inaccurate values
Post by: EgonOlsen on July 19, 2013, 09:17:59 pm
That's what i need, but i don't know how to implement it.
It is maybe just one or two lines to do it, but i don't get it to work.
I would try to define some threshold (0.xy...) and ignore changes below this value. Once a higher value occurs, i would start to move the model and stop again once i fall below the threshold for some time. I've no idea if this is applicable to this kind of sensor though.
Title: Re: Linear Accelerometer has inaccurate values
Post by: Yerst on July 19, 2013, 11:12:14 pm
I tried it, but then the problem is when my object moves, it trembles while moving...
Title: Re: Linear Accelerometer has inaccurate values
Post by: ned flanders on July 20, 2013, 12:32:54 am
Have you tried a running average, maybe over a sliding window?
Title: Re: Linear Accelerometer has inaccurate values
Post by: Yerst on July 20, 2013, 05:18:16 pm
Sorry, but i have no idea what you mean^^
Title: Re: Linear Accelerometer has inaccurate values
Post by: ned flanders on July 20, 2013, 06:04:23 pm
Store successive values in a circular (ring) buffer.

This is like an array of limited size, say 10 entries, into which you store values as you receive them.  Once the buffer fills up (reaches 10 entries), as you add each new entry, the oldest entry is removed.  You can easily implement this with a standard array, and an index which resets to zero every time it reaches the end of the array.

Then, rather than use the jittery output values directly, you push them into the circular buffer, and use the buffer's average value.  I called this a running average, but if the average is over a sliding window of data (as with the ring buffer), then it's a moving average....a very simple way to smooth out jittery data a bit.

https://en.wikipedia.org/wiki/Moving_average
Title: Re: Linear Accelerometer has inaccurate values
Post by: Yerst on July 21, 2013, 01:05:22 pm
Thanks, that worked great!
Even much better than expected!  ;D