#include #include "imu.h" #include "bar.h" #include "med2.h" #include "ori.h" #include "quat.h" static const float PI = 3.14159265359f; static const float TO_DEG = 180.0f/PI; static const float TO_RAD = PI/180.0f; static float FK_PR = 0.01f; static float FK_Y = 0.01f; static float MEGA_BAR; static float MEGA_BAR_MIN=0.00001f; static float MEGA_BAR_MAX=0.1f; static float MEGA_BAR_MUL = 100.0f; static float MEGA_BAR_POW = 2.0f; static float MEGA_BAR_CNT = 7.0f; ORI_Data DataORI; const int BAR_MedCount=50; long BAR_MedData[BAR_MedCount]; unsigned char BAR_MedIndex[BAR_MedCount]; MED2_Data BAR_Med = {BAR_MedCount, 0, BAR_MedIndex, BAR_MedData, 20}; static float MegaFilterAlt(const long Freq, const float Alt, float& Speed, float& Acc) { static float falt=0; falt=falt*(1.0f-MEGA_BAR)+(Alt)*MEGA_BAR; static float alt_speed=0, alt_acc=0; static int count=0; if(count>=MEGA_BAR_CNT) { static float last_b=0, last_s=0; alt_speed=(falt-last_b)*Freq/MEGA_BAR_CNT; alt_acc=(alt_speed-last_s); last_b=falt; last_s=alt_speed; count=0; } else count++; float coef_w, coef_s; coef_w=MEGA_BAR_MIN; float sub=fabsf(Alt-falt); coef_w*=powf(sub*MEGA_BAR_MUL, MEGA_BAR_POW); if(coef_w>MEGA_BAR_MAX) coef_w=MEGA_BAR_MAX; if(coef_w=MEGA_BAR_CNT) { static float last_b=0; alt_speed=(falt-last_b)*Freq/MEGA_BAR_CNT; last_b=falt; count=0; } else count++; Speed=MED2_Update(alt_speed*1000.0f, BAR_Med2)/1000.0f; return falt; }*/ //------------------------------------------------------------------------------ static float MEGA_ACC=0.01f; static const long MEGA_Count=60; // 600ms at 100Hz static float MEGA_Alt_Buff[MEGA_Count]; static float MEGA_Spd_Buff[MEGA_Count]; static long MEGA_Index=0; static float MegaFilterAcc(struct ORI_Data& Data) { float acc; acc=fabsf(Data.Bar.Acc)*100.0f; float filt = MEGA_ACC; if(acc>1) filt/=acc; acc=fabsf(Data.Iner.Z)*100.0f; if(acc>1) filt/=acc; const float g=9.80665f; static float i_speed=0; i_speed+=Data.Iner.Z*g/Data.Freq; MEGA_Alt_Buff[MEGA_Index++]=i_speed; if(MEGA_Index>=MEGA_Count) MEGA_Index=0; static float delay_speed; delay_speed=(delay_speed+MEGA_Alt_Buff[MEGA_Index])/2.0f; float shift=Data.Bar.Speed-delay_speed; for(int a=0; a