Skip to content

Commit

Permalink
[math] Add air density calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
fvantienen committed Mar 5, 2019
1 parent 49e6313 commit 1e748f0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sw/airborne/math/pprz_isa.h
Expand Up @@ -62,6 +62,8 @@ extern "C" {
#define PPRZ_ISA_AIR_GAS_CONSTANT (PPRZ_ISA_GAS_CONSTANT/PPRZ_ISA_MOLAR_MASS)
/** standard air density in kg/m^3 */
#define PPRZ_ISA_AIR_DENSITY 1.225
/** absolute null in celcius */
#define PPRZ_ISA_ABS_NULL -273.15

static const float PPRZ_ISA_M_OF_P_CONST = (PPRZ_ISA_AIR_GAS_CONSTANT *PPRZ_ISA_SEA_LEVEL_TEMP / PPRZ_ISA_GRAVITY);

Expand Down Expand Up @@ -181,6 +183,18 @@ static inline float pprz_isa_temperature_of_altitude(float alt)
return PPRZ_ISA_SEA_LEVEL_TEMP - PPRZ_ISA_TEMP_LAPS_RATE * alt;
}

/**
* Get the air density (rho) from a given pressure and temperature
*
* @param pressure current pressure in Pascal (Pa)
* @param temp temperature in celcius
* @return air density rho
*/
static inline float pprz_isa_density_of_pressure(float pressure, float temp)
{
return pressure * (1.0f / (PPRZ_ISA_AIR_GAS_CONSTANT * (temp - PPRZ_ISA_ABS_NULL)));
}

#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down

0 comments on commit 1e748f0

Please sign in to comment.