Skip to content

Commit

Permalink
*Waaaay better (sum all) air time detection
Browse files Browse the repository at this point in the history
*Fixed headers order on all reports (problem with Q_OS_LINUX not being defined before adding normal Qt headers)
*NormFeet device replaces invalid readings with the readings from the other foot
*Fuzzy detector considers only imu.acc.z reading (further consideration of sqrt(imu.acc.x**2 + imu.acc.y**2) is considered)



git-svn-id: http://www.cpscotti.com/pushsnowboarding@14 c819a03f-852d-4de4-a68c-c3ac47756727
  • Loading branch information
cpscotti committed Feb 15, 2011
1 parent 79a02c7 commit 41db957
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 104 deletions.
30 changes: 19 additions & 11 deletions PushBurton2/FilesystemConventions.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
#ifndef FILESYSTEMCONVENTIONS_H
#define FILESYSTEMCONVENTIONS_H

#define FSC_FSYS_SLASH "/"
//#define FSC_FSYS_SLASH "/"

//#warning FSC loaded

#ifdef Q_OS_SYMBIAN
#define FSC_RUNS_FOLDERS_ROOT "E:/"
#define FSC_FSYS_SLASH "/"
#define FSC_SETTINGS_FOLDER ""
// #warning Q_OS_SYMBIAN Selected
#else
#ifdef Q_OS_LINUX
#define FSC_RUNS_FOLDERS_ROOT "/home/cpscotti/"
#define FSC_FSYS_SLASH "/"
#define FSC_SETTINGS_FOLDER "NPBSettings/"
// #warning Q_OS_LINUX Selected
#else
#ifdef Q_OS_WIN32
#define FSC_RUNS_FOLDERS_ROOT "C:\\"
#define FSC_FSYS_SLASH "\\"
#define FSC_SETTINGS_FOLDER "NPBSettings\\"
// #warning Q_OS_WIN32 Selected
#else
#error NO PLATFORM Selected
#endif
#endif

#ifdef Q_OS_LINUX
#define FSC_RUNS_FOLDERS_ROOT "/home/cpscotti/"
#define FSC_FSYS_SLASH "/"
#define FSC_SETTINGS_FOLDER "NPBSettings/"
#endif

#ifdef Q_OS_WIN32
#define FSC_RUNS_FOLDERS_ROOT "C:\\"
#define FSC_FSYS_SLASH "\\"
#define FSC_SETTINGS_FOLDER "NPBSettings\\"
#endif

#define FSC_RUNS_PREFIX "NPBRun"
Expand Down
82 changes: 46 additions & 36 deletions PushBurton2/fuzzydetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,40 @@
FuzzyDetector::FuzzyDetector()
{
fp_onAir.push_back(Relation(0.0, 1.0));//No pressure, air
fp_onAir.push_back(Relation(2000.0, 1.0));
fp_onAir.push_back(Relation(2600.0, 0.0));
fp_onAir.push_back(Relation(1900.0, 1.0));
fp_onAir.push_back(Relation(2100.0, 0.0));
fp_onAir.push_back(Relation(4024.0, 0.0));//full pressure, dunno

fp_onGrnd.push_back(Relation(0.0, 0.0));//No pressure, dunno
fp_onGrnd.push_back(Relation(2600.0, 0.0));
fp_onGrnd.push_back(Relation(3000.0, 0.9));
fp_onGrnd.push_back(Relation(2100.0, 0.0));
fp_onGrnd.push_back(Relation(2500.0, 0.8));
fp_onGrnd.push_back(Relation(2800.0, 1.0));
fp_onGrnd.push_back(Relation(4024.0, 1.0));//full pressure, ground

pa_onAir.push_back(Relation(0.0, 1.0));//no gravity, on air!
pa_onAir.push_back(Relation(3.0, 1.0));
pa_onAir.push_back(Relation(6.6, 0.0));
pa_onAir.push_back(Relation(7.0, 0.0));
pa_onAir.push_back(Relation(50.0, 0.0));//hell no!

// fp_onGrnd.push_back(Relation(0.0, 0.0));//No pressure, dunno
// fp_onGrnd.push_back(Relation(2600.0, 0.0));
// fp_onGrnd.push_back(Relation(3300.0, 1.0));
// fp_onGrnd.push_back(Relation(4024.0, 1.0));//full pressure, ground

// pa_onAir.push_back(Relation(0.0, 1.0));//no gravity, on air!
// pa_onAir.push_back(Relation(3.0, 1.0));
// pa_onAir.push_back(Relation(6.0, 0.0));
// pa_onAir.push_back(Relation(50.0, 0.0));//hell no!

pa_onGrnd.push_back(Relation(0.0, 0.0));//no gravity, hell no
pa_onGrnd.push_back(Relation(6.0, 0.0));
pa_onGrnd.push_back(Relation(9.0, 1.0));
pa_onGrnd.push_back(Relation(7.0, 0.0));
pa_onGrnd.push_back(Relation(9.0, 0.5));
pa_onGrnd.push_back(Relation(15.0, 1.0));//definitely on ground
pa_onGrnd.push_back(Relation(50.0, 1.0));//definitely on ground

ia_onAir.push_back(Relation(0.0, 0.8));
ia_onAir.push_back(Relation(0.6, 0.0));
ia_onAir.push_back(Relation(8.0, 0.0));

ia_onGrnd.push_back(Relation(0.0, 0.0));
ia_onGrnd.push_back(Relation(1.0, 0.0));
ia_onGrnd.push_back(Relation(3.0, 1.0));
ia_onGrnd.push_back(Relation(8.0, 1.0));
ia_onAir.push_back(Relation(-10.0, 0.0));
ia_onAir.push_back(Relation(-0.5, 0.0));
ia_onAir.push_back(Relation(0.0, 1.0));
ia_onAir.push_back(Relation(1.0, 1.0));
ia_onAir.push_back(Relation(1.5, 0.0));
ia_onAir.push_back(Relation(10.0, 0.0));

ia_onGrnd.push_back(Relation(-10.0, 1.0));
ia_onGrnd.push_back(Relation(-3.0, 1.0));
ia_onGrnd.push_back(Relation(-1.0, 0.6));
ia_onGrnd.push_back(Relation(-0.3, 0.0));
ia_onGrnd.push_back(Relation(10.0, 0.0));

LoadFromXml((QString(FSC_RUNS_FOLDERS_ROOT)+FSC_SETTINGS_FOLDER)+"atdsettings.xml");//if file doesn't exist, do nothing + save it

Expand All @@ -86,7 +83,6 @@ Response FuzzyDetector::FuzzyficateToAirOrGround(double fp, double pa, double ia
oa_fp = fp_onAir.fuzificate(fp);
og_fp = fp_onGrnd.fuzificate(fp);
}

if(!isnan(pa)) {
oa_pa = pa_onAir.fuzificate(pa);
og_pa = pa_onGrnd.fuzificate(pa);
Expand All @@ -97,25 +93,23 @@ Response FuzzyDetector::FuzzyficateToAirOrGround(double fp, double pa, double ia
og_ia = ia_onGrnd.fuzificate(ia);
}

double onAir = std::max(oa_fp, std::max(oa_pa, oa_ia));
double onGround = std::max(og_fp, std::max(og_pa, og_ia));
//Most certain dictates all
// double onAir = std::max(oa_fp, std::max(oa_pa, oa_ia));
// double onGround = std::max(og_fp, std::max(og_pa, og_ia));

//Sum of all votes
double onAir = (oa_fp+oa_pa+oa_ia)/3.0;
double onGround = (og_fp+og_pa+og_ia)/3.0;

Response resp;
if(onAir > onGround) {
if(onAir > 0.8 && onGround < 0.5) {
if(onAir > 0.15) {// && onGround < 0.6) {
resp = FlyingLikeAnEagle;

// qDebug() << "onAir " << oa_fp <<"(fp)/"
// << oa_pa <<"(pa)/"
// << oa_ia << "(ia), onGround "
// << og_fp <<"(fp)/"
// << og_pa <<"(pa)/"
// << og_ia << "ia";
} else {
resp = CantHelpYouOnThisOne;
}
} else if(onAir < onGround){
if(onGround > 0.8 && onAir < 0.5) {
if(onGround > 0.15) {// && onAir < 0.6) {
resp = SlidingDownLikeAPenguin;
} else {
resp = CantHelpYouOnThisOne;
Expand All @@ -124,6 +118,22 @@ Response FuzzyDetector::FuzzyficateToAirOrGround(double fp, double pa, double ia
resp = CantHelpYouOnThisOne;
}

QString sresp;
if(resp == FlyingLikeAnEagle) {
sresp = " AIR ";
} else if(resp == SlidingDownLikeAPenguin) {
sresp = " GROUND ";
} else {
sresp = " UNKNOWN ";
}

qDebug() << sresp << ": onAir (" << onAir << ") " << oa_fp <<"(fp)/"
<< oa_pa <<"(pa)/"
<< oa_ia << "(ia), onGround (" << onGround << ")"
<< og_fp <<"(fp)/"
<< og_pa <<"(pa)/"
<< og_ia << "ia";

return resp;
}

Expand Down
4 changes: 2 additions & 2 deletions PushBurton2/npushreportairtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#ifndef NPUSHREPORTAIRTIME_H
#define NPUSHREPORTAIRTIME_H

#include "FilesystemConventions.h"

#include "npushgenreport.h"
#include <QList>
#include <QObject>
Expand All @@ -40,6 +38,8 @@
#include <QXmlStreamReader>
#include <QFile>

#include "FilesystemConventions.h"

class NPushReportAirTime : public NPushGenReport
{
Q_OBJECT
Expand Down
4 changes: 2 additions & 2 deletions PushBurton2/npushreportaltitude.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#ifndef NPUSHREPORTALTITUDE_H
#define NPUSHREPORTALTITUDE_H

#include "FilesystemConventions.h"

#include "npushgenreport.h"
#include <QVector>
#include <QObject>
Expand All @@ -42,6 +40,8 @@

#include "selfshrinkinglist.h"

#include "FilesystemConventions.h"

class NPushReportAltitude : public NPushGenReport
{
Q_OBJECT
Expand Down
3 changes: 1 addition & 2 deletions PushBurton2/npushreportgsr.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#ifndef NPUSHREPORTGSR_H
#define NPUSHREPORTGSR_H

#include "FilesystemConventions.h"

#include "npushgenreport.h"
#include <QVector>
#include <QObject>
Expand All @@ -42,6 +40,7 @@

#include "selfshrinkinglist.h"

#include "FilesystemConventions.h"
class NPushReportGSR : public NPushGenReport
{
Q_OBJECT
Expand Down
4 changes: 2 additions & 2 deletions PushBurton2/npushreportheart.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#ifndef NPUSHREPORTHEART_H
#define NPUSHREPORTHEART_H

#include "FilesystemConventions.h"

#include "npushgenreport.h"
#include <QVector>
#include <QObject>
Expand All @@ -42,6 +40,8 @@

#include "selfshrinkinglist.h"

#include "FilesystemConventions.h"

class NPushReportHeart : public NPushGenReport
{
Q_OBJECT
Expand Down
4 changes: 2 additions & 2 deletions PushBurton2/npushreportspeed.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#ifndef NPUSHREPORTSPEED_H
#define NPUSHREPORTSPEED_H

#include "FilesystemConventions.h"

#include "npushgenreport.h"
#include <QVector>
#include <QObject>
Expand All @@ -40,6 +38,8 @@
#include <QXmlStreamReader>
#include <QFile>

#include "FilesystemConventions.h"

#include "selfshrinkinglist.h"

class NPushReportSpeed : public NPushGenReport
Expand Down
22 changes: 18 additions & 4 deletions PushBurton2/pushn8absnormfeetdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,25 @@ void PushN8AbsNormFeetDevice::incomming_reading(NPushLogTick * gtick)
NPushFootTick * ftick = (NPushFootTick *)gtick;

if(ftick->side == 'L') {
pdata.LToe.update(ftick->toes);
pdata.LHeel.update(ftick->heel);
pdata.LToe.update(
(ftick->toes > FOOT_PRESSURE_INVALID_THRESHOLD)?
ftick->toes : pdata.RToe.rawVal
);

pdata.LHeel.update(
(ftick->heel > FOOT_PRESSURE_INVALID_THRESHOLD)?
ftick->heel : pdata.RHeel.rawVal
);
} else {
pdata.RToe.update(ftick->toes);
pdata.RHeel.update(ftick->heel);
pdata.RToe.update(
(ftick->toes > FOOT_PRESSURE_INVALID_THRESHOLD)?
ftick->toes : pdata.LToe.rawVal
);

pdata.RHeel.update(
(ftick->heel > FOOT_PRESSURE_INVALID_THRESHOLD)?
ftick->heel : pdata.LHeel.rawVal
);
}

if((ftick->msecsToEpoch - lastReading) < 100 &&
Expand Down
11 changes: 8 additions & 3 deletions PushBurton2/pushn8airtimedetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ void PushN8AirTimeDetector::incomming_reading(NPushLogTick * gtick)
currentTstamp = ftick->msecsToEpoch;

runFuzzy = true;
if(fp < 2000) {
qDebug() << "Got air here";
}


// qDebug() << "Got Sum: " << ftick->pdata.totalRawSum;
Expand All @@ -61,9 +64,10 @@ void PushN8AirTimeDetector::incomming_reading(NPushLogTick * gtick)
nacc[1] = (((double)itick->accel[1]) -512.0)*1.0/107.0;
nacc[2] = (((double)itick->accel[2]) -512.0)*1.0/107.0;

qreal imuAccAbs = qSqrt(nacc[0]*nacc[0] + nacc[1]*nacc[1] + nacc[2]*nacc[2]);
// qreal imuAccAbs = qSqrt(nacc[0]*nacc[0] + nacc[1]*nacc[1] + nacc[2]*nacc[2]);

ia = imuAccAbs;
// ia = imuAccAbs;
ia = nacc[2];//imu.acc.z

// qDebug() << "Got IMU: " << nacc[0] << "," << nacc[1] << "," << nacc[2] << " abs: " << imuAccAbs;

Expand All @@ -78,7 +82,7 @@ void PushN8AirTimeDetector::incomming_reading(NPushLogTick * gtick)

if( (!isnan(fp) || !isnan(pa) || !isnan(ia))
&& runFuzzy) {
// qDebug() << currentTstamp;
qDebug() << QString::number(currentTstamp/1000.0, 'f', 3);
Response resp = fuzzyDetector.FuzzyficateToAirOrGround(fp, pa, ia);

// handle_response(resp);
Expand All @@ -100,6 +104,7 @@ void PushN8AirTimeDetector::handle_response_new(Response resp)

takeOffTime = currentTstamp;
lastAirborneTime = takeOffTime;
qDebug() << "take off: " << takeOffTime;
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion PushBurton2/pushn8airtimedetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class PushN8AirTimeDetector : public PushBurtonGenericDevice

double fp,pa,ia;

static const quint64 air_threshold = 400;//how big an air needs to be to be even considered
static const quint64 air_threshold = 200;//how big an air needs to be to be even considered

static const quint64 ground_threshold = 200;//for how long the rider needs to be on the
//ground to count as landing
Expand Down
Loading

0 comments on commit 41db957

Please sign in to comment.