dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
atmospheric_math.c
Go to the documentation of this file.
1 
11 /*
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20  * for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, see <http://www.gnu.org/licenses/>
24  */
25 
26 #include "math.h"
27 
28 #include "atmospheric_math.h" /* API declarations */
29 #include "physical_constants.h"
30 
39 {
40  float pressure = air_pressure_from_altitude(altitude, air);
41  float rho = pressure*air->M / (air->univ_gas_constant*(air->air_temperature_at_surface - air->temperature_lapse_rate*altitude));
42 
43  return rho;
44 }
45 
54 {
55  float pressure = air->sea_level_press* powf(1 - air->temperature_lapse_rate*altitude / air->air_temperature_at_surface, GRAVITY*air->M / (air->univ_gas_constant*air->temperature_lapse_rate));
56 
57  return pressure;
58 }
59 
68 float cas2tas(float CAS, float altitude, struct AirParameters *air)
69 {
70  float rho=air_density_from_altitude(altitude, air);
71  float TAS = CAS * sqrtf(air->air_density_at_surface/rho);
72 
73  return TAS;
74 }
75 
84 float tas2cas(float TAS, float altitude, struct AirParameters *air)
85 {
86  float rho=air_density_from_altitude(altitude, air);
87  float CAS = TAS / sqrtf(air->air_density_at_surface/rho);
88 
89  return CAS;
90 }
91 
92 
98 {
99  struct AirParameters air;
100 
101  air.sea_level_press = STANDARD_AIR_SEA_LEVEL_PRESSURE;
102  air.air_density_at_surface = STANDARD_AIR_DENSITY;
103  air.air_temperature_at_surface = STANDARD_AIR_TEMPERATURE;
104  air.temperature_lapse_rate = STANDARD_AIR_LAPSE_RATE;
105  air.univ_gas_constant = UNIVERSAL_GAS_CONSTANT;
106  air.dry_air_constant = DRY_AIR_CONSTANT;
107  air.relative_humidity = STANDARD_AIR_RELATIVE_HUMIDITY;
108  air.M = STANDARD_AIR_MOLS2KG;
109 
110  return air;
111 }
float cas2tas(float CAS, float altitude, struct AirParameters *air)
cas2tas calculate TAS from CAS and altitude. http://en.wikipedia.org/wiki/Airspeed ...
struct AirParameters initialize_air_structure()
initialize_air_structure Initializes the structure with standard-temperature-pressure values ...
float air_density_at_surface
float air_temperature_at_surface
float air_pressure_from_altitude(float altitude, struct AirParameters *air)
air_pressure_from_altitude Get air pressure from altitude and atmospheric conditions.
uint16_t altitude
Definition: msp_messages.h:100
float temperature_lapse_rate
float tas2cas(float TAS, float altitude, struct AirParameters *air)
tas2cas calculate CAS from TAS and altitude. http://en.wikipedia.org/wiki/Airspeed ...
float air_density_from_altitude(float altitude, struct AirParameters *air)
air_density_from_altitude calculate air density from altitude. http://en.wikipedia.org/wiki/Density_of_air