* Calculate class to process accelerometer data
*
* @author Kai Rasilainen
+ * @author Jukka Kurttila <jukka.kurttila@fudeco.com>
* @copyright (c) 2010 Speed Freak team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
peakPower = 0;
currentPower = 0;
currentSpeed = 0;
+ maxSpeed = 0;
distanceTraveled = 0;
lastAcceleration = 0;
lastDistance = 0;
lastSpeed = 0;
numOfIterations = 0;
totalTime = 0;
- //count = 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];
}
// 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));
numOfIterations--;
}
- // Checkpoints
- if ((lastSpeed == 0))
- {
- lastCheckpoint = 0;
- }
-
- // List of checkpoints
- if (!(speedCheckPoints.isEmpty()))
+ if( (checkPoint > 0) && (currentSpeed*3.6 > checkPoint) )
{
- foreach (double speed, speedCheckPoints)
+ //Update checkPoint
+ if( checkPointCounter <= speedCheckPoints.count() )
{
- if ((lastCheckpoint != floor(speed)) && (floor(getCurrentSpeed()) == floor(speed)))
+ //Save time
+ valuesMap.insert( checkPoint, totalTime );
+ if( checkPointCounter < speedCheckPoints.count() )
{
- emit checkPointReached(totalTime, getCurrentSpeed());
- lastCheckpoint = floor(getCurrentSpeed());
+ checkPoint = speedCheckPoints[checkPointCounter];
}
+ else
+ {
+ checkPoint = 0;
+ }
+ checkPointCounter++;
}
}
* 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++;
count = 0;
}
- // if count exceeds 15, we assume that velocity is zero
- if (count >= 15)
+ // if count exceeds 25, we assume that velocity is zero
+ if (count >= 25)
{
currentSpeed=0;
}
}
-*/
+
// Getters and setters
double Calculate::getAverageSpeed()
averagePower = value;
}
+double Calculate::getMaxSpeed()
+{
+ return maxSpeed;
+}
+void Calculate::setMaxSpeed(double value)
+{
+ maxSpeed = value;
+}
+
+QMap<int,double> Calculate::getValuesMap()
+{
+ return valuesMap;
+}