Skip to content

Commit e975413

Browse files
author
BasicAirData
committed
Fup
Minimal Example
1 parent dd538fb commit e975413

5 files changed

Lines changed: 180 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <AirDC.h>
2+
#include <stdio.h>
3+
4+
/*
5+
Minimal -Basic Air Data calculations with AirDC library
6+
Created by J. Larragueta, December 3, 2015.
7+
Refer to http:\\www.basicairdata.eu
8+
*/
9+
AirDC BasicAirData(1);
10+
11+
void setup() {
12+
// put your setup code here, to run once:
13+
Serial.begin(9600);
14+
}
15+
16+
void loop() {
17+
BasicAirData.RhoAir(101325,288.15,0,1);
18+
BasicAirData.IAS(100,1);
19+
delay(500);
20+
// put your main code here, to run repeatedly:
21+
Serial.println(BasicAirData._Rho,10);
22+
Serial.println(BasicAirData._uRho,10);
23+
Serial.println(BasicAirData._IAS,10);
24+
Serial.println(BasicAirData._uIAS,10);
25+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
//Default parameters values
12+
_pid = pid;
13+
//Parameter values
14+
_Rho=1.225;
15+
_p=101325;
16+
_T=288.15;
17+
_RH=0.0;
18+
_qc=0.0;
19+
_IAS=0.0;
20+
//Uncertainty of measurements
21+
_uRho=0.0; //To be calculated, 0 default value
22+
_up=5.0;
23+
_uT=0.8;
24+
_uRH=0.05;
25+
_uqc=5.0;
26+
_uIAS=0.0;//To be calculated, 0 default value
27+
}
28+
//RhoAir(Pressure,Temperature,Relative Humidity,mode)
29+
//Mode 1 is the default BasicAirData routine
30+
//http://www.basicairdata.eu/calculation-routines.html
31+
void AirDC::RhoAir(double p, double T,double RH, int mode)
32+
{
33+
switch (mode)
34+
{
35+
case 1:
36+
//Some definition
37+
const double R= 8.314510;//J/(mol°K)
38+
const double xco2=0.0004;//Co2 fraction
39+
const double A=1.2378847e-5;
40+
const double B=-1.9121316e-2;
41+
const double C=33.93711047;
42+
const double D=-6.3431645e3;
43+
const double alfa=1.00062;
44+
const double bet=3.14e-8;
45+
const double gama=5.6e-7;
46+
const double a0=1.58123e-6;
47+
const double a1=-2.9331e-8;
48+
const double a2=1.1043e-10;
49+
const double b0=5.707e-6;
50+
const double b1=-2.051e-8;
51+
const double c0=1.9898e-4;
52+
const double c1=-2.376e-6;
53+
const double d=1.83e-11;
54+
const double e=- 0.765e-8;
55+
const double Ma=28.9635 + 12.011*(xco2- 0.0004);
56+
const double Mv=18.01528;
57+
double psv,t,f,xv,Z;
58+
double Sp,ST,SRH; //sensibility factors
59+
_p=p;
60+
_T=T;
61+
_RH=RH;
62+
//Sequential computation
63+
psv=1*exp(A*pow(T,2)+B*T+C+D/T);
64+
t=T-273.15;
65+
f=alfa+bet*p+gama*pow(t,2);
66+
xv=RH*f*psv/p;
67+
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));
68+
//Assign calculated values to actual status
69+
_Rho=p*Ma/(Z*R*T)*(1-xv*(1-Mv/Ma))*0.001;
70+
//Calculates Sensibility factor for p
71+
p=p+10;
72+
psv=1*exp(A*pow(T,2)+B*T+C+D/T);
73+
t=T-273.15;
74+
f=alfa+bet*p+gama*pow(t,2);
75+
xv=RH*f*psv/p;
76+
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));
77+
Sp=((p*Ma/(Z*R*T)*(1-xv*(1-Mv/Ma))*0.001)-_Rho)/10;
78+
p=p-10;
79+
//Calculates Sensibility factor for T
80+
T=T+10;
81+
psv=1*exp(A*pow(T,2)+B*T+C+D/T);
82+
t=T-273.15;
83+
f=alfa+bet*p+gama*pow(t,2);
84+
xv=RH*f*psv/p;
85+
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));
86+
ST=((p*Ma/(Z*R*T)*(1-xv*(1-Mv/Ma))*0.001)-_Rho)/10;
87+
T=T-10;
88+
//Calculates Sensibility factor for RH
89+
RH=RH+0.1;
90+
psv=1*exp(A*pow(T,2)+B*T+C+D/T);
91+
t=T-273.15;
92+
f=alfa+bet*p+gama*pow(t,2);
93+
xv=RH*f*psv/p;
94+
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));
95+
SRH=((p*Ma/(Z*R*T)*(1-xv*(1-Mv/Ma))*0.001)-_Rho)*10;
96+
_uRho=sqrt(Sp*Sp*_up*_up+ST*ST*_uT*_uT+SRH*SRH*_uRH*_uRH);
97+
break;
98+
}
99+
}
100+
void AirDC::IAS(double qc,int mode)
101+
{
102+
switch (mode){
103+
case 1:
104+
_IAS=1.27775310604201*sqrt(qc);
105+
_uIAS=0.638876553021004/(sqrt(qc))*_uqc;
106+
break;
107+
}
108+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
void RhoAir(double p, double T,double RH,int mode);
15+
void IAS(double qc,int mode);
16+
//private:
17+
int _pid;
18+
double _Rho;
19+
double _p;
20+
double _T;
21+
double _RH;
22+
double _qc;
23+
double _IAS;
24+
double _up;
25+
double _uT;
26+
double _uRH;
27+
double _uRho;
28+
double _uqc;
29+
double _uIAS;
30+
};
31+
#endif
32+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <AirDC.h>
2+
3+
4+
void setup() {
5+
// put your setup code here, to run once:
6+
7+
}
8+
9+
void loop() {
10+
// put your main code here, to run repeatedly:
11+
12+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
AirDC KEYWORD1
2+
RhoAir KEYWORD2
3+
IAS KEYWORD2

0 commit comments

Comments
 (0)