Fixed errors in accelerometer class
authorRikhard Kuutti <rikhard.kuutti@fudeco.com>
Fri, 5 Mar 2010 11:06:24 +0000 (13:06 +0200)
committerRikhard Kuutti <rikhard.kuutti@fudeco.com>
Fri, 5 Mar 2010 11:08:45 +0000 (13:08 +0200)
Client/accelerometer.cpp
Client/accelerometer.h

index 7b2531a..1a36361 100644 (file)
@@ -67,27 +67,31 @@ void Accelerometer::start()
  */
 void Accelerometer::initValues()
 {
  */
 void Accelerometer::initValues()
 {
-    accelerationX=0;
-    accelerationY=0;
-    accelerationZ=0;
-    trueAccelerationX=0;
-    trueAccelerationY=0;
-    trueAccelerationZ=0;
-    previousAccelerationX=0;
-    previousAccelerationY=0;
-    previousAccelerationZ=0;
-    previousSpeed=0;
-    currentSpeed=0;
-    currentAcceleration=0;
-    previousAcceleration=0;
-    totalAcceleration=0;
-    intervalTime=0;
-    totalTime=0;
-    distanceTraveled=0;
-    lastDistanceTraveled=0;
-    averageSpeed=0;
-    sampleRate=0;
-    reverseAcceleration = false;
+    calculate->reset();
+    accelerationX = 0;
+    accelerationY = 0;
+    accelerationZ = 0;
+    trueAccelerationX = 0;
+    trueAccelerationY = 0;
+    trueAccelerationZ = 0;
+    previousAccelerationX = 0;
+    previousAccelerationY = 0;
+    previousAccelerationZ = 0;
+    previousSpeed = 0;
+    currentSpeed = 0;
+    currentAcceleration = 0;
+    previousAcceleration = 0;
+    totalAcceleration = 0;
+    intervalTime = 0;
+    totalTime = 0;
+    distanceTraveled = 0;
+    lastDistanceTraveled = 0;
+    averageSpeed = 0;
+    sampleRate = 0;
+    firstRun = true;
+    calibrationX = 0;
+    calibrationY = 0;
+    calibrationZ = 0;
 }
 
 /**
 }
 
 /**
@@ -228,6 +232,21 @@ qreal Accelerometer::getTotalTime()
     return totalTime;
 }
 
     return totalTime;
 }
 
+int Accelerometer::getCalibrationX()
+{
+    return calibrationX;
+}
+
+int Accelerometer::getCalibrationY()
+{
+    return calibrationY;
+}
+
+int Accelerometer::getCalibrationZ()
+{
+    return calibrationZ;
+}
+
 /**
  * Processes Accelerometer data
  *
 /**
  * Processes Accelerometer data
  *
@@ -316,10 +335,12 @@ void Accelerometer::smoothData(qreal x, qreal y, qreal z)
     accelerationX = x;
     accelerationY = y;
     accelerationZ = z;
     accelerationX = x;
     accelerationY = y;
     accelerationZ = z;
-    if(sampleIndex>0) {
+    if (sampleIndex > 0)
+    {
         accelerationX = previousAccelerationX + (accelerationX-previousAccelerationX) * kFilteringFactor;
         accelerationY = previousAccelerationY + (accelerationY-previousAccelerationY) * kFilteringFactor;
         accelerationZ = previousAccelerationZ + (accelerationZ-previousAccelerationZ) * kFilteringFactor;
     }
     sampleIndex++;
 }
         accelerationX = previousAccelerationX + (accelerationX-previousAccelerationX) * kFilteringFactor;
         accelerationY = previousAccelerationY + (accelerationY-previousAccelerationY) * kFilteringFactor;
         accelerationZ = previousAccelerationZ + (accelerationZ-previousAccelerationZ) * kFilteringFactor;
     }
     sampleIndex++;
 }
+
index 31e5588..52990df 100644 (file)
@@ -40,9 +40,9 @@ public:
     qreal getTotalAcceleration();
     qreal getPreviousTotalAcceleration();
 
     qreal getTotalAcceleration();
     qreal getPreviousTotalAcceleration();
 
-    int calibrationX;
-    int calibrationY;
-    int calibrationZ;
+    int getCalibrationX();
+    int getCalibrationY();
+    int getCalibrationZ();
 
     qreal getIntervalTime();
     qreal getTotalTime();
 
     qreal getIntervalTime();
     qreal getTotalTime();
@@ -60,6 +60,8 @@ private:
     qreal previousSpeed, currentSpeed;
     qreal currentAcceleration, previousAcceleration, totalAcceleration;
 
     qreal previousSpeed, currentSpeed;
     qreal currentAcceleration, previousAcceleration, totalAcceleration;
 
+    int calibrationX, calibrationY, calibrationZ;
+
     QTime now;
     QTimer *timer;
 
     QTime now;
     QTimer *timer;
 
@@ -70,7 +72,8 @@ private:
     double averageSpeed;
     double sampleRate;
 
     double averageSpeed;
     double sampleRate;
 
-    bool reverseAcceleration;
+    bool firstRun;
 };
 
 #endif // ACCELEROMETER_H
 };
 
 #endif // ACCELEROMETER_H
+