X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Client%2Fcarmainwindow.cpp;h=5da33b71d655daf542776022249ecf33762cf3a3;hp=e7345f39d38019f47488d23c1cddaf7c9fb5d7dc;hb=b8104711348ebb86e8c93b23067af8f699870626;hpb=22dc1e626b0a47b33e5e13ec3ab117235e3f3beb diff --git a/Client/carmainwindow.cpp b/Client/carmainwindow.cpp index e7345f3..5da33b7 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 */ @@ -14,8 +15,8 @@ #include "carmainwindow.h" #include "math.h" -#define kAccelerometerSampleRate 50 -#define kFilteringFactor 0.2 +#define kAccelerometerSampleRate 40 +#define kFilteringFactor 0.1 #define kSecondsInHour 3600 /** @@ -26,6 +27,11 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca { ui->setupUi(this); ui->tabWidget->setCurrentWidget(this->ui->StartTab); + + //Disable start buttons before calibration + ui->autoStartButton->setEnabled(false); + ui->manualStartButton->setEnabled(false); + result = new ResultDialog(); //measure = new MeasureDialog(); welcomeDialog = new WelcomeDialog(); @@ -64,13 +70,14 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca // Accelerometer accelerometer = new Accelerometer(); + movingAverageZ = new MovingAverage(10); reverseAccelerationFlag = false; vehicleStartedMoving = false; isNewRun = true; isSetup = false; stopTime = 0; - accelerationStartThreshold = 0.02; + accelerationStartThreshold = 0.1; accelerometerTimer = new QTimer(this); connect(accelerometerTimer, SIGNAL(timeout()), this, SLOT(readAccelerometerData())); @@ -149,11 +156,12 @@ void CarMainWindow::on_listViewStartTabAccelerationCategories_clicked(QModelInde { QString str = index.data().toString(); QStringList list = str.split("-"); - QStringList list2 = list[1].split(" "); + QStringList list3 = list[1].split(" "); + QStringList list2 = list[0].split(" "); - ui->lineEditStartTabMin->setText(list[0]); - ui->lineEditStartTabMax->setText(list2[0]); - updateComboBoxStartTabUnits(list2[1]); + ui->lineEditStartTabMin->setText(list2[1]); + ui->lineEditStartTabMax->setText(list3[0]); + updateComboBoxStartTabUnits(list3[1]); } /** @@ -238,7 +246,7 @@ void CarMainWindow::initListViewStartTabAccelerationCategories() catList.insert(1,"acceleration-0-100"); catList.insert(2,"acceleration-0-10"); - accelerationCategoriesStartTab << "0-40 km/h" << "0-100 km/h" << "0-10 km/h"; + accelerationCategoriesStartTab << "Acceleration 0-40 km/h" << "Acceleration 0-100 km/h" << "Acceleration 0-10 km/h"; //<< "0-1/4 Mile" << "0-1/8 Mile" << "50-100 Mile" << "0-60 Mph" << "0-100 m" << "0-50 ft" << "0-50 yrd" << "0-500 in"; QAbstractItemModel *model = new StringListModel(accelerationCategoriesStartTab); ui->listViewStartTabAccelerationCategories->setModel(model); @@ -438,6 +446,11 @@ void CarMainWindow::on_drawRoutePushButton_clicked() } } +void CarMainWindow::on_sendRoutePushButton_clicked() +{ + myHttpClient->sendRouteXml(); +} + /** * Opens result dialog when show result button is clicked. * Sends measures as parameter to the resultdialogs saveMeasuresToArray-function. @@ -463,13 +476,13 @@ void CarMainWindow::resetAccelerometerMeasurements() currentSpeed = ""; currentTime = 0; distanceTraveled = ""; - firstAcceleration = 0; + //firstAcceleration = 0; //horsepower = null; isNewRun = true; //lastScreenUpdateInSeconds = 0; previousTime = 0; reverseAccelerationFlag = false; - stopWatch.setHMS(0, 0, 0, 0); + stopWatch.start(); //accelerometer->stop(); totalTime = ""; vehicleStartedMoving = false; @@ -582,7 +595,15 @@ void CarMainWindow::readAccelerometerData() qreal x, y, z; accelerometer->getAcceleration(x, y, z); - accelerometer->smoothData(x, y, z); + + // keep the following line as close to the SetKinematicsProperties method as possible + currentTime = stopWatch.elapsed(); + + //accelerometer->smoothData(x, y, z); + + //Calculate average + movingAverageZ->Enqueue(z); + z = movingAverageZ->Average(); // Apply calibration x -= accelerometer->getCalibrationX(); @@ -593,54 +614,22 @@ void CarMainWindow::readAccelerometerData() "acc y: " + QString::number(y) + "\n" + "acc z: " + QString::number(z) + "\n"); - if (!vehicleStartedMoving) - { - if (isNewRun) - { - firstAcceleration = sqrt(x*x + y*y + z*z); - //firstAcceleration = y; // first read - isNewRun = false; - } - } - - currentAcceleration = sqrt(x*x + y*y + z*z); - changeInAcceleration = (currentAcceleration - firstAcceleration); // firstAcceleration only gets set once + currentAcceleration = z;//sqrt(x*x + y*y + z*z); + changeInAcceleration = currentAcceleration; if (((fabs(changeInAcceleration) <= accelerationStartThreshold) && !vehicleStartedMoving)) { return; } - - if (reverseAccelerationFlag) - { - // will be false until after 1st calculation - if ((changeInAcceleration <= 0)) - { - // actually increasing here... - changeInAcceleration = fabs(changeInAcceleration); - } - else - { - // actually decreasing here... - changeInAcceleration = (changeInAcceleration * -1); - } - } - if (!vehicleStartedMoving) + else if(!vehicleStartedMoving) { - if ((changeInAcceleration < 0)) - { - // we started to move backwards first time through - reverseAccelerationFlag = true; - changeInAcceleration = fabs(changeInAcceleration); - } vehicleStartedMoving = true; - - stopWatch.setHMS(0, 0, 0, 0); stopWatch.start(); + previousTime = 0; + currentTime = 0; } - // keep the following line as close to the SetKinematicsProperties method as possible - currentTime = stopWatch.elapsed(); + calculate->calculateParameters(changeInAcceleration, (currentTime - previousTime)/1000); previousTime = currentTime; @@ -649,8 +638,8 @@ void CarMainWindow::readAccelerometerData() speed = 0.0; speed = calculate->getCurrentSpeed(); - speed = ((speed*1000)/kSecondsInHour); - s.sprintf("%.2f", speed); + speed = speed*3.6;//((speed*1000)/kSecondsInHour); + s.sprintf("%.1f", speed); currentSpeed = s; s.sprintf("%.2f", calculate->getDistanceTraveled()); @@ -778,7 +767,7 @@ void CarMainWindow::gpsStatus() */ void CarMainWindow::gpsTimerTimeout() { - int time1000ms; + int time1000ms = 0; time1000ms += 10; //IF time is 1 second @@ -847,3 +836,12 @@ void CarMainWindow::setTimeAxisGapAndShowResult(double pTime) result->setDiagramGapHorizontal(20); } } + +void CarMainWindow::on_calibrateButton_clicked() +{ + ui->autoStartButton->setEnabled(true); + ui->manualStartButton->setEnabled(true); + + this->accelerometer->calibrate(); +} +