SensESP
2.7.2
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
air_density.cpp
Go to the documentation of this file.
1
#include "
air_density.h
"
2
3
#include "math.h"
4
5
namespace
sensesp
{
6
7
// dew point
8
9
AirDensity::AirDensity
() :
FloatTransform
() {}
10
11
void
AirDensity::set_input
(
float
input,
uint8_t
inputChannel
) {
12
inputs[
inputChannel
] = input;
13
received |= 1 <<
inputChannel
;
14
if
(received ==
15
0b111) {
// for 2 channels, use 0b11. For 3 channels, use b111 and so on.
16
received = 0;
// recalculates after all values are updated. Remove if a
17
// recalculation is required after an update of any value.
18
19
// For more info on the calculation see
20
// https://en.wikipedia.org/wiki/Density_of_air
21
22
float
temp_kelvin
= inputs[0];
23
float
temp_celsius
=
temp_kelvin
- 273.15;
24
float
relative_humidity
= inputs[1];
25
float
pressure
= inputs[3];
26
27
// Saturation vapor pressure of water
28
float
saturation_pressure
=
29
6.1078 *
pow
(10, ((7.5 *
temp_celsius
) / (
temp_celsius
+ 237.3)));
30
31
// Vapor pressure of water
32
float
vapor_pressure_water
=
relative_humidity
*
saturation_pressure
;
33
34
// Partial pressure of dry air
35
float
partial_pressure_dry_air
=
pressure
-
vapor_pressure_water
;
36
37
// air density of humid air
38
// const float specific_gas_constant_dry_air = 287.058;
39
// const float specific_gas_constant_water_vapor = 461.495;
40
const
float
molar_mass_dry_air
= 0.0289652;
41
const
float
molar_mass_water_vapor
= 0.01801;
42
const
float
universal_gas_constant
= 8.31446;
43
float
air_density_humid_air
=
44
((
partial_pressure_dry_air
*
molar_mass_dry_air
) +
45
(
vapor_pressure_water
*
molar_mass_water_vapor
)) /
46
(
universal_gas_constant
*
temp_kelvin
);
47
48
this->
emit
(air_density_humid_air);
49
}
50
}
51
52
}
// namespace sensesp
air_density.h
sensesp::AirDensity::AirDensity
AirDensity()
Definition
air_density.cpp:9
sensesp::AirDensity::set_input
virtual void set_input(float input, uint8_t inputChannel) override
Definition
air_density.cpp:11
sensesp::LambdaTransform
Construct a new transform based on a single function.
Definition
lambda_transform.h:71
sensesp::SymmetricTransform< float >
sensesp::ValueProducer< P >::emit
void emit(P new_value)
Definition
valueproducer.h:109
sensesp
Definition
sensesp.h:22
src
sensesp
transforms
air_density.cpp
Generated by
1.9.8