X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Client%2Fcalculate.cpp;h=edd4246ad88600341b7c9f2b154538c68c756779;hp=bbbdf9d9e21f987e1920393c4178850b4aba292f;hb=b6fc8202f51384f76be1c9e4fe073d738fde3389;hpb=9f59e05380da5887e6141cb89bdfab1ce9122f15 diff --git a/Client/calculate.cpp b/Client/calculate.cpp index bbbdf9d..edd4246 100644 --- a/Client/calculate.cpp +++ b/Client/calculate.cpp @@ -2,6 +2,7 @@ * Calculate class to process accelerometer data * * @author Kai Rasilainen + * @author Jukka Kurttila * @copyright (c) 2010 Speed Freak team * @license http://opensource.org/licenses/gpl-license.php GNU Public License */ @@ -36,7 +37,11 @@ Calculate::~Calculate() void Calculate::reset() { averageSpeed = 0; + averagePower = 0; + peakPower = 0; + currentPower = 0; currentSpeed = 0; + maxSpeed = 0; distanceTraveled = 0; lastAcceleration = 0; lastDistance = 0; @@ -45,10 +50,22 @@ void Calculate::reset() totalTime = 0; count = 0; - speedCheckPoints.append(10); - speedCheckPoints.append(20); - speedCheckPoints.append(30); - speedCheckPoints.append(40); + if(speedCheckPoints.count() == 0) + { + speedCheckPoints.append(10); + speedCheckPoints.append(20); + speedCheckPoints.append(30); + speedCheckPoints.append(40); + speedCheckPoints.append(50); + speedCheckPoints.append(60); + speedCheckPoints.append(70); + speedCheckPoints.append(80); + speedCheckPoints.append(90); + speedCheckPoints.append(100); + } + + checkPointCounter = 0; + checkPoint = speedCheckPoints[checkPointCounter]; } @@ -59,11 +76,13 @@ void Calculate::reset() * This function should be called 20-30 times/second to minimize * calculation error. - * To be added: params like horsepower. + * To be added: --- */ void Calculate::calculateParameters(double currentAcceleration, double seconds) { double force, power1, power2; + + currentAcceleration *= G_ACCELERATION; numOfIterations++; totalTime = (totalTime + seconds); @@ -73,6 +92,10 @@ void Calculate::calculateParameters(double currentAcceleration, double seconds) // First integration of acceleration provides speed currentSpeed = (lastSpeed + (((currentAcceleration + lastAcceleration) * seconds) / 2)); + // Update maximum speed + if (currentSpeed > maxSpeed) + maxSpeed = currentSpeed; + // Second integration: distance. distanceTraveled = (lastDistance + (((currentSpeed + lastSpeed) * seconds) / 2)); @@ -104,27 +127,27 @@ void Calculate::calculateParameters(double currentAcceleration, double seconds) numOfIterations--; } - // Checkpoints - if ((lastSpeed == 0)) + if( (checkPoint > 0) && (currentSpeed*3.6 > checkPoint) ) { - lastCheckpoint = 0; - } - - // List of checkpoints - if (!(speedCheckPoints.isEmpty())) - { - foreach (double speed, speedCheckPoints) + //Update checkPoint + if( checkPointCounter <= speedCheckPoints.count() ) { - if ((lastCheckpoint != floor(speed)) && (floor(currentSpeed) == floor(speed))) + //Save time + valuesMap.insert( checkPoint, totalTime ); + if( checkPointCounter < speedCheckPoints.count() ) { - emit checkPointReached(totalTime, currentSpeed); - lastCheckpoint = floor(currentSpeed); + checkPoint = speedCheckPoints[checkPointCounter]; } + else + { + checkPoint = 0; + } + checkPointCounter++; } } // Check for movement - accelStoppedCheck(currentAcceleration); + //accelStoppedCheck(currentAcceleration); lastSpeed = currentSpeed; lastAcceleration = currentAcceleration; @@ -138,7 +161,6 @@ void Calculate::calculateParameters(double currentAcceleration, double seconds) */ void Calculate::accelStoppedCheck(double currentAcceleration) { - // counting number of acceleration samples that equals zero if (currentAcceleration==0) { count++; @@ -234,3 +256,55 @@ void Calculate::setTotalTime(double value) { totalTime = value; } + +double Calculate::getCurrentPower() +{ + return currentPower; +} + +void Calculate::setCurrentPower(double value) +{ + currentPower = value; +} + +double Calculate::getPeakPower() +{ + return peakPower; +} + +void Calculate::setPeakPower(double value) +{ + peakPower = value; +} + +double Calculate::getAveragePower() +{ + if (numOfIterations > 0) + { + return (averagePower/numOfIterations); + } + else + { + return 0; + } +} + +void Calculate::setAveragePower(double value) +{ + averagePower = value; +} + +double Calculate::getMaxSpeed() +{ + return maxSpeed; +} + +void Calculate::setMaxSpeed(double value) +{ + maxSpeed = value; +} + +QMap Calculate::getValuesMap() +{ + return valuesMap; +}