69,9 → 69,10 |
|
volatile s16vec_t MagVector; // is written by mk3mag or ncmag implementation |
volatile s16vec_t AccVector; // current acceleration vector of compass, not supported by any HW version |
volatile s16vec_t MagVectorHorizontal; // vector componenents in horizontal projection |
volatile s16 Compass_Heading; // is written by mk3mag or ncmag implementation |
volatile u8 Compass_CalState; // is written by mk3mag or ncmag implementation |
s16 Hx = 0, Hy = 0; |
|
s32 EarthMagneticField = 100; |
s32 EarthMagneticFieldFiltered = 100; |
s32 EarthMagneticInclination = 0; |
148,7 → 149,6 |
else // fc attitude is avialable and no compass calibration active |
{ |
// calculate attitude correction |
// a float implementation takes too long |
s16 tmp; |
s32 sinnick, cosnick, sinroll, cosroll; |
tmp = FromFlightCtrl.AngleNick/10; // in deg |
157,11 → 157,10 |
tmp = FromFlightCtrl.AngleRoll/10; // in deg |
sinroll = (s32)c_sin_8192(tmp); |
cosroll = (s32)c_cos_8192(tmp); |
// tbd. compensation signs and oriantation has to be fixed |
Hx = (s16)((MagVector.Y * cosnick + MagVector.Z * sinnick)/8192L); |
Hy = (s16)((MagVector.X * cosroll - MagVector.Z * sinroll)/8192L); |
MagVectorHorizontal.X = (s16)((MagVector.Y * cosnick + MagVector.Z * sinnick)/8192L); |
MagVectorHorizontal.Y = (s16)((MagVector.X * cosroll - MagVector.Z * sinroll)/8192L); |
// calculate heading |
tmp = (s16)(c_atan2_546(Hy, Hx)/546L); |
tmp = (s16)(c_atan2_546(MagVectorHorizontal.Y, MagVectorHorizontal.X)/546L); |
if (tmp > 0) tmp = 360 - tmp; |
else tmp = -tmp; |
Compass_Heading = tmp; |