From bdc023af59fd2c9ca9f127e86db32eb326acecff Mon Sep 17 00:00:00 2001 From: Jukka Kurttila Date: Thu, 25 Mar 2010 14:42:07 +0200 Subject: [PATCH] Average calculation for acceleration added. --- Client/UI.pro | 6 ++++-- Client/accelerometer.cpp | 1 + Client/accelerometer.h | 1 + Client/carmainwindow.cpp | 8 +++++++- Client/carmainwindow.h | 2 ++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Client/UI.pro b/Client/UI.pro index d11e0d4..b036ad2 100644 --- a/Client/UI.pro +++ b/Client/UI.pro @@ -27,7 +27,8 @@ SOURCES += main.cpp \ gpsdata.cpp \ maemo5locationprivate.cpp \ maemo5location.cpp \ - routedialog.cpp + routedialog.cpp \ + movingaverage.cpp HEADERS += carmainwindow.h \ resultdialog.h \ stringlistmodel.h \ @@ -45,7 +46,8 @@ HEADERS += carmainwindow.h \ gpsdata.h \ maemo5locationprivate.h \ maemo5location.h \ - routedialog.h + routedialog.h \ + movingaverage.h FORMS += carmainwindow.ui \ resultdialog.ui \ measuredialog.ui \ diff --git a/Client/accelerometer.cpp b/Client/accelerometer.cpp index 8daf06f..0495135 100644 --- a/Client/accelerometer.cpp +++ b/Client/accelerometer.cpp @@ -3,6 +3,7 @@ * * @author Rikhard Kuutti * @author Kai Rasilainen + * @author Jukka Kurttila * @copyright (c) 2010 Speed Freak team * @license http://opensource.org/licenses/gpl-license.php GNU Public License */ diff --git a/Client/accelerometer.h b/Client/accelerometer.h index 83e44e4..24063cd 100644 --- a/Client/accelerometer.h +++ b/Client/accelerometer.h @@ -3,6 +3,7 @@ * * @author Rikhard Kuutti * @author Kai Rasilainen + * @author Jukka Kurttila * @copyright (c) 2010 Speed Freak team * @license http://opensource.org/licenses/gpl-license.php GNU Public License */ diff --git a/Client/carmainwindow.cpp b/Client/carmainwindow.cpp index 88f8af1..9a48d90 100644 --- a/Client/carmainwindow.cpp +++ b/Client/carmainwindow.cpp @@ -7,6 +7,7 @@ * @author Olavi Pulkkinen * @author Rikhard Kuutti * @author Kai Rasilainen + * @author Jukka Kurttila * @copyright (c) 2010 Speed Freak team * @license http://opensource.org/licenses/gpl-license.php GNU Public License */ @@ -69,6 +70,7 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca // Accelerometer accelerometer = new Accelerometer(); + movingAverageZ = new MovingAverage(10); reverseAccelerationFlag = false; vehicleStartedMoving = false; @@ -593,6 +595,10 @@ void CarMainWindow::readAccelerometerData() //accelerometer->smoothData(x, y, z); + //Calculate average + movingAverageZ->Enqueue(z); + z = movingAverageZ->Average(); + // Apply calibration x -= accelerometer->getCalibrationX(); y -= accelerometer->getCalibrationY(); @@ -755,7 +761,7 @@ void CarMainWindow::gpsStatus() */ void CarMainWindow::gpsTimerTimeout() { - int time1000ms; + int time1000ms = 0; time1000ms += 10; //IF time is 1 second diff --git a/Client/carmainwindow.h b/Client/carmainwindow.h index 0cfe583..433ee9d 100644 --- a/Client/carmainwindow.h +++ b/Client/carmainwindow.h @@ -44,6 +44,7 @@ #include "routedialog.h" #include "calculate.h" #include "gpsdata.h" +#include "movingaverage.h" #include namespace Ui { @@ -90,6 +91,7 @@ private: QTimer *timer; Accelerometer *accelerometer; + MovingAverage* movingAverageZ; double time; double speed; Measures *measures; -- 1.7.9.5