Question

I know how to get the accel data but was wondering if anyone knows of any code samples that would determine whether the ios device is stable (swaying or shaking)

Was it helpful?

Solution

Store the last 30 samples of the accelerometer, get per-component averages (x, y, z) and standard deviation for each. Define how little deviation is "stable".

Obj-C: Calculate the standard deviation of an NSArray of NSNumber objects?

That will do. Make 3 arrays, each will have 30(or more or less depening on the time frame you want to compare) nsnumbers. You will get 3 standard deviations. The smaller those numbers are, the less the device is moving. Check that the 3 of them are smaller than any arbitrary amount you want, like 0.1.s

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top