small fix. added getter and setter!
This commit is contained in:
@@ -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!");
|
||||
|
||||
@@ -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<History> input;
|
||||
std::vector<History> inputInterp;
|
||||
std::vector<History> output;
|
||||
std::vector<float> sumHist;
|
||||
std::vector<float> mvAvgHist;
|
||||
std::vector<History> actHist;
|
||||
|
||||
std::vector<History> output;
|
||||
Activity currentActivity;
|
||||
MovingAVG<float> mvAvg = MovingAVG<float>(20);
|
||||
|
||||
@@ -47,8 +39,8 @@ public:
|
||||
* FixedFrequencyInterpolator<float> ffi = FixedFrequencyInterpolator<float>(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<float> butter = Filter::ButterworthLP<float>(10,0.05f,2);
|
||||
Filter::ButterworthLP<float> butter2 = Filter::ButterworthLP<float>(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<float> 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<float> getSensorHistory(){
|
||||
std::vector<float> tmp;
|
||||
|
||||
for(History val : input){
|
||||
tmp.push_back(val.data.hPa);
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
std::vector<float> getInterpolatedHistory(){
|
||||
std::vector<float> tmp;
|
||||
|
||||
for(History val : inputInterp){
|
||||
tmp.push_back(val.data.hPa);
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
std::vector<float> getOutputHistory(){
|
||||
|
||||
std::vector<float> tmp;
|
||||
|
||||
for(History val : output){
|
||||
tmp.push_back(val.data.hPa);
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
std::vector<float> getSumHistory(){
|
||||
return sumHist;
|
||||
}
|
||||
|
||||
|
||||
std::vector<History> getActHistory(){
|
||||
|
||||
return actHist;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // ACTIVITYBUTTERPRESSURE_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<History> input;
|
||||
std::vector<History> inputInterp;
|
||||
std::vector<History> output;
|
||||
std::vector<float> sumHist;
|
||||
std::vector<float> mvAvgHist;
|
||||
std::vector<ActivityProbabilities> actHist;
|
||||
|
||||
std::vector<History> 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<float> butter = Filter::ButterworthLP<float>(10,0.05f,2);
|
||||
FixedFrequencyInterpolator<float> ffi = FixedFrequencyInterpolator<float>(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<float> densities = std::vector<float>(5, 1);
|
||||
std::vector<float> densitiesOld = std::vector<float>(5, 1);;
|
||||
std::vector<float> densitiesOld = std::vector<float>(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<float> 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<float> getSensorHistory(){
|
||||
std::vector<float> tmp;
|
||||
|
||||
for(History val : input){
|
||||
tmp.push_back(val.data.hPa);
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
std::vector<float> getInterpolatedHistory(){
|
||||
std::vector<float> tmp;
|
||||
|
||||
for(History val : inputInterp){
|
||||
tmp.push_back(val.data.hPa);
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
std::vector<float> getOutputHistory(){
|
||||
|
||||
std::vector<float> tmp;
|
||||
|
||||
for(History val : output){
|
||||
tmp.push_back(val.data.hPa);
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
std::vector<float> getSumHistory(){
|
||||
return sumHist;
|
||||
}
|
||||
|
||||
|
||||
std::vector<ActivityProbabilities> getActHistory(){
|
||||
|
||||
return actHist;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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;}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user