MPU6050 Gyro value going back to initial value irrespective of Angle

I do only 300 iterations to get the average drift rate of the X, Y, and Z values. I found that less than 50 iterations does not yield good results and more than 300 iterations does not produce better results.

I calibrate for the following offsets using average values:

GX, GY, Gz, Az, Ay, AX, X_Rotation, and Y_Rotation.

I have the MPU-6050 on a X-Y platform and I set the platform, using an X and a Y servo to being as level as possible, with no loud music blaring, or doors slamming, and other low frequency vibrations. The X Y platform is ran by the Arduino which receives MPU-6050 torque info from a RPi3b. I use, on the Arduino Servo.h and the .writeMicroseconds() function to to torque the servos.

Using a level I found my X servo levels out at 1498 uSec and my Y servo levels out at 1502uSec.

I have a delay of 1 second between readings of the averaging routine. The delay is important for the drift formula.

I calculate GX_Drift, Gy_Drift, and GZ_drift that uses the averages and time to get drift rates.

Here is my code to calculate drift rate of the Gyros:

def fCal_Gyro_Drift():
    iCount = 0
    timeOld = 0.0
    timeNew  = 0.0
    timeDiff = 0.0
    fltGyro_x_int = 0.0
    fltGyro_y_int = 0.0
    fltGyro_z_int = 0.0
    fltGyro_x = 0.0
    fltGyro_y = 0.0
    fltGyro_z = 0.0
    fltGyro_AvgDriftRate_X = 0.0
    fltGyro_AvgDriftRate_Y = 0.0
    fltGyro_AvgDriftRate_Z = 0.0
        
    print ("calibrating gyro (min average error selection) - getting drift")
    print ("Start time " + str(datetime.datetime.now()))
    MPU_Init()
    while iCount < iCaliPoints:
        iCount = iCount + 1

        timeNew = millisTime()        
        timeDiff = timeNew - timeOld
        MPU_ReadRawData()
        timeOld = timeNew
        #apply offset 
        fltGyro_x = GxRaw + GX_OFFSET
        fltGyro_y = GyRaw + GY_OFFSET
        fltGyro_z = GzRaw + GZ_OFFSET

        fltGyro_x_int += (fltGyro_x / timeDiff)
        fltGyro_y_int += (fltGyro_y / timeDiff) 
        fltGyro_z_int += (fltGyro_z / timeDiff)
        print ("Pass number: " + str(iCount))
        sleep(iCaliSleepTime)
    fltGyro_AvgDriftRate_X = -(fltGyro_x_int / iCount)
    fltGyro_AvgDriftRate_Y = -(fltGyro_y_int / iCount)
    fltGyro_AvgDriftRate_Z = -(fltGyro_z_int / iCount)
    print ("Calibrating loops (rad/sec) %d  x:%f y:%f z:%f"
        %(iCount, fltGyro_AvgDriftRate_X, fltGyro_AvgDriftRate_Y, fltGyro_AvgDriftRate_Z))
    print ("End time " + str(datetime.datetime.now()))

    return;

fCal_Gyro_Drift() is dependent upon the delay time, iterations, and time of each pass for proper results.

Notice at the end of Cali and GyroDrift I reverse the signs of the results.

Here is how I apply the GyroCali and GryoDrift:

Gx = round(Gx +Gx_OFFSET + GX_DRIFT, iRound)

My round value is 8.

I have used .13 degrees is the lowest value I have sent to the servos, converted to a uSec torque value to keep the platform level. I found that down at .13 the platform will develop oscillations from time to time. I found .15 degrees and above works well to and at .17 degrees the platform does not develop any oscillations, so far.