MPU6050 drift

alaa72:
dear Idahowalker
yes, actually! or it isn't?

When you set the MPU on the table top what does accel Z axis read? Why?
Using all those floats, what is the MCU you are using? Using an Uno and lots of floatties, slow is to be expected.
Complementary filter, taken from my python code.
lastX = K * ( lastX + ( Gx * tDiff ) ) + ( K1 * AxRot )
lastY = K * lastY + ( Gy * tDiff ) ) + ( K1 * ayRot ) )

K = 0.93
K1 = 1 - K

I found K < .70 does a terrible job. You may find lowering the K to the lower 90's may give better results. Learn to use the graphing display in monitor to observe the oscillations and tune K to get the range of oscillations you want

I compute tDiff using microSeconds instead of milliSeconds, otherwise I get 0's for time. 0's in a multiplication result in 0's. Using a Complementary or a Kalman (GitHub - denyssene/SimpleKalmanFilter: A basic implementation of Kalman Filter for single variable models. filter requires an accurate time count.

For me calibration is 100 averaged readings with .1S between each reading, then doing the calibration math, storing the calibration data. I apply calibration data for accel during Ax, Ay, Az calculations:

preScaled = AxRaw
AxRaw = AxRaw/ACCEL_SCALE
Ax = (prescaled * AX_OFFSET )

I do not apply gyro offsets before calculating the scaled reading. Apply gyro offsets one step before the filter: Gx += ( GX_OFFSET - X_Rotation_Offest )