initial commit before ownership transfer
This commit is contained in:
91
code/toni/BarometerSensorReader.h
Executable file
91
code/toni/BarometerSensorReader.h
Executable file
@@ -0,0 +1,91 @@
|
||||
#pragma once
|
||||
|
||||
#include "circular.h"
|
||||
#include "BarometerObservation.h"
|
||||
#include "../SensorReader.h"
|
||||
#include <sstream>
|
||||
|
||||
//circular_buffer<double> measurementHistory(1000);
|
||||
|
||||
|
||||
class BarometerSensorReader{
|
||||
|
||||
private:
|
||||
circular_buffer<double> measurementHistory;
|
||||
|
||||
public:
|
||||
|
||||
BarometerSensorReader(){
|
||||
if(!USE_STATIC_CIRCULAR_BUFFERING){
|
||||
//8.33min
|
||||
measurementHistory.reserve(10000);
|
||||
}
|
||||
else{
|
||||
//30 * 500ms = 1,5s
|
||||
measurementHistory.reserve(30);
|
||||
}
|
||||
}
|
||||
|
||||
BarometerObservation* readBarometer(const SensorEntry& se) {
|
||||
|
||||
std::string tmp = se.data;
|
||||
BarometerObservation* obs = new BarometerObservation();
|
||||
|
||||
//Read the hPa
|
||||
double hPa = stod(tmp);
|
||||
|
||||
// load the measurement at current time into the history
|
||||
double currentMeasurement = hPa - measurementHistory[0];
|
||||
|
||||
if(USE_BAROMETER_SMOOTHING_RC_LOWPASS){
|
||||
|
||||
//smoothing with alpha value
|
||||
if(measurementHistory.size() > 1){
|
||||
double alpha = 0.1;
|
||||
double lastMeasurement = measurementHistory[measurementHistory.size() - 1];
|
||||
currentMeasurement = (alpha * currentMeasurement) + ((1.0 - alpha) * lastMeasurement);
|
||||
|
||||
obs->hpa = currentMeasurement;
|
||||
}else{
|
||||
obs->hpa = 0;
|
||||
}
|
||||
|
||||
measurementHistory.push_back(currentMeasurement);
|
||||
}
|
||||
else if (USE_BAROMETER_SMOOTHING_HEAD_TAIL){
|
||||
|
||||
currentMeasurement = hPa;
|
||||
measurementHistory.push_back(currentMeasurement);
|
||||
|
||||
// calculate the relative air pressure by getting the mean of the first and last three entrys of the history
|
||||
// and subtract them.
|
||||
if (measurementHistory.size() > 5){
|
||||
double meanTail = (measurementHistory[0] + measurementHistory[1] + measurementHistory[2]) / 3.0;
|
||||
double meanHead = (measurementHistory[measurementHistory.size() - 1] + measurementHistory[measurementHistory.size() - 2] + measurementHistory[measurementHistory.size() - 3]) / 3.0;
|
||||
|
||||
obs->hpa = meanHead - meanTail;
|
||||
}
|
||||
else{
|
||||
obs->hpa = 0;
|
||||
}
|
||||
}
|
||||
else //no data smoothing
|
||||
{
|
||||
measurementHistory.push_back(currentMeasurement);
|
||||
obs->hpa = currentMeasurement;
|
||||
}
|
||||
|
||||
return obs;
|
||||
|
||||
}
|
||||
|
||||
//TODO
|
||||
void readVerticalAcceleration(const SensorEntry& se){
|
||||
|
||||
//Problem: Koordinatensystem LinearAcceleraton ist relativ zum Telefon und nicht zum
|
||||
//Weltkoordinatensystem. Brauchen die Beschleunigung nach Oben in Weltkoordinaten.
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user