This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Fusion2016/code/toni/BarometerSensorReader.h
FrankE cc899d1c46 updates the visualisation
removed obsolte parts
fixed baromter stuff
worked on eval
added ground-truth
2016-01-30 19:50:58 +01:00

107 lines
2.9 KiB
C++
Executable File

#pragma once
#include "circular.h"
#include "BarometerObservation.h"
#include "../reader/SensorReader.h"
#include <sstream>
#include <Indoor/math/MovingAVG.h>
//circular_buffer<double> measurementHistory(1000);
class BarometerSensorReader{
private:
// circular_buffer<double> measurementHistory;
MovingAVG<float> avg;
public:
BarometerSensorReader(): avg(3) {
// 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();
// get the next hPa reading and average it
avg.add(stod(tmp));
const double hPa = avg.get();
// everything realtive to the first measurement
static double first_hPa = 0;
if (avg.getNumUsed() < avg.getSize()) {first_hPa = avg.get();}
obs->hpa = hPa - first_hPa;
std::cout << obs->hpa << std::endl;
// done
return obs;
// 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.
}
};