Accelerometer Low Pass Filter Smoothing

2019-08-12 03:14发布

问题:

I am using the device accelerometer and try to smooth the Accelerometer Data CMAcceleration.

I am doing this with help of this code:

-(void)proccessAccelerometerData:(CMAcceleration)accelData {
    currentAccelX = (kUpdateInterval * accelData.x) + ((1.0 - kUpdateInterval) * currentAccelX);
    currentAccelY = (kUpdateInterval * accelData.y) + ((1.0 - kUpdateInterval) * currentAccelY);
}

Which currentAccelX and currentAccelY is the last accelerometer x and y data.

Now, I have the smooth x and y values, What is my value of x or y to determine id the user move the device left/right/up/down?

Just to make things more clear, for example, let's say that I have 4 buttons, one for each direction left/right/up/down and I want to determine which direction the user user swipe the device? (not swipe gesture). Thanks in advance!

回答1:

Assuming you hold the device in portrait orientation, the x-Axis indicates the movement to the left and right (positive x is to the right and negative x to the left).
The y-Axis indicates the movement of the device up and down (positive y is upwards and negative y is downwards).
The z-Axis indicates the movement of the device forwards and backwards (positive z is towards the user and negative z is away from the user).
There is an info graphic by Apple: developer.apple.com