When an electronic compass, such as a hmc5883l or MPU9250, AK8963 the azimuth, it is often found that the angular jitter of the measurement is severe. Even though it does not move, the angle changes in a small range. At this time, we need to use the gyroscope to compensate the azimuth angle and fusion, and obtain the stable data. This paper only discusses the azimuth of 2D space, which is the z-axis data of the electronic Compass X, y two-axis data fusion gyroscope.
1. Electronic compass and gyroscope measurement physical significance
Electronic compass: 0-360 degrees of azimuth, also known as yaw. Angle is arctan2 (y,x)
Gyroscope: angular velocity around an axis, where we only consider the z-axis, which is equivalent to the speed at which the azimuth changes.
2. Fusion Algorithm Formula
At some point in time TX , the electronic compass value is YawcompassTX, the gyroscope value is YawgyroTX, the fused data is YawfuzeTX
At the next point in time tx+1, the gyroscope calculates an angle change of Delta_yaw = Yawgyrotx+1* delta_t, where delta_t = tx+1 - t X
Yawfuzetx+1 = K * (yawfuzeTx+ delta_yaw) + (1-k) * Yawcompasstx+1
The value of k is generally [0.9, 1], the physical meaning is the degree of trust of the gyroscope.
At T0 Point in time, YawFuzeT0 = YawCompassT0
Data fusion of gyroscope and electronic compass using compensation algorithm to calculate azimuth