1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-30 08:24:11 +01:00

Reformat attitude configuration gadget to use static access methods for

AttitudeSettings.  This helps compiler catch errors.
This commit is contained in:
James Cotton 2011-06-23 19:19:11 -05:00
parent ab7ff56d96
commit 0dc541cbaa
2 changed files with 31 additions and 38 deletions

View File

@ -27,6 +27,7 @@
#include "configccattitudewidget.h"
#include "ui_ccattitude.h"
#include "utils/coordinateconversions.h"
#include "attitudesettings.h"
#include <QMutexLocker>
#include <QMessageBox>
#include <QDebug>
@ -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<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);
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<UAVDataObject*>(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<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));
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<UAVDataObject*>(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<UAVDataObject*>(getObjectManager()->getObject(QString("AttitudeRaw")));

View File

@ -60,6 +60,7 @@ private:
Ui_ccattitude *ui;
QTimer timer;
UAVObject::Metadata initialMdata;
quint8 initialBiasCorrected;
int updates;