Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accelerometer calibration

I'm using the accelerometer to move something around in X/Y on the screen.

This is easy if the phone starts flat on the table.

I've come up with something in an attempt to be able to start at any given position, and work from there. But it doesn't seem to work naturally.

How do I calibrate things so I can get the difference in orientation from the starting point?

cursorX -= accelerometerCalibrationY - getAccelerometerY();
cursorY += accelerometerCalibrationX - getAccelerometerX();

This works fine for flat on the table, and SOME starting positions. The variables are just getAccelerometerXY at the start.

like image 985
Richard Taylor Avatar asked Mar 02 '11 16:03

Richard Taylor


2 Answers

You need to do some math. Use getRotationMatrix to determine current phone orientation Matrix (M). Using M, you can calc vector g (Gravity) in device local coordinate system. Then get accel (Accel) from sensor. Calc Ans = Accel-Gravity vector. Ans' x/y components is what you need. Filter it to get better results.

Here is another easy way. Get Accel vector. Filter it with high-pass filter to remove DC component and low-pass to remove unnecessary noise (you will spent some time looking for appropriate filter params). Filtered x/y components is what you need.

like image 169
Leonidos Avatar answered Oct 28 '22 11:10

Leonidos


Accelerometer delivers you an vector - so just compute some reasonable average on start of your activity and use it as staring point. Converting difference to coordinate steering values is straightforward.

like image 37
Konstantin Pribluda Avatar answered Oct 28 '22 09:10

Konstantin Pribluda