Comment by viky on September 3, 2009 at 8:12am 
Comment by Laurent on September 3, 2009 at 2:33pm 
energyg=9.8*gps_z+((airspeed)*(airspeed))/2;//pot + kin energy wo mass energygsum=(99*energygsum+energyg)/100;
if((ch[7] > 1750)&&((altitude-home_alt) < 350)&&((altitude-home_alt)*4>dist_home)){//hunt for thermals!
if(state_flag&(113)){//new gps altitude received
if((gps_z > gps_z_old+1)&&(energyg > energygsum)){//if both altitude and energy are increasing, then enter/continue turn
liftcounter=10;//if lift is lost, then circle 10 sec more
if(gps_lat >0){//northern or southern hemisphere dictates circling direction
turndir=TRIGHT;//turn right
} else {
turndir=TLEFT;
}
} else {
if(liftcounter>0){
liftcounter-=1;
if(gps_lat >0){
turndir=TFRIGHT;//we are out of lift; turn right faster
} else {
turndir=TFLEFT;
}
} else {
turndir=dir_set;
}
}
}
} else {
liftcounter=0;
turndir=dir_set;
}
void calc_altitude(void){//calculate altitude (in m) based on pressure
//
//mpx2125A output voltage formula is vout=vs*(0.009*pressure(kpa)-0.095)
//we are using 12-bit ADC, maximum ADC value is 2^12-1
//metric altitude=(1-(pressure/groundpressure)^0.190263)*44308
//input is altinp which contains pressure sensor ADC value
//output is in variable altitude.
//ground pressure is set to 101325 or to maximum measured pressure
double p;
unsigned int d1;
extern unsigned int state_flag;
extern int altinp, altitude;//, gps_z;
extern double ground_pressure;
extern unsigned int d;
#ifdef __DEBUG
altinp=0x0cfe;
#endif
d1=TMR1;//this code is used for timing below code segment
p=1000000.0/9.0/4096.0*altinp+95000.0/9.0;
if((ground_pressure
15)))ground_pressure=p; //ground pressure update ok until gps fix obtained
//altitude=gps_z;//lets skip barometric stuff and use gps
altitude=(int)(44308.0*(1-pow(p/ground_pressure, .190263)));
d=TMR1-d1;//this code is used for timing above code segment
state_flag &= ~(111); //bclr _state_flag,#11
asm("nop");
return;
}
Season Two of the Trust Time Trial (T3) Contest has now begun. The third round was a reliablilty/aerial photography round for both planes and copters, which is now closed. Stay tuned for the next round, beginning soon.61 members
57 members
95 members
108 members
617 members
© 2012 Created by Chris Anderson.

You need to be a member of DIY Drones to add comments!
Join DIY Drones