Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
67 
69 #define CelsiusOfKelvin(_t) (_t - 274.15f)
70 
71 #define KelvinOfCelsius(_t) (_t + 274.15f)
72 
80 static inline float pprz_isa_altitude_of_pressure(float pressure)
81 {
82  if (pressure > 0.) {
83  return (PPRZ_ISA_M_OF_P_CONST * logf(PPRZ_ISA_SEA_LEVEL_PRESSURE / pressure));
84  } else {
85  return 0.;
86  }
87 }
88 
100 static inline float pprz_isa_height_of_pressure(float pressure, float ref_p)
101 {
102  if (pressure > 0. && ref_p > 0.) {
103  return (PPRZ_ISA_M_OF_P_CONST * logf(ref_p / pressure));
104  } else {
105  return 0.;
106  }
107 }
108 
115 static inline float pprz_isa_pressure_of_altitude(float altitude)
116 {
117  return (PPRZ_ISA_SEA_LEVEL_PRESSURE * expf((-1. / PPRZ_ISA_M_OF_P_CONST) * altitude));
118 }
119 
127 static inline float pprz_isa_pressure_of_height(float height, float ref_p)
128 {
129  return (ref_p * expf((-1. / PPRZ_ISA_M_OF_P_CONST) * height));
130 }
131 
132 
144 static inline float pprz_isa_height_of_pressure_full(float pressure, float ref_p)
145 {
146  if (ref_p > 0.) {
147  const float prel = pressure / ref_p;
148  const float inv_expo = PPRZ_ISA_GAS_CONSTANT * PPRZ_ISA_TEMP_LAPS_RATE /
150  return (1 - powf(prel, inv_expo)) * PPRZ_ISA_SEA_LEVEL_TEMP / PPRZ_ISA_TEMP_LAPS_RATE;
151  } else {
152  return 0.;
153  }
154 }
155 
164 static inline float pprz_isa_ref_pressure_of_height_full(float pressure, float height)
165 {
166  // Trel = 1 - L*h/T0;
167  const float Trel = 1.0 - PPRZ_ISA_TEMP_LAPS_RATE * height / PPRZ_ISA_SEA_LEVEL_TEMP;
170  return pressure / pow(Trel, expo);
171 }
172 
179 static inline float pprz_isa_temperature_of_altitude(float alt)
180 {
182 }
183 
184 #ifdef __cplusplus
185 } /* extern "C" */
186 #endif
187 
188 #endif /* PPRZ_ISA_H */
189 
static float pprz_isa_pressure_of_altitude(float altitude)
Get pressure in Pa from absolute altitude (using simplified equation).
Definition: pprz_isa.h:115
#define PPRZ_ISA_GRAVITY
earth-surface gravitational acceleration in m/s^2
Definition: pprz_isa.h:56
#define PPRZ_ISA_TEMP_LAPS_RATE
temperature laps rate in K/m
Definition: pprz_isa.h:54
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:127
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:164
#define PPRZ_ISA_MOLAR_MASS
molar mass of dry air in kg/mol
Definition: pprz_isa.h:60
#define PPRZ_ISA_AIR_GAS_CONSTANT
universal gas constant / molar mass of dry air in J*kg/K
Definition: pprz_isa.h:62
#define PPRZ_ISA_SEA_LEVEL_TEMP
ISA sea level standard temperature in Kelvin.
Definition: pprz_isa.h:52
#define PPRZ_ISA_GAS_CONSTANT
universal gas constant in J/(mol*K)
Definition: pprz_isa.h:58
static int32_t altitude
Definition: airspeed_uADC.c:58
static const float PPRZ_ISA_M_OF_P_CONST
Definition: pprz_isa.h:66
static float pprz_isa_altitude_of_pressure(float pressure)
Get absolute altitude from pressure (using simplified equation).
Definition: pprz_isa.h:80
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:144
#define PPRZ_ISA_SEA_LEVEL_PRESSURE
ISA sea level standard atmospheric pressure in Pascal.
Definition: pprz_isa.h:50
static float pprz_isa_temperature_of_altitude(float alt)
Get ISA temperature from a MSL altitude.
Definition: pprz_isa.h:179
static float pprz_isa_height_of_pressure(float pressure, float ref_p)
Get relative altitude from pressure (using simplified equation).
Definition: pprz_isa.h:100