Hello, I find a small problem in EKF2/3 in function NavEKF3_core::alignMagStateDeclination(), this function calls function NavEKF3_core::FuseDeclination(float declErr), the question is that FuseDeclination() here seems no useful. Because that in alignMagStateDeclination(), stateStruct.earth_magfield has already been set to:
stateStruct.earth_magfield.x = magLengthNE cosf(magDecAng);
stateStruct.earth_magfield.y = magLengthNE sinf(magDecAng);
So in FuseDeclination(), this peice os code eques to zero:
// Calculate the innovation
float innovation = atan2f(magE , magN) - magDecAng;
Why innovation is zero? Because here:
float magN = stateStruct.earth_magfield.x; = magLengthNE cosf(magDecAng);
float magE = stateStruct.earth_magfield.y; = magLengthNE sinf(magDecAng);
So atan2f(magE , magN) = magDecAng! Because both magDecAng in the two function are set by
float magDecAng = use_compass() ? _ahrs->get_compass()->get_declination() : 0;
and called very closely, so the two magDecAng are supposed to the same. So the innovation is zero, so FuseDeclination() called here seems of no ues, the only use I think is to reduce the P (error between estimated value and true value).