From 3a1cd1bcccf10107e112ef83974237fb8de08218 Mon Sep 17 00:00:00 2001 From: kazu Date: Sun, 2 Oct 2016 18:28:17 +0200 Subject: [PATCH] fixed fallback step-logger moved vap-grouping to settings-file sanity-checks --- Controller.cpp | 20 +++++++---- Controller.h | 5 +-- Settings.h | 17 ++++++++- ipin/Config.h | 7 ++-- ipin/IPINHelper.h | 3 +- ipin/StepLogger.h | 6 ++-- ipin/StepLoggerWrapper.h | 62 +++++++++++++++++++++++++++------ ipin/StepLoggerWrapperAndroid.h | 2 +- nav/Filter.h | 5 +-- 9 files changed, 95 insertions(+), 32 deletions(-) diff --git a/Controller.cpp b/Controller.cpp index 680ba42..84e5d71 100644 --- a/Controller.cpp +++ b/Controller.cpp @@ -33,7 +33,7 @@ #include "nav/NavController.h" -Controller::Controller() : sl(scaler) { +Controller::Controller() { // OpenGL setup // MUST happen before anything gets visible (= gets initialized) @@ -51,9 +51,9 @@ Controller::Controller() : sl(scaler) { //SensorFactory::set(new SensorFactoryOffline(Settings::Data::getOfflineDir() + "bergwerk/path3/nexus/vor/1454782562231.csv")); //SensorFactory::set(new SensorFactoryOffline(Settings::Data::getOfflineDir() + "/bergwerk/path4/nexus/rueck/1454776724285_rueck.csv")); - //SensorFactory::set(new SensorFactoryOffline(Settings::Data::getOfflineDir() + "/bergwerk/path4/nexus/vor/1454776525797.csv")); + SensorFactory::set(new SensorFactoryOffline(Settings::Data::getOfflineDir() + "/bergwerk/path4/nexus/vor/1454776525797.csv")); - SensorFactory::set(new SensorFactoryAndroid()); +// SensorFactory::set(new SensorFactoryAndroid()); // SensorFactory::get().getAccelerometer().start(); // SensorFactory::get().getGyroscope().start(); // SensorFactory::get().getBarometer().start(); @@ -62,6 +62,9 @@ Controller::Controller() : sl(scaler) { // create the main window mainWindow = new MainWindow(); + sl = new StepLoggerWrapperAndroid(scaler); + //sl = new StepLoggerWrapper(scaler, mainWindow); + // attach logger LoggerComposite* log = new LoggerComposite(); @@ -120,10 +123,10 @@ void buildGridOnce(Grid* grid, Floorplan::IndoorMap* map, const std: // WiFi setup WiFiModelLogDistCeiling wifiModel(map); if (replyWiFiFP == QMessageBox::Yes) { - VAPGrouper vg(VAPGrouper::Mode::LAST_MAC_DIGIT_TO_ZERO, VAPGrouper::Aggregation::AVERAGE); + WiFiCalibrationDataModel mdl(fpFile); Assert::isFalse(mdl.getFingerprints().empty(), "no fingerprints available!"); - WiFiOptimizer opt(map, vg); + WiFiOptimizer opt(map, Settings::WiFiModel::vg_calib); for (const WiFiFingerprint& fp : mdl.getFingerprints()) { opt.addFingerprint(fp); } @@ -135,8 +138,11 @@ void buildGridOnce(Grid* grid, Floorplan::IndoorMap* map, const std: } } else { + // NOTE IPIN UAH map does not make sense.. APs look like VAPs but are not + // -> disable VAP-grouping in Settings.h [this is for eval and here] + // load all APs from the floorplan and use same TXP/EXP/WAF for all of them - wifiModel.loadAPs(map, Settings::WiFiModel::TXP, Settings::WiFiModel::EXP, Settings::WiFiModel::WAF); + wifiModel.loadAPs(map, Settings::WiFiModel::vg_calib, Settings::WiFiModel::TXP, Settings::WiFiModel::EXP, Settings::WiFiModel::WAF); Assert::isFalse(wifiModel.getAllAPs().empty(), "no AccessPoints stored within the map.xml"); } @@ -227,7 +233,7 @@ void Controller::onLoadButton() { getMapView3D()->setVisible(false); // attach ipin step logger - nav->addListener(&sl); + nav->addListener(sl); } diff --git a/Controller.h b/Controller.h index a5c9989..3e1be79 100644 --- a/Controller.h +++ b/Controller.h @@ -44,8 +44,9 @@ protected: // scaling for the UAH building IPINScaler scaler = IPINScaler(1869, 1869, 40.51312440, -3.34959080, -40.73112000, 0.07596002); - //StepLoggerWrapper sl; - StepLoggerWrapperAndroid sl; + + //StepLoggerWrapper* sl = nullptr; + StepLoggerWrapperAndroid* sl = nullptr; private slots: diff --git a/Settings.h b/Settings.h index 9b93fee..a1ee335 100644 --- a/Settings.h +++ b/Settings.h @@ -3,6 +3,7 @@ #include #include +#include #include @@ -25,6 +26,9 @@ namespace Settings { } + + + //const GridPoint destination = GridPoint(70*100, 35*100, 0*100); // use destination const GridPoint destination = GridPoint(0,0,0); // do not use destination @@ -33,11 +37,21 @@ namespace Settings { } namespace WiFiModel { + constexpr float sigma = 13.0; + /** if the wifi-signal-strengths are stored on the grid-nodes, this needs a grid rebuild! */ constexpr float TXP = -48; constexpr float EXP = 2.5; constexpr float WAF = -5.0; + + // how to perform VAP grouping. see + // - calibration in Controller.cpp + // - eval in Filter.h + // NOTE: maybe the UAH does not allow valid VAP grouping? delete the grid and rebuild without! + const VAPGrouper vg_calib = VAPGrouper(VAPGrouper::Mode::LAST_MAC_DIGIT_TO_ZERO, VAPGrouper::Aggregation::AVERAGE); + const VAPGrouper vg_eval = VAPGrouper(VAPGrouper::Mode::LAST_MAC_DIGIT_TO_ZERO, VAPGrouper::Aggregation::AVERAGE); + } @@ -71,7 +85,8 @@ namespace Settings { if (QFile(f2.c_str()).exists()) {return f2;} throw Exception("data folder missing"); #else - return "/home/toni/Documents/programme/localization/YASMIN/YASMIN_DATA/"; + //return "/home/toni/Documents/programme/localization/YASMIN/YASMIN_DATA/"; + return "/apps/android/workspace/YASMIN_DATA/"; #endif } diff --git a/ipin/Config.h b/ipin/Config.h index dae9d7e..cbe177f 100644 --- a/ipin/Config.h +++ b/ipin/Config.h @@ -7,6 +7,8 @@ #include #include "IPINHelper.h" +#include + class EvalConfig { private: @@ -31,9 +33,10 @@ public: /** load the given configuration file */ void load(const std::string& file) { + std::ifstream inp(file); - if (!inp.good()) {throw "error while opening config file " + file;} + if (!inp.good()) {throw Exception("error while opening config file " + file);} std::string line; @@ -78,7 +81,7 @@ private: // split key and value const size_t pos = line.find(" = "); - if (pos == std::string::npos) {throw "something wrong";} + if (pos == std::string::npos) {throw Exception("something wrong");} const std::string key = line.substr(0, pos); const std::string val = line.substr(pos+3); diff --git a/ipin/IPINHelper.h b/ipin/IPINHelper.h index 973f721..2a525ae 100644 --- a/ipin/IPINHelper.h +++ b/ipin/IPINHelper.h @@ -11,7 +11,8 @@ public: static std::string getDataFolder() { #ifdef ANDROID - return getenv("DIRECTORY_DOWNLOADS"); + //return std::string(getenv("DIRECTORY_DOWNLOADS")) + "/"; + return "/sdcard/Download/"; #else return "/apps/android/workspace/YASMIN_DATA/"; #endif diff --git a/ipin/StepLogger.h b/ipin/StepLogger.h index 2b978b6..257ecb5 100644 --- a/ipin/StepLogger.h +++ b/ipin/StepLogger.h @@ -43,7 +43,7 @@ public: void onButtonPress() { // sanity check - if (isDone()) {throw "all waypoints were processed";} + if (isDone()) {throw Exception("all waypoints were processed");} // construct output string std::stringstream ss; @@ -142,8 +142,8 @@ private: const std::string fPos = folder + "positions.log"; // open two output files - outButtons.open(fBtn); if (!outButtons.good()) {throw "error while creating file";} - outPositions.open(fPos); if (!outPositions.good()) {throw "error while creating file";} + outButtons.open(fBtn); if (!outButtons.good()) {throw Exception("error while creating file");} + outPositions.open(fPos); if (!outPositions.good()) {throw Exception("error while creating file");} // reset current WayPoint curWP = 0; diff --git a/ipin/StepLoggerWrapper.h b/ipin/StepLoggerWrapper.h index 9da6a59..0c22b3b 100644 --- a/ipin/StepLoggerWrapper.h +++ b/ipin/StepLoggerWrapper.h @@ -6,10 +6,15 @@ #include "../nav/NavControllerListener.h" #include +#include #include #include #include #include +#include +#include + +#include /** * helper class to connect our NavigationController with the StepLogger @@ -21,13 +26,17 @@ private: /** convert from our position-format to ipin position-format */ IPINScaler& scaler; - QMainWindow* window; - QPushButton* btn; + QWidget* widget = nullptr; + QPushButton* btn = nullptr; + QLabel* lblInfo = nullptr; + QWidget* parent;// = nullptr; + int cnt = 0; + Timestamp lastEstTS; public: /** ctor */ - StepLoggerWrapper(IPINScaler& scaler) : scaler(scaler) { + StepLoggerWrapper(IPINScaler& scaler, QWidget* parent) : scaler(scaler), parent(parent) { setupUI(); } @@ -44,6 +53,12 @@ public: // inform the logger StepLogger::onNewEstimation(ipin.lat, ipin.lon, ipin.floorNr); + ++cnt; + const Timestamp curTS = Timestamp::fromUnixTime(); + const Timestamp diff = curTS - lastEstTS; + lastEstTS = curTS; + lblInfo->setText("Est: " + QString::number(cnt) + " time: " + QString::number(diff.ms())); + } private: @@ -51,23 +66,43 @@ private: /** create a clickable check button */ void setupUI() { - window = new QMainWindow(); - //window->setTitle("StepLogger"); - btn = new QPushButton(window); - // almost fullscreen QRect geom = QDesktopWidget().availableGeometry(); - const int w = geom.width() * 0.9; - const int h = geom.height() * 0.6; + const int w = std::min(geom.width(), geom.height()) * 0.4; + const int h = w; + + /* + window = new QDialog(); // center and set always-on-top - window->setGeometry(geom.width()/2 - w/2, geom.height()/2 - h/2, w, h); + window->setGeometry(geom.width()*0.7 - w/2, geom.height()*0.7 - h/2, w, h); const Qt::WindowFlags flags = window->windowFlags(); window->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint); + btn = new QPushButton(window); btn->setGeometry(5,5,w-5-5,h-5-5); - window->show(); + */ + + + widget = new QWidget(parent); + widget->setGeometry(geom.width() - w - 5, geom.height()*0.85 - h, w, h); + widget->setWindowFlags(widget->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint); + widget->setVisible(true); + + QGridLayout* lay = new QGridLayout(widget); + + btn = new QPushButton(); + btn->setMinimumSize(w-10, h*0.8); + btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + btn->setWindowFlags(btn->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint); + + lay->addWidget(btn, 0, 0, 1, 1); + + lblInfo = new QLabel(); + lblInfo->setMinimumHeight(32); lblInfo->setMaximumHeight(32); + lblInfo->setText("123"); + lay->addWidget(lblInfo, 1, 0, 1, 1); // button clicked -> next waypoint btn->connect(btn, &QPushButton::clicked, [&] () { @@ -78,6 +113,11 @@ private: // show the current waypoint updateButton(); +// //window->exec(); +// window->setFocusPolicy(Qt::StrongFocus); +// window->setAttribute(Qt::WA_AcceptTouchEvents, true); +// window->show(); + } /** update the current button label */ diff --git a/ipin/StepLoggerWrapperAndroid.h b/ipin/StepLoggerWrapperAndroid.h index 5fde888..0c6560c 100644 --- a/ipin/StepLoggerWrapperAndroid.h +++ b/ipin/StepLoggerWrapperAndroid.h @@ -53,7 +53,7 @@ private: double rounded_z = std::round(z); int res = QAndroidJniObject::callStaticMethod("indoor/java/StepLoggerClient", "log", "(DDD)I", x, y, rounded_z); - //if (res != 1337) {throw Exception("invalid return code while sending the current position to StepLogger.\nService Down?");} + if (res != 1337) {throw Exception("invalid return code while sending the current position to StepLogger.\nService Down?");} #endif } diff --git a/nav/Filter.h b/nav/Filter.h index d751572..eb3db90 100644 --- a/nav/Filter.h +++ b/nav/Filter.h @@ -154,9 +154,6 @@ class PFEval : public K::ParticleFilterEvaluation { //WiFiObserverFree wiFiProbability; // free-calculation WiFiObserverGrid wiFiProbability; // grid-calculation - // how to perform VAP grouping. also see calibration in Controller.cpp - VAPGrouper vg = VAPGrouper(VAPGrouper::Mode::LAST_MAC_DIGIT_TO_ZERO, VAPGrouper::Aggregation::AVERAGE); - // smartphone is 1.3 meter above ground const Point3 person = Point3(0,0,Settings::smartphoneAboveGround); @@ -203,7 +200,7 @@ public: // vap-grouping const int numAP1 = observation.wifi.entries.size(); - const WiFiMeasurements wifiObs = vg.group(_observation.wifi); + const WiFiMeasurements wifiObs = Settings::WiFiModel::vg_eval.group(_observation.wifi); const int numAP2 = wifiObs.entries.size(); Log::add("Filter", "VAP: " + std::to_string(numAP1) + " -> " + std::to_string(numAP2));