1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Make the leveling panel not crash for new gyro/accel objects but still needs

tweaking for CC3D.
This commit is contained in:
James Cotton 2012-01-24 16:11:03 -06:00
parent b6c056fef2
commit 4b3dcc4cc2
3 changed files with 24 additions and 18 deletions

View File

@ -33,6 +33,8 @@
#include <QDebug>
#include <QDesktopServices>
#include <QUrl>
#include <accels.h>
#include <gyros.h>
ConfigCCAttitudeWidget::ConfigCCAttitudeWidget(QWidget *parent) :
ConfigTaskWidget(parent),
@ -60,25 +62,29 @@ ConfigCCAttitudeWidget::~ConfigCCAttitudeWidget()
delete ui;
}
void ConfigCCAttitudeWidget::attitudeRawUpdated(UAVObject * obj) {
void ConfigCCAttitudeWidget::accelsUpdated(UAVObject * obj) {
QMutexLocker locker(&startStop);
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));
field = obj->getField(QString("gyros"));
x_gyro_accum.append(field->getDouble(0));
y_gyro_accum.append(field->getDouble(1));
z_gyro_accum.append(field->getDouble(2));;
Accels * accels = Accels::GetInstance(getObjectManager());
Accels::DataFields accelsData = accels->getData();
x_accum.append(accelsData.x);
y_accum.append(accelsData.y);
z_accum.append(accelsData.z);
Gyros * gyros = Gyros::GetInstance(getObjectManager());
Gyros::DataFields gyrosData = gyros->getData();
x_gyro_accum.append(gyrosData.x);
y_gyro_accum.append(gyrosData.y);
z_gyro_accum.append(gyrosData.z);
} else if ( updates == NUM_ACCEL_UPDATES ) {
updates++;
timer.stop();
disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(attitudeRawUpdated(UAVObject*)));
disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(accelsUpdated(UAVObject*)));
disconnect(&timer,SIGNAL(timeout()),this,SLOT(timeout()));
float x_bias = listMean(x_accum) / ACCEL_SCALE;
@ -109,8 +115,8 @@ void ConfigCCAttitudeWidget::attitudeRawUpdated(UAVObject * obj) {
void ConfigCCAttitudeWidget::timeout() {
QMutexLocker locker(&startStop);
UAVDataObject * obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("AttitudeRaw")));
disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(attitudeRawUpdated(UAVObject*)));
UAVDataObject * obj = Accels::GetInstance(getObjectManager());
disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(accelsUpdated(UAVObject*)));
disconnect(&timer,SIGNAL(timeout()),this,SLOT(timeout()));
QMessageBox msgBox;
@ -138,8 +144,8 @@ void ConfigCCAttitudeWidget::startAccelCalibration() {
AttitudeSettings::GetInstance(getObjectManager())->setData(attitudeSettingsData);
// Set up to receive updates
UAVDataObject * obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("AttitudeRaw")));
connect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(attitudeRawUpdated(UAVObject*)));
UAVDataObject * obj = Accels::GetInstance(getObjectManager());
connect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(accelsUpdated(UAVObject*)));
// Set up timeout timer
timer.start(10000);

View File

@ -47,7 +47,7 @@ public:
~ConfigCCAttitudeWidget();
private slots:
void attitudeRawUpdated(UAVObject * obj);
void accelsUpdated(UAVObject * obj);
void timeout();
void startAccelCalibration();
void openHelp();

View File

@ -2006,7 +2006,7 @@
<dataSize>60</dataSize>
<plotCurve0>
<color>4283804160</color>
<uavField>Z</uavField>
<uavField>z</uavField>
<uavObject>Gyros</uavObject>
<yMaximum>0</yMaximum>
<yMinimum>0</yMinimum>
@ -2014,7 +2014,7 @@
</plotCurve0>
<plotCurve1>
<color>4283782655</color>
<uavField>Y</uavField>
<uavField>y</uavField>
<uavObject>Gyros</uavObject>
<yMaximum>0</yMaximum>
<yMinimum>0</yMinimum>
@ -2022,7 +2022,7 @@
</plotCurve1>
<plotCurve2>
<color>4294901760</color>
<uavField>X</uavField>
<uavField>x</uavField>
<uavObject>Gyros</uavObject>
<yMaximum>0</yMaximum>
<yMinimum>0</yMinimum>