From 0dc541cbaa518e721f6d438c1b705f029f8c9759 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Thu, 23 Jun 2011 19:19:11 -0500 Subject: [PATCH] Reformat attitude configuration gadget to use static access methods for AttitudeSettings. This helps compiler catch errors. --- .../plugins/config/configccattitudewidget.cpp | 68 ++++++++----------- .../plugins/config/configccattitudewidget.h | 1 + 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configccattitudewidget.cpp b/ground/openpilotgcs/src/plugins/config/configccattitudewidget.cpp index 72e59d236..067743833 100644 --- a/ground/openpilotgcs/src/plugins/config/configccattitudewidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configccattitudewidget.cpp @@ -27,6 +27,7 @@ #include "configccattitudewidget.h" #include "ui_ccattitude.h" #include "utils/coordinateconversions.h" +#include "attitudesettings.h" #include #include #include @@ -48,7 +49,7 @@ ConfigCCAttitudeWidget::ConfigCCAttitudeWidget(QWidget *parent) : enableControls(true); refreshValues(); // The 1st time this panel is instanciated, the autopilot is already connected. - UAVObject * settings = getObjectManager()->getObject(QString("AttitudeSettings")); + UAVObject * settings = AttitudeSettings::GetInstance(getObjectManager()); connect(settings,SIGNAL(objectUpdated(UAVObject*)), this, SLOT(refreshValues())); // Connect the help button @@ -98,17 +99,17 @@ void ConfigCCAttitudeWidget::attitudeRawUpdated(UAVObject * obj) { float z_gyro_bias = listMean(z_gyro_accum); obj->setMetadata(initialMdata); - UAVDataObject * settings = dynamic_cast(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); - field = settings->getField("GyroBias"); - field->setDouble(x_gyro_bias,0); - field->setDouble(y_gyro_bias,1); - field->setDouble(z_gyro_bias,2); - settings->getField("BiasCorrectedGyro")->setValue("True"); - settings->updated(); + AttitudeSettings::DataFields attitudeSettingsData = AttitudeSettings::GetInstance(getObjectManager())->getData(); + // We offset the gyro bias by current bias to help precision + attitudeSettingsData.AccelBias[0] += x_bias; + attitudeSettingsData.AccelBias[1] += y_bias; + attitudeSettingsData.AccelBias[2] += z_bias; + attitudeSettingsData.GyroBias[0] = -x_gyro_bias; + attitudeSettingsData.GyroBias[1] = -y_gyro_bias; + attitudeSettingsData.GyroBias[2] = -z_gyro_bias; + attitudeSettingsData.BiasCorrectGyro = initialBiasCorrected; + AttitudeSettings::GetInstance(getObjectManager())->setData(attitudeSettingsData); + ui->status->setText("Calibration done."); } else { // Possible to get here if weird threading stuff happens. Just ignore updates. @@ -131,32 +132,22 @@ void ConfigCCAttitudeWidget::timeout() { } void ConfigCCAttitudeWidget::applyAttitudeSettings() { - UAVDataObject * settings = dynamic_cast(getObjectManager()->getObject(QString("AttitudeSettings"))); - UAVObjectField * field = settings->getField("BoardRotation"); - - field->setValue(ui->rollBias->value(),0); - field->setValue(ui->pitchBias->value(),1); - field->setValue(ui->yawBias->value(),2); - - field = settings->getField("ZeroDuringArming"); - // Handling of boolean values is done through enums on - // uavobjects... - field->setValue((ui->zeroGyroBiasOnArming->isChecked()) ? "TRUE": "FALSE"); - - settings->updated(); + AttitudeSettings::DataFields attitudeSettingsData = AttitudeSettings::GetInstance(getObjectManager())->getData(); + attitudeSettingsData.BoardRotation[AttitudeSettings::BOARDROTATION_ROLL] = ui->rollBias->value(); + attitudeSettingsData.BoardRotation[AttitudeSettings::BOARDROTATION_PITCH] = ui->pitchBias->value(); + attitudeSettingsData.BoardRotation[AttitudeSettings::BOARDROTATION_YAW] = ui->yawBias->value(); + attitudeSettingsData.ZeroDuringArming = ui->zeroGyroBiasOnArming->isChecked() ? AttitudeSettings::ZERODURINGARMING_TRUE : + AttitudeSettings::ZERODURINGARMING_FALSE; + AttitudeSettings::GetInstance(getObjectManager())->setData(attitudeSettingsData); } void ConfigCCAttitudeWidget::refreshValues() { - UAVDataObject * settings = dynamic_cast(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)); - field = settings->getField("ZeroDuringArming"); - // Handling of boolean values is done through enums on - // uavobjects... - bool enabled = (field->getValue().toString() == "FALSE") ? false : true; - ui->zeroGyroBiasOnArming->setChecked(enabled); + AttitudeSettings::DataFields attitudeSettingsData = AttitudeSettings::GetInstance(getObjectManager())->getData(); + + ui->rollBias->setValue(attitudeSettingsData.BoardRotation[0]); + ui->pitchBias->setValue(attitudeSettingsData.BoardRotation[1]); + ui->yawBias->setValue(attitudeSettingsData.BoardRotation[2]); + ui->zeroGyroBiasOnArming->setChecked(attitudeSettingsData.ZeroDuringArming == AttitudeSettings::ZERODURINGARMING_TRUE); } @@ -174,9 +165,10 @@ void ConfigCCAttitudeWidget::startAccelCalibration() { ui->status->setText(tr("Calibrating...")); // Disable gyro bias correction to see raw data - UAVDataObject * settings = dynamic_cast(getObjectManager()->getObject(QString("AttitudeSettings"))); - settings->getField("BiasCorrectedGyro")->setValue("False"); - settings->updated(); + AttitudeSettings::DataFields attitudeSettingsData = AttitudeSettings::GetInstance(getObjectManager())->getData(); + initialBiasCorrected = attitudeSettingsData.BiasCorrectGyro; + attitudeSettingsData.BiasCorrectGyro = AttitudeSettings::BIASCORRECTGYRO_FALSE; + AttitudeSettings::GetInstance(getObjectManager())->setData(attitudeSettingsData); // Set up to receive updates UAVDataObject * obj = dynamic_cast(getObjectManager()->getObject(QString("AttitudeRaw"))); diff --git a/ground/openpilotgcs/src/plugins/config/configccattitudewidget.h b/ground/openpilotgcs/src/plugins/config/configccattitudewidget.h index 54497880d..27176b22f 100644 --- a/ground/openpilotgcs/src/plugins/config/configccattitudewidget.h +++ b/ground/openpilotgcs/src/plugins/config/configccattitudewidget.h @@ -60,6 +60,7 @@ private: Ui_ccattitude *ui; QTimer timer; UAVObject::Metadata initialMdata; + quint8 initialBiasCorrected; int updates;