Subversion Repositories NaviCtrl

Compare Revisions

Regard whitespace Rev 492 → Rev 493

/trunk/compass.c
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;
/trunk/compass.h
13,16 → 13,16
 
extern volatile s16vec_t MagVector; // current magnetic field vector
extern volatile s16vec_t AccVector; // current acceleration vector of compass, not supported by any HW version
extern volatile s16vec_t MagVectorHorizontal; // vector componenents in horizontal projection
extern volatile s16 Compass_Heading; // current heading direction
extern volatile u8 Compass_CalState; // current calibration state
extern s32 EarthMagneticField;
extern s32 EarthMagneticFieldFiltered;
extern s32 EarthMagneticInclination;
extern s32 EarthMagneticInclinationFiltered;
extern s32 EarthMagneticInclinationTheoretic;
extern s32 EarthMagneticFieldFiltered;
extern u8 ErrorDisturbedEarthMagnetField;
extern s16 EarthMagneticStrengthTheoretic;
extern s16 Hx, Hy;
 
#define COMPASS_NONE 0
#define COMPASS_MK3MAG 1
/trunk/mymath.c
1,5 → 1,6
#include "91x_lib.h"
#include "mymath.h"
#include <math.h>
 
// discrete mathematics
 
150,4 → 151,3
}
return(root >> 1);
}