Author Topic: Linear Accelerometer has inaccurate values  (Read 1124 times)

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Linear Accelerometer has inaccurate values
« 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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Linear Accelerometer has inaccurate values
« Reply #1 on: July 18, 2013, 11:38:25 pm »
Maybe use some damping or a threshold?

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Re: Linear Accelerometer has inaccurate values
« Reply #2 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.

Offline ned flanders

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Linear Accelerometer has inaccurate values
« Reply #3 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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Linear Accelerometer has inaccurate values
« Reply #4 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.

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Re: Linear Accelerometer has inaccurate values
« Reply #5 on: July 19, 2013, 11:12:14 pm »
I tried it, but then the problem is when my object moves, it trembles while moving...

Offline ned flanders

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Linear Accelerometer has inaccurate values
« Reply #6 on: July 20, 2013, 12:32:54 am »
Have you tried a running average, maybe over a sliding window?

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Re: Linear Accelerometer has inaccurate values
« Reply #7 on: July 20, 2013, 05:18:16 pm »
Sorry, but i have no idea what you mean^^

Offline ned flanders

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Linear Accelerometer has inaccurate values
« Reply #8 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

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Re: Linear Accelerometer has inaccurate values
« Reply #9 on: July 21, 2013, 01:05:22 pm »
Thanks, that worked great!
Even much better than expected!  ;D