From 41c1d90c54fd2e288d0c4c1b77c5bc67710ff621 Mon Sep 17 00:00:00 2001 From: toni Date: Wed, 16 Nov 2016 12:40:16 +0100 Subject: [PATCH] small fix. added getter and setter! --- .../beacon/model/BeaconModelLogDistCeiling.h | 2 +- sensors/pressure/ActivityButterPressure.h | 67 +---------- .../pressure/ActivityButterPressurePercent.h | 109 +++--------------- sensors/radio/WiFiMeasurement.h | 23 ++-- tests/sensors/pressure/TestBarometer.cpp | 4 +- 5 files changed, 34 insertions(+), 171 deletions(-) diff --git a/sensors/beacon/model/BeaconModelLogDistCeiling.h b/sensors/beacon/model/BeaconModelLogDistCeiling.h index a10a128..8e794a6 100644 --- a/sensors/beacon/model/BeaconModelLogDistCeiling.h +++ b/sensors/beacon/model/BeaconModelLogDistCeiling.h @@ -91,7 +91,7 @@ public: // sanity check Assert::isBetween(params.waf, -99.0f, 0.0f, "WAF out of bounds [-99:0]"); - Assert::isBetween(params.txp, -50.0f, -30.0f, "TXP out of bounds [-50:-30]"); + Assert::isBetween(params.txp, -90.0f, -30.0f, "TXP out of bounds [-50:-30]"); Assert::isBetween(params.exp, 1.0f, 4.0f, "EXP out of bounds [1:4]"); Assert::equal(beacons.find(beacon), beacons.end(), "AccessPoint already present!"); diff --git a/sensors/pressure/ActivityButterPressure.h b/sensors/pressure/ActivityButterPressure.h index 2d1617c..be53031 100644 --- a/sensors/pressure/ActivityButterPressure.h +++ b/sensors/pressure/ActivityButterPressure.h @@ -18,8 +18,6 @@ public: enum Activity {DOWN, STAY, UP}; - - struct History { Timestamp ts; BarometerData data; @@ -27,14 +25,8 @@ public: }; private: - //just for debugging and plotting - std::vector input; - std::vector inputInterp; - std::vector output; - std::vector sumHist; - std::vector mvAvgHist; - std::vector actHist; + std::vector output; Activity currentActivity; MovingAVG mvAvg = MovingAVG(20); @@ -47,8 +39,8 @@ public: * FixedFrequencyInterpolator ffi = FixedFrequencyInterpolator(Timestamp::fromMS(100)); */ const bool additionalLowpassFilter = false; - const int diffSize = 20; //the number values used for finding the activity. - const float threshold = 0.025; // if diffSize is getting smaller, treshold needs to be adjusted in the same direction! + const unsigned long diffSize = 20; //the number values used for finding the activity. + const float threshold = 0.025f; // if diffSize is getting smaller, treshold needs to be adjusted in the same direction! Filter::ButterworthLP butter = Filter::ButterworthLP(10,0.05f,2); Filter::ButterworthLP butter2 = Filter::ButterworthLP(10,0.05f,2); @@ -76,14 +68,11 @@ public: return STAY; } - //input.push_back(History(ts, baro)); - bool newInterpolatedValues = false; //interpolate & butter auto callback = [&] (const Timestamp ts, const float val) { float interpValue = val; - //inputInterp.push_back(History(ts, BarometerData(interpValue))); //butter float butterValue = butter.process(interpValue); @@ -97,10 +86,10 @@ public: if(newInterpolatedValues == true){ //getActivity - if((int)output.size() > diffSize){ + if(output.size() > diffSize){ //diff std::vector diff; - for(int i = output.size() - diffSize; i < output.size() - 1; ++i){ + for(unsigned long i = output.size() - diffSize; i < output.size() - 1; ++i){ float diffVal = output[i+1].data.hPa - output[i].data.hPa; @@ -121,7 +110,6 @@ public: }else{ actValue = sum; } - //sumHist.push_back(actValue); if(actValue > threshold){ currentActivity = DOWN; @@ -135,8 +123,6 @@ public: } } - //actHist.push_back(History(ts, BarometerData(currentActivity))); - return currentActivity; } @@ -145,49 +131,6 @@ public: Activity getCurrentActivity() { return currentActivity; } - - std::vector getSensorHistory(){ - std::vector tmp; - - for(History val : input){ - tmp.push_back(val.data.hPa); - } - - return tmp; - } - - std::vector getInterpolatedHistory(){ - std::vector tmp; - - for(History val : inputInterp){ - tmp.push_back(val.data.hPa); - } - - return tmp; - } - - std::vector getOutputHistory(){ - - std::vector tmp; - - for(History val : output){ - tmp.push_back(val.data.hPa); - } - - return tmp; - } - - std::vector getSumHistory(){ - return sumHist; - } - - - std::vector getActHistory(){ - - return actHist; - } - - }; #endif // ACTIVITYBUTTERPRESSURE_H diff --git a/sensors/pressure/ActivityButterPressurePercent.h b/sensors/pressure/ActivityButterPressurePercent.h index 85290e2..c20583e 100644 --- a/sensors/pressure/ActivityButterPressurePercent.h +++ b/sensors/pressure/ActivityButterPressurePercent.h @@ -14,6 +14,8 @@ /** * receives pressure measurements, interpolates them to a ficex frequency, lowpass filtering * activity recognition based on a small window given by matlabs diff(window) + * + * todo: if an elevator is detected, first we have a short time the stairs are more prober. */ class ActivityButterPressurePercent { @@ -44,20 +46,14 @@ public: }; private: - //just for debugging and plotting - std::vector input; - std::vector inputInterp; - std::vector output; - std::vector sumHist; - std::vector mvAvgHist; - std::vector actHist; + std::vector output; bool initialize; ActivityProbabilities currentActivity; /** change this values for much success */ - const int diffSize = 20; //the number values used for finding the activity. + const unsigned long diffSize = 20; //the number values used for finding the activity. Filter::ButterworthLP butter = Filter::ButterworthLP(10,0.05f,2); FixedFrequencyInterpolator ffi = FixedFrequencyInterpolator(Timestamp::fromMS(100)); @@ -65,10 +61,10 @@ private: const float muStairs = 0.04f; const float muStay = 0.00f; - const float muEleveator = 0.08; + const float muEleveator = 0.08f; std::vector densities = std::vector(5, 1); - std::vector densitiesOld = std::vector(5, 1);; + std::vector densitiesOld = std::vector(5, 1); public: @@ -90,14 +86,11 @@ public: return currentActivity; } - //input.push_back(History(ts, baro)); - bool newInterpolatedValues = false; //interpolate & butter auto callback = [&] (const Timestamp ts, const float val) { float interpValue = val; - //inputInterp.push_back(History(ts, BarometerData(interpValue))); //butter float butterValue = butter.process(interpValue); @@ -114,7 +107,7 @@ public: if(output.size() > diffSize){ //diff std::vector diff; - for(int i = output.size() - diffSize; i < output.size() - 1; ++i){ + for(unsigned long i = output.size() - diffSize; i < output.size() - 1; ++i){ float diffVal = output[i+1].data.hPa - output[i].data.hPa; @@ -127,7 +120,6 @@ public: } float actValue = sum; - //sumHist.push_back(actValue); //calculate the probabilites of walking down/up etc... densitiesOld = densities; @@ -152,17 +144,11 @@ public: _assertTrue( (densityStairsUp == densityStairsUp), "the probability of densityStairsUp is null!"); _assertTrue( (densityElevatorUp == densityElevatorUp), "the probability of densityElevatorUp is null!"); - //_assertTrue( (densityElevatorDown != 0), "the probability of densityElevatorDown is null!"); - //_assertTrue( (densityStairsDown != 0), "the probability of densityStairsDown is null!"); - //_assertTrue( (densityStay != 0), "the probability of densityStay is null!"); - //_assertTrue( (densityStairsUp != 0), "the probability of densityStairsUp is null!"); - //_assertTrue( (densityElevatorUp != 0), "the probability of densityElevatorUp is null!"); - - - //todo: aging: wahrscheinlichkeit aufzug zu fahren oder treppe zu steigen, wird nicht knall hart auf 0 gesetzt, - //sobald der sensors nichts mehr hat, sondern wird mit der zeit geringer. größer NV? - - //const Timestamp age = ts - ap.getTimestamp(); + _assertTrue( (densityElevatorDown != 0.0f), "the probability of densityElevatorDown is null!"); + _assertTrue( (densityStairsDown != 0.0f), "the probability of densityStairsDown is null!"); + _assertTrue( (densityStay != 0.0f), "the probability of densityStay is null!"); + _assertTrue( (densityStairsUp != 0.0f), "the probability of densityStairsUp is null!"); + _assertTrue( (densityElevatorUp != 0.0f), "the probability of densityElevatorUp is null!"); //wenn aufzug / treppe der größte wert, werden für x timestamps auf die jeweilige katerogie multipliziert. densities[0] = densityElevatorDown; @@ -171,47 +157,19 @@ public: densities[3] = densityStairsUp; densities[4] = densityElevatorUp; - //int highestValueIdx = densities.at(distance(densities.begin(), max_element (densities.begin(),densities.end()))); - // if an activity other then staying is detected with a high probability, we are using the previous probability - // to keep it a little while longer. this prevents hard activity changes and helping the transition and evaluation - // to not jump between elevators/stairs and the floor and provide somewhat a smooother floorchange. - // TODO: Put this into the Project and not in Indoor, since this class should only provide the probability of the - // given activity! Since i had no time, this was the fastest solution for now. -// if(highestValueIdx != 2){ -// for(int i = 0; i < densities.size(); ++i){ -// densities[i] *= densitiesOld[i]; -// } -// } - - //normalize float densitySum = densities[0] + densities[1] + densities[2] + densities[3] + densities[4]; - for(int i = 0; i < densities.size(); ++i){ + for(unsigned long i = 0; i < densities.size(); ++i){ densities[i] /= densitySum; //values cant be zero! densities[i] = (densities[i] > 0.0f ? densities[i] : 0.01f); } -// densityElevatorDown /= densitySum; -// densityStairsDown /= densitySum; -// densityStay /= densitySum; -// densityStairsUp /= densitySum; -// densityElevatorUp /= densitySum; - - // if one value is 1.0 and all other are 0.0, fix that by providing a small possibility -// densityElevatorDown = (densityElevatorDown > 0.0f ? densityElevatorDown : 0.01f); -// densityStairsDown = (densityStairsDown > 0.0f ? densityStairsDown : 0.01f); -// densityStay = (densityStay > 0.0f ? densityStay : 0.01f); -// densityStairsUp = (densityStairsUp > 0.0f ? densityStairsUp : 0.01f); -// densityElevatorUp = (densityElevatorUp > 0.0f ? densityElevatorUp : 0.01f); - currentActivity = ActivityProbabilities(densities[0], densities[1], densities[2], densities[3], densities[4]); } - - //actHist.push_back(currentActivity); } //retruns for every call, indepedent of callback. @@ -223,47 +181,6 @@ public: return currentActivity; } - std::vector getSensorHistory(){ - std::vector tmp; - - for(History val : input){ - tmp.push_back(val.data.hPa); - } - - return tmp; - } - - std::vector getInterpolatedHistory(){ - std::vector tmp; - - for(History val : inputInterp){ - tmp.push_back(val.data.hPa); - } - - return tmp; - } - - std::vector getOutputHistory(){ - - std::vector tmp; - - for(History val : output){ - tmp.push_back(val.data.hPa); - } - - return tmp; - } - - std::vector getSumHistory(){ - return sumHist; - } - - - std::vector getActHistory(){ - - return actHist; - } - }; diff --git a/sensors/radio/WiFiMeasurement.h b/sensors/radio/WiFiMeasurement.h index 0b63d75..d84327d 100644 --- a/sensors/radio/WiFiMeasurement.h +++ b/sensors/radio/WiFiMeasurement.h @@ -37,10 +37,10 @@ public: ; } - /** ctor with timestamp */ - WiFiMeasurement(const AccessPoint& ap, const float rssi, const Timestamp ts) : ap(ap), rssi(rssi), ts(ts) { - ; - } + /** ctor with timestamp */ + WiFiMeasurement(const AccessPoint& ap, const float rssi, const Timestamp ts) : ap(ap), rssi(rssi), ts(ts) { + ; + } /** ctor with timestamp and freq*/ WiFiMeasurement(const AccessPoint& ap, const float rssi, const float freq, const Timestamp ts) : ap(ap), rssi(rssi), freq(freq), ts(ts) { @@ -49,20 +49,23 @@ public: public: - /** get the AP we got the measurement for */ - const AccessPoint& getAP() const {return ap;} + /** 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;} + /** 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;} + /** OPTIONAL: get the measurement's timestamp (if known!) */ + const Timestamp& getTimestamp() const {return ts;} /** OPTIONAL: get the measurement's frequence (if known!) */ float getFrequency() const {return freq;} /** set another signal strength */ void setRssi(float value){rssi = value;} + + /** set the timestamp */ + void setTimestamp(const Timestamp& val){ts = val;} }; diff --git a/tests/sensors/pressure/TestBarometer.cpp b/tests/sensors/pressure/TestBarometer.cpp index 1fef297..7c3451f 100644 --- a/tests/sensors/pressure/TestBarometer.cpp +++ b/tests/sensors/pressure/TestBarometer.cpp @@ -178,7 +178,7 @@ TEST(Barometer, Activity) { gpRaw.draw(plotRaw); gpRaw.flush(); - sleep(1); + sleep(5); } @@ -236,7 +236,7 @@ TEST(Barometer, ActivityPercent) { gpRaw.draw(plotRaw); gpRaw.flush(); - sleep(1000); + sleep(5); }