Skip to content

Commit a7ffe9e

Browse files
author
BasicAirData
committed
Code
Used Iteration in RhoAir. Avoided recursion.
1 parent 56c485e commit a7ffe9e

1 file changed

Lines changed: 50 additions & 25 deletions

File tree

Software/Arduino/Libraries/AirDC/AirDC.cpp

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,43 +59,68 @@ void AirDC::RhoAir(int mode)
5959
p=_p;
6060
T=_T;
6161
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
62+
for (int i=1;i<5;i++){
63+
switch (i){
64+
case 1:
65+
{
7166
p=p+10;
67+
break;
68+
}
69+
case 2:
70+
{
71+
p=p+10;
72+
break;
73+
}
74+
case 3:
75+
{
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+
}
7287
psv=1*exp(A*pow(T,2)+B*T+C+D/T);
7388
t=T-273.15;
7489
f=alfa+bet*p+gama*pow(t,2);
7590
xv=RH*f*psv/p;
7691
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));
92+
93+
switch (i){
94+
case 1:
95+
{
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:
101+
{
102+
//Calculates Sensibility factor for p
77103
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));
104+
break;
105+
}
106+
case 3:
107+
{
108+
//Calculates Sensibility factor for T
86109
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));
110+
break;
111+
}
112+
case 4:
113+
{
114+
//Calculates Sensibility factor for RH
95115
SRH=((p*Ma/(Z*R*T)*(1-xv*(1-Mv/Ma))*0.001)-_Rho)*10;
96116
_uRho=sqrt(Sp*Sp*_up*_up+ST*ST*_uT*_uT+SRH*SRH*_uRH*_uRH);
97117
break;
118+
}
119+
}
120+
}
121+
break;
98122
}
123+
99124
}
100125
void AirDC::IAS(int mode)
101126
{

0 commit comments

Comments
 (0)