added motion axis stuff
This commit is contained in:
115
main.cpp
115
main.cpp
@@ -1,4 +1,3 @@
|
||||
#include "FileReader.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "filter/Structs.h"
|
||||
@@ -15,12 +14,13 @@
|
||||
#include <Indoor/grid/factory/v2/Importance.h>
|
||||
|
||||
#include <Indoor/geo/Point2.h>
|
||||
|
||||
#include <Indoor/sensors/offline/FileReader.h>
|
||||
|
||||
#include <KLib/math/statistics/Statistics.h>
|
||||
|
||||
#include <Indoor/sensors/imu/TurnDetection.h>
|
||||
#include <Indoor/sensors/imu/StepDetection.h>
|
||||
#include <Indoor/sensors/imu/MotionDetection.h>
|
||||
#include <Indoor/sensors/pressure/RelativePressure.h>
|
||||
#include <Indoor/sensors/radio/WiFiGridEstimator.h>
|
||||
#include <Indoor/sensors/beacon/model/BeaconModelLogDistCeiling.h>
|
||||
@@ -62,13 +62,13 @@ struct DataSetup {
|
||||
std::string wifiParams;
|
||||
int minWifiOccurences;
|
||||
VAPGrouper::Mode vapMode;
|
||||
int buildingNum;
|
||||
std::string grid;
|
||||
};
|
||||
|
||||
/** all configured datasets */
|
||||
struct Data {
|
||||
|
||||
DataSetup SHL = {
|
||||
DataSetup BERKWERK = {
|
||||
|
||||
mapDir + "SHL/SHL25.xml",
|
||||
|
||||
@@ -86,7 +86,27 @@ struct Data {
|
||||
dataDir + "bergwerk/wifiParams.txt",
|
||||
40,
|
||||
VAPGrouper::Mode::LAST_MAC_DIGIT_TO_ZERO,
|
||||
10
|
||||
mapDir + "SHL/grid25.dat"
|
||||
};
|
||||
|
||||
DataSetup IPIN2015 = {
|
||||
|
||||
mapDir + "SHL/SHL_IPIN2015_gt.xml",
|
||||
|
||||
{
|
||||
dataDir + "ipin2015/galaxy/Path0/1433581471902.csv",
|
||||
dataDir + "ipin2015/nexus/Path0/1433606195078.csv",
|
||||
dataDir + "ipin2015/galaxy/Path1/1433587749492.csv",
|
||||
dataDir + "ipin2015/nexus/Path1/1433606670723.csv",
|
||||
dataDir + "ipin2015/galaxy/Path2/1433581471902.csv",
|
||||
dataDir + "ipin2015/nexus/Path2/1433607251262.csv",
|
||||
dataDir + "eiszeit/path2/1479986737368.csv"
|
||||
},
|
||||
|
||||
dataDir + "bergwerk/wifiParams.txt",
|
||||
40,
|
||||
VAPGrouper::Mode::LAST_MAC_DIGIT_TO_ZERO,
|
||||
mapDir + "SHL/grid_IPIN2015_gt.dat"
|
||||
};
|
||||
|
||||
} data;
|
||||
@@ -105,22 +125,25 @@ void run(DataSetup setup, int numFile, std::string folder) {
|
||||
Assert::isFalse(WiFiModel.getAllAPs().empty(), "no AccessPoints stored within the map.xml");
|
||||
|
||||
BeaconModelLogDistCeiling beaconModel(map);
|
||||
BeaconModelLogDistCeiling::APEntry beacon1(Point3(69.84f,45.26f,3.8f+3.4f+1.2f),-81,Settings::BeaconModel::EXP, Settings::BeaconModel::WAF);
|
||||
beaconModel.addBeacon(MACAddress("48:EF:8D:77:66:DF"), beacon1);
|
||||
beaconModel.loadBeaconsFromMap(map, Settings::BeaconModel::TXP, Settings::BeaconModel::EXP, Settings::BeaconModel::WAF);
|
||||
Assert::isFalse(beaconModel.getAllBeacons().empty(), "no Beacons stored within the map.xml");
|
||||
|
||||
BeaconModelLogDistCeiling::APEntry beacon2(Point3(69.84f,45.26f,3.8f+3.4f+1.2f),-81,Settings::BeaconModel::EXP, Settings::BeaconModel::WAF);
|
||||
beaconModel.addBeacon(MACAddress("6F:5F:39:0C:51:E4"), beacon2);
|
||||
|
||||
BeaconModelLogDistCeiling::APEntry beacon3(Point3(69.84f,45.26f,3.8f+3.4f+1.2f),-81,Settings::BeaconModel::EXP, Settings::BeaconModel::WAF);
|
||||
beaconModel.addBeacon(MACAddress("49:23:D8:7F:E8:D2"), beacon3);
|
||||
|
||||
//beaconModel.loadBeaconsFromMap(map, Settings::WiFiModel::TXP, Settings::WiFiModel::EXP, Settings::WiFiModel::WAF);
|
||||
Assert::isFalse(beaconModel.getAllBeacons().empty(), "no AccessPoints stored within the map.xml");
|
||||
|
||||
// build the grid
|
||||
std::ifstream inp(setup.grid, std::ifstream::binary);
|
||||
Grid<MyNode> grid(20);
|
||||
GridFactory<MyNode> factory(grid);
|
||||
factory.build(map);
|
||||
|
||||
// grid.dat empty? -> build one and save it
|
||||
if (!inp.good() || (inp.peek()&&0) || inp.eof()) {
|
||||
std::ofstream onp;
|
||||
onp.open(setup.grid);
|
||||
GridFactory<MyNode> factory(grid);
|
||||
factory.build(map);
|
||||
grid.write(onp);
|
||||
} else {
|
||||
grid.read(inp);
|
||||
}
|
||||
|
||||
|
||||
// add node-importance
|
||||
Importance::addImportance(grid);
|
||||
@@ -128,14 +151,16 @@ void run(DataSetup setup, int numFile, std::string folder) {
|
||||
// stamp WiFi signal-strengths onto the grid
|
||||
WiFiGridEstimator::estimate(grid, WiFiModel, Settings::smartphoneAboveGround);
|
||||
|
||||
|
||||
// reading file
|
||||
FileReader fr(setup.training[numFile]);
|
||||
|
||||
//std::vector<int> gt;
|
||||
|
||||
|
||||
// doing ground truth stuff
|
||||
//fr.getGroundTruthPath(map, gt_1);
|
||||
std::vector<int> path_0 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 1, 0};
|
||||
std::vector<int> path_1 = {29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 13, 14, 15, 16, 17, 18, 19, 2, 1, 0};
|
||||
std::vector<int> path_2 = {29, 28, 27, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 19, 18, 17, 16, 15, 14, 13, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29};
|
||||
Interpolator<uint64_t, Point3> gtInterpolator = fr.getGroundTruthPath(map, path_1);
|
||||
|
||||
|
||||
Plotti plot;
|
||||
@@ -151,20 +176,21 @@ void run(DataSetup setup, int numFile, std::string folder) {
|
||||
ctrl.resetAfterTransition();
|
||||
MyObs obs;
|
||||
|
||||
int numParticles = 5000;
|
||||
int numParticles = 10000;
|
||||
|
||||
PFEval* eval = new PFEval(WiFiModel, beaconModel, grid);
|
||||
|
||||
//filter init
|
||||
//std::unique_ptr<PFInit> init =
|
||||
K::ParticleFilterHistory<MyState, MyControl, MyObs> pf(numParticles, std::unique_ptr<PFInit>(new PFInit(grid)));
|
||||
//K::ParticleFilterHistory<MyState, MyControl, MyObs> pf(numParticles, std::unique_ptr<PFInit>(new PFInit(grid)));
|
||||
K::ParticleFilterHistory<MyState, MyControl, MyObs> pf(numParticles, std::unique_ptr<PFInitFixed>(new PFInitFixed(grid, GridPoint(1120.0f, 750.0f, 1080.0f), 90.0f)));
|
||||
pf.setTransition(std::unique_ptr<PFTrans>(new PFTrans(grid, &ctrl)));
|
||||
pf.setEvaluation(std::unique_ptr<PFEval>(eval));
|
||||
|
||||
//resampling
|
||||
//pf.setResampling(std::unique_ptr<K::ParticleFilterResamplingSimple<MyState>>(new K::ParticleFilterResamplingSimple<MyState>()));
|
||||
pf.setResampling(std::unique_ptr<K::ParticleFilterResamplingPercent<MyState>>(new K::ParticleFilterResamplingPercent<MyState>(0.04)));
|
||||
pf.setNEffThreshold(0.85);
|
||||
pf.setResampling(std::unique_ptr<K::ParticleFilterResamplingSimple<MyState>>(new K::ParticleFilterResamplingSimple<MyState>()));
|
||||
//pf.setResampling(std::unique_ptr<K::ParticleFilterResamplingPercent<MyState>>(new K::ParticleFilterResamplingPercent<MyState>(0.4)));
|
||||
pf.setNEffThreshold(0.95);
|
||||
|
||||
//estimation
|
||||
//pf.setEstimation(std::unique_ptr<K::ParticleFilterEstimationWeightedAverage<MyState>>(new K::ParticleFilterEstimationWeightedAverage<MyState>()));
|
||||
@@ -177,11 +203,13 @@ void run(DataSetup setup, int numFile, std::string folder) {
|
||||
|
||||
StepDetection sd;
|
||||
TurnDetection td;
|
||||
MotionDetection md;
|
||||
|
||||
RelativePressure relBaro; relBaro.setCalibrationTimeframe( Timestamp::fromMS(5000) );
|
||||
|
||||
K::Statistics<float> errorStats;
|
||||
|
||||
//file writing for offline competition
|
||||
//file writing for error data
|
||||
long int t = static_cast<long int>(time(NULL));
|
||||
std::ofstream errorFile;
|
||||
errorFile.open (errorDir + folder + "/error_" + std::to_string(numFile) + "_" + std::to_string(t) + ".csv");
|
||||
@@ -209,22 +237,34 @@ void run(DataSetup setup, int numFile, std::string folder) {
|
||||
|
||||
} else if (e.type == FileReader::Sensor::GYRO) {
|
||||
const FileReader::TS<GyroscopeData>& _gyr = fr.getGyroscope()[e.idx];
|
||||
const float delta = td.addGyroscope(ts, _gyr.data);
|
||||
ctrl.turnSinceLastTransition_rad += delta;
|
||||
const float delta_gyro = td.addGyroscope(ts, _gyr.data);
|
||||
|
||||
ctrl.turnSinceLastTransition_rad += delta_gyro;
|
||||
|
||||
} else if (e.type == FileReader::Sensor::BARO) {
|
||||
relBaro.add(ts, fr.getBarometer()[e.idx].data);
|
||||
obs.relativePressure = relBaro.getPressureRealtiveToStart();
|
||||
obs.sigmaPressure = relBaro.getSigma();
|
||||
|
||||
} else if (e.type == FileReader::Sensor::LIN_ACC) {
|
||||
md.addLinearAcceleration(ts, fr.getLinearAcceleration()[e.idx].data);
|
||||
|
||||
} else if (e.type == FileReader::Sensor::GRAVITY) {
|
||||
md.addGravity(ts, fr.getGravity()[e.idx].data);
|
||||
Eigen::Vector2f curVec = md.getCurrentMotionAxis();
|
||||
ctrl.motionDeltaAngle_rad = md.getMotionChangeInRad();
|
||||
}
|
||||
|
||||
if (ts.ms() - lastTimestamp.ms() > 500) {
|
||||
if (ts.ms() - lastTimestamp.ms() > 500) {
|
||||
|
||||
obs.currentTime = ts;
|
||||
|
||||
MyState est = pf.update(&ctrl, obs);
|
||||
Point3 estPos = est.position.inMeter();
|
||||
|
||||
//current ground truth position
|
||||
Point3 gtPos = gtInterpolator.get(static_cast<uint64_t>(ts.ms()));
|
||||
|
||||
plot.pInterest.clear();
|
||||
|
||||
// plotting stuff
|
||||
@@ -238,7 +278,7 @@ void run(DataSetup setup, int numFile, std::string folder) {
|
||||
//plot.debugProb(grid, std::bind(&PFEval::getALL, eval, std::placeholders::_1, std::placeholders::_2), obs);
|
||||
|
||||
plot.setEst(estPos);
|
||||
//plot.setGT(mapPos);
|
||||
plot.setGT(gtPos);
|
||||
plot.addEstimationNode(estPos);
|
||||
plot.addParticles(pf.getParticles());
|
||||
//plot.gp << "set arrow 919 from " << tt.pos.x << "," << tt.pos.y << "," << tt.pos.z << " to "<< tt.pos.x << "," << tt.pos.y << "," << tt.pos.z+1 << "lw 3\n";
|
||||
@@ -249,12 +289,12 @@ void run(DataSetup setup, int numFile, std::string folder) {
|
||||
//plot.gp << "set label 1002 at screen 0.98, 0.98 'act:" << ctrl.barometer.act << "'\n";
|
||||
|
||||
// error between GT and estimation
|
||||
//float err_m = mapPos.getDistance(estPos);
|
||||
// errorStats.add(err_m);
|
||||
//errorFile << err_m << "\n";
|
||||
float err_m = gtPos.getDistance(estPos);
|
||||
errorStats.add(err_m);
|
||||
errorFile << err_m << "\n";
|
||||
|
||||
plot.show();
|
||||
usleep(100*10);
|
||||
usleep(33*10);
|
||||
|
||||
|
||||
lastTimestamp = ts;
|
||||
@@ -267,6 +307,9 @@ void run(DataSetup setup, int numFile, std::string folder) {
|
||||
|
||||
errorFile.close();
|
||||
|
||||
std::cout << "Statistical Analysis: " << std::endl;
|
||||
std::cout << "Median: " << errorStats.getMedian() << " Average: " << errorStats.getAvg() << std::endl;
|
||||
|
||||
//Write the current plotti buffer into file
|
||||
std::ofstream plotFile;
|
||||
plotFile.open(errorDir + std::to_string(numFile) + "_" + std::to_string(t) + ".gp");
|
||||
@@ -295,7 +338,7 @@ void run(DataSetup setup, int numFile, std::string folder) {
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
//Testing files
|
||||
run(data.SHL, 6, "EVAL"); // Nexus vor
|
||||
|
||||
//run(data.BERKWERK, 6, "EVALBERGWERK"); // Nexus vor
|
||||
run(data.IPIN2015, 3, "EVALIPIN2015"); // Nexus Path2
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user