huge commit
- worked on about everything - grid walker using plugable modules - wifi models - new distributions - worked on geometric data-structures - added typesafe timestamps - worked on grid-building - added sensor-classes - added sensor analysis (step-detection, turn-detection) - offline data reader - many test-cases
This commit is contained in:
@@ -59,7 +59,7 @@ public:
|
||||
|
||||
}
|
||||
|
||||
/** convert to hex-string ("xx:xx:xx:xx:xx:xx") */
|
||||
/** convert to lower-case hex-string ("xx:xx:xx:xx:xx:xx") */
|
||||
std::string asString() const {
|
||||
|
||||
std::string str = ":::::::::::::::::";
|
||||
@@ -85,6 +85,11 @@ public:
|
||||
return o.asLong() == asLong();
|
||||
}
|
||||
|
||||
/** not equal? */
|
||||
bool operator != (const MACAddress& o) const {
|
||||
return o.asLong() != asLong();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** convert the given hex char [0-F] to an integer [0-15] */
|
||||
|
||||
23
sensors/imu/AccelerometerData.h
Normal file
23
sensors/imu/AccelerometerData.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef ACCELEROMETERDATA_H
|
||||
#define ACCELEROMETERDATA_H
|
||||
|
||||
#include <cmath>
|
||||
|
||||
/** data received from an accelerometer sensor */
|
||||
struct AccelerometerData {
|
||||
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
|
||||
AccelerometerData() : x(0), y(0), z(0) {;}
|
||||
|
||||
AccelerometerData(const float x, const float y, const float z) : x(x), y(y), z(z) {;}
|
||||
|
||||
float magnitude() const {
|
||||
return std::sqrt( x*x + y*y + z*z );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // ACCELEROMETERDATA_H
|
||||
23
sensors/imu/GyroscopeData.h
Normal file
23
sensors/imu/GyroscopeData.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef GYROSCOPEDATA_H
|
||||
#define GYROSCOPEDATA_H
|
||||
|
||||
#include <cmath>
|
||||
|
||||
/** data received from a gyroscope sensor */
|
||||
struct GyroscopeData {
|
||||
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
|
||||
GyroscopeData() : x(0), y(0), z(0) {;}
|
||||
|
||||
GyroscopeData(const float x, const float y, const float z) : x(x), y(y), z(z) {;}
|
||||
|
||||
float magnitude() const {
|
||||
return std::sqrt( x*x + y*y + z*z );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // GYROSCOPEDATA_H
|
||||
112
sensors/imu/StepDetection.h
Normal file
112
sensors/imu/StepDetection.h
Normal file
@@ -0,0 +1,112 @@
|
||||
#ifndef STEPDETECTION_H
|
||||
#define STEPDETECTION_H
|
||||
|
||||
|
||||
#include "AccelerometerData.h"
|
||||
#include "../../data/Timestamp.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
#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>
|
||||
|
||||
|
||||
#include "../../Assertions.h"
|
||||
|
||||
|
||||
/**
|
||||
* simple step detection based on accelerometer magnitude.
|
||||
* magnitude > threshold? -> step!
|
||||
* block for several msec until detecting the next one
|
||||
*/
|
||||
class StepDetection {
|
||||
|
||||
private:
|
||||
|
||||
/** low pass acc-magnitude */
|
||||
float avg1 = 0;
|
||||
|
||||
/** even-more low-pass acc-magnitude */
|
||||
float avg2 = 0;
|
||||
|
||||
private:
|
||||
|
||||
class Stepper {
|
||||
|
||||
private:
|
||||
|
||||
/** block for 300 ms after every step */
|
||||
const Timestamp blockTime = Timestamp::fromMS(300);
|
||||
|
||||
/** the threshold for detecting a spike as step */
|
||||
const float threshold = 0.17;
|
||||
|
||||
/** block until the given timestamp before detecting additional steps */
|
||||
Timestamp blockUntil;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** is the given (relative!) magnitude (mag - ~9.81) a step? */
|
||||
bool isStep(const Timestamp ts, const float mag) {
|
||||
|
||||
// still blocking
|
||||
if (ts < blockUntil) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// threshold reached? -> step!
|
||||
if (mag > threshold) {
|
||||
|
||||
// block x milliseconds until detecting the next step
|
||||
blockUntil = ts + blockTime;
|
||||
|
||||
// we have a step
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
// no step
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
Stepper stepper;
|
||||
|
||||
public:
|
||||
|
||||
/** does the given data indicate a step? */
|
||||
bool isStep(const Timestamp ts, const AccelerometerData& acc) {
|
||||
|
||||
avg1 = avg1 * 0.91 + acc.magnitude() * 0.09; // short-time average [filtered steps]
|
||||
avg2 = avg2 * 0.97 + acc.magnitude() * 0.03; // long-time average [gravity]
|
||||
|
||||
// average maginitude must be > 9.0 to be stable enough to proceed
|
||||
if (avg2 > 9) {
|
||||
|
||||
// gravity-free magnitude
|
||||
const float avg = avg1 - avg2;
|
||||
|
||||
// detect steps
|
||||
return stepper.isStep(ts, avg);
|
||||
|
||||
} else {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // STEPDETECTION_H
|
||||
493
sensors/imu/TurnDetection.h
Normal file
493
sensors/imu/TurnDetection.h
Normal file
@@ -0,0 +1,493 @@
|
||||
#ifndef TURNDETECTION_H
|
||||
#define TURNDETECTION_H
|
||||
|
||||
#include "GyroscopeData.h"
|
||||
#include "AccelerometerData.h"
|
||||
#include "../../data/Timestamp.h"
|
||||
|
||||
#include <eigen3/Eigen/Dense>
|
||||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
#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>
|
||||
|
||||
|
||||
#include "../../Assertions.h"
|
||||
|
||||
class TurnDetection {
|
||||
|
||||
private:
|
||||
|
||||
//std::vector<AccelerometerData> accData;
|
||||
std::vector<GyroscopeData> gyroData;
|
||||
|
||||
Timestamp lastGyro;
|
||||
Timestamp lastRotMatEst;
|
||||
|
||||
Eigen::Matrix3f rotMat;
|
||||
Eigen::Vector3f avgAcc;
|
||||
|
||||
Eigen::Vector3f leGyro;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
TurnDetection() : rotMat(Eigen::Matrix3f::Identity()) {
|
||||
|
||||
}
|
||||
|
||||
float addGyroscope(const Timestamp& ts, const GyroscopeData& gyro) {
|
||||
|
||||
if (lastGyro.isZero()) {lastGyro = ts;}
|
||||
|
||||
|
||||
// TESTING!
|
||||
gyroData.push_back(gyro);
|
||||
static Eigen::Matrix3f rotMat = Eigen::Matrix3f::Identity();
|
||||
if (gyroData.size() > 25) {
|
||||
Eigen::Vector3f sum = Eigen::Vector3f::Zero();
|
||||
int cnt = 0;
|
||||
for (GyroscopeData gd : gyroData) {
|
||||
//if (gd.z > gd.x && gd.z > gd.y) {
|
||||
Eigen::Vector3f vec; vec << (gd.x), (gd.y), (gd.z);
|
||||
sum += vec;
|
||||
++cnt;
|
||||
//}
|
||||
}
|
||||
gyroData.clear();
|
||||
if (cnt > 10) {
|
||||
Eigen::Vector3f z; z << 0,0, sum(2) < 0 ? -1 : +1;
|
||||
rotMat = getRotationMatrix(sum.normalized(), z.normalized());
|
||||
}
|
||||
}
|
||||
|
||||
// current gyro-reading as vector
|
||||
Eigen::Vector3f vec; vec << gyro.x, gyro.y, gyro.z;
|
||||
leGyro = vec;
|
||||
|
||||
// current value, rotated into the new coordinate system
|
||||
Eigen::Vector3f curVec = rotMat * vec;
|
||||
|
||||
// previous value
|
||||
static Eigen::Vector3f oldVec = curVec;
|
||||
|
||||
// time-difference between previous and current value
|
||||
const Timestamp diff = ts - lastGyro;
|
||||
lastGyro = ts;
|
||||
|
||||
// area
|
||||
Eigen::Vector3f area = Eigen::Vector3f::Zero();
|
||||
if (!diff.isZero()) {
|
||||
area = (oldVec * diff.sec()) + // squared region
|
||||
((curVec - oldVec) * 0.5 * diff.sec()); // triangle region to the next (enhances the quality)
|
||||
}
|
||||
|
||||
// update the old value
|
||||
oldVec = curVec;
|
||||
|
||||
const float delta = area(2);// * 0.8;
|
||||
|
||||
|
||||
|
||||
|
||||
static int i = 0; ++i;
|
||||
if (i % 50 == 0) {
|
||||
|
||||
static K::Gnuplot gp;
|
||||
|
||||
gp << "set view equal xyz\n";
|
||||
gp << "set xrange[-1:+1]\n";
|
||||
gp << "set yrange[-1:+1]\n";
|
||||
gp << "set zrange[-1:+1]\n";
|
||||
|
||||
K::GnuplotSplot plot;
|
||||
K::GnuplotSplotElementLines lines; plot.add(&lines);
|
||||
|
||||
K::GnuplotPoint3 p0(0,0,0);
|
||||
//K::GnuplotPoint3 pO(vec(0), vec(1), vec(2));
|
||||
|
||||
K::GnuplotPoint3 px(rotMat(0,0), rotMat(1,0), rotMat(2,0)); //px = px * eval(0);
|
||||
K::GnuplotPoint3 py(rotMat(0,1), rotMat(1,1), rotMat(2,1)); //py = py * eval(1);
|
||||
K::GnuplotPoint3 pz(rotMat(0,2), rotMat(1,2), rotMat(2,2)); //pz = pz * eval(2);
|
||||
|
||||
lines.addSegment(p0, px*0.15);
|
||||
lines.addSegment(p0, py*0.4);
|
||||
lines.addSegment(p0, pz*1.0);
|
||||
|
||||
Eigen::Vector3f ori = leGyro;
|
||||
Eigen::Vector3f re = rotMat * leGyro;
|
||||
Eigen::Vector3f avg = est.lastAvg * 0.3;
|
||||
|
||||
gp << "set arrow 1 from 0,0,0 to " << avg(0) << "," << avg(1) << "," << avg(2) << " lw 2\n";
|
||||
|
||||
gp << "set arrow 2 from 0,0,0 to " << ori(0) << "," << ori(1) << "," << ori(2) << " lw 1 dashtype 2 \n";
|
||||
gp << "set arrow 3 from 0,0,0 to " << re(0) << "," << re(1) << "," << re(2) << " lw 1\n";
|
||||
|
||||
// gp << "set arrow 2 from 0,0,0 to " << vec(0) << "," << vec(1) << "," << vec(2) << "\n";
|
||||
// gp << "set arrow 3 from 0,0,0 to " << nVec(0) << "," << nVec(1) << "," << nVec(2) << "\n";
|
||||
|
||||
gp.draw(plot);
|
||||
//gp.flush();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static Eigen::Vector3f sum = Eigen::Vector3f::Zero();
|
||||
sum += area;
|
||||
|
||||
if (i % 30 == 0) {
|
||||
|
||||
static int idx = 0;
|
||||
static K::Gnuplot gp2;
|
||||
gp2 << "set arrow 1 from 0,0 to 10000,0\n";
|
||||
gp2 << "set arrow 2 from 0,5 to 10000,5\n";
|
||||
gp2 << "set arrow 3 from 0,10 to 10000,10\n";
|
||||
|
||||
K::GnuplotPlot plot2;
|
||||
static K::GnuplotPlotElementLines linesX; plot2.add(&linesX);
|
||||
static K::GnuplotPlotElementLines linesY; plot2.add(&linesY);
|
||||
static K::GnuplotPlotElementLines linesZ; plot2.add(&linesZ);
|
||||
|
||||
//linesX.add(K::GnuplotPoint2(idx, sum(0) + 0));
|
||||
//linesY.add(K::GnuplotPoint2(idx, sum(1) + 5));
|
||||
linesZ.add(K::GnuplotPoint2(idx, sum(2) + 10));
|
||||
++idx;
|
||||
|
||||
gp2.draw(plot2);
|
||||
//gp2.flush();
|
||||
|
||||
}
|
||||
|
||||
return delta;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void addAccelerometer(const Timestamp& ts, const AccelerometerData& acc) {
|
||||
|
||||
// add accelerometer data
|
||||
//pca.add(std::abs(acc.x), std::abs(acc.y), std::abs(acc.z));
|
||||
est.add((acc.x), (acc.y), (acc.z));
|
||||
|
||||
// start with the first available timestamp
|
||||
if (lastRotMatEst.isZero()) {lastRotMatEst = ts;}
|
||||
|
||||
// if we have at-least 1 sec of acc-data, re-calculate the current smartphone holding
|
||||
if (ts - lastRotMatEst > Timestamp::fromMS(500)) {
|
||||
rotMat = est.get();
|
||||
lastRotMatEst = ts;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// /** estimate the smartphones current holding position */
|
||||
// void estimateHolding2() {
|
||||
|
||||
|
||||
// // z-axis points through the device and is the axis we are interested in
|
||||
// // http://www.kircherelectronics.com/blog/index.php/11-android/sensors/15-android-gyroscope-basics
|
||||
|
||||
// avgAcc = Eigen::Vector3f::Zero();
|
||||
|
||||
// for (const AccelerometerData& acc : accData) {
|
||||
// //for (const GyroscopeData& acc : gyroData) {
|
||||
// Eigen::Vector3f vec; vec << std::abs(acc.x), std::abs(acc.y), std::abs(acc.z);
|
||||
// // Eigen::Vector3f vec; vec << std::abs(acc.x), std::abs(acc.y), std::abs(acc.z);
|
||||
// avgAcc += vec;
|
||||
// }
|
||||
|
||||
// //avgAcc /= accData.size();
|
||||
// avgAcc = avgAcc.normalized();
|
||||
|
||||
// Eigen::Vector3f rev; rev << 0,0,1;
|
||||
|
||||
// rotMat = getRotationMatrix(avgAcc, rev);
|
||||
|
||||
|
||||
// //Assert::isTrue(avgAcc(2) > avgAcc(0), "z is not the gravity axis");
|
||||
// //Assert::isTrue(avgAcc(2) > avgAcc(1), "z is not the gravity axis");
|
||||
//// Eigen::Vector3f re = rotMat * avgAcc;
|
||||
//// Eigen::Vector3f diff = rev-re;
|
||||
//// Assert::isTrue(diff.norm() < 0.001, "rotation error");
|
||||
|
||||
// }
|
||||
|
||||
public:
|
||||
|
||||
/** get a matrix that rotates the vector "from" into the vector "to" */
|
||||
static Eigen::Matrix3f getRotationMatrix(const Eigen::Vector3f& from, const Eigen::Vector3f to) {
|
||||
|
||||
// http://math.stackexchange.com/questions/293116/rotating-one-3d-vector-to-another
|
||||
|
||||
const Eigen::Vector3f x = from.cross(to) / from.cross(to).norm();
|
||||
const float angle = std::acos( from.dot(to) / from.norm() / to.norm() );
|
||||
|
||||
Eigen::Matrix3f A; A <<
|
||||
0, -x(2), x(1),
|
||||
x(2), 0, -x(0),
|
||||
-x(1), x(0), 0;
|
||||
|
||||
return Eigen::Matrix3f::Identity() + (std::sin(angle) * A) + ((1-std::cos(angle)) * (A*A));
|
||||
|
||||
}
|
||||
|
||||
|
||||
struct XYZ {
|
||||
|
||||
Eigen::Vector3f lastAvg;
|
||||
Eigen::Vector3f avg;
|
||||
int cnt;
|
||||
|
||||
XYZ() {
|
||||
reset();
|
||||
}
|
||||
|
||||
void add(const float x, const float y, const float z) {
|
||||
|
||||
Eigen::Vector3f vec; vec << x,y,z;
|
||||
avg += vec;
|
||||
++cnt;
|
||||
|
||||
}
|
||||
|
||||
Eigen::Matrix3f get() {
|
||||
|
||||
avg/= cnt;
|
||||
lastAvg = avg;
|
||||
|
||||
// rotate average accelerometer into (0,0,1)
|
||||
Eigen::Vector3f zAxis; zAxis << 0, 0, 1;
|
||||
const Eigen::Matrix3f rotMat = getRotationMatrix(avg.normalized(), zAxis);
|
||||
|
||||
// sanity check
|
||||
Eigen::Vector3f aligned = (rotMat * avg).normalized();
|
||||
Assert::isTrue((aligned-zAxis).norm() < 0.1f, "deviation too high");
|
||||
|
||||
reset();
|
||||
|
||||
return rotMat;
|
||||
|
||||
}
|
||||
|
||||
void reset() {
|
||||
cnt = 0;
|
||||
avg = Eigen::Vector3f::Zero();
|
||||
}
|
||||
|
||||
|
||||
} est;
|
||||
|
||||
|
||||
// struct RotationMatrixEstimationUsingAccAngle {
|
||||
|
||||
// Eigen::Vector3f lastAvg;
|
||||
// Eigen::Vector3f avg;
|
||||
// int cnt;
|
||||
|
||||
// RotationMatrixEstimationUsingAccAngle() {
|
||||
// reset();
|
||||
// }
|
||||
|
||||
// void add(const float x, const float y, const float z) {
|
||||
|
||||
// Eigen::Vector3f vec; vec << x,y,z;
|
||||
// avg += vec;
|
||||
// ++cnt;
|
||||
|
||||
// }
|
||||
|
||||
// void reset() {
|
||||
// cnt = 0;
|
||||
// avg = Eigen::Vector3f::Zero();
|
||||
// }
|
||||
|
||||
// Eigen::Matrix3f get() {
|
||||
|
||||
// // http://www.hobbytronics.co.uk/accelerometer-info
|
||||
|
||||
// avg /= cnt;
|
||||
// lastAvg = avg;
|
||||
|
||||
// //const float mag = avg.norm();
|
||||
|
||||
// const float baseX = 0;
|
||||
// const float baseY = 0;
|
||||
// const float baseZ = 0; // mag?
|
||||
|
||||
// const float x = avg(0) - baseX;
|
||||
// const float y = avg(1) - baseY;
|
||||
// const float z = avg(2) - baseZ;
|
||||
|
||||
// const float ax = std::atan( x / (std::sqrt(y*y + z*z)) );
|
||||
// const float ay = std::atan( y / (std::sqrt(x*x + z*z)) );
|
||||
|
||||
// const Eigen::Matrix3f rotMat = getRotation(ay, -ax, 0); // TODO -ax or +ax?
|
||||
|
||||
// // sanity check
|
||||
// Eigen::Vector3f zAxis; zAxis << 0, 0, 1;
|
||||
// Eigen::Vector3f aligned = (rotMat * avg).normalized();
|
||||
// Assert::isTrue((aligned-zAxis).norm() < 0.1f, "deviation too high");
|
||||
// // int i = 0; (void) i;
|
||||
|
||||
// reset();
|
||||
// return rotMat;
|
||||
|
||||
// }
|
||||
|
||||
// } est;
|
||||
|
||||
|
||||
/** get a rotation matrix for the given x,y,z rotation (in radians) */
|
||||
static Eigen::Matrix3f getRotation(const float x, const float y, const float z) {
|
||||
const float g = x; const float b = y; const float a = z;
|
||||
const float a11 = std::cos(a)*std::cos(b);
|
||||
const float a12 = std::cos(a)*std::sin(b)*std::sin(g)-std::sin(a)*std::cos(g);
|
||||
const float a13 = std::cos(a)*std::sin(b)*std::cos(g)+std::sin(a)*std::sin(g);
|
||||
const float a21 = std::sin(a)*std::cos(b);
|
||||
const float a22 = std::sin(a)*std::sin(b)*std::sin(g)+std::cos(a)*std::cos(g);
|
||||
const float a23 = std::sin(a)*std::sin(b)*std::cos(g)-std::cos(a)*std::sin(g);
|
||||
const float a31 = -std::sin(b);
|
||||
const float a32 = std::cos(b)*std::sin(g);
|
||||
const float a33 = std::cos(b)*std::cos(g);
|
||||
Eigen::Matrix3f m;
|
||||
m <<
|
||||
a11, a12, a13,
|
||||
a21, a22, a23,
|
||||
a31, a32, a33;
|
||||
;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
// struct PCA {
|
||||
|
||||
// Eigen::Vector3f avg;
|
||||
// Eigen::Vector3f lastAvg;
|
||||
// Eigen::Matrix3f covar;
|
||||
// int cnt = 0;
|
||||
|
||||
// PCA() {
|
||||
// reset();
|
||||
// }
|
||||
|
||||
// void add(const float x, const float y, const float z) {
|
||||
|
||||
// Eigen::Vector3f vec; vec << x,y,z;
|
||||
// avg += vec;
|
||||
// covar += vec*vec.transpose();
|
||||
// ++cnt;
|
||||
|
||||
// }
|
||||
|
||||
// Eigen::Matrix3f get() {
|
||||
|
||||
// avg /= cnt;
|
||||
// covar /= cnt;
|
||||
// lastAvg = avg;
|
||||
|
||||
// std::cout << avg << std::endl;
|
||||
|
||||
// Eigen::Matrix3f Q = covar;// - avg*avg.transpose();
|
||||
// for (int i = 0; i < 9; ++i) {Q(i) = std::abs(Q(i));}
|
||||
|
||||
// Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> solver(Q);
|
||||
// solver.eigenvalues();
|
||||
// solver.eigenvectors();
|
||||
|
||||
// const auto eval = solver.eigenvalues();
|
||||
// const auto evec = solver.eigenvectors();
|
||||
// Assert::isTrue(eval(2) > eval(1) && eval(1) > eval(0), "eigenvalues are not sorted!");
|
||||
|
||||
// Eigen::Matrix3f rotMat;
|
||||
// rotMat.col(0) = evec.col(0);
|
||||
// rotMat.col(1) = evec.col(1);
|
||||
// rotMat.col(2) = evec.col(2); // 0,0,1 (z-axis) belongs to the strongest eigenvalue
|
||||
// rotMat.transposeInPlace();
|
||||
|
||||
// //Eigen::Vector3f gy; gy << 0, 30, 30;
|
||||
// Eigen::Vector3f avg1 = rotMat * avg;
|
||||
// int i = 0; (void) i;
|
||||
|
||||
// reset();
|
||||
|
||||
// return rotMat;
|
||||
|
||||
// }
|
||||
|
||||
// void reset() {
|
||||
// cnt = 0;
|
||||
// avg = Eigen::Vector3f::Zero();
|
||||
// covar = Eigen::Matrix3f::Zero();
|
||||
// }
|
||||
|
||||
|
||||
// } pca1;
|
||||
|
||||
|
||||
|
||||
|
||||
// /** estimate the smartphones current holding position */
|
||||
// void estimateHolding() {
|
||||
|
||||
// Eigen::Vector3f avg = Eigen::Vector3f::Zero();
|
||||
// Eigen::Matrix3f covar = Eigen::Matrix3f::Zero();
|
||||
|
||||
// for (const AccelerometerData& acc : accData) {
|
||||
//// for (const GyroscopeData& acc : gyroData) {
|
||||
// Eigen::Vector3f vec; vec << std::abs(acc.x), std::abs(acc.y), std::abs(acc.z);
|
||||
//// Eigen::Vector3f vec; vec << (acc.x), (acc.y), (acc.z);
|
||||
// avg += vec;
|
||||
// covar += vec * vec.transpose();
|
||||
// }
|
||||
|
||||
// avg /= accData.size(); // TODO
|
||||
// covar /= accData.size(); //TODO
|
||||
|
||||
// avgAcc = avg.normalized();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//// static K::Gnuplot gp;
|
||||
//// gp << "set view equal xyz\n";
|
||||
//// gp << "set xrange[-1:+1]\n";
|
||||
//// gp << "set yrange[-1:+1]\n";
|
||||
//// gp << "set zrange[-1:+1]\n";
|
||||
|
||||
//// K::GnuplotSplot plot;
|
||||
//// K::GnuplotSplotElementLines lines; plot.add(&lines);
|
||||
|
||||
//// K::GnuplotPoint3 p0(0,0,0);
|
||||
//// K::GnuplotPoint3 px(evec(0,0), evec(1,0), evec(2,0)); //px = px * eval(0);
|
||||
//// K::GnuplotPoint3 py(evec(0,1), evec(1,1), evec(2,1)); //py = py * eval(1);
|
||||
//// K::GnuplotPoint3 pz(evec(0,2), evec(1,2), evec(2,2)); //pz = pz * eval(2);
|
||||
|
||||
//// K::GnuplotPoint3 pa(avg(0), avg(1), avg(2));
|
||||
|
||||
//// lines.addSegment(p0, px);
|
||||
//// lines.addSegment(p0, py);
|
||||
//// lines.addSegment(p0, pz);
|
||||
//// lines.addSegment(p0, pa);
|
||||
|
||||
//// gp.draw(plot);
|
||||
//// gp.flush();
|
||||
|
||||
// }
|
||||
|
||||
};
|
||||
|
||||
#endif // TURNDETECTION_H
|
||||
200
sensors/offline/OfflineAndroid.h
Normal file
200
sensors/offline/OfflineAndroid.h
Normal file
@@ -0,0 +1,200 @@
|
||||
#ifndef OFFLINEANDROID_H
|
||||
#define OFFLINEANDROID_H
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include "../../Assertions.h"
|
||||
#include "../../math/Interpolator.h"
|
||||
#include "../../geo/Point3.h"
|
||||
#include "../../data/Timestamp.h"
|
||||
#include "../radio/WiFiMeasurements.h"
|
||||
|
||||
template <typename SensorData> struct OfflineEntry {
|
||||
|
||||
Timestamp ts;
|
||||
SensorData data;
|
||||
|
||||
/** ctor */
|
||||
OfflineEntry(const Timestamp ts, const SensorData& data) : ts(ts), data(data) {;}
|
||||
|
||||
};
|
||||
|
||||
struct GroundTruthID {
|
||||
int id;
|
||||
GroundTruthID() {;}
|
||||
GroundTruthID(const int id) : id(id) {;}
|
||||
};
|
||||
|
||||
struct WalkedPath {
|
||||
std::vector<Point3> pos_cm;
|
||||
};
|
||||
|
||||
|
||||
/** read recorded android sensor data files */
|
||||
class OfflineAndroid {
|
||||
|
||||
|
||||
private:
|
||||
|
||||
std::vector<OfflineEntry<WiFiMeasurements>> wifi;
|
||||
std::vector<OfflineEntry<GroundTruthID>> groundTruth;
|
||||
WalkedPath walkedPath;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
OfflineAndroid(const std::string& file) {
|
||||
parse(file);
|
||||
}
|
||||
|
||||
/** get all ground truth readings */
|
||||
const std::vector<OfflineEntry<GroundTruthID>>& getGroundTruth() const {return groundTruth;}
|
||||
|
||||
/** get all WiFi readings */
|
||||
const std::vector<OfflineEntry<WiFiMeasurements>>& getWiFi() const {return wifi;}
|
||||
|
||||
/** get the walked path */
|
||||
const WalkedPath& getWalkedPath() const {return walkedPath;}
|
||||
|
||||
/** get the interpolated walked path */
|
||||
Interpolator<Timestamp, Point3> getWalkedPathInterpolatorCM() const {
|
||||
Assert::equal(getWalkedPath().pos_cm.size(), getGroundTruth().size(), "entry-number mismatch!");
|
||||
Interpolator<Timestamp, Point3> interpol;
|
||||
for (const OfflineEntry<GroundTruthID>& entry : getGroundTruth()) {
|
||||
interpol.add(entry.ts, getWalkedPath().pos_cm[entry.data.id]);
|
||||
}
|
||||
return interpol;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void parse(const std::string& file) {
|
||||
|
||||
// open the stream
|
||||
std::ifstream inp(file);
|
||||
|
||||
// sanity check
|
||||
if (!inp.is_open() || inp.bad() || inp.eof()) {throw Exception("failed to open " +file);}
|
||||
|
||||
// parse one line
|
||||
while(!inp.eof()) {
|
||||
|
||||
// temporals
|
||||
uint64_t ts;
|
||||
char delim;
|
||||
int32_t sensorID = 999999; // avoids issues with the last line
|
||||
std::string sensorData;
|
||||
|
||||
// read from file
|
||||
inp >> ts;
|
||||
inp >> delim;
|
||||
inp >> sensorID;
|
||||
inp >> delim;
|
||||
inp >> sensorData;
|
||||
|
||||
if (delim == 0) {break;}
|
||||
|
||||
parse(Timestamp::fromMS(ts), sensorID, sensorData);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** parse the given data */
|
||||
void parse(const Timestamp ts, const int32_t sensorID, const std::string& sensorData) {
|
||||
|
||||
// how to parse
|
||||
switch(sensorID) {
|
||||
case 8: {
|
||||
OfflineEntry<WiFiMeasurements> entry(ts, parseWiFi(sensorData));
|
||||
wifi.push_back(entry);
|
||||
break;
|
||||
}
|
||||
case 99: {
|
||||
OfflineEntry<GroundTruthID> entry (ts, parseGroundTruthTick(sensorData));
|
||||
groundTruth.push_back(entry);
|
||||
break;
|
||||
}
|
||||
case 100: {
|
||||
walkedPath = parseWalkedPath(sensorData);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** parse the given WiFiObservation string "MAC;freq;RSSI;MAC;freq;RSSI;...." */
|
||||
static inline WiFiMeasurements parseWiFi(std::string data) {
|
||||
|
||||
WiFiMeasurements obs;
|
||||
|
||||
// process all APs
|
||||
while(!data.empty()) {
|
||||
|
||||
const std::string mac = data.substr(0, 17);
|
||||
data = data.substr(17);
|
||||
assert(data[0] == ';'); data = data.substr(1);
|
||||
|
||||
const std::string freq = data.substr(0, 4);
|
||||
data = data.substr(4);
|
||||
assert(data[0] == ';'); data = data.substr(1);
|
||||
|
||||
const int pos = data.find(';');
|
||||
const std::string rssi = data.substr(0, pos);
|
||||
data = data.substr(pos);
|
||||
assert(data[0] == ';'); data = data.substr(1);
|
||||
|
||||
const WiFiMeasurement e(mac, std::stof(rssi));
|
||||
obs.entries.push_back(e);
|
||||
|
||||
}
|
||||
|
||||
return obs;
|
||||
|
||||
}
|
||||
|
||||
/** parse the given GroundTruth entry */
|
||||
static inline GroundTruthID parseGroundTruthTick(const std::string& data) {
|
||||
|
||||
GroundTruthID id;
|
||||
const int pos = data.find(';');
|
||||
id.id = std::stoi(data.substr(0, pos));
|
||||
return id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** parse the given WalkedPath string "x,y,z;x,y,z;x,y,..." */
|
||||
static inline WalkedPath parseWalkedPath(std::string data) {
|
||||
|
||||
WalkedPath path;
|
||||
|
||||
// process all points
|
||||
while(!data.empty()) {
|
||||
|
||||
const int pos1 = data.find(',');
|
||||
const int pos2 = data.find(',', pos1+1);
|
||||
const int pos3 = data.find(';', pos2+1);
|
||||
|
||||
const std::string x = data.substr(0, pos1);
|
||||
const std::string y = data.substr(pos1+1, pos2-pos1-1);
|
||||
const std::string z = data.substr(pos2+1, pos3-pos2-1);
|
||||
|
||||
path.pos_cm.push_back(Point3(std::stof(x), std::stof(y), std::stof(z)));
|
||||
|
||||
data = data.substr(pos3+1);
|
||||
|
||||
}
|
||||
|
||||
return path;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // OFFLINEANDROID_H
|
||||
18
sensors/pressure/BarometerData.h
Normal file
18
sensors/pressure/BarometerData.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef BAROMETERDATA_H
|
||||
#define BAROMETERDATA_H
|
||||
|
||||
|
||||
#include <cmath>
|
||||
|
||||
/** data received from a barometer sensor */
|
||||
struct BarometerData {
|
||||
|
||||
float hPa;
|
||||
|
||||
explicit BarometerData() : hPa(0) {;}
|
||||
|
||||
explicit BarometerData(const float hPa) : hPa(hPa) {;}
|
||||
|
||||
};
|
||||
|
||||
#endif // BAROMETERDATA_H
|
||||
227
sensors/pressure/PressureTendence.h
Normal file
227
sensors/pressure/PressureTendence.h
Normal file
@@ -0,0 +1,227 @@
|
||||
#ifndef PRESSURETENDENCE_H
|
||||
#define PRESSURETENDENCE_H
|
||||
|
||||
#include "../../data/Timestamp.h"
|
||||
#include "../../math/MovingAVG.h"
|
||||
#include "../../math/MovingMedian.h"
|
||||
#include "../../math/Median.h"
|
||||
|
||||
#include "BarometerData.h"
|
||||
|
||||
#include <KLib/misc/gnuplot/Gnuplot.h>
|
||||
#include <KLib/misc/gnuplot/GnuplotPlot.h>
|
||||
#include <KLib/misc/gnuplot/GnuplotPlotElementLines.h>
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class PressureTendence {
|
||||
|
||||
private:
|
||||
|
||||
/** barometer history entries (timestamp -> value) */
|
||||
struct History {
|
||||
Timestamp ts;
|
||||
BarometerData data;
|
||||
History(const Timestamp ts, const BarometerData data) : ts(ts), data(data) {;}
|
||||
};
|
||||
|
||||
Timestamp timeframe;
|
||||
|
||||
std::vector<History> history;
|
||||
|
||||
public:
|
||||
|
||||
enum class Type {
|
||||
STRONG_MOVING_UPWARDS,
|
||||
MOVING_UPWARDS,
|
||||
NO_CHANGE,
|
||||
MOVING_DOWNWARDS,
|
||||
STRONG_MOVING_DOWNWARDS,
|
||||
};
|
||||
|
||||
struct Debug {
|
||||
|
||||
K::Gnuplot gp;
|
||||
K::GnuplotPlot plot;
|
||||
|
||||
K::GnuplotPlotElementLines raw;
|
||||
K::GnuplotPlotElementLines avg;
|
||||
K::GnuplotPlotElementLines tendence;
|
||||
|
||||
Debug() {
|
||||
plot.add(&raw); raw.setColorHex("#999999");
|
||||
plot.add(&avg); avg.setColorHex("#000000");
|
||||
plot.add(&tendence); tendence.setLineWidth(2);
|
||||
tendence.setCustomAttr(" axes x1y2 ");
|
||||
gp << "set y2tics\n";
|
||||
gp << "set y2range[-0.3:+0.3]\n";
|
||||
}
|
||||
|
||||
void addRaw(Timestamp ts, float val) {
|
||||
raw.add(K::GnuplotPoint2(ts.ms(), val));
|
||||
}
|
||||
|
||||
void addAvg(Timestamp ts, float val) {
|
||||
avg.add(K::GnuplotPoint2(ts.ms(), val));
|
||||
}
|
||||
|
||||
void addTendence(Timestamp ts, float val) {
|
||||
tendence.add(K::GnuplotPoint2(ts.ms(), val));
|
||||
}
|
||||
|
||||
void show() {
|
||||
static int cnt = 0;
|
||||
if (++cnt % 4 == 0) {
|
||||
gp.draw(plot);
|
||||
gp.flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
Debug debug;
|
||||
|
||||
|
||||
/** ctor with the timeframe to use. 1.0 sec should be fine */
|
||||
PressureTendence(const Timestamp timeframe) : timeframe(timeframe) {
|
||||
|
||||
}
|
||||
|
||||
/** add new sensor readings that were received at the given timestamp */
|
||||
void add(const Timestamp& ts, const BarometerData& baro) {
|
||||
|
||||
static MovingAVG<float> avg(5);
|
||||
avg.add(baro.hPa);
|
||||
|
||||
debug.addRaw(ts, baro.hPa);
|
||||
debug.addAvg(ts, avg.get());
|
||||
debug.show();
|
||||
|
||||
// add to the history
|
||||
//history.push_back(History(ts, baro));
|
||||
history.push_back(History(ts, BarometerData(avg.get())));
|
||||
|
||||
// remove too old values
|
||||
while( (ts - history[0].ts) > Timestamp::fromMS(2000)) {history.erase(history.begin());}
|
||||
|
||||
}
|
||||
|
||||
/** get the current tendence */
|
||||
float get() {
|
||||
|
||||
// static MovingAVG<float> avg(3);
|
||||
|
||||
if (history.empty()) {return 0;}
|
||||
|
||||
// const float tendence = history.back().data.hPa - history.front().data.hPa;
|
||||
// avg.add(tendence);
|
||||
|
||||
// debug.addTendence(history.back().ts, avg.get());
|
||||
|
||||
// return tendence;
|
||||
|
||||
|
||||
// const int ws = 5;
|
||||
|
||||
// if (history.size() < (ws+1)) {return 0;}
|
||||
|
||||
// const int s = history.size() - 1;
|
||||
|
||||
// bool rising = true;
|
||||
// for (int i = s-ws; i < s; ++i) {
|
||||
// if (history[i+0].data.hPa >= history[i+1].data.hPa) {rising = false; break;}
|
||||
// }
|
||||
|
||||
// bool falling = true;
|
||||
// for (int i = s-ws; i < s; ++i) {
|
||||
// if (history[i+0].data.hPa <= history[i+1].data.hPa) {falling = false; break;}
|
||||
// }
|
||||
|
||||
// float tendence = 0;
|
||||
// if (rising) {tendence = +0.1;}
|
||||
// if (falling) {tendence = -0.1;}
|
||||
|
||||
|
||||
float tendence = 0;
|
||||
|
||||
|
||||
|
||||
// if (delta > +0.1) {tendence = +0.1;}
|
||||
// if (delta < -0.1) {tendence = -0.1;}
|
||||
|
||||
int numUp = 0;
|
||||
int numDown = 0;
|
||||
|
||||
float slopeSum = 0;
|
||||
float slopeUp = 0;
|
||||
float slopeDown = 0;
|
||||
|
||||
int cnt=0;
|
||||
|
||||
for (int i = 0; i < history.size() - 1; ++i) {
|
||||
if (history[i+0].data.hPa < history[i+1].data.hPa) {++numUp;} else {++numDown;}
|
||||
const float slope = history[i+0].data.hPa - history[i+1].data.hPa;
|
||||
slopeSum += slope;
|
||||
if (slope > 0) {slopeUp += slope;}
|
||||
if (slope < 0) {slopeDown += slope;}
|
||||
++cnt;
|
||||
}
|
||||
|
||||
//tendence = (numUp-numDown)/((float)cnt)/10.0f;
|
||||
tendence = (std::abs(slopeUp) - std::abs(slopeDown)) ;
|
||||
//slopeSum /= cnt;
|
||||
|
||||
|
||||
// const float sd = std::abs(slopeUp) - std::abs(slopeDown);
|
||||
// tendence = sd;
|
||||
// if (std::abs(sd) > 0.07) {
|
||||
// tendence = 0.1;
|
||||
// }
|
||||
|
||||
// const int delta = numUp - numDown;
|
||||
// if (std::abs(delta) > cnt*0.3) {
|
||||
// if (delta < 0) {tendence = -0.1;}
|
||||
// if (delta > 0) {tendence = +0.1;}
|
||||
// }
|
||||
|
||||
//if (std::abs(deltaP) < 0.005) {tendence = 0;}
|
||||
|
||||
|
||||
// const float delta = history.front().data.hPa - history.back().data.hPa;
|
||||
// tendence = delta > 0.15;
|
||||
|
||||
debug.addTendence(history.back().ts, tendence);
|
||||
|
||||
|
||||
|
||||
|
||||
return tendence;
|
||||
|
||||
|
||||
// const int avgSize = 7;
|
||||
|
||||
// if (history.size() < avgSize) {return 0;}
|
||||
|
||||
// Median<float> hPa1;
|
||||
// Median<float> hPa2;
|
||||
|
||||
// int s = history.size() - 1;
|
||||
|
||||
// for (int i = 0; i < avgSize; ++i) {
|
||||
// hPa1.add(history[0+i].data.hPa);
|
||||
// hPa2.add(history[s-i].data.hPa);
|
||||
// }
|
||||
|
||||
// const float diff = (hPa2.get()) - (hPa1.get());
|
||||
// return diff;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // PRESSURETENDENCE_H
|
||||
139
sensors/pressure/RelativePressure.h
Normal file
139
sensors/pressure/RelativePressure.h
Normal file
@@ -0,0 +1,139 @@
|
||||
#ifndef BAROMETER_H
|
||||
#define BAROMETER_H
|
||||
|
||||
#include "../../data/Timestamp.h"
|
||||
#include "../../math/MovingAVG.h"
|
||||
|
||||
#include "BarometerData.h"
|
||||
|
||||
/**
|
||||
* calculates the pressure realtive to a startup-calibration of a barometer
|
||||
* hereafter all returned values are relative to the calibration
|
||||
*
|
||||
*/
|
||||
class RelativePressure {
|
||||
|
||||
private:
|
||||
|
||||
/** barometer history entries (timestamp -> value) */
|
||||
struct History {
|
||||
Timestamp ts;
|
||||
BarometerData data;
|
||||
History(const Timestamp ts, const BarometerData data) : ts(ts), data(data) {;}
|
||||
};
|
||||
|
||||
/** barometer calibration helper */
|
||||
struct Calibration {
|
||||
|
||||
Timestamp neededTimeframe = Timestamp::fromMS(5000);
|
||||
|
||||
std::vector<History> history;
|
||||
bool isCalibrated = false;
|
||||
float baseAvg = 0;
|
||||
float sigma = 0;
|
||||
|
||||
// prevent sensor-startup-issues and skip the first 25% of measurement values
|
||||
float skipStart = 0.25;
|
||||
|
||||
void tryToCalibrate() {
|
||||
|
||||
// determine the timeframe contained within the history
|
||||
const Timestamp timeframe = history.back().ts - history.front().ts;
|
||||
|
||||
// do we have enough values to perform a calibration?
|
||||
if (timeframe < neededTimeframe) {return;}
|
||||
|
||||
// we need double as float would lead to huge rounding errors!
|
||||
double sum = 0;
|
||||
double sum2 = 0;
|
||||
int cnt = 0;
|
||||
|
||||
// calculate sum and sum²
|
||||
for (int i = (int)(skipStart*history.size()); i < (int)history.size(); ++i) {
|
||||
const History& h = history[i];
|
||||
sum += h.data.hPa;
|
||||
sum2 += ((double)h.data.hPa * (double)h.data.hPa);
|
||||
++cnt;
|
||||
}
|
||||
|
||||
// calculate E(x) and E(x²)
|
||||
double avg = sum / (double)cnt;
|
||||
double avg2 = sum2 / (double)cnt;
|
||||
|
||||
// set calibrated values
|
||||
this->baseAvg = avg;
|
||||
this->sigma = std::sqrt( avg2 - (avg*avg) );
|
||||
this->isCalibrated = true;
|
||||
|
||||
}
|
||||
|
||||
void reset() {
|
||||
history.clear();
|
||||
isCalibrated = false;
|
||||
sigma = 0;
|
||||
baseAvg = 0;
|
||||
}
|
||||
|
||||
} calib;
|
||||
|
||||
float latesthPa;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
RelativePressure() {
|
||||
|
||||
}
|
||||
|
||||
/** set the timeframe used for the startup calibration (e.g. 5 seconds) */
|
||||
void setCalibrationTimeframe(const Timestamp timeframe) {
|
||||
this->calib.neededTimeframe = timeframe;
|
||||
}
|
||||
|
||||
/** add new sensor readings that were received at the given timestamp */
|
||||
void add(const Timestamp& ts, const BarometerData& baro) {
|
||||
|
||||
// perform calibration?
|
||||
if (!calib.isCalibrated) {
|
||||
calib.history.push_back(History(ts, baro));
|
||||
calib.tryToCalibrate();
|
||||
}
|
||||
|
||||
// most recent pressure reading
|
||||
latesthPa = baro.hPa;
|
||||
|
||||
}
|
||||
|
||||
/** get the most recent pressure reading realtive to the startup calibration. returns 0 until the sensor is calibrated */
|
||||
float getPressureRealtiveToStart() {
|
||||
if (calib.isCalibrated) {
|
||||
return latesthPa - calib.baseAvg;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/** reset the sensor's calibration */
|
||||
void reset() {
|
||||
calib.reset();
|
||||
}
|
||||
|
||||
/** get the barometer's calibrated uncertainty determined during the startup calibration */
|
||||
float getSigma() {
|
||||
return calib.sigma;
|
||||
}
|
||||
|
||||
/** get the barometer's calibrated average during the startup calibration */
|
||||
float getBaseAvg() {
|
||||
return calib.baseAvg;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // BAROMETER_H
|
||||
@@ -10,26 +10,50 @@
|
||||
*/
|
||||
class AccessPoint {
|
||||
|
||||
public:
|
||||
private:
|
||||
|
||||
/** the AP's MAC-Address */
|
||||
const MACAddress mac;
|
||||
MACAddress mac;
|
||||
|
||||
/** the AP's readable SSID */
|
||||
const std::string ssid;
|
||||
/** OPTIONAL the AP's readable SSID */
|
||||
std::string ssid;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
/** empty ctor */
|
||||
AccessPoint() {
|
||||
;
|
||||
}
|
||||
|
||||
/** ctor with MAC and SSID */
|
||||
AccessPoint(const MACAddress& mac, const std::string& ssid) : mac(mac), ssid(ssid) {
|
||||
;
|
||||
}
|
||||
|
||||
/** ctor */
|
||||
/** ctor with MAC and SSID */
|
||||
AccessPoint(const std::string& mac, const std::string& ssid) : mac(mac), ssid(ssid) {
|
||||
;
|
||||
}
|
||||
|
||||
/** ctor with MAC and without SSID */
|
||||
AccessPoint(const MACAddress& mac) : mac(mac), ssid() {
|
||||
;
|
||||
}
|
||||
|
||||
/** ctor with MAC and without SSID */
|
||||
AccessPoint(const std::string& mac) : mac(mac), ssid() {
|
||||
;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/** get the AP's MAC address */
|
||||
inline const MACAddress& getMAC() const {return mac;}
|
||||
|
||||
/** OPTIONAL: get the AP's ssid (if any) */
|
||||
inline const std::string& getSSID() const {return ssid;}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // ACCESSPOINT_H
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "../../floorplan/v2/Floorplan.h"
|
||||
|
||||
/**
|
||||
* describes an access-point including its position
|
||||
* describes an access-point including its position (in meter)
|
||||
*/
|
||||
class LocatedAccessPoint : public AccessPoint, public Point3 {
|
||||
|
||||
|
||||
172
sensors/radio/VAPGrouper.h
Normal file
172
sensors/radio/VAPGrouper.h
Normal file
@@ -0,0 +1,172 @@
|
||||
#ifndef VAPGROUPER_H
|
||||
#define VAPGROUPER_H
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <cmath>
|
||||
|
||||
#include "../../math/Median.h"
|
||||
|
||||
#include "WiFiMeasurements.h"
|
||||
|
||||
class VAPGrouper {
|
||||
|
||||
public:
|
||||
|
||||
/** the mode denotes the algorithm that is used for grouping VAPs together */
|
||||
enum class Mode {
|
||||
|
||||
/** group VAPs by setting the MAC's last digit to zero */
|
||||
LAST_MAC_DIGIT_TO_ZERO,
|
||||
|
||||
};
|
||||
|
||||
/** describes how to calculate the final signal-strengh of the VAP-grouped entry */
|
||||
enum class Aggregation {
|
||||
|
||||
/** use the average signal-strength of all grouped APs */
|
||||
AVERAGE,
|
||||
|
||||
/** use the median signal-strength of all grouped APs */
|
||||
MEDIAN,
|
||||
|
||||
/** use the maximum signal-strength of all grouped APs */
|
||||
MAXIMUM,
|
||||
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
/** the mode to use for grouping VAPs */
|
||||
const Mode mode;
|
||||
|
||||
/** the signal-strength aggregation algorithm to use */
|
||||
const Aggregation agg;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
VAPGrouper(const Mode mode, const Aggregation agg) : mode(mode), agg(agg) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** get a vap-grouped version of the given input */
|
||||
WiFiMeasurements group(const WiFiMeasurements& original) const {
|
||||
|
||||
// first, group all VAPs into a vector [one vector per VAP-group]
|
||||
std::unordered_map<MACAddress, std::vector<WiFiMeasurement>> grouped;
|
||||
|
||||
for (const WiFiMeasurement& m : original.entries) {
|
||||
|
||||
// the vap-base-mac this entry belongs to
|
||||
const MACAddress baseMAC = getBaseMAC(m.getAP().getMAC());
|
||||
grouped[baseMAC].push_back(m);
|
||||
|
||||
}
|
||||
|
||||
// output
|
||||
WiFiMeasurements result;
|
||||
|
||||
// perform aggregation on each VAP-group
|
||||
for (auto it : grouped) {
|
||||
|
||||
const MACAddress& base = it.first;
|
||||
const std::vector<WiFiMeasurement>& vaps = it.second;
|
||||
|
||||
// group all VAPs into one measurement
|
||||
const WiFiMeasurement groupedMeasurement = groupVAPs(base, vaps);
|
||||
|
||||
// add it to the result-vector
|
||||
result.entries.push_back(groupedMeasurement);
|
||||
|
||||
}
|
||||
|
||||
// done
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/** get the VAP-base-MAC-Address that is the same for all APs that belong to a VAP-Group */
|
||||
MACAddress getBaseMAC(const MACAddress& mac) const {
|
||||
|
||||
switch(mode) {
|
||||
case Mode::LAST_MAC_DIGIT_TO_ZERO: return lastMacDigitToZero(mac);
|
||||
default: throw Exception("unsupported vap-grouping mode given");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** combine all of the given VAPs into one entry using the configured aggregation method */
|
||||
WiFiMeasurement groupVAPs(const MACAddress& baseMAC, const std::vector<WiFiMeasurement>& vaps) const {
|
||||
|
||||
// the resulting entry is an AP with the base-MAC all of the given VAPs have in common
|
||||
const AccessPoint baseAP(baseMAC);
|
||||
|
||||
// the resultign timestamp
|
||||
const Timestamp baseTS = vaps.front().getTimestamp();
|
||||
|
||||
// calculate the rssi using the configured aggregate function
|
||||
float rssi = NAN;
|
||||
switch(agg) {
|
||||
case Aggregation::AVERAGE: rssi = getAVG(vaps); break;
|
||||
case Aggregation::MEDIAN: rssi = getMedian(vaps); break;
|
||||
case Aggregation::MAXIMUM: rssi = getMax(vaps); break;
|
||||
default: throw Exception("unsupported vap-aggregation method");
|
||||
}
|
||||
|
||||
// create the result measurement
|
||||
return WiFiMeasurement(baseAP, rssi, baseTS);
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** get the average signal strength */
|
||||
inline float getAVG(const std::vector<WiFiMeasurement>& vaps) const {
|
||||
|
||||
float rssi = 0;
|
||||
for (const WiFiMeasurement& vap : vaps) {
|
||||
rssi += vap.getRSSI();
|
||||
}
|
||||
return rssi / vaps.size();
|
||||
|
||||
}
|
||||
|
||||
/** get the median signal strength */
|
||||
inline float getMedian(const std::vector<WiFiMeasurement>& vaps) const {
|
||||
|
||||
Median<float> median;
|
||||
for (const WiFiMeasurement& vap : vaps) {
|
||||
median.add(vap.getRSSI());
|
||||
}
|
||||
return median.get();
|
||||
|
||||
}
|
||||
|
||||
/** get the maximum signal strength */
|
||||
inline float getMax(const std::vector<WiFiMeasurement>& vaps) const {
|
||||
|
||||
float max = -9999999;
|
||||
for (const WiFiMeasurement& vap : vaps) {
|
||||
if (vap.getRSSI() > max) {max = vap.getRSSI();}
|
||||
}
|
||||
return max;
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** convert the MAC by setting the last (right-most) digit to zero (0) */
|
||||
static inline MACAddress lastMacDigitToZero(const MACAddress& mac) {
|
||||
std::string str = mac.asString();
|
||||
str.back() = '0';
|
||||
return MACAddress(str);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // VAPGROUPER_H
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "model/WiFiModel.h"
|
||||
#include "WiFiGridNode.h"
|
||||
#include "../../Assertions.h"
|
||||
#include "../../floorplan/v2/Floorplan.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
@@ -16,6 +17,25 @@ class WiFiGridEstimator {
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* convenience method
|
||||
*/
|
||||
template <typename Node> static void estimate(Grid<Node>& grid, WiFiModel& mdl, const Floorplan::IndoorMap* im) {
|
||||
|
||||
// list of all APs
|
||||
std::vector<LocatedAccessPoint> aps;
|
||||
for (const Floorplan::Floor* f : im->floors) {
|
||||
for (const Floorplan::AccessPoint* ap : f->accesspoints) {
|
||||
aps.push_back(LocatedAccessPoint(*ap));
|
||||
}
|
||||
}
|
||||
|
||||
// perform estimation
|
||||
estimate(grid, mdl, aps);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* perform a signal-strength estimation for all of the given access points
|
||||
* using the provided signal-strength prediction model.
|
||||
|
||||
@@ -79,13 +79,6 @@ template <int maxAccessPoints> struct WiFiGridNode {
|
||||
WiFiGridNode() {;}
|
||||
|
||||
|
||||
|
||||
/** shared vector of all accesspoints the are present within the map. the IDX referes to this vector */
|
||||
static std::vector<AccessPoint>& getMapAPs() {
|
||||
static std::vector<AccessPoint> list;
|
||||
return list;
|
||||
}
|
||||
|
||||
/** get the maximum number of APs each node is able to store */
|
||||
int getMaxAPs() const {return maxAccessPoints;}
|
||||
|
||||
@@ -104,7 +97,7 @@ template <int maxAccessPoints> struct WiFiGridNode {
|
||||
float getRSSI(const MACAddress mac) const {
|
||||
for (const WiFiGridNodeAP ap : strongestAPs) {
|
||||
if (!ap.isValid()) {break;} // reached the end
|
||||
if (getMapAPs()[ap.getAPIdx()].mac == mac) {return ap.getRSSI();}
|
||||
if (getMapAPs()[ap.getAPIdx()].getMAC() == mac) {return ap.getRSSI();}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -117,6 +110,44 @@ template <int maxAccessPoints> struct WiFiGridNode {
|
||||
return getMaxAPs();
|
||||
}
|
||||
|
||||
/** shared vector of all accesspoints the are present within the map. the IDX referes to this vector */
|
||||
static std::vector<AccessPoint>& getMapAPs() {
|
||||
static std::vector<AccessPoint> list;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** serialize static members */
|
||||
static void staticSerialize(std::ostream& out) {
|
||||
|
||||
// number of APs within map
|
||||
const int numAPs = getMapAPs().size();
|
||||
|
||||
// serialize number and APs within map
|
||||
out.write((const char*) &numAPs, sizeof(numAPs));
|
||||
out.write((const char*) getMapAPs().data(), sizeof(getMapAPs()[0])*numAPs);
|
||||
|
||||
}
|
||||
|
||||
/** deserialize static members */
|
||||
static void staticDeserialize(std::istream& inp) {
|
||||
|
||||
// get number of APs within map
|
||||
int numAPs;
|
||||
inp.read((char*) &numAPs, sizeof(numAPs));
|
||||
|
||||
// allocate
|
||||
getMapAPs().resize(numAPs);
|
||||
|
||||
// deserialize APs within map
|
||||
inp.read((char*) getMapAPs().data(), sizeof(getMapAPs()[0])*numAPs);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
};// __attribute__((packed));
|
||||
|
||||
|
||||
50
sensors/radio/WiFiMeasurement.h
Normal file
50
sensors/radio/WiFiMeasurement.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef WIFIMEASUREMENT_H
|
||||
#define WIFIMEASUREMENT_H
|
||||
|
||||
#include "AccessPoint.h"
|
||||
#include "../../data/Timestamp.h"
|
||||
|
||||
/**
|
||||
* describes a measurement received for one access-point at a given time
|
||||
*/
|
||||
class WiFiMeasurement {
|
||||
|
||||
private:
|
||||
|
||||
friend class VAPGrouper;
|
||||
|
||||
/** the access-point we got a measurement for */
|
||||
AccessPoint ap;
|
||||
|
||||
/** the measured signal strength */
|
||||
float rssi;
|
||||
|
||||
/** OPTIONAL. timestamp the measurement was recorded at */
|
||||
Timestamp ts;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
WiFiMeasurement(const AccessPoint& ap, const float rssi) : ap(ap), rssi(rssi) {
|
||||
;
|
||||
}
|
||||
|
||||
/** ctor with timestamp */
|
||||
WiFiMeasurement(const AccessPoint& ap, const float rssi, const Timestamp ts) : ap(ap), rssi(rssi), ts(ts) {
|
||||
;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/** get the AP we got the measurement for */
|
||||
const AccessPoint& getAP() const {return ap;}
|
||||
|
||||
/** get the measurement's signal strength */
|
||||
float getRSSI() const {return rssi;}
|
||||
|
||||
/** OPTIONAL: get the measurement's timestamp (if known!) */
|
||||
const Timestamp& getTimestamp() const {return ts;}
|
||||
|
||||
};
|
||||
|
||||
#endif // WIFIMEASUREMENT_H
|
||||
18
sensors/radio/WiFiMeasurements.h
Normal file
18
sensors/radio/WiFiMeasurements.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef WIFIMEASUREMENTS_H
|
||||
#define WIFIMEASUREMENTS_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "WiFiMeasurement.h"
|
||||
|
||||
/**
|
||||
* group of several wifi measurements
|
||||
*/
|
||||
struct WiFiMeasurements {
|
||||
|
||||
/** all contained measurements */
|
||||
std::vector<WiFiMeasurement> entries;
|
||||
|
||||
};
|
||||
|
||||
#endif // WIFIMEASUREMENTS_H
|
||||
@@ -1,100 +0,0 @@
|
||||
#ifndef WIFIOBSERVATION_H
|
||||
#define WIFIOBSERVATION_H
|
||||
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
|
||||
#include "../MACAddress.h"
|
||||
#include "../../math/Distributions.h"
|
||||
|
||||
|
||||
/** observed one AP with the given signal strength */
|
||||
struct WiFiObservationEntry {
|
||||
|
||||
/** AP's MAC address */
|
||||
MACAddress mac;
|
||||
|
||||
/** AP's RSSI */
|
||||
float rssi;
|
||||
|
||||
/** ctor */
|
||||
WiFiObservationEntry(const MACAddress& mac, const float rssi) : mac(mac), rssi(rssi) {;}
|
||||
|
||||
};
|
||||
|
||||
/** all observed APs and their signal strength */
|
||||
struct WiFiObservation {
|
||||
|
||||
/** one entry per AP */
|
||||
std::vector<WiFiObservationEntry> entries;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class WiFiObserver {
|
||||
|
||||
private:
|
||||
|
||||
float sigma = 8.0f;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
WiFiObserver(const float sigma) : sigma(sigma) {
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the given GridNode's probability based on the provided WiFi measurements
|
||||
*/
|
||||
template <typename Node> double getProbability(const Node& n, const WiFiObservation& obs, const int age_ms = 0) {
|
||||
|
||||
double prob = 0;
|
||||
|
||||
// sigma grows with measurement age
|
||||
const double sigma = this->sigma * (1 + age_ms / 500.0f);
|
||||
|
||||
// process each observed AP
|
||||
for (const WiFiObservationEntry& ap : obs.entries) {
|
||||
|
||||
// the RSSI from the scan
|
||||
const float measuredRSSI = ap.rssi;
|
||||
|
||||
// the RSSI from the model (if available!)
|
||||
const float modelRSSI = n.getRSSI(ap.mac);
|
||||
|
||||
// no model RSSI available?
|
||||
if (modelRSSI == 0) {continue;}
|
||||
|
||||
// compare both
|
||||
const double p = Distribution::Normal<double>::getProbability(measuredRSSI, sigma, modelRSSI);
|
||||
|
||||
// adjust using log
|
||||
prob += std::log(p);
|
||||
|
||||
}
|
||||
|
||||
//return std::pow(std::exp(prob), 0.1);
|
||||
return std::exp(prob);
|
||||
|
||||
}
|
||||
|
||||
/** gnuplot debug dump */
|
||||
template <typename Node> void dump(Grid<Node>& grid, const WiFiObservation& obs, const std::string& fileName) {
|
||||
|
||||
std::ofstream out(fileName);
|
||||
out << "splot '-' with points palette\n";
|
||||
|
||||
for (const Node& n : grid) {
|
||||
const float p = getProbability(n, obs);
|
||||
out << n.x_cm << " " << n.y_cm << " " << n.z_cm << " " << p << "\n";
|
||||
}
|
||||
out << "e\n";
|
||||
|
||||
out.close();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // WIFIOBSERVATION_H
|
||||
15
sensors/radio/WiFiProbability.h
Normal file
15
sensors/radio/WiFiProbability.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef WIFPROBABILITY_H
|
||||
#define WIFPROBABILITY_H
|
||||
|
||||
#include "WiFiMeasurements.h"
|
||||
|
||||
/**
|
||||
* base class for all WiFi probability calculators.
|
||||
* such a calculator determines the probabilty for a location (e.g. x,y,z)
|
||||
* given WiFiMeasurements
|
||||
*/
|
||||
class WiFiProbability {
|
||||
|
||||
};
|
||||
|
||||
#endif // WIFPROBABILITY_H
|
||||
77
sensors/radio/WiFiProbabilityFree.h
Normal file
77
sensors/radio/WiFiProbabilityFree.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef WIFIPROBABILITYFREE_H
|
||||
#define WIFIPROBABILITYFREE_H
|
||||
|
||||
#include "WiFiProbability.h"
|
||||
#include "model/WiFiModel.h"
|
||||
#include "../../math/Distributions.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
/**
|
||||
* compare WiFi-Measurements within LIVE (exact) predictions
|
||||
* just based on the distance to the access-point
|
||||
*/
|
||||
class WiFiObserverFree : public WiFiProbability {
|
||||
|
||||
private:
|
||||
|
||||
const float sigma = 8.0f;
|
||||
|
||||
const float sigmaPerSecond = 1.5f;
|
||||
|
||||
WiFiModel& model;
|
||||
std::unordered_map<MACAddress, LocatedAccessPoint> aps;
|
||||
Floorplan::IndoorMap* map;
|
||||
|
||||
public:
|
||||
|
||||
WiFiObserverFree(const float sigma, WiFiModel& model, const std::vector<LocatedAccessPoint>& aps) : sigma(sigma), model(model) {
|
||||
|
||||
for (const LocatedAccessPoint& ap : aps) {
|
||||
this->aps.insert(std::pair<MACAddress, LocatedAccessPoint>(ap.getMAC(), ap));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
double getProbability(const Point3& pos, const Timestamp curTime, const WiFiMeasurements& obs) const {
|
||||
|
||||
double prob = 1.0;
|
||||
|
||||
for (const WiFiMeasurement& entry : obs.entries) {
|
||||
|
||||
auto it = aps.find(entry.getAP().getMAC());
|
||||
|
||||
// AP is unknown
|
||||
if (it == aps.end()) {continue;}
|
||||
|
||||
// get the AP
|
||||
const LocatedAccessPoint& ap = it->second;
|
||||
|
||||
// model and scan rssi
|
||||
const float modelRSSI = model.getRSSI(ap, pos);
|
||||
const float scanRSSI = entry.getRSSI();
|
||||
|
||||
// the measurement's age
|
||||
const Timestamp age = curTime - entry.getTimestamp();
|
||||
|
||||
// sigma grows with measurement age
|
||||
const float sigma = this->sigma + this->sigmaPerSecond * age.sec();
|
||||
|
||||
// update probability
|
||||
prob *= Distribution::Normal<double>::getProbability(modelRSSI, sigma, scanRSSI);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return prob;
|
||||
|
||||
}
|
||||
|
||||
template <typename Node> double getProbability(const Node& n, const Timestamp curTime, const WiFiMeasurements& obs, const int age_ms = 0) const {
|
||||
throw "todo??";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // WIFIPROBABILITYFREE_H
|
||||
92
sensors/radio/WiFiProbabilityGrid.h
Normal file
92
sensors/radio/WiFiProbabilityGrid.h
Normal file
@@ -0,0 +1,92 @@
|
||||
#ifndef WIFIPROBABILITYGRID_H
|
||||
#define WIFIPROBABILITYGRID_H
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "../../math/Distributions.h"
|
||||
#include "../../data/Timestamp.h"
|
||||
|
||||
#include "WiFiProbability.h"
|
||||
|
||||
|
||||
/**
|
||||
* probability is calculated by comparing pre-calculated wifi-signal-strengths
|
||||
* attached to each grid-node with a given WiFiMeasurements data structure
|
||||
*/
|
||||
class WiFiObserverGrid : public WiFiProbability {
|
||||
|
||||
private:
|
||||
|
||||
/** base-sigma to use for comparison */
|
||||
float sigma = 8.0f;
|
||||
|
||||
/** additional sigma-per-second (measurement age) to*/
|
||||
float sigmaPerSecond = 1.5;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** ctor with uncertainty */
|
||||
WiFiObserverGrid(const float sigma) : sigma(sigma) {
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the given GridNode's probability.
|
||||
* compares the predicted signal-strengths stored on the given node
|
||||
* with the provided WiFi measurements
|
||||
*/
|
||||
template <typename Node> double getProbability(const Node& n, const Timestamp curTime, const WiFiMeasurements& obs) const {
|
||||
|
||||
double prob = 0;
|
||||
|
||||
// process each observed measurement
|
||||
for (const WiFiMeasurement& measurement : obs.entries) {
|
||||
|
||||
// determine the age for this measurement
|
||||
const Timestamp age = curTime - measurement.getTimestamp();
|
||||
|
||||
// sigma grows with measurement age
|
||||
const float sigma = this->sigma + this->sigmaPerSecond * age.sec();
|
||||
|
||||
// the RSSI from the scan
|
||||
const float measuredRSSI = measurement.getRSSI();
|
||||
|
||||
// the RSSI from the model (if available!)
|
||||
const float modelRSSI = n.getRSSI(measurement.getAP().getMAC());
|
||||
|
||||
// no model RSSI available?
|
||||
if (modelRSSI == 0) {continue;}
|
||||
|
||||
// compare both
|
||||
const double p = Distribution::Normal<double>::getProbability(measuredRSSI, sigma, modelRSSI);
|
||||
|
||||
// adjust using log
|
||||
prob += std::log(p);
|
||||
|
||||
}
|
||||
|
||||
//return std::pow(std::exp(prob), 0.1);
|
||||
return std::exp(prob);
|
||||
|
||||
}
|
||||
|
||||
/** gnuplot debug dump */
|
||||
template <typename Node> void dump(Grid<Node>& grid, const Timestamp curTime, const WiFiMeasurements& obs, const std::string& fileName) {
|
||||
|
||||
std::ofstream out(fileName);
|
||||
out << "splot '-' with points palette\n";
|
||||
|
||||
for (const Node& n : grid) {
|
||||
const float p = getProbability(n, curTime, obs);
|
||||
out << n.x_cm << " " << n.y_cm << " " << n.z_cm << " " << p << "\n";
|
||||
}
|
||||
out << "e\n";
|
||||
|
||||
out.close();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // WIFIPROBABILITYGRID_H
|
||||
65
sensors/radio/model/WiFiModelLogDistCeiling.h
Normal file
65
sensors/radio/model/WiFiModelLogDistCeiling.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef WIFIMODELLOGDISTCEILING_H
|
||||
#define WIFIMODELLOGDISTCEILING_H
|
||||
|
||||
#include "../../../floorplan/v2/Floorplan.h"
|
||||
|
||||
#include "WiFiModel.h"
|
||||
#include "LogDistanceModel.h"
|
||||
|
||||
/**
|
||||
* signal-strength estimation using log-distance model
|
||||
* including ceilings between AP and position
|
||||
*/
|
||||
class WiFiModelLogDistCeiling : public WiFiModel {
|
||||
|
||||
private:
|
||||
|
||||
float txp; // sending power (-40)
|
||||
float exp; // path-loss-exponent (~2.0 - 4.0)
|
||||
float waf; // attenuation per ceiling/floor (~-8.0)
|
||||
|
||||
/** position (height) of all ceilings (in meter) */
|
||||
std::vector<float> ceilingsAtHeight_m;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
WiFiModelLogDistCeiling(const float txp, const float exp, const float waf, const Floorplan::IndoorMap* map) : txp(txp), exp(exp), waf(waf) {
|
||||
|
||||
Assert::isTrue(waf <= 0, "WAF must be a negative number!");
|
||||
|
||||
// position of all ceilings
|
||||
for (Floorplan::Floor* f : map->floors) {
|
||||
ceilingsAtHeight_m.push_back(f->atHeight);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** get the given access-point's RSSI at the provided location */
|
||||
float getRSSI(const LocatedAccessPoint& ap, const Point3 p) override {
|
||||
const int numCeilings = numCeilingsBetween(ap.z, p.z);
|
||||
const float rssi = LogDistanceModel::distanceToRssi(txp, exp, ap.getDistance(p));
|
||||
return rssi + (numCeilings * waf);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** get the number of ceilings between z1 and z2 */
|
||||
int numCeilingsBetween(const float z1, const float z2) const {
|
||||
|
||||
int cnt = 0;
|
||||
const float zMin = std::min(z1, z2);
|
||||
const float zMax = std::max(z1, z2);
|
||||
|
||||
for (float z : ceilingsAtHeight_m) {
|
||||
if (zMin < z && zMax > z) {++cnt;}
|
||||
}
|
||||
|
||||
return cnt;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // WIFIMODELLOGDISTCEILING_H
|
||||
Reference in New Issue
Block a user