Sleek UIAccelerometer

How to smooth the iPhone / iPod Touch Accelerometer?

+4
source share
1 answer

You can smooth the data of the accelerometer by applying a filter to the incoming data before using it. The first thing you want to do is set up a constant for your filter.

#define kFilteringFactor 0.1 

In your didAccelerate method you need to add the following filtering code

 - (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration { sx = acceleration.x * kFilteringFactor + sx * (1.0 - kFilteringFactor); sy = acceleration.y * kFilteringFactor + sy * (1.0 - kFilteringFactor); sz = acceleration.z * kFilteringFactor + sz * (1.0 - kFilteringFactor); } 

The code above should smooth the data for you. The values ​​sx, sy, and sz are of type UIAccelerationValue.

There is a lot of relevant information in the Apple documentation that may be useful in this regard.

+9
source

All Articles