Using accelerometer, gyroscope and compass to calculate device’s movement in 3D world

The accelerometer gives you three directions (x, y, z). They are acceleration measurements which is harder to know what the position of the device is. But, remember acceleration is related to position through integration:

a(t) = a[x]
v(t) = a[x]t + c
x(t) = a[x]t ^ 2 + ct + d

Problem is you can’t know c or d because as you take the derivative the constants drop out. So there is some amount you can’t get right with c and d missing. You can attempt to compensate by remembering the values you used last for those. So after grabbing 3 samples you can start to calculate position from that.

There is a significant amount of information about how to interpret the data from the sensors. Like figuring out where gravity is for orientation, and subtracting out gravity to get linear acceleration.

http://developer.android.com/reference/android/hardware/SensorEvent.html

Here is a way to come up with position using an accelerometer along with an algorithm for finding position in detail:

https://www.nxp.com/docs/en/application-note/AN3397.pdf

Leave a Comment