Skip to content

Commit e587787

Browse files
author
BasicAirData
committed
ADC Library
ADC General Purpose Library
1 parent fdea38e commit e587787

3 files changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
AirDC.cpp - Library for Basic Air Data calculations
3+
Created by J. Larragueta, December 3, 2015.
4+
Refer to http:\\www.basicairdata.eu
5+
*/
6+
#include "AirDC.h"
7+
#include <math.h>
8+
9+
AirDC::AirDC(int pid)
10+
{
11+
//pinMode(pin, OUTPUT);
12+
_pid = pid;
13+
}
14+
//Rho(Pressure,Temperature,Relative Humidity)
15+
//http://www.basicairdata.eu/calculation-routines.html
16+
double AirDC::Rho(double p, double T,double RH)
17+
{
18+
//Some definition
19+
const double R= 8.314510;//J/(mol°K)
20+
const double xco2=0.0004;//Co2 fraction
21+
const double A=1.2378847e-5;
22+
const double B=-1.9121316e-2;
23+
const double C=33.93711047;
24+
const double D=-6.3431645e3;
25+
const double alfa=1.00062;
26+
const double bet=3.14e-8;
27+
const double gama=5.6e-7;
28+
const double a0=1.58123e-6;
29+
const double a1=-2.9331e-8;
30+
const double a2=1.1043e-10;
31+
const double b0=5.707e-6;
32+
const double b1=-2.051e-8;
33+
const double c0=1.9898e-4;
34+
const double c1=-2.376e-6;
35+
const double d=1.83e-11;
36+
const double e=- 0.765e-8;
37+
const double Ma=28.9635 + 12.011*(xco2- 0.0004);
38+
const double Mv=18.01528;
39+
double psv,t,f,xv,Z,rho,h;
40+
h=RH;
41+
psv=1*exp(A*pow(T,2)+B*T+C+D/T);
42+
t=T-273.15;
43+
f=alfa+bet*p+gama*pow(t,2);
44+
xv=h*f*psv/p;
45+
Z=1-p/T*(a0+a1*t+a2*pow(t,2)+(b0+b1*t)*xv+(c0+c1*t)*pow(xv,2))+pow(p,2)/pow(T,2)*(d+e*pow(xv,2));
46+
rho=p*Ma/(Z*R*T)*(1-xv*(1-Mv/Ma))*0.001;
47+
//Class Variables undate and Output
48+
return rho;
49+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
AirDC.cpp - Library for Basic Air Data calculations
3+
Created by J. Larragueta, December 3, 2015.
4+
Refer to http:\\www.basicairdata.eu
5+
*/
6+
7+
#ifndef AirDC_h
8+
#define AirDC_h
9+
#include "Arduino.h"
10+
class AirDC
11+
{
12+
public:
13+
AirDC(int pid);
14+
double Rho(double T, double p,double RH);
15+
private:
16+
int _pid;
17+
double _p;
18+
double _t;
19+
double _RH;
20+
};
21+
#endif
22+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
AirDC KEYWORD1
2+
Rho KEYWORD2

0 commit comments

Comments
 (0)