Skip to content

Commit 6b4027a

Browse files
author
BasicAirData
committed
Added TAS
Added TAS
1 parent a7ffe9e commit 6b4027a

7 files changed

Lines changed: 112 additions & 73 deletions

File tree

Software/Arduino/Libraries/AirDC/AirDC.cpp

Lines changed: 66 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -59,71 +59,78 @@ void AirDC::RhoAir(int mode)
5959
p=_p;
6060
T=_T;
6161
RH=_RH;
62-
for (int i=1;i<5;i++){
63-
switch (i){
64-
case 1:
65-
{
66-
p=p+10;
67-
break;
68-
}
69-
case 2:
70-
{
71-
p=p+10;
72-
break;
73-
}
74-
case 3:
62+
for (int i=1; i<5; i++)
7563
{
76-
p=p-10;
77-
T=T+10;
78-
break;
79-
}
80-
case 4:
81-
{
82-
T=T-10;
83-
RH=RH+0.1;
84-
break;
85-
}
86-
}
87-
psv=1*exp(A*pow(T,2)+B*T+C+D/T);
88-
t=T-273.15;
89-
f=alfa+bet*p+gama*pow(t,2);
90-
xv=RH*f*psv/p;
91-
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));
64+
switch (i)
65+
{
66+
case 1:
67+
{
68+
p=p+10;
69+
break;
70+
}
71+
case 2:
72+
{
73+
p=p+10;
74+
break;
75+
}
76+
case 3:
77+
{
78+
p=p-10;
79+
T=T+10;
80+
break;
81+
}
82+
case 4:
83+
{
84+
T=T-10;
85+
RH=RH+0.1;
86+
break;
87+
}
88+
}
89+
psv=1*exp(A*pow(T,2)+B*T+C+D/T);
90+
t=T-273.15;
91+
f=alfa+bet*p+gama*pow(t,2);
92+
xv=RH*f*psv/p;
93+
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));
9294

93-
switch (i){
94-
case 1:
95+
switch (i)
9596
{
96-
//Calculates Sensibility factor for p
97-
_Rho=p*Ma/(Z*R*T)*(1-xv*(1-Mv/Ma))*0.001;
98-
break;
99-
}
100-
case 2:
97+
case 1:
10198
{
102-
//Calculates Sensibility factor for p
103-
Sp=((p*Ma/(Z*R*T)*(1-xv*(1-Mv/Ma))*0.001)-_Rho)/10;
104-
break;
105-
}
106-
case 3:
99+
//Calculates Sensibility factor for p
100+
_Rho=p*Ma/(Z*R*T)*(1-xv*(1-Mv/Ma))*0.001;
101+
break;
102+
}
103+
case 2:
107104
{
108-
//Calculates Sensibility factor for T
109-
ST=((p*Ma/(Z*R*T)*(1-xv*(1-Mv/Ma))*0.001)-_Rho)/10;
110-
break;
111-
}
112-
case 4:
105+
//Calculates Sensibility factor for p
106+
Sp=((p*Ma/(Z*R*T)*(1-xv*(1-Mv/Ma))*0.001)-_Rho)/10;
107+
break;
108+
}
109+
case 3:
110+
{
111+
//Calculates Sensibility factor for T
112+
ST=((p*Ma/(Z*R*T)*(1-xv*(1-Mv/Ma))*0.001)-_Rho)/10;
113+
break;
114+
}
115+
case 4:
113116
{
114117
//Calculates Sensibility factor for RH
115-
SRH=((p*Ma/(Z*R*T)*(1-xv*(1-Mv/Ma))*0.001)-_Rho)*10;
116-
_uRho=sqrt(Sp*Sp*_up*_up+ST*ST*_uT*_uT+SRH*SRH*_uRH*_uRH);
117-
break;
118-
}
119-
}
118+
SRH=((p*Ma/(Z*R*T)*(1-xv*(1-Mv/Ma))*0.001)-_Rho)*10;
119+
_uRho=sqrt(Sp*Sp*_up*_up+ST*ST*_uT*_uT+SRH*SRH*_uRH*_uRH);
120+
break;
121+
}
122+
}
120123
}
121124
break;
122125
}
123126

124127
}
125128
void AirDC::IAS(int mode)
126129
{
130+
//Indicated Airspeed
131+
//IAS=ASI=EAS
132+
//http://www.basicairdata.eu/pitot-tube.html
133+
//https://en.wikipedia.org/wiki/Equivalent_airspeed
127134
switch (mode)
128135
{
129136
case 1:
@@ -143,3 +150,11 @@ void AirDC::IAS(int mode)
143150
break;
144151
}
145152
}
153+
void AirDC::TAS(int mode)
154+
{
155+
//True Airspeed
156+
//http://www.basicairdata.eu/pitot-tube.html
157+
//TAS=IAS*(rhostandard/rhoair)^0.5
158+
_TAS=_IAS*sqrt(1.225/_Rho);
159+
_uTAS= sqrt((1.225/_Rho)*pow(_uIAS,2)+ pow(0.5*_IAS*1.225/(pow(_Rho,1.5)),2)*pow(_uRho,2));
160+
}

Software/Arduino/Libraries/AirDC/AirDC.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,28 @@
99
#include "Arduino.h"
1010
class AirDC
1111
{
12-
public:
12+
public:
1313
AirDC(int pid);
1414
void RhoAir(int mode);
1515
void IAS(int mode);
16-
//private:
16+
void TAS(int mode);
17+
//private:
1718
int _pid;
1819
double _Rho;
1920
double _p;
2021
double _T;
2122
double _RH;
2223
double _qc;
2324
double _IAS;
25+
double _TAS;
26+
//uncertainty terms
2427
double _up;
2528
double _uT;
2629
double _uRH;
2730
double _uRho;
2831
double _uqc;
2932
double _uIAS;
33+
double _uTAS;
3034
};
3135
#endif
3236

Software/Arduino/Libraries/AirDC/Examples/DifferentialPressureSensor/DifferentialPressureSensor.ino

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@
88
#include <AirSensor.h>
99

1010
#define DPSENSOR 3 //Selects the differential pressure Hardware sensor see AirSensor.cpp for details on Hookup
11+
#define PSENSOR 1 //Selects the static pressure Hardware sensor see AirSensor.cpp for details on Hookup
1112

1213
#if DPSENSOR==1
1314
#include <Wire.h>
1415
#endif
1516
#if DPSENSOR==2
1617
#include <SPI.h>
1718
#endif
18-
int dpsensor;
19+
int dpsensor,psensor;
1920
double p; //Static Pressure
2021
AirSensor AirDataSensor(1);
2122
AirDC AirDataComputer(1);
2223

2324
void setup() {
2425
Serial.begin(9600);
26+
//Impact pressure, qc, differential pressure sensor related setup
2527
#if DPSENSOR==1
2628
dpsensor = 1;
2729
Wire.begin();
@@ -36,21 +38,31 @@ void setup() {
3638
#if DPSENSOR==3
3739
dpsensor = 3;
3840
#endif
39-
41+
//Static pressure sensor related setup
42+
#if PSENSOR==1
43+
psensor = 1;
44+
#endif
4045
}
4146

4247
void loop() {
4348
AirDC *ptrAirDC;
4449
ptrAirDC = &AirDataComputer;
4550
AirDataSensor.ReadDifferentialPressure(ptrAirDC, dpsensor);
51+
AirDataSensor.ReadStaticPressure(ptrAirDC, psensor);
4652
AirDataComputer.IAS(1);// Calculates the IAS, Algorithm 1
4753
AirDataComputer.RhoAir(1);// Calculates the air density, Algorithm 1
54+
AirDataComputer.TAS(1);// Calculates the IAS, Algorithm 1
4855
delay(1000); //loop delay
49-
Serial.println(dpsensor); //Sends the Selected sensor
50-
Serial.println(AirDataComputer._qc); //Sends the differential pressure reading
51-
Serial.println(AirDataComputer._uqc, 10); //Sends the uncertainty of differential pressure measurement
56+
Serial.println(dpsensor); //Prints the Selected sensor
57+
Serial.println(psensor); //Prints the Selected sensor
58+
Serial.println(AirDataComputer._qc); //Differential pressure reading
59+
Serial.println(AirDataComputer._uqc, 10); //Uncertainty of differential pressure measurement
60+
Serial.println(AirDataComputer._p); //Static Pressure
61+
Serial.println(AirDataComputer._up, 10); //Uncertainty of static pressure
5262
Serial.println(AirDataComputer._IAS);//Sends the indicated Airspeed
5363
Serial.println(AirDataComputer._uIAS, 10); //Sends the uncertainty of IAS measurement
54-
Serial.println(AirDataComputer._Rho);//Sends the density of Air
64+
Serial.println(AirDataComputer._Rho,4);//Sends the density of Air
5565
Serial.println(AirDataComputer._uRho, 10); //Sends the uncertainty of the density of air
66+
Serial.println(AirDataComputer._TAS); //True Airspeed
67+
Serial.println(AirDataComputer._uTAS); //True Airspeed uncertainty
5668
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
AirDC KEYWORD1
22
RhoAir KEYWORD2
3-
IAS KEYWORD2
3+
IAS KEYWORD2
4+
TAS KEYWORD2

Software/Arduino/Libraries/AirSensor/AirSensor.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ void AirSensor::ReadDifferentialPressure(AirDC *out,int sensor)
8080
SPI.transfer(GETMEASURE);
8181
digitalWrite(cs, HIGH);
8282
digitalWrite(cs, LOW);
83-
byte h = SPI.transfer(0x00);
84-
byte l = SPI.transfer(0x00);
83+
byte hb = SPI.transfer(0x00);
84+
byte lb = SPI.transfer(0x00);
8585
digitalWrite(cs, HIGH);
86-
result=word(h,l);
86+
result=word(hb,lb);
8787
rawpressure=result*sensorgain;
8888
out->_qc=rawpressure; //pa
8989
out->_uqc=5.0;//pa
@@ -104,10 +104,24 @@ void AirSensor::ReadDifferentialPressure(AirDC *out,int sensor)
104104
raw = analogRead(analogPin);
105105
Vread=5.0/1023.0*(raw);
106106
Pread=(Vread-2.5-offsetv)*1000;
107+
Pread=1000;
107108
out->_qc=Pread; //pa
108109
out->_uqc=50.0;//pa
109110
}
110111
break;
111112
}
112113
}
113114

115+
void AirSensor::ReadStaticPressure(AirDC *out,int sensor)
116+
{
117+
switch (sensor)
118+
{
119+
case 1 :
120+
{
121+
out->_p=90000;
122+
out->_up=100;
123+
break;
124+
}
125+
}
126+
}
127+

Software/Arduino/Libraries/AirSensor/AirSensor.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,7 @@ class AirSensor
1313
public:
1414
AirSensor(int pid);
1515
void ReadDifferentialPressure(AirDC *out,int mode);
16-
//private:
16+
void ReadStaticPressure(AirDC *out,int mode);
1717
int _pid;
18-
/* double _p;
19-
double _T;
20-
double _RH;
21-
double _qc;
22-
double _up;
23-
double _uT;
24-
double _uRH;
25-
double _uqc;*/
2618
};
2719
#endif
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
AirSensor KEYWORD1
2-
ReadDifferentialPressure KEYWORD2
2+
ReadDifferentialPressure KEYWORD2
3+
ReadStaticPressure KEYWORD2

0 commit comments

Comments
 (0)