* @author Olavi Pulkkinen <olavi.pulkkinen@fudeco.com>
* @author Rikhard Kuutti <rikhard.kuutti@fudeco.com>
* @author Kai Rasilainen <kai.rasilainen@fudeco.com>
+ * @author Jukka Kurttila <jukka.kurttila@fudeco.com>
* @copyright (c) 2010 Speed Freak team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
#include "carmainwindow.h"
#include "math.h"
-#define kAccelerometerSampleRate 50
-#define kFilteringFactor 0.2
+#define kAccelerometerSampleRate 40
+#define kFilteringFactor 0.1
#define kSecondsInHour 3600
/**
{
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();
// 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()));
{
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]);
}
/**
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);
}
}
+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.
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;
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();
"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;
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());
*/
void CarMainWindow::gpsTimerTimeout()
{
- int time1000ms;
+ int time1000ms = 0;
time1000ms += 10;
//IF time is 1 second
result->setDiagramGapHorizontal(20);
}
}
+
+void CarMainWindow::on_calibrateButton_clicked()
+{
+ ui->autoStartButton->setEnabled(true);
+ ui->manualStartButton->setEnabled(true);
+
+ this->accelerometer->calibrate();
+}
+