From: Rikhard Kuutti Date: Wed, 3 Mar 2010 07:35:09 +0000 (+0200) Subject: Changes to Calculate class. X-Git-Tag: v0.1~94 X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=commitdiff_plain;h=46200e79ec53dc19e79b2cd6352b4b28ba894206 Changes to Calculate class. Added accelStoppedCheck function. --- diff --git a/Client/calculate.cpp b/Client/calculate.cpp index 9fd6e8b..781f7f9 100644 --- a/Client/calculate.cpp +++ b/Client/calculate.cpp @@ -126,13 +126,37 @@ void Calculate::CalculateParameters(double currentAcceleration, double seconds) */ averageSpeed = (distanceTraveled / totalTime); + /* Check for movement + */ + accelStoppedCheck(currentAcceleration); + lastSpeed = currentSpeed; lastAcceleration = currentAcceleration; lastDistance = distanceTraveled; } - - - +/** + * This function checks if acceleration has stopped for + * a short period of time. Velocity is set to zero to avoid + * distance errors. + */ +void Calculate::accelStoppedCheck(double currentAcceleration) { + + // counting number of acceleration samples that equals zero + if (currentAcceleration==0) + { + count++; + } + else + { + count = 0; + } + + // if count exceeds 25, we assume that velocity is zero + if (count >= 25) + { + currentSpeed=0; + } +} diff --git a/Client/calculate.h b/Client/calculate.h index 0008a87..db86aed 100644 --- a/Client/calculate.h +++ b/Client/calculate.h @@ -14,6 +14,7 @@ public: void reset(); void CalculateParameters(double currentAcceleration, double seconds); + void accelStoppedCheck(double currentAcceleration); double AverageSpeed(); void AverageSpeed(double value); @@ -52,7 +53,7 @@ private: double lastSpeed; long numOfIterations; double totalTime; - + int count; };