Skip to content

Commit 56c485e

Browse files
author
BasicAirData
committed
MultipleSensorLib
1 parent 0b402f4 commit 56c485e

10 files changed

Lines changed: 246 additions & 105 deletions

File tree

Software/Arduino/Libraries/AirDC/AirDC.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ AirDC::AirDC(int pid)
2828
//RhoAir(Pressure,Temperature,Relative Humidity,mode)
2929
//Mode 1 is the default BasicAirData routine
3030
//http://www.basicairdata.eu/calculation-routines.html
31-
void AirDC::RhoAir(double p, double T,double RH, int mode)
31+
void AirDC::RhoAir(int mode)
3232
{
3333
switch (mode)
3434
{
@@ -54,11 +54,11 @@ void AirDC::RhoAir(double p, double T,double RH, int mode)
5454
const double e=- 0.765e-8;
5555
const double Ma=28.9635 + 12.011*(xco2- 0.0004);
5656
const double Mv=18.01528;
57-
double psv,t,f,xv,Z;
57+
double p,T,RH,psv,t,f,xv,Z;
5858
double Sp,ST,SRH; //sensibility factors
59-
_p=p;
60-
_T=T;
61-
_RH=RH;
59+
p=_p;
60+
T=_T;
61+
RH=_RH;
6262
//Sequential computation
6363
psv=1*exp(A*pow(T,2)+B*T+C+D/T);
6464
t=T-273.15;
@@ -97,12 +97,24 @@ void AirDC::RhoAir(double p, double T,double RH, int mode)
9797
break;
9898
}
9999
}
100-
void AirDC::IAS(double qc,int mode)
100+
void AirDC::IAS(int mode)
101101
{
102-
switch (mode){
103-
case 1:
104-
_IAS=1.27775310604201*sqrt(qc);
105-
_uIAS=0.638876553021004/(sqrt(qc))*_uqc;
106-
break;
102+
switch (mode)
103+
{
104+
case 1:
105+
if (_qc<0)
106+
{
107+
_qc=0;
108+
}
109+
_IAS=1.27775310604201*sqrt(_qc);
110+
if (_qc>0)
111+
{
112+
_uIAS=0.638876553021004/(sqrt(_qc))*_uqc;
113+
}
114+
else
115+
{
116+
_uIAS=0;
117+
}
118+
break;
107119
}
108120
}

Software/Arduino/Libraries/AirDC/AirDC.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class AirDC
1111
{
1212
public:
1313
AirDC(int pid);
14-
void RhoAir(double p, double T,double RH,int mode);
15-
void IAS(double qc,int mode);
14+
void RhoAir(int mode);
15+
void IAS(int mode);
1616
//private:
1717
int _pid;
1818
double _Rho;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
DifferentialPressureSensor.ino - AirDc Library Example File
3+
Reads a differential pressure sensor and printout air density. Measurements are given with uncertainty.
4+
Created by J. Larragueta, December 3, 2015.
5+
Refer to http:\\www.basicairdata.eu
6+
*/
7+
#include <AirDC.h>
8+
#include <AirSensor.h>
9+
10+
#define DPSENSOR 3 //Selects the differential pressure Hardware sensor see AirSensor.cpp for details on Hookup
11+
12+
#if DPSENSOR==1
13+
#include <Wire.h>
14+
#endif
15+
#if DPSENSOR==2
16+
#include <SPI.h>
17+
#endif
18+
int dpsensor;
19+
double p; //Static Pressure
20+
AirSensor AirDataSensor(1);
21+
AirDC AirDataComputer(1);
22+
23+
void setup() {
24+
Serial.begin(9600);
25+
#if DPSENSOR==1
26+
dpsensor = 1;
27+
Wire.begin();
28+
#endif
29+
#if DPSENSOR==2
30+
dpsensor = 2;
31+
int cs = 10;
32+
pinMode (cs, OUTPUT);
33+
SPI.begin();
34+
SPI.setBitOrder(MSBFIRST);
35+
#endif
36+
#if DPSENSOR==3
37+
dpsensor = 3;
38+
#endif
39+
40+
}
41+
42+
void loop() {
43+
AirDC *ptrAirDC;
44+
ptrAirDC = &AirDataComputer;
45+
AirDataSensor.ReadDifferentialPressure(ptrAirDC, dpsensor);
46+
AirDataComputer.IAS(1);// Calculates the IAS, Algorithm 1
47+
AirDataComputer.RhoAir(1);// Calculates the air density, Algorithm 1
48+
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
52+
Serial.println(AirDataComputer._IAS);//Sends the indicated Airspeed
53+
Serial.println(AirDataComputer._uIAS, 10); //Sends the uncertainty of IAS measurement
54+
Serial.println(AirDataComputer._Rho);//Sends the density of Air
55+
Serial.println(AirDataComputer._uRho, 10); //Sends the uncertainty of the density of air
56+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
DifferentialPressureSensor.ino - AirDc Library Example File
3+
Reads a differential pressure sensor and printout air density. Measurements are given with uncertainty.
4+
Interrupt Based Measurement cycle
5+
Created by J. Larragueta, December 3, 2015.
6+
Refer to http:\\www.basicairdata.eu
7+
*/
8+
#include <AirDC.h>
9+
#include <AirSensor.h>
10+
11+
#define DPSENSOR 3 //Selects the differential pressure Hardware sensor see AirSensor.cpp for details on Hookup
12+
13+
#if DPSENSOR==
14+
#include <Wire.h>
15+
#endif
16+
#if DPSENSOR==2
17+
#include <SPI.h>
18+
#endif
19+
const int ledPin=13;
20+
volatile const int basescaledivider=5;// Divides the main interrupt frequency. Main interrupt is triggere 5 times per second, divided freq is 1 per second
21+
volatile int countwme=0; //Cycle counter
22+
int dpsensor;
23+
double p; //Static Pressure
24+
AirSensor AirDataSensor(1);
25+
AirDC AirDataComputer(1);
26+
27+
void setup() {
28+
//Common Init
29+
pinMode(ledPin, OUTPUT);
30+
Serial.begin(9600);
31+
//Sensor Specific
32+
#if DPSENSOR==1
33+
dpsensor = 1;
34+
Wire.begin();
35+
#endif
36+
#if DPSENSOR==2
37+
dpsensor = 2;
38+
int cs = 10;
39+
pinMode (cs, OUTPUT);
40+
SPI.begin();
41+
SPI.setBitOrder(MSBFIRST);
42+
#endif
43+
#if DPSENSOR==3
44+
dpsensor = 3;
45+
#endif
46+
//Interrupt Specific
47+
// Time 1 by compare setup
48+
noInterrupts(); // disable all interrupts
49+
TCCR1A = 0;
50+
TCCR1B = 0;
51+
TCNT1 = 0;
52+
OCR1A = 12500; // Desired Frequency 5 Hz OCR1A = 16000000/256/5
53+
TCCR1B |= (1 << WGM12); // CTC mode
54+
TCCR1B |= (1 << CS12); // 256 prescaler
55+
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
56+
interrupts(); // enable all interrupts
57+
}
58+
//Interrupt Handler
59+
ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
60+
{
61+
countwme ++; //Frequency divider variable
62+
AirDC *ptrAirDC;
63+
ptrAirDC = &AirDataComputer;
64+
noInterrupts();
65+
AirDataSensor.ReadDifferentialPressure(ptrAirDC, dpsensor);
66+
interrupts();
67+
if (countwme==basescaledivider){
68+
noInterrupts();
69+
digitalWrite(ledPin, digitalRead(ledPin) ^ 1); // toggle LED pin
70+
AirDataComputer.IAS(1);// Calculates the IAS, Algorithm 1
71+
AirDataComputer.RhoAir(1);// Calculates the air density, Algorithm 1
72+
countwme=0;
73+
interrupts();
74+
}
75+
76+
}
77+
78+
void loop() {
79+
delay(1500); //loop delay
80+
Serial.println(dpsensor); //Sends the Selected sensor
81+
Serial.println(AirDataComputer._qc); //Sends the differential pressure reading
82+
Serial.println(AirDataComputer._uqc, 10); //Sends the uncertainty of differential pressure measurement
83+
Serial.println(AirDataComputer._IAS);//Sends the indicated Airspeed
84+
Serial.println(AirDataComputer._uIAS, 10); //Sends the uncertainty of IAS measurement
85+
Serial.println(AirDataComputer._Rho);//Sends the density of Air
86+
Serial.println(AirDataComputer._uRho, 10); //Sends the uncertainty of the density of air
87+
}

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

Lines changed: 0 additions & 25 deletions
This file was deleted.

Software/Arduino/Libraries/AirDC/Examples/WithSensors/PressureSensor.ino

Lines changed: 0 additions & 33 deletions
This file was deleted.

Software/Arduino/Libraries/AirDC/Examples/WithoutSensors/Minimal.ino

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)