How can I smooth the accelerometer of the iPhone/iPod Touch?
You can smooth the accelerometer data by applying a filter to the incoming data before using it. The first thing you'll want to do it set up a constant for your filter.
#define kFilteringFactor 0.1
In your didAccelerate method, you'll 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 sx, sy and sz values are of type UIAccelerationValue.
There's lots of related information in Apple's documentation that you may find similarly useful in respect to this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With