I have been trying to get yaw values from gyro MPU6050 for my application. The application is basically to control a robot's movement with respect gyro readings.
Recently I started facing some issues relating calibration of the gyro. In my code I am mapping all the values of the whole range of yaw (-180 to 180) to pwm range (0 to 200). So ideally the sensor should get calibrated every time at value 100.
The situation I am facing is that it gets calibrated at 100 just 3 times out of 10. What may be the possible issue?
I am attaching the code for reference.