2014/07/02

Get distance with accelerometer of iPhone 5s

I had been interested to get distance with the accelerometer of iPhone.
It is possible to get distance from acceleration and time. So I tried with iPhone 5s which has M7 coprocessor.

(1) About code
I got acceleration with CoreMotion framework. You can get accelerations from CMDeviceMotion object which can be get from CMMotionManager object.
The app gets only acceleration of y direction by :
motion.userAcceleration.y;

And I moved my iPhone 5s from this position:

device start position

to this :

device end position

The actual displacement is 35cm.

You can also get precise time with :
motion.timestamp


(2) Results
The distance should be 35cm and the result is here :

test result 1

↑34.8cm !
x axis is time, gray line means acceleration and green line shows velocity.
The blue vertical two lines shows start time and end time, they are decided from the acceleration by threshold.

Tell you the truth, the result above is the one I selected because the distance was almost right. There were many other results which did not look good like these :

test result 2

test result 3

The velocity (green line) is NOT zero when the device stops.

test result 4

↑The result got perfectly strange when you move the device slowly.

Anyway you can not use iPhone’s accelerometer to get distance.
I hoped iPhone 5s with A7,M7 might be able to trace the distance… but it was wrong.


By the way, many people try the same thing but it looks difficult according to this page :
iphone - Need to find Distance using Gyro+Accelerometer - Stack Overflow
Develop | Comments(0) | Trackback(0)
Comment

管理者のみに表示