Merge branch 'master' of https://git.frank-ebner.de/FHWS/Indoor
This commit is contained in:
@@ -11,13 +11,20 @@
|
||||
#include "../../math/MovingAverageTS.h"
|
||||
#include "../../math/MovingStdDevTS.h"
|
||||
|
||||
#include "../../data/HistoryTS.h"
|
||||
|
||||
#include "../activity/Activity.h"
|
||||
|
||||
//#define ACT_DET_DEBUG_PLOT
|
||||
|
||||
#ifdef ACT_DET_DEBUG_PLOT
|
||||
#include <KLib/misc/gnuplot/Gnuplot.h>
|
||||
#include <KLib/misc/gnuplot/GnuplotSplot.h>
|
||||
#include <KLib/misc/gnuplot/GnuplotSplotElementLines.h>
|
||||
#include <KLib/misc/gnuplot/GnuplotPlot.h>
|
||||
#include <KLib/misc/gnuplot/GnuplotPlotElementLines.h>
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* simple step detection based on accelerometer magnitude.
|
||||
@@ -37,50 +44,49 @@ private:
|
||||
MovingAverageTS<float> baroAvgSlow;
|
||||
MovingAverageTS<float> baroAvgFast;
|
||||
|
||||
MovingAverageTS<float> baroAvg;
|
||||
HistoryTS<float> baroHistory;
|
||||
|
||||
Activity current;
|
||||
|
||||
public:
|
||||
|
||||
#ifdef ACT_DET_DEBUG_PLOT
|
||||
K::Gnuplot gp;
|
||||
K::GnuplotPlot gplot;
|
||||
K::GnuplotPlotElementLines l1;
|
||||
K::GnuplotPlotElementLines l2;
|
||||
#endif
|
||||
|
||||
/** ctor */
|
||||
ActivityDetector() : avgLong(Timestamp::fromMS(1500), 0), avgShort(Timestamp::fromMS(500), 0),
|
||||
stdDev(Timestamp::fromMS(200), 0), stdDev2(Timestamp::fromMS(2000), 0) {
|
||||
stdDev(Timestamp::fromMS(150), 0), stdDev2(Timestamp::fromMS(2000), 0),
|
||||
baroAvg(Timestamp::fromMS(500), 0), baroHistory(Timestamp::fromMS(4000)) {
|
||||
;
|
||||
gplot.add(&l1);
|
||||
gplot.add(&l2); l2.getStroke().getColor().setHexStr("#ff0000");
|
||||
|
||||
#ifdef ACT_DET_DEBUG_PLOT
|
||||
gplot.add(&l1);
|
||||
gplot.add(&l2); l2.getStroke().getColor().setHexStr("#ff0000");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
//int xx = 0;
|
||||
|
||||
/** add barometer data */
|
||||
void add(const Timestamp ts, const BarometerData& baro) {
|
||||
if (baro.isValid()) {
|
||||
baroAvgSlow.add(ts, baro.hPa);
|
||||
baroAvgFast.add(ts, baro.hPa);
|
||||
baroAvg.add(ts, baro.hPa);
|
||||
const float avg = baroAvg.get();
|
||||
baroHistory.add(ts, avg);
|
||||
//l1.add(K::GnuplotPoint2(xx, avg));
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
Activity get() {
|
||||
|
||||
// delta in acceleration
|
||||
const float delta_acc = std::abs(avgLong.get() - avgShort.get());
|
||||
|
||||
if (delta_acc < 0.3) {
|
||||
return Activity::STANDING;
|
||||
}
|
||||
|
||||
// delta in pressure
|
||||
const float delta_hPa = baroAvgFast.get() - baroAvgSlow.get();
|
||||
|
||||
if (std::abs(delta_hPa) < 0.1) {
|
||||
return Activity::WALKING;
|
||||
} else if (delta_hPa > 0) {
|
||||
return Activity::WALKING_DOWN;
|
||||
} else {
|
||||
return Activity::WALKING_UP;
|
||||
}
|
||||
|
||||
/** get the currently detected activity */
|
||||
Activity get() const {
|
||||
return current;
|
||||
}
|
||||
|
||||
/** does the given data indicate a step? */
|
||||
@@ -96,13 +102,6 @@ public:
|
||||
|
||||
// static int x = 0; ++x;
|
||||
|
||||
//// if (x % 10 == 0) {
|
||||
//// l1.add({x, avgLong.get()});
|
||||
//// l2.add({x, avgShort.get()});
|
||||
//// gp.draw(gplot);
|
||||
//// gp.flush();
|
||||
//// }
|
||||
|
||||
// if (delta < 0.3) {
|
||||
// return Activity::STANDING;
|
||||
// }
|
||||
@@ -118,8 +117,41 @@ public:
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/** estimate the current activity based on the sensor data */
|
||||
void update() {
|
||||
|
||||
// delta in acceleration
|
||||
const float delta_acc = std::abs(avgLong.get() - avgShort.get());
|
||||
|
||||
if (delta_acc < 0.015) {
|
||||
current = Activity::STANDING;
|
||||
return;
|
||||
}
|
||||
|
||||
// delta in pressure
|
||||
const float delta_hPa = baroHistory.getMostRecent() - baroHistory.getOldest();
|
||||
|
||||
#ifdef ACT_DET_DEBUG_PLOT
|
||||
l2.add(K::GnuplotPoint2(xx, delta_hPa));
|
||||
gp.draw(gplot);
|
||||
gp.flush();
|
||||
++xx;
|
||||
#endif
|
||||
|
||||
if (std::abs(delta_hPa) < 0.042) {
|
||||
current = Activity::WALKING;
|
||||
return;
|
||||
} else if (delta_hPa > 0) {
|
||||
current = Activity::WALKING_DOWN;
|
||||
return;
|
||||
} else {
|
||||
current = Activity::WALKING_UP;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user