From 77288b723adf096196b4548f870d3ed7144decad Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Tue, 4 Feb 2014 00:54:57 +0100 Subject: [PATCH] OP-1150 UI for thermal calibration: show a message if calibration failed, some cleanup. --- .../thermal/boardsetuptransition.h | 4 ---- .../compensationcalculationtransition.h | 11 +++++++-- .../thermal/dataacquisitiontransition.h | 2 -- .../thermal/settingshandlingtransitions.h | 6 +---- .../thermal/thermalcalibrationhelper.cpp | 18 ++++++--------- .../thermal/thermalcalibrationhelper.h | 7 +++++- .../thermal/thermalcalibrationmodel.cpp | 23 +++++++++++-------- .../thermal/thermalcalibrationmodel.h | 9 +++++--- .../plugins/config/calibration/wizardstate.h | 2 +- 9 files changed, 43 insertions(+), 39 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/calibration/thermal/boardsetuptransition.h b/ground/openpilotgcs/src/plugins/config/calibration/thermal/boardsetuptransition.h index a0256c325..94defe04e 100644 --- a/ground/openpilotgcs/src/plugins/config/calibration/thermal/boardsetuptransition.h +++ b/ground/openpilotgcs/src/plugins/config/calibration/thermal/boardsetuptransition.h @@ -48,14 +48,12 @@ public: virtual bool eventTest(QEvent *e) { - qDebug() << "BoardSetupTransition::eventTest"; if (!QSignalTransition::eventTest(e)) { return false; } QStateMachine::SignalEvent *se = static_cast(e); // check wether status save was successful and retry if not - qDebug() << "BoardSetupTransition::eventTest - " << se->arguments().at(0).toBool(); if (se->arguments().at(0).toBool()) { return true; } else { @@ -67,8 +65,6 @@ public: virtual void onTransition(QEvent *e) { QStateMachine::SignalEvent *se = static_cast(e); - - qDebug() << "BoardSetupTransition::onTransition" << se->arguments().at(0).toBool(); } public slots: void enterState() diff --git a/ground/openpilotgcs/src/plugins/config/calibration/thermal/compensationcalculationtransition.h b/ground/openpilotgcs/src/plugins/config/calibration/thermal/compensationcalculationtransition.h index f9ce5f727..d08510182 100644 --- a/ground/openpilotgcs/src/plugins/config/calibration/thermal/compensationcalculationtransition.h +++ b/ground/openpilotgcs/src/plugins/config/calibration/thermal/compensationcalculationtransition.h @@ -32,6 +32,7 @@ #include #include +#include "../wizardstate.h" #include "thermalcalibrationhelper.h" namespace OpenPilot { class CompensationCalculationTransition : public QSignalTransition { @@ -49,13 +50,19 @@ public: virtual void onTransition(QEvent *e) { Q_UNUSED(e); - qDebug() << "CompensationCalculationTransition::collectionCompleted"; + QString nextStateName; + if (m_helper->calibrationSuccessful()) { + nextStateName = tr("Calibration completed succesfully"); + } else { + nextStateName = tr("Calibration failed! Please read the instructions and retry"); + } + static_cast(targetState())->setStepName(nextStateName); } + public slots: void enterState() { - qDebug() << "CompensationCalculationTransition::enterStatus"; m_helper->calculate(); } private: diff --git a/ground/openpilotgcs/src/plugins/config/calibration/thermal/dataacquisitiontransition.h b/ground/openpilotgcs/src/plugins/config/calibration/thermal/dataacquisitiontransition.h index 456f760ee..35fc44a93 100644 --- a/ground/openpilotgcs/src/plugins/config/calibration/thermal/dataacquisitiontransition.h +++ b/ground/openpilotgcs/src/plugins/config/calibration/thermal/dataacquisitiontransition.h @@ -50,13 +50,11 @@ public: { Q_UNUSED(e); m_helper->endAcquisition(); - qDebug() << "DataAcquisitionTransition::collectionCompleted"; } public slots: void enterState() { - qDebug() << "DataAcquisitionTransition::enterStatus"; m_helper->initAcquisition(); } private: diff --git a/ground/openpilotgcs/src/plugins/config/calibration/thermal/settingshandlingtransitions.h b/ground/openpilotgcs/src/plugins/config/calibration/thermal/settingshandlingtransitions.h index a16375bb5..020d44049 100644 --- a/ground/openpilotgcs/src/plugins/config/calibration/thermal/settingshandlingtransitions.h +++ b/ground/openpilotgcs/src/plugins/config/calibration/thermal/settingshandlingtransitions.h @@ -47,14 +47,12 @@ public: virtual bool eventTest(QEvent *e) { - qDebug() << "BoardStatusSaveTransition::eventTest"; if (!QSignalTransition::eventTest(e)) { return false; } QStateMachine::SignalEvent *se = static_cast(e); // check wether status stave was successful and retry if not - qDebug() << "BoardStatusSavedTransition::eventTest - " << se->arguments().at(0).toBool(); if (se->arguments().at(0).toBool()) { return true; } else { @@ -66,8 +64,6 @@ public: virtual void onTransition(QEvent *e) { QStateMachine::SignalEvent *se = static_cast(e); - - qDebug() << "BoardStatusSaveTransition :" << se->arguments().at(0).toBool(); } public slots: void enterState() @@ -102,7 +98,6 @@ public: if (se->arguments().at(0).toBool()) { return true; } else { - qDebug() << "BoardStatusRestoreTransition::eventTest - statusRestore() "; m_helper->statusRestore(); } return false; @@ -110,6 +105,7 @@ public: public slots: void enterState() { + m_helper->endAcquisition(); m_helper->statusRestore(); } private: diff --git a/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationhelper.cpp b/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationhelper.cpp index 6db822f53..81737ccd9 100644 --- a/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationhelper.cpp +++ b/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationhelper.cpp @@ -143,7 +143,7 @@ bool ThermalCalibrationHelper::saveBoardInitialSettings() // accelGyroSettings data /* - * Note: for revolution it is not neede but in case of CC we would prevent having + * TODO: for revolution it is not neede but in case of CC we would prevent having * a new set of xxxSensor UAVOs beside actual xxxState so it may be needed to reset the following AccelGyroSettings *accelGyroSettings = AccelGyroSettings::GetInstance(objManager); Q_ASSERT(accelGyroSettings); @@ -378,16 +378,16 @@ void ThermalCalibrationHelper::calculate() */ m_results.accelCalibrated = false; QString str; - str += QStringLiteral("info::Calibration results"); + str += QStringLiteral("INFO::Calibration results"); - str += QStringLiteral("info::Baro cal {%1, %2, %3, %4}; initial variance: %5; Calibrated variance %6") + str += QStringLiteral("INFO::Baro cal {%1, %2, %3, %4}; initial variance: %5; Calibrated variance %6") .arg(m_results.baro[0]).arg(m_results.baro[1]).arg(m_results.baro[2]).arg(m_results.baro[3]) .arg(m_results.baroInSigma).arg(m_results.baroOutSigma) + QChar::CarriageReturn; - str += QStringLiteral("info::Gyro cal x{%1} y{%2} z{%3, %4}; initial variance: {%5, %6, %7}; Calibrated variance {%8, %9, %10}") + str += QStringLiteral("INFO::Gyro cal x{%1} y{%2} z{%3, %4}; initial variance: {%5, %6, %7}; Calibrated variance {%8, %9, %10}") .arg(m_results.gyro[0]).arg(m_results.gyro[1]).arg(m_results.gyro[2]).arg(m_results.baro[3]) .arg(m_results.gyroInSigma[0]).arg(m_results.gyroInSigma[1]).arg(m_results.gyroInSigma[2]) .arg(m_results.gyroOutSigma[0]).arg(m_results.gyroOutSigma[1]).arg(m_results.gyroOutSigma[2]) + QChar::CarriageReturn; - str += QStringLiteral("info::Accel cal x{%1} y{%2} z{%3}; initial variance: {%4, %5, %6}; Calibrated variance {%7, %8, %9}") + str += QStringLiteral("INFO::Accel cal x{%1} y{%2} z{%3}; initial variance: {%4, %5, %6}; Calibrated variance {%7, %8, %9}") .arg(m_results.accel[0]).arg(m_results.accel[1]).arg(m_results.accel[2]) .arg(m_results.accelInSigma[0]).arg(m_results.accelInSigma[1]).arg(m_results.accelInSigma[2]) .arg(m_results.accelOutSigma[0]).arg(m_results.accelOutSigma[1]).arg(m_results.accelOutSigma[2]) + QChar::CarriageReturn; @@ -449,7 +449,6 @@ void ThermalCalibrationHelper::updateTemp(float temp) void ThermalCalibrationHelper::endAcquisition() { disconnectUAVOs(); - setProcessPercentage(ProcessPercentageBaseCalculation); } void ThermalCalibrationHelper::connectUAVOs() @@ -498,7 +497,7 @@ void ThermalCalibrationHelper::createDebugLog() m_debugStream.setDevice(0); return; } - qDebug() << "Saving debug data to " << dir.filePath(filename); + qDebug() << "Saving debug data for this session to " << dir.filePath(filename); m_debugStream.setDevice(&m_debugFile); @@ -536,7 +535,7 @@ void ThermalCalibrationHelper::copyResultToSettings() Q_ASSERT(objManager); - if (m_results.baroCalibrated) { + if (calibrationSuccessful()) { RevoSettings *revosettings = RevoSettings::GetInstance(objManager); Q_ASSERT(revosettings); RevoSettings::DataFields revosettingsdata = revosettings->getData(); @@ -548,9 +547,7 @@ void ThermalCalibrationHelper::copyResultToSettings() revosettingsdata.BaroTempCorrectionExtent[1] = m_results.baroTempMax; revosettings->setData(revosettingsdata); revosettings->updated(); - } - if (m_results.gyroCalibrated || m_results.accelCalibrated) { AccelGyroSettings *accelGyroSettings = AccelGyroSettings::GetInstance(objManager); Q_ASSERT(accelGyroSettings); AccelGyroSettings::DataFields data = accelGyroSettings->getData(); @@ -573,7 +570,6 @@ void ThermalCalibrationHelper::copyResultToSettings() accelGyroSettings->setData(data); accelGyroSettings->updated(); } - setProcessPercentage(100.0f); } void ThermalCalibrationHelper::setMetadataForCalibration(UAVDataObject *uavo) diff --git a/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationhelper.h b/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationhelper.h index a5c4beeac..1b620ac44 100644 --- a/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationhelper.h +++ b/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationhelper.h @@ -105,6 +105,12 @@ public: } void endAcquisition(); + bool calibrationSuccessful() + { + return m_results.baroCalibrated && + ((m_results.baroTempMax - m_results.baroTempMin) > 10.0f); + } + signals: void statusRestoreCompleted(bool succesful); void statusSaveCompleted(bool succesful); @@ -210,7 +216,6 @@ private: void setMetadataForCalibration(UAVDataObject *uavo); UAVObjectManager *getObjectManager(); - }; } #endif // THERMALCALIBRATIONHELPER_H diff --git a/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationmodel.cpp b/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationmodel.cpp index 9c8141375..c2952a16e 100644 --- a/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationmodel.cpp +++ b/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationmodel.cpp @@ -32,9 +32,6 @@ #include "dataacquisitiontransition.h" #include "compensationcalculationtransition.h" -#define NEXT_EVENT "next" -#define PREVIOUS_EVENT "previous" -#define ABORT_EVENT "abort" namespace OpenPilot { ThermalCalibrationModel::ThermalCalibrationModel(QObject *parent) : WizardModel(parent) @@ -50,11 +47,12 @@ ThermalCalibrationModel::ThermalCalibrationModel(QObject *parent) : m_acquisitionState = new WizardState(tr("*** Please Wait *** Samples acquisition, this can take several minutes"), m_workingState); m_restoreState = new WizardState(tr("Restore board settings"), m_workingState); - m_calculateState = new WizardState(tr("Calculate calibration matrix"), m_workingState); + m_calculateState = new WizardState(tr("Calculate calibration data"), m_workingState); - m_abortState = new WizardState("Canceled", this); + m_abortState = new WizardState(tr("Canceled"), this); - m_completedState = new WizardState("Completed", this); + // note: step name for this state is changed by CompensationCalculationTransition based on result + m_completedState = new WizardState(NULL, this); setTransitions(); connect(m_helper.data(), SIGNAL(gradientChanged(float)), this, SLOT(setTemperatureGradient(float))); @@ -87,22 +85,27 @@ void ThermalCalibrationModel::stepChanged(WizardState *state) void ThermalCalibrationModel::setTransitions() { m_readyState->addTransition(this, SIGNAL(next()), m_workingState); + m_readyState->assignProperty(this, "progress", 0); + m_completedState->addTransition(this, SIGNAL(next()), m_workingState); - // handles board status save + m_completedState->assignProperty(this, "progress", 100); + + // handles board initial status save // Ready->WorkingState->saveSettings->setup m_saveSettingState->addTransition(new BoardStatusSaveTransition(m_helper.data(), m_saveSettingState, m_setupState)); // board setup // setup m_setupState->addTransition(new BoardSetupTransition(m_helper.data(), m_setupState, m_acquisitionState)); - // acquisition -revertSettings-> calculation + // acquisition>revertSettings>calculation(save state) // revert settings after acquisition is completed - // m_acquisitionState->addTransition(new BoardStatusRestoreTransition(m_helper, m_acquisitionState, m_calculateState)); m_acquisitionState->addTransition(new DataAcquisitionTransition(m_helper.data(), m_acquisitionState, m_restoreState)); m_restoreState->addTransition(new BoardStatusRestoreTransition(m_helper.data(), m_restoreState, m_calculateState)); m_calculateState->addTransition(new CompensationCalculationTransition(m_helper.data(), m_calculateState, m_completedState)); + + // abort causes initial settings to be restored and acquisition stopped. m_abortState->addTransition(new BoardStatusRestoreTransition(m_helper.data(), m_abortState, m_readyState)); - m_workingState->addTransition(m_helper.data(), SIGNAL(abort()), m_abortState); + m_workingState->addTransition(this, SIGNAL(abort()), m_abortState); // Ready } } diff --git a/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationmodel.h b/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationmodel.h index a39200fb7..388fb9caa 100644 --- a/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationmodel.h +++ b/ground/openpilotgcs/src/plugins/config/calibration/thermal/thermalcalibrationmodel.h @@ -45,7 +45,7 @@ class ThermalCalibrationModel : public WizardModel { Q_PROPERTY(QString temperature READ temperature NOTIFY temperatureChanged) Q_PROPERTY(QString temperatureGradient READ temperatureGradient NOTIFY temperatureGradientChanged) - Q_PROPERTY(int progress READ progress NOTIFY progressChanged) + Q_PROPERTY(int progress READ progress WRITE setProgress NOTIFY progressChanged) Q_OBJECT public: explicit ThermalCalibrationModel(QObject *parent = 0); @@ -54,10 +54,12 @@ public: { return m_startEnabled; } + bool endEnabled() { return m_endEnabled; } + bool cancelEnabled() { return m_cancelEnabled; @@ -78,6 +80,7 @@ public: emit endEnabledChanged(status); } } + void setCancelEnabled(bool status) { if (m_cancelEnabled != status) { @@ -112,6 +115,7 @@ public slots: emit temperatureChanged(tmp); } } + void setTemperatureGradient(float status) { QString tmp = QString("%1").arg(status, 5, 'f', 2); @@ -121,6 +125,7 @@ public slots: emit temperatureGradientChanged(tmp); } } + void setProgress(int status) { m_progress = status; @@ -163,7 +168,6 @@ private: WizardState *m_completedState; void setTransitions(); - signals: void startEnabledChanged(bool state); void endEnabledChanged(bool state); @@ -186,7 +190,6 @@ public slots: void btnEnd() { - // emit previous(); m_helper->stopAcquisition(); } diff --git a/ground/openpilotgcs/src/plugins/config/calibration/wizardstate.h b/ground/openpilotgcs/src/plugins/config/calibration/wizardstate.h index 8a5952e75..55f8f267e 100644 --- a/ground/openpilotgcs/src/plugins/config/calibration/wizardstate.h +++ b/ground/openpilotgcs/src/plugins/config/calibration/wizardstate.h @@ -34,7 +34,7 @@ class WizardState : public QState { Q_OBJECT Q_PROPERTY(bool isActive READ isActive NOTIFY isActiveChanged) Q_PROPERTY(bool isDone READ isDone NOTIFY isDoneChanged) Q_PROPERTY(qint8 completion READ completion NOTIFY completionChanged) - Q_PROPERTY(QString stepName READ stepName NOTIFY stepNameChanged) + Q_PROPERTY(QString stepName READ stepName WRITE setStepName NOTIFY stepNameChanged) public: explicit WizardState(QString name, QState *parent = 0); bool isActive()