Paparazzi UAS  v5.12_stable-4-g9b43e9b
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 
75 static inline float pprz_isa_altitude_of_pressure(float pressure)
76 {
77  if (pressure > 0.) {
78  return (PPRZ_ISA_M_OF_P_CONST * logf(PPRZ_ISA_SEA_LEVEL_PRESSURE / pressure));
79  } else {
80  return 0.;
81  }
82 }
83 
95 static inline float pprz_isa_height_of_pressure(float pressure, float ref_p)
96 {
97  if (pressure > 0. && ref_p > 0.) {
98  return (PPRZ_ISA_M_OF_P_CONST * logf(ref_p / pressure));
99  } else {
100  return 0.;
101  }
102 }
103 
110 static inline float pprz_isa_pressure_of_altitude(float altitude)
111 {
112  return (PPRZ_ISA_SEA_LEVEL_PRESSURE * expf((-1. / PPRZ_ISA_M_OF_P_CONST) * altitude));
113 }
114 
122 static inline float pprz_isa_pressure_of_height(float height, float ref_p)
123 {
124  return (ref_p * expf((-1. / PPRZ_ISA_M_OF_P_CONST) * height));
125 }
126 
127 
139 static inline float pprz_isa_height_of_pressure_full(float pressure, float ref_p)
140 {
141  if (ref_p > 0.) {
142  const float prel = pressure / ref_p;
143  const float inv_expo = PPRZ_ISA_GAS_CONSTANT * PPRZ_ISA_TEMP_LAPS_RATE /
145  return (1 - powf(prel, inv_expo)) * PPRZ_ISA_SEA_LEVEL_TEMP / PPRZ_ISA_TEMP_LAPS_RATE;
146  } else {
147  return 0.;
148  }
149 }
150 
159 static inline float pprz_isa_ref_pressure_of_height_full(float pressure, float height)
160 {
161  // Trel = 1 - L*h/T0;
162  const float Trel = 1.0 - PPRZ_ISA_TEMP_LAPS_RATE * height / PPRZ_ISA_SEA_LEVEL_TEMP;
165  return pressure / pow(Trel, expo);
166 }
167 
168 #ifdef __cplusplus
169 } /* extern "C" */
170 #endif
171 
172 #endif /* PPRZ_ISA_H */
173 
static float pprz_isa_pressure_of_altitude(float altitude)
Get pressure in Pa from absolute altitude (using simplified equation).
Definition: pprz_isa.h:110
#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:122
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:159
#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:75
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:139
#define PPRZ_ISA_SEA_LEVEL_PRESSURE
ISA sea level standard atmospheric pressure in Pascal.
Definition: pprz_isa.h:50
static float pprz_isa_height_of_pressure(float pressure, float ref_p)
Get relative altitude from pressure (using simplified equation).
Definition: pprz_isa.h:95