1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

OP-1351 improved instructions handling for thermal calibration (removed duplicates, specified instruction types)

This commit is contained in:
Philippe Renon 2014-05-28 23:07:31 +02:00
parent c9b64d6399
commit 60700cab7f
13 changed files with 109 additions and 86 deletions

View File

@ -29,13 +29,15 @@
#ifndef BOARDSETUPTRANSITION_H
#define BOARDSETUPTRANSITION_H
#include "thermalcalibrationhelper.h"
#include <QSignalTransition>
#include <QEventTransition>
#include "thermalcalibrationhelper.h"
namespace OpenPilot {
class BoardSetupTransition : public QSignalTransition {
Q_OBJECT
public:
BoardSetupTransition(ThermalCalibrationHelper *helper, QState *currentState, QState *targetState)
: QSignalTransition(helper, SIGNAL(setupBoardCompleted(bool))),
@ -66,11 +68,14 @@ public:
{
Q_UNUSED(e);
}
public slots:
void enterState()
{
m_helper->addInstructions(tr("Configuring board for calibration."));
m_helper->setupBoard();
}
private:
ThermalCalibrationHelper *m_helper;
};

View File

@ -34,9 +34,11 @@
#include "../wizardstate.h"
#include "thermalcalibrationhelper.h"
namespace OpenPilot {
class CompensationCalculationTransition : public QSignalTransition {
Q_OBJECT
public:
CompensationCalculationTransition(ThermalCalibrationHelper *helper, QState *currentState, QState *targetState)
: QSignalTransition(helper, SIGNAL(calculationCompleted())),
@ -52,19 +54,19 @@ public:
Q_UNUSED(e);
QString nextStateName;
if (m_helper->calibrationSuccessful()) {
nextStateName = tr("Calibration completed succesfully");
m_helper->addInstructions(tr("Calibration completed successfully."), WizardModel::Success);
} else {
nextStateName = tr("Calibration failed! Please read the instructions and retry");
m_helper->addInstructions(tr("Calibration failed! Please read the instructions and retry."), WizardModel::Failure);
}
static_cast<WizardState *>(targetState())->setStepName(nextStateName);
}
public slots:
void enterState()
{
m_helper->addInstructions("Calculating calibration data.");
m_helper->calculate();
}
private:
ThermalCalibrationHelper *m_helper;
};

View File

@ -29,13 +29,15 @@
#ifndef DATAACQUISITIONTRANSITION_H
#define DATAACQUISITIONTRANSITION_H
#include "thermalcalibrationhelper.h"
#include <QSignalTransition>
#include <QEventTransition>
#include "thermalcalibrationhelper.h"
namespace OpenPilot {
class DataAcquisitionTransition : public QSignalTransition {
Q_OBJECT
public:
DataAcquisitionTransition(ThermalCalibrationHelper *helper, QState *currentState, QState *targetState)
: QSignalTransition(helper, SIGNAL(collectionCompleted())),
@ -55,8 +57,10 @@ public:
public slots:
void enterState()
{
m_helper->addInstructions(tr("Please wait during samples acquisition. This can take several minutes..."), WizardModel::Prompt);
m_helper->initAcquisition();
}
private:
ThermalCalibrationHelper *m_helper;
};

View File

@ -28,13 +28,16 @@
#ifndef SETTINGSHANDLINGTRANSITIONS_H
#define SETTINGSHANDLINGTRANSITIONS_H
#include "thermalcalibrationhelper.h"
#include <QSignalTransition>
#include <QEventTransition>
#include "thermalcalibrationhelper.h"
namespace OpenPilot {
class BoardStatusSaveTransition : public QSignalTransition {
Q_OBJECT
public:
BoardStatusSaveTransition(ThermalCalibrationHelper *helper, QState *currentState, QState *targetState)
: QSignalTransition(helper, SIGNAL(statusSaveCompleted(bool))),
@ -65,18 +68,21 @@ public:
{
Q_UNUSED(e);
}
public slots:
void enterState()
{
m_helper->addInstructions(tr("Saving initial settings."));
m_helper->statusSave();
}
private:
ThermalCalibrationHelper *m_helper;
};
class BoardStatusRestoreTransition : public QSignalTransition {
Q_OBJECT
public:
BoardStatusRestoreTransition(ThermalCalibrationHelper *helper, QState *currentState, QState *targetState)
: QSignalTransition(helper, SIGNAL(statusRestoreCompleted(bool))),
@ -102,12 +108,15 @@ public:
}
return false;
}
public slots:
void enterState()
{
m_helper->addInstructions(tr("Restoring board configuration."));
m_helper->endAcquisition();
m_helper->statusRestore();
}
private:
ThermalCalibrationHelper *m_helper;
};

View File

@ -199,7 +199,7 @@ bool ThermalCalibrationHelper::restoreInitialSettings()
void ThermalCalibrationHelper::setupBoard()
{
setProcessPercentage(ProcessPercentageSetupBoard);
setProgress(ProcessPercentageSetupBoard);
if (setupBoardForCalibration()) {
emit setupBoardCompleted(true);
} else {
@ -219,7 +219,7 @@ void ThermalCalibrationHelper::statusRestore()
void ThermalCalibrationHelper::statusSave()
{
setProcessPercentage(ProcessPercentageSaveSettings);
setProgress(ProcessPercentageSaveSettings);
// prevent saving multiple times
if (!isBoardInitialSettingsSaved() && saveBoardInitialSettings()) {
emit statusSaveCompleted(true);
@ -230,7 +230,7 @@ void ThermalCalibrationHelper::statusSave()
void ThermalCalibrationHelper::initAcquisition()
{
setProcessPercentage(ProcessPercentageBaseAcquisition);
setProgress(ProcessPercentageBaseAcquisition);
QMutexLocker lock(&sensorsUpdateLock);
m_targetduration = 0;
m_gradient = 0.0f;
@ -325,7 +325,7 @@ void ThermalCalibrationHelper::cleanup()
void ThermalCalibrationHelper::calculate()
{
setProcessPercentage(ProcessPercentageBaseCalculation);
setProgress(ProcessPercentageBaseCalculation);
int count = m_baroSamples.count();
Eigen::VectorXf datax(count);
Eigen::VectorXf datay(1);
@ -341,7 +341,7 @@ void ThermalCalibrationHelper::calculate()
m_results.baroTempMin = datat.array().minCoeff();
m_results.baroTempMax = datat.array().maxCoeff();
setProcessPercentage(processPercentage() + 2);
setProgress(processPercentage() + 2);
count = m_gyroSamples.count();
datax.resize(count);
datay.resize(count);
@ -360,7 +360,7 @@ void ThermalCalibrationHelper::calculate()
m_results.accelGyroTempMax = datat.array().maxCoeff();
// TODO: sanity checks needs to be enforced before accel calibration can be enabled and usable.
/*
setProcessPercentage(processPercentage() + 2);
setProgress(processPercentage() + 2);
count = m_accelSamples.count();
datax.resize(count);
datay.resize(count);
@ -413,7 +413,7 @@ void ThermalCalibrationHelper::updateTemp(float temp)
// gradient is expressed in °C/min
float gradient = 60.0 * (m_temperature - m_lastCheckpointTemp) / (float)secondsSinceLastCheck;
m_gradient = gradient;
emit gradientChanged(gradient);
emit temperatureGradientChanged(gradient);
qDebug() << "Temp Gradient " << gradient << " Elapsed" << elapsed;
m_debugStream << "INFO::Trace Temp Gradient " << gradient << " Elapsed" << elapsed << endl;
@ -431,10 +431,9 @@ void ThermalCalibrationHelper::updateTemp(float temp)
}
if (m_targetduration != 0) {
int tmp = ((ProcessPercentageBaseCalculation - ProcessPercentageBaseAcquisition)
* elapsed) / m_targetduration;
int tmp = ((ProcessPercentageBaseCalculation - ProcessPercentageBaseAcquisition) * elapsed) / m_targetduration;
tmp = tmp > ProcessPercentageBaseCalculation - 5 ? ProcessPercentageBaseCalculation - 5 : tmp;
setProcessPercentage(tmp);
setProgress(tmp);
} else if (m_gradient > .1 && m_initialGradient / 2.0f > m_gradient) {
qDebug() << "M_gradient " << m_gradient << " Elapsed" << elapsed << " m_initialGradient" << m_initialGradient;
// make a rough estimation of the time needed

View File

@ -47,11 +47,13 @@
#include <magsensor.h>
#include "accelgyrosettings.h"
// Calibration data
#include <accelgyrosettings.h>
#include <revocalibration.h>
#include <revosettings.h>
#include "../wizardmodel.h"
namespace OpenPilot {
typedef struct {
// this is not needed for revo, but should for CC/CC3D
@ -85,10 +87,13 @@ typedef struct {
float accelGyroTempMin;
float accelGyroTempMax;
} thermalCalibrationResults;
class ThermalCalibrationHelper : public QObject {
Q_OBJECT
public:
explicit ThermalCalibrationHelper(QObject *parent = 0);
float temperature()
{
return m_temperature;
@ -103,6 +108,7 @@ public:
{
return m_processPercentage;
}
void endAcquisition();
bool calibrationSuccessful()
@ -112,12 +118,13 @@ public:
}
signals:
void instructionsAdded(QString text, WizardModel::MessageType type = WizardModel::Info);
void statusRestoreCompleted(bool succesful);
void statusSaveCompleted(bool succesful);
void setupBoardCompleted(bool succesful);
void temperatureChanged(float value);
void gradientChanged(float value);
void processPercentageChanged(int percentage);
void temperatureGradientChanged(float value);
void progressChanged(int value);
void collectionCompleted();
void calculationCompleted();
void abort();
@ -152,14 +159,19 @@ public slots:
void calculate();
void collectSample(UAVObject *sample);
void setProcessPercentage(int value)
void setProgress(int value)
{
if (m_processPercentage != value) {
m_processPercentage = value;
emit processPercentageChanged(value);
emit progressChanged(value);
}
}
void addInstructions(QString text, WizardModel::MessageType type = WizardModel::Info)
{
emit instructionsAdded(text, type);
}
void cleanup();
private:

View File

@ -33,7 +33,6 @@
#include "compensationcalculationtransition.h"
namespace OpenPilot {
ThermalCalibrationModel::ThermalCalibrationModel(QObject *parent) :
WizardModel(parent),
m_startEnabled(false),
@ -42,27 +41,29 @@ ThermalCalibrationModel::ThermalCalibrationModel(QObject *parent) :
m_initDone(false)
{
m_helper.reset(new ThermalCalibrationHelper());
m_readyState = new WizardState("", this),
m_workingState = new WizardState(NULL, this);
m_saveSettingState = new WizardState(tr("Saving initial settings"), m_workingState);
m_readyState = new WizardState("Ready", this),
m_workingState = new WizardState("Working", this);
m_saveSettingState = new WizardState("Storing Settings", m_workingState);
m_workingState->setInitialState(m_saveSettingState);
m_setupState = new WizardState(tr("Setup board for calibration"), m_workingState);
m_setupState = new WizardState("SetupBoard", m_workingState);
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 data"), m_workingState);
m_acquisitionState = new WizardState("Acquiring", m_workingState);
m_restoreState = new WizardState("Restoring Settings", m_workingState);
m_calculateState = new WizardState("Calculating", m_workingState);
m_abortState = new WizardState(tr("Canceled"), this);
m_abortState = new WizardState("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)));
connect(m_helper.data(), SIGNAL(temperatureChanged(float)), this, SLOT(setTemperature(float)));
connect(m_helper.data(), SIGNAL(processPercentageChanged(int)), this, SLOT(setProgress(int)));
connect(m_helper.data(), SIGNAL(temperatureGradientChanged(float)), this, SLOT(setTemperatureGradient(float)));
connect(m_helper.data(), SIGNAL(progressChanged(int)), this, SLOT(setProgress(int)));
connect(m_helper.data(), SIGNAL(instructionsAdded(QString, WizardModel::MessageType)), this, SLOT(addInstructions(QString, WizardModel::MessageType)));
connect(m_readyState, SIGNAL(entered()), this, SLOT(wizardReady()));
connect(m_readyState, SIGNAL(exited()), this, SLOT(wizardStarted()));
connect(m_completedState, SIGNAL(entered()), this, SLOT(wizardReady()));
@ -117,5 +118,4 @@ void ThermalCalibrationModel::setTransitions()
m_workingState->addTransition(this, SIGNAL(abort()), m_abortState);
// Ready
}
}

View File

@ -30,25 +30,21 @@
#define THERMALCALIBRATIONMODEL_H
#include "thermalcalibrationhelper.h"
#include "../wizardstate.h"
#include "../wizardmodel.h"
#include <QObject>
#include <QState>
#include <QStateMachine>
#include "../wizardstate.h"
#include "../wizardmodel.h"
namespace OpenPilot {
class ThermalCalibrationModel : public WizardModel {
Q_PROPERTY(bool startEnable READ startEnabled NOTIFY startEnabledChanged)
Q_OBJECT Q_PROPERTY(bool startEnable READ startEnabled NOTIFY startEnabledChanged)
Q_PROPERTY(bool endEnable READ endEnabled NOTIFY endEnabledChanged)
Q_PROPERTY(bool cancelEnable READ cancelEnabled NOTIFY cancelEnabledChanged)
Q_PROPERTY(float temperature READ temperature NOTIFY temperatureChanged)
Q_PROPERTY(float temperatureGradient READ temperatureGradient NOTIFY temperatureGradientChanged)
Q_PROPERTY(int progress READ progress WRITE setProgress NOTIFY progressChanged)
Q_OBJECT
public:
explicit ThermalCalibrationModel(QObject *parent = 0);
@ -92,7 +88,6 @@ public:
}
}
public slots:
int progress()
{
@ -125,13 +120,10 @@ public slots:
}
}
void setProgress(int status)
void setProgress(int progress)
{
m_progress = status;
emit progressChanged(status);
if (this->currentState()) {
setInstructions(this->currentState()->stepName());
}
m_progress = progress;
emit progressChanged(progress);
}
private:
@ -164,7 +156,7 @@ private:
WizardState *m_finalizeState;
// revert board settings if something goes wrong
WizardState *m_abortState;
// just the same as readystate, but it is reached after havign completed the calibration
// just the same as ready state, but it is reached after having completed the calibration
WizardState *m_completedState;
void setTransitions();
@ -184,14 +176,13 @@ signals:
void previous();
void abort();
public slots:
public slots:
void stepChanged(WizardState *state);
void init();
void btnStart()
{
// HACKS
// clear instructions
setInstructions(QString());
emit temperatureGradientChanged(0);
// END OF HACKS
emit next();
@ -213,10 +204,10 @@ signals:
}
void wizardStarted()
{
started();
setStartEnabled(false);
setEndEnabled(true);
setCancelEnabled(true);
started();
}
};
}

View File

@ -28,17 +28,19 @@
#ifndef WIZARDMODEL_H
#define WIZARDMODEL_H
#include <QStateMachine>
#include <QQmlListProperty>
#include "wizardstate.h"
#include <accelsensor.h>
#include <QStateMachine>
#include <QQmlListProperty>
class WizardModel : public QStateMachine {
Q_OBJECT Q_PROPERTY(QQmlListProperty<QObject> steps READ steps CONSTANT)
//Q_PROPERTY(QString instructions READ instructions NOTIFY instructionsChanged)
// Q_PROPERTY(QString instructions READ instructions NOTIFY instructionsChanged)
Q_PROPERTY(WizardState * currentState READ currentState NOTIFY currentStateChanged)
public:
enum MessageType { Info, Notice, Warning, Error };
enum MessageType { Info, Prompt, Warn, Success, Failure };
explicit WizardModel(QObject *parent = 0);
@ -52,12 +54,14 @@ public:
return m_instructions;
}
void setInstructions(QString text, MessageType type = WizardModel::Info)
WizardState *currentState();
public slots:
void addInstructions(QString text, WizardModel::MessageType type = WizardModel::Info)
{
m_instructions = text;
emit displayInstructions(text, type);
emit instructionsAdded(text, type);
}
WizardState *currentState();
protected:
QList<QObject *> m_steps;
@ -66,9 +70,8 @@ private:
QString m_instructions;
signals:
void displayInstructions(QString text, WizardModel::MessageType type = WizardModel::Info);
void instructionsAdded(QString text, WizardModel::MessageType type = WizardModel::Info);
void currentStateChanged(WizardState *status);
};
#endif // WIZARDMODEL_H

View File

@ -27,6 +27,7 @@
*/
#include "wizardstate.h"
#include "QDebug"
WizardState::WizardState(QString name, QState *parent) :
QState(parent)
{
@ -41,12 +42,6 @@ void WizardState::setCompletion(qint8 completion)
emit completionChanged();
}
void WizardState::setStepName(QString name)
{
m_stepName = name;
emit stepNameChanged();
}
void WizardState::onEntry(QEvent *event)
{
Q_UNUSED(event);

View File

@ -34,9 +34,11 @@ 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 WRITE setStepName NOTIFY stepNameChanged)
Q_PROPERTY(QString stepName READ stepName)
public:
explicit WizardState(QString name, QState *parent = 0);
bool isActive()
{
return m_active;
@ -57,17 +59,18 @@ public:
return m_stepName;
}
void setStepName(QString name);
void setCompletion(qint8 completion);
virtual void onEntry(QEvent *event) Q_DECL_OVERRIDE;
virtual void onExit(QEvent *event) Q_DECL_OVERRIDE;
signals:
void isActiveChanged();
void isDoneChanged();
void stepNameChanged();
void completionChanged();
public slots:
void clean();
private:
void setIsDone(bool done);
bool m_done;

View File

@ -109,8 +109,8 @@ ConfigRevoWidget::ConfigRevoWidget(QWidget *parent) :
connect(m_thermalCalibrationModel, SIGNAL(started()), this, SLOT(disableAllCalibrations()));
connect(m_thermalCalibrationModel, SIGNAL(stopped()), this, SLOT(enableAllCalibrations()));
connect(m_thermalCalibrationModel, SIGNAL(displayInstructions(QString, WizardModel::MessageType)),
this, SLOT(displayInstructions(QString, WizardModel::MessageType)));
connect(m_thermalCalibrationModel, SIGNAL(instructionsAdded(QString, WizardModel::MessageType)),
this, SLOT(addInstructions(QString, WizardModel::MessageType)));
connect(m_thermalCalibrationModel, SIGNAL(temperatureChanged(float)), this, SLOT(displayTemperature(float)));
connect(m_thermalCalibrationModel, SIGNAL(temperatureGradientChanged(float)), this, SLOT(displayTemperatureGradient(float)));
connect(m_thermalCalibrationModel, SIGNAL(progressChanged(int)), m_ui->thermalBiasProgress, SLOT(setValue(int)));
@ -127,11 +127,11 @@ ConfigRevoWidget::ConfigRevoWidget(QWidget *parent) :
connect(m_sixPointCalibrationModel, SIGNAL(storeAndClearBoardRotation()), this, SLOT(storeAndClearBoardRotation()));
connect(m_sixPointCalibrationModel, SIGNAL(recallBoardRotation()), this, SLOT(recallBoardRotation()));
connect(m_sixPointCalibrationModel, SIGNAL(displayInstructions(QString, WizardModel::MessageType)),
this, SLOT(displayInstructions(QString, WizardModel::MessageType)));
this, SLOT(addInstructions(QString, WizardModel::MessageType)));
connect(m_sixPointCalibrationModel, SIGNAL(displayVisualHelp(QString)), this, SLOT(displayVisualHelp(QString)));
connect(m_sixPointCalibrationModel, SIGNAL(savePositionEnabledChanged(bool)), this->m_ui->sixPointsSave, SLOT(setEnabled(bool)));
// level calibration
// board level calibration
m_levelCalibrationModel = new OpenPilot::LevelCalibrationModel(this);
connect(m_ui->boardLevelStart, SIGNAL(clicked()), m_levelCalibrationModel, SLOT(start()));
connect(m_ui->boardLevelSavePos, SIGNAL(clicked()), m_levelCalibrationModel, SLOT(savePosition()));
@ -139,7 +139,7 @@ ConfigRevoWidget::ConfigRevoWidget(QWidget *parent) :
connect(m_levelCalibrationModel, SIGNAL(started()), this, SLOT(disableAllCalibrations()));
connect(m_levelCalibrationModel, SIGNAL(stopped()), this, SLOT(enableAllCalibrations()));
connect(m_levelCalibrationModel, SIGNAL(displayInstructions(QString, WizardModel::MessageType)),
this, SLOT(displayInstructions(QString, WizardModel::MessageType)));
this, SLOT(addInstructions(QString, WizardModel::MessageType)));
connect(m_levelCalibrationModel, SIGNAL(displayVisualHelp(QString)), this, SLOT(displayVisualHelp(QString)));
connect(m_levelCalibrationModel, SIGNAL(savePositionEnabledChanged(bool)), this->m_ui->boardLevelSavePos, SLOT(setEnabled(bool)));
connect(m_levelCalibrationModel, SIGNAL(progressChanged(int)), this->m_ui->boardLevelProgress, SLOT(setValue(int)));
@ -155,7 +155,7 @@ ConfigRevoWidget::ConfigRevoWidget(QWidget *parent) :
connect(m_gyroBiasCalibrationModel, SIGNAL(storeAndClearBoardRotation()), this, SLOT(storeAndClearBoardRotation()));
connect(m_gyroBiasCalibrationModel, SIGNAL(recallBoardRotation()), this, SLOT(recallBoardRotation()));
connect(m_gyroBiasCalibrationModel, SIGNAL(displayInstructions(QString, WizardModel::MessageType)),
this, SLOT(displayInstructions(QString, WizardModel::MessageType)));
this, SLOT(addInstructions(QString, WizardModel::MessageType)));
connect(m_gyroBiasCalibrationModel, SIGNAL(displayVisualHelp(QString)), this, SLOT(displayVisualHelp(QString)));
connect(m_ui->hlClearButton, SIGNAL(clicked()), this, SLOT(clearHomeLocation()));
@ -248,17 +248,16 @@ void ConfigRevoWidget::clearInstructions()
m_ui->calibrationInstructions->clear();
}
void ConfigRevoWidget::displayInstructions(QString text, WizardModel::MessageType type)
void ConfigRevoWidget::addInstructions(QString text, WizardModel::MessageType type)
{
if (!text.isNull()) {
switch(type) {
case WizardModel::Error:
switch (type) {
case WizardModel::Failure:
text = QString("<font color='red'>%1</font>").arg(text);
break;
case WizardModel::Notice:
case WizardModel::Prompt:
text = QString("<font color='blue'>%1</font>").arg(text);
break;
case WizardModel::Info:
default:
break;
}
@ -266,7 +265,8 @@ void ConfigRevoWidget::displayInstructions(QString text, WizardModel::MessageTyp
}
}
void ConfigRevoWidget::displayTemperature(float temp) {
void ConfigRevoWidget::displayTemperature(float temp)
{
m_ui->temperatureLabel->setText(tr("Temperature %1 °C").arg(temp, 5, 'f', 2));
}

View File

@ -69,7 +69,7 @@ private slots:
void recallBoardRotation();
void displayVisualHelp(QString elementID);
void clearInstructions();
void displayInstructions(QString instructions, WizardModel::MessageType type = WizardModel::Info);
void addInstructions(QString text, WizardModel::MessageType type = WizardModel::Info);
void displayTemperature(float temp);
void displayTemperatureGradient(float tempGradient);