Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
pprz_isa.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Gautier Hattenberger
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
38 #ifndef PPRZ_ISA_H
39 #define PPRZ_ISA_H
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 #include "std.h"
46 #include <math.h>
47 
48 // Standard Atmosphere constants
50 #define PPRZ_ISA_SEA_LEVEL_PRESSURE 101325.0
51 
52 #define PPRZ_ISA_SEA_LEVEL_TEMP 288.15
53 
54 #define PPRZ_ISA_TEMP_LAPS_RATE 0.0065
55 
56 #define PPRZ_ISA_GRAVITY 9.80665
57 
58 #define PPRZ_ISA_GAS_CONSTANT 8.31447
59 
60 #define PPRZ_ISA_MOLAR_MASS 0.0289644
61 
62 #define PPRZ_ISA_AIR_GAS_CONSTANT (PPRZ_ISA_GAS_CONSTANT/PPRZ_ISA_MOLAR_MASS)
63 
64 #define PPRZ_ISA_AIR_DENSITY 1.225
65 
66 #define PPRZ_ISA_ABS_NULL -273.15
67 
69 
71 #define CelsiusOfKelvin(_t) (_t - 274.15f)
72 
73 #define KelvinOfCelsius(_t) (_t + 274.15f)
74 
82 static inline float pprz_isa_altitude_of_pressure(float pressure)
83 {
84  if (pressure > 0.) {
85  return (PPRZ_ISA_M_OF_P_CONST * logf(PPRZ_ISA_SEA_LEVEL_PRESSURE / pressure));
86  } else {
87  return 0.;
88  }
89 }
90 
102 static inline float pprz_isa_height_of_pressure(float pressure, float ref_p)
103 {
104  if (pressure > 0. && ref_p > 0.) {
105  return (PPRZ_ISA_M_OF_P_CONST * logf(ref_p / pressure));
106  } else {
107  return 0.;
108  }
109 }
110 
117 static inline float pprz_isa_pressure_of_altitude(float altitude)
118 {
120 }
121 
129 static inline float pprz_isa_pressure_of_height(float height, float ref_p)
130 {
131  return (ref_p * expf((-1. / PPRZ_ISA_M_OF_P_CONST) * height));
132 }
133 
134 
146 static inline float pprz_isa_height_of_pressure_full(float pressure, float ref_p)
147 {
148  if (ref_p > 0.) {
149  const float prel = pressure / ref_p;
150  const float inv_expo = PPRZ_ISA_GAS_CONSTANT * PPRZ_ISA_TEMP_LAPS_RATE /
152  return (1 - powf(prel, inv_expo)) * PPRZ_ISA_SEA_LEVEL_TEMP / PPRZ_ISA_TEMP_LAPS_RATE;
153  } else {
154  return 0.;
155  }
156 }
157 
166 static inline float pprz_isa_ref_pressure_of_height_full(float pressure, float height)
167 {
168  // Trel = 1 - L*h/T0;
169  const float Trel = 1.0 - PPRZ_ISA_TEMP_LAPS_RATE * height / PPRZ_ISA_SEA_LEVEL_TEMP;
172  return pressure / pow(Trel, expo);
173 }
174 
181 static inline float pprz_isa_temperature_of_altitude(float alt)
182 {
184 }
185 
193 static inline float pprz_isa_density_of_pressure(float pressure, float temp)
194 {
195  return pressure * (1.0f / (PPRZ_ISA_AIR_GAS_CONSTANT * (temp - PPRZ_ISA_ABS_NULL)));
196 }
197 
198 #ifdef __cplusplus
199 } /* extern "C" */
200 #endif
201 
202 #endif /* PPRZ_ISA_H */
203 
pprz_isa_density_of_pressure
static float pprz_isa_density_of_pressure(float pressure, float temp)
Get the air density (rho) from a given pressure and temperature.
Definition: pprz_isa.h:193
PPRZ_ISA_AIR_GAS_CONSTANT
#define PPRZ_ISA_AIR_GAS_CONSTANT
universal gas constant / molar mass of dry air in J*kg/K
Definition: pprz_isa.h:62
PPRZ_ISA_GRAVITY
#define PPRZ_ISA_GRAVITY
earth-surface gravitational acceleration in m/s^2
Definition: pprz_isa.h:56
pprz_isa_ref_pressure_of_height_full
static float pprz_isa_ref_pressure_of_height_full(float pressure, float height)
Get reference pressure (QFE or QNH) from current pressure and height.
Definition: pprz_isa.h:166
PPRZ_ISA_GAS_CONSTANT
#define PPRZ_ISA_GAS_CONSTANT
universal gas constant in J/(mol*K)
Definition: pprz_isa.h:58
pprz_isa_temperature_of_altitude
static float pprz_isa_temperature_of_altitude(float alt)
Get ISA temperature from a MSL altitude.
Definition: pprz_isa.h:181
std.h
pprz_isa_altitude_of_pressure
static float pprz_isa_altitude_of_pressure(float pressure)
Get absolute altitude from pressure (using simplified equation).
Definition: pprz_isa.h:82
PPRZ_ISA_M_OF_P_CONST
static const float PPRZ_ISA_M_OF_P_CONST
Definition: pprz_isa.h:68
pprz_isa_height_of_pressure_full
static float pprz_isa_height_of_pressure_full(float pressure, float ref_p)
Get relative altitude from pressure (using full equation).
Definition: pprz_isa.h:146
PPRZ_ISA_MOLAR_MASS
#define PPRZ_ISA_MOLAR_MASS
molar mass of dry air in kg/mol
Definition: pprz_isa.h:60
PPRZ_ISA_SEA_LEVEL_TEMP
#define PPRZ_ISA_SEA_LEVEL_TEMP
ISA sea level standard temperature in Kelvin.
Definition: pprz_isa.h:52
pprz_isa_height_of_pressure
static float pprz_isa_height_of_pressure(float pressure, float ref_p)
Get relative altitude from pressure (using simplified equation).
Definition: pprz_isa.h:102
pprz_isa_pressure_of_altitude
static float pprz_isa_pressure_of_altitude(float altitude)
Get pressure in Pa from absolute altitude (using simplified equation).
Definition: pprz_isa.h:117
altitude
static int32_t altitude
Definition: airspeed_uADC.c:59
PPRZ_ISA_ABS_NULL
#define PPRZ_ISA_ABS_NULL
absolute null in celcius
Definition: pprz_isa.h:66
PPRZ_ISA_TEMP_LAPS_RATE
#define PPRZ_ISA_TEMP_LAPS_RATE
temperature laps rate in K/m
Definition: pprz_isa.h:54
PPRZ_ISA_SEA_LEVEL_PRESSURE
#define PPRZ_ISA_SEA_LEVEL_PRESSURE
ISA sea level standard atmospheric pressure in Pascal.
Definition: pprz_isa.h:50
pprz_isa_pressure_of_height
static float pprz_isa_pressure_of_height(float height, float ref_p)
Get pressure in Pa from height (using simplified equation).
Definition: pprz_isa.h:129