2011-03-28 21:16:38 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file configccattitudewidget.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
|
|
|
* @addtogroup ConfigPlugin Config Plugin
|
|
|
|
* @{
|
|
|
|
* @brief Configure Attitude module on CopterControl
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
#include "configccattitudewidget.h"
|
|
|
|
#include "ui_ccattitude.h"
|
2011-04-15 08:37:16 +02:00
|
|
|
#include "utils/coordinateconversions.h"
|
2011-03-28 21:16:38 +02:00
|
|
|
#include <QMutexLocker>
|
2011-04-26 18:02:32 +02:00
|
|
|
#include <QMessageBox>
|
2011-03-28 21:16:38 +02:00
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
ConfigCCAttitudeWidget::ConfigCCAttitudeWidget(QWidget *parent) :
|
|
|
|
ConfigTaskWidget(parent),
|
|
|
|
ui(new Ui_ccattitude)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
connect(ui->zeroBias,SIGNAL(clicked()),this,SLOT(startAccelCalibration()));
|
2011-05-05 20:04:56 +02:00
|
|
|
connect(ui->saveButton,SIGNAL(clicked()),this,SLOT(saveAttitudeSettings()));
|
|
|
|
connect(ui->applyButton,SIGNAL(clicked()),this,SLOT(applyAttitudeSettings()));
|
|
|
|
connect(ui->getCurrentButton,SIGNAL(clicked()),this,SLOT(getCurrentAttitudeSettings()));
|
2011-03-28 21:16:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfigCCAttitudeWidget::~ConfigCCAttitudeWidget()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigCCAttitudeWidget::attitudeRawUpdated(UAVObject * obj) {
|
|
|
|
QMutexLocker locker(&startStop);
|
|
|
|
UAVDataObject * attitudeRaw = dynamic_cast<UAVDataObject*>(obj);
|
|
|
|
|
|
|
|
ui->zeroBiasProgress->setValue((float) updates / NUM_ACCEL_UPDATES * 100);
|
|
|
|
|
|
|
|
if(updates < NUM_ACCEL_UPDATES) {
|
|
|
|
updates++;
|
|
|
|
UAVObjectField * field = obj->getField(QString("accels"));
|
|
|
|
x_accum.append(field->getDouble(0));
|
|
|
|
y_accum.append(field->getDouble(1));
|
|
|
|
z_accum.append(field->getDouble(2));
|
|
|
|
} else {
|
|
|
|
timer.stop();
|
|
|
|
disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(attitudeRawUpdated(UAVObject*)));
|
|
|
|
disconnect(&timer,SIGNAL(timeout()),this,SLOT(timeout()));
|
|
|
|
|
|
|
|
float x_bias = listMean(x_accum) / ACCEL_SCALE;
|
|
|
|
float y_bias = listMean(y_accum) / ACCEL_SCALE;
|
|
|
|
float z_bias = (listMean(z_accum) + 9.81) / ACCEL_SCALE;
|
|
|
|
|
|
|
|
obj->setMetadata(initialMdata);
|
|
|
|
|
|
|
|
UAVDataObject * settings = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("AttitudeSettings")));
|
|
|
|
UAVObjectField * field = settings->getField("AccelBias");
|
|
|
|
field->setDouble(field->getDouble(0) + x_bias,0);
|
|
|
|
field->setDouble(field->getDouble(1) + y_bias,1);
|
|
|
|
field->setDouble(field->getDouble(2) + z_bias,2);
|
|
|
|
settings->updated();
|
2011-03-29 22:32:09 +02:00
|
|
|
ui->status->setText("Calibration done.");
|
|
|
|
|
2011-03-28 21:16:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigCCAttitudeWidget::timeout() {
|
|
|
|
QMutexLocker locker(&startStop);
|
|
|
|
UAVObjectManager * objMngr = getObjectManager();
|
|
|
|
UAVDataObject * obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("AttitudeRaw")));
|
|
|
|
disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(attitudeRawUpdated(UAVObject*)));
|
|
|
|
disconnect(&timer,SIGNAL(timeout()),this,SLOT(timeout()));
|
|
|
|
|
2011-04-26 18:02:32 +02:00
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText(tr("Calibration timed out before receiving required updates."));
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
|
|
|
msgBox.exec();
|
|
|
|
|
2011-03-28 21:16:38 +02:00
|
|
|
}
|
|
|
|
|
2011-05-05 20:04:56 +02:00
|
|
|
void ConfigCCAttitudeWidget::applyAttitudeSettings() {
|
2011-04-15 08:37:16 +02:00
|
|
|
UAVDataObject * settings = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("AttitudeSettings")));
|
2011-05-05 20:04:56 +02:00
|
|
|
UAVObjectField * field = settings->getField("BoardRotation");
|
2011-04-15 08:37:16 +02:00
|
|
|
|
2011-05-05 20:04:56 +02:00
|
|
|
field->setValue(ui->rollBias->value(),0);
|
|
|
|
field->setValue(ui->pitchBias->value(),1);
|
|
|
|
field->setValue(ui->yawBias->value(),2);
|
2011-04-15 08:37:16 +02:00
|
|
|
|
|
|
|
settings->updated();
|
|
|
|
}
|
|
|
|
|
2011-05-05 20:04:56 +02:00
|
|
|
void ConfigCCAttitudeWidget::getCurrentAttitudeSettings() {
|
|
|
|
UAVDataObject * settings = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("AttitudeSettings")));
|
|
|
|
UAVObjectField * field = settings->getField("BoardRotation");
|
|
|
|
ui->rollBias->setValue(field->getDouble(0));
|
|
|
|
ui->pitchBias->setValue(field->getDouble(1));
|
|
|
|
ui->yawBias->setValue(field->getDouble(2));
|
|
|
|
}
|
|
|
|
|
2011-03-28 21:16:38 +02:00
|
|
|
void ConfigCCAttitudeWidget::startAccelCalibration() {
|
|
|
|
QMutexLocker locker(&startStop);
|
|
|
|
|
|
|
|
updates = 0;
|
|
|
|
x_accum.clear();
|
|
|
|
y_accum.clear();
|
|
|
|
z_accum.clear();
|
|
|
|
|
2011-04-26 18:02:32 +02:00
|
|
|
ui->status->setText(tr("Calibrating..."));
|
2011-03-29 22:32:09 +02:00
|
|
|
|
2011-03-28 21:16:38 +02:00
|
|
|
// Set up to receive updates
|
|
|
|
UAVDataObject * obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("AttitudeRaw")));
|
|
|
|
connect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(attitudeRawUpdated(UAVObject*)));
|
|
|
|
|
|
|
|
// Set up timeout timer
|
|
|
|
timer.start(2000);
|
|
|
|
connect(&timer,SIGNAL(timeout()),this,SLOT(timeout()));
|
|
|
|
|
|
|
|
// Speed up updates
|
|
|
|
initialMdata = obj->getMetadata();
|
|
|
|
UAVObject::Metadata mdata = initialMdata;
|
|
|
|
mdata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC;
|
|
|
|
mdata.flightTelemetryUpdatePeriod = 100;
|
|
|
|
obj->setMetadata(mdata);
|
|
|
|
|
|
|
|
}
|
2011-03-28 23:31:44 +02:00
|
|
|
|
|
|
|
void ConfigCCAttitudeWidget::saveAttitudeSettings() {
|
2011-05-05 20:04:56 +02:00
|
|
|
applyAttitudeSettings();
|
|
|
|
|
2011-03-28 23:31:44 +02:00
|
|
|
UAVDataObject * obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("AttitudeSettings")));
|
|
|
|
saveObjectToSD(obj);
|
|
|
|
}
|