UKHAS Wiki

UK High Altitude Society

User Tools

Site Tools


code:sqrt_density_lookup_table_calculator_for_fast_drag_coefficient_calculations

Source - this is for a 256 byte lookup table up to 25.5Km

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
 
float air_density(float alt)					//model from NASA
{    
     float temp,pres;
     if (alt < 11000.0)
     {    // below 11Km - Troposphere
          temp = 15.04 - (0.00649 * alt);
          pres = 101.29 * pow((temp + 273.1) / 288.08, 5.256); 
     }
     else
     {
         if (alt < 25000.0)
         { // between 11Km and 25Km - lower Stratosphere
              temp = -56.46;
              pres = 22.65 * exp(1.73 - ( 0.000157 * alt));
         }
         else
         { // above 25Km - upper Stratosphere
               temp = -131.21 + (0.00299 * alt);
               pres = 2.488 * pow((temp + 273.1) / 216.6, -11.388);
         }
     }
     return(pres / (0.2869 * (temp + 273.1)));
}
 
int main()
{
	int n;
	float a;
	FILE * output;
	output=fopen("sqrt_density.h","w");
	fprintf(output,"u08 sqrt_density[256] PROGMEM={");
	a=air_density(-50.0);	
	for(n=0;n<256;n++)
	{
		fprintf(output,"%d,",(int)(255.0*sqrt(air_density((n*100)-50.0)/a)));
	}
	fprintf(output,"};");
	fclose(output);
}

Output

u08 sqrt_density[256] PROGMEM={255,253,252,251,250,248,247,246,245,244,242,241,240,239,238,237,235,234,233,232,231,230,228,227,226,225,224,223,222,220,219,218,217,216,215,214,213,211,210,209,208,207,206,205,204,203,202,201,199,198,197,196,195,194,193,192,191,190,189,188,187,186,185,184,183,182,181,180,179,178,177,176,175,174,173,172,171,170,169,168,167,166,165,164,163,162,161,160,159,158,157,156,155,154,153,152,151,151,150,149,148,147,146,145,144,143,142,141,141,140,139,138,137,136,135,134,132,131,130,129,128,127,126,125,124,123,122,121,121,120,119,118,117,116,115,114,113,112,111,111,110,109,108,107,106,105,105,104,103,102,101,101,100,99,98,97,97,96,95,94,94,93,92,91,91,90,89,89,88,87,87,86,85,85,84,83,83,82,81,81,80,79,79,78,77,77,76,76,75,74,74,73,73,72,72,71,70,70,69,69,68,68,67,67,66,66,65,65,64,64,63,63,62,62,61,61,60,60,59,59,58,58,57,57,56,56,56,55,55,54,54,53,53,53,52,52,51,51,51,50,50,49,49,49,48,48,47,47,47,46,46,45,45,44,44,44,};

Test with Badger data

The lookup table was tested by calculating the coefficient used for layer weighting from the transit time over 100m vertical distances during the descent, then dividing by the appropriate lookup table value. This should give a constant, and any errors will be proportional to the resulting error in layer weighting for landing spot prediction or optimal glider waypoint calculation.

As can be seen all the errors are within +- 15%, which is sufficient for most purposes. There is plenty of room for improvement be using GFS data or carrying a MEMS barometer onboard.

code/sqrt_density_lookup_table_calculator_for_fast_drag_coefficient_calculations.txt · Last modified: 2009/01/19 04:20 by laurenceb

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki