1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-27 16:54:15 +01:00

OP-1150 UI for thermal calibration: Uncrustify

This commit is contained in:
Alessio Morale 2014-01-18 13:48:41 +01:00
parent 25f75f0b8e
commit ab0406a6c8
11 changed files with 52 additions and 52 deletions

View File

@ -74,14 +74,14 @@ bool CalibrationUtils::PolynomialCalibration(Eigen::VectorXf samplesX, Eigen::Ve
x.col(i) = tmp2;
}
Eigen::MatrixXd xt = x.transpose();
Eigen::MatrixXd xt = x.transpose();
Eigen::MatrixXd xtx = xt * x;
Eigen::MatrixXd xtx = xt * x;
Eigen::VectorXd xty = xt * doubleY;
Eigen::VectorXd xty = xt * doubleY;
Eigen::VectorXd tmpx = xtx.fullPivHouseholderQr().solve(xty);
result = tmpx.cast<float>();
double relativeError = (xtx*tmpx - xty).norm() / xty.norm();
double relativeError = (xtx * tmpx - xty).norm() / xty.norm();
std::cout << "Estimated relative error " << relativeError << "; Max allowed error " << maxRelativeError << std::endl;
return relativeError < maxRelativeError;
}

View File

@ -34,7 +34,6 @@
#include "thermalcalibrationhelper.h"
namespace OpenPilot {
class BoardSetupTransition : public QSignalTransition {
Q_OBJECT
public:

View File

@ -34,7 +34,6 @@
#include "thermalcalibrationhelper.h"
namespace OpenPilot {
class CompensationCalculationTransition : public QSignalTransition {
Q_OBJECT
public:

View File

@ -34,7 +34,6 @@
#include "thermalcalibrationhelper.h"
namespace OpenPilot {
class DataAcquisitionTransition : public QSignalTransition {
Q_OBJECT
public:

View File

@ -33,7 +33,6 @@
#include "thermalcalibrationhelper.h"
namespace OpenPilot {
class BoardStatusSaveTransition : public QSignalTransition {
Q_OBJECT
public:

View File

@ -40,14 +40,14 @@ class ThermalCalibration {
static const int ACCEL_Z_POLY_DEGREE = 1;
static const int BARO_PRESSURE_POLY_DEGREE = 3;
//TODO: determine max allowable relative error
// TODO: determine max allowable relative error
static const double BARO_PRESSURE_MAX_REL_ERROR = 1E-6f;
static const double ACCEL_X_MAX_REL_ERROR = 1E-6f;
static const double ACCEL_Y_MAX_REL_ERROR = 1E-6f;
static const double ACCEL_Z_MAX_REL_ERROR = 1E-6f;
static const double GYRO_X_MAX_REL_ERROR = 1E-6f;
static const double GYRO_Y_MAX_REL_ERROR = 1E-6f;
static const double GYRO_Z_MAX_REL_ERROR = 1E-6f;
static const double ACCEL_X_MAX_REL_ERROR = 1E-6f;
static const double ACCEL_Y_MAX_REL_ERROR = 1E-6f;
static const double ACCEL_Z_MAX_REL_ERROR = 1E-6f;
static const double GYRO_X_MAX_REL_ERROR = 1E-6f;
static const double GYRO_Y_MAX_REL_ERROR = 1E-6f;
static const double GYRO_Z_MAX_REL_ERROR = 1E-6f;
public:
/**
* @brief produce the calibration polinomial coefficients from pressure and temperature samples

View File

@ -31,13 +31,12 @@ namespace OpenPilot {
ThermalCalibrationHelper::ThermalCalibrationHelper(QObject *parent) :
QObject(parent)
{
m_boardInitialSettings = thermalCalibrationBoardSettings();
m_boardInitialSettings = thermalCalibrationBoardSettings();
m_boardInitialSettings.statusSaved = false;
m_results = thermalCalibrationResults();
m_results.accelCalibrated = false;
m_results.baroCalibrated = false;
m_results.gyroCalibrated = false;
m_results.baroCalibrated = false;
m_results.gyroCalibrated = false;
}
/**
@ -267,7 +266,7 @@ void ThermalCalibrationHelper::calculate()
Eigen::VectorXf dataz(1);
Eigen::VectorXf datat(count);
for(int x = 0; x < count; x++){
for (int x = 0; x < count; x++) {
datax[x] = m_baroSamples[x].Pressure;
datat[x] = m_baroSamples[x].Temperature;
}
@ -281,7 +280,7 @@ void ThermalCalibrationHelper::calculate()
dataz.resize(count);
datat.resize(count);
for(int x = 0; x < count; x++){
for (int x = 0; x < count; x++) {
datax[x] = m_gyroSamples[x].x;
datay[x] = m_gyroSamples[x].y;
dataz[x] = m_gyroSamples[x].z;
@ -290,24 +289,24 @@ void ThermalCalibrationHelper::calculate()
m_results.gyroCalibrated = ThermalCalibration::GyroscopeCalibration(datax, datay, dataz, datat, m_results.gyro);
//TODO: sanity checks needs to be enforced before accel calibration can be enabled and usable.
// TODO: sanity checks needs to be enforced before accel calibration can be enabled and usable.
/*
setProcessPercentage(processPercentage() + 2);
count = m_accelSamples.count();
datax.resize(count);
datay.resize(count);
dataz.resize(count);
datat.resize(count);
setProcessPercentage(processPercentage() + 2);
count = m_accelSamples.count();
datax.resize(count);
datay.resize(count);
dataz.resize(count);
datat.resize(count);
for(int x = 0; x < count; x++){
for(int x = 0; x < count; x++){
datax[x] = m_accelSamples[x].x;
datay[x] = m_accelSamples[x].y;
dataz[x] = m_accelSamples[x].z;
datat[x] = m_accelSamples[x].temperature;
}
}
m_results.accelCalibrated = ThermalCalibration::AccelerometerCalibration(datax, datay, dataz, datat, m_results.accel);
*/
m_results.accelCalibrated = ThermalCalibration::AccelerometerCalibration(datax, datay, dataz, datat, m_results.accel);
*/
m_results.accelCalibrated = false;
copyResultToSettings();
emit calculationCompleted();
@ -366,6 +365,7 @@ void ThermalCalibrationHelper::endAcquisition()
void ThermalCalibrationHelper::connectUAVOs()
{
AccelSensor *accel = AccelSensor::GetInstance(getObjectManager());
connect(accel, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(collectSample(UAVObject *)));
GyroSensor *gyro = GyroSensor::GetInstance(getObjectManager());
@ -381,6 +381,7 @@ void ThermalCalibrationHelper::connectUAVOs()
void ThermalCalibrationHelper::disconnectUAVOs()
{
AccelSensor *accel = AccelSensor::GetInstance(getObjectManager());
disconnect(accel, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(collectSample(UAVObject *)));
GyroSensor *gyro = GyroSensor::GetInstance(getObjectManager());
@ -396,9 +397,10 @@ void ThermalCalibrationHelper::disconnectUAVOs()
void ThermalCalibrationHelper::copyResultToSettings()
{
UAVObjectManager *objManager = getObjectManager();
Q_ASSERT(objManager);
if(m_results.baroCalibrated) {
if (m_results.baroCalibrated) {
RevoSettings *revosettings = RevoSettings::GetInstance(objManager);
Q_ASSERT(revosettings);
revosettings->setBaroTempCorrectionPolynomial_a(m_results.baro[0]);
@ -408,19 +410,19 @@ void ThermalCalibrationHelper::copyResultToSettings()
revosettings->updated();
}
if(m_results.gyroCalibrated || m_results.accelCalibrated){
if (m_results.gyroCalibrated || m_results.accelCalibrated) {
AccelGyroSettings *accelGyroSettings = AccelGyroSettings::GetInstance(objManager);
Q_ASSERT(accelGyroSettings);
AccelGyroSettings::DataFields data = accelGyroSettings->getData();
AccelGyroSettings::DataFields data = accelGyroSettings->getData();
if(m_results.gyroCalibrated){
if (m_results.gyroCalibrated) {
data.gyro_temp_coeff[0] = m_results.gyro[0];
data.gyro_temp_coeff[1] = m_results.gyro[1];
data.gyro_temp_coeff[2] = m_results.gyro[2];
data.gyro_temp_coeff[3] = m_results.gyro[3];
}
if(m_results.accelCalibrated){
if (m_results.accelCalibrated) {
data.accel_temp_coeff[0] = m_results.gyro[0];
data.accel_temp_coeff[1] = m_results.gyro[1];
data.accel_temp_coeff[2] = m_results.gyro[2];

View File

@ -50,7 +50,6 @@
#include <revocalibration.h>
#include <revosettings.h>
namespace OpenPilot {
typedef struct {
// this is not needed for revo, but should for CC/CC3D
// AccelGyroSettings::DataFields accelGyroSettings;
@ -62,11 +61,11 @@ typedef struct {
} thermalCalibrationBoardSettings;
typedef struct {
bool baroCalibrated;
bool baroCalibrated;
float baro[4];
bool accelCalibrated;
bool accelCalibrated;
float accel[3];
bool gyroCalibrated;
bool gyroCalibrated;
float gyro[4];
} thermalCalibrationResults;
class ThermalCalibrationHelper : public QObject {
@ -121,7 +120,8 @@ public slots:
*/
void initAcquisition();
void stopAcquisition(){
void stopAcquisition()
{
QMutexLocker lock(&sensorsUpdateLock);
emit collectionCompleted();
}
@ -164,7 +164,7 @@ private:
const static int ProcessPercentageSetupBoard = 10;
const static int ProcessPercentageBaseAcquisition = 15;
const static int ProcessPercentageBaseCalculation = 85;
const static int ProcessPercentageSaveResults = 95;
const static int ProcessPercentageSaveResults = 95;
const static float TargetGradient = 0.35f;
int m_targetduration;
int m_processPercentage;

View File

@ -36,7 +36,6 @@
#define PREVIOUS_EVENT "previous"
#define ABORT_EVENT "abort"
namespace OpenPilot {
ThermalCalibrationModel::ThermalCalibrationModel(QObject *parent) :
WizardModel(parent)
{
@ -50,7 +49,7 @@ ThermalCalibrationModel::ThermalCalibrationModel(QObject *parent) :
m_setupState = new WizardState(tr("Setup board for calibration"), 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_restoreState = new WizardState(tr("Restore board settings"), m_workingState);
m_calculateState = new WizardState(tr("Calculate calibration matrix"), m_workingState);
m_abortState = new WizardState("Canceled", this);
@ -80,7 +79,8 @@ void ThermalCalibrationModel::init()
emit instructionsChanged(instructions());
}
void ThermalCalibrationModel::stepChanged(WizardState *state) {
void ThermalCalibrationModel::stepChanged(WizardState *state)
{
Q_UNUSED(state);
}
@ -98,11 +98,11 @@ void ThermalCalibrationModel::setTransitions()
// acquisition -revertSettings-> calculation
// revert settings after acquisition is completed
// m_acquisitionState->addTransition(new BoardStatusRestoreTransition(m_helper, m_acquisitionState, m_calculateState));
m_acquisitionState->addTransition(new DataAcquisitionTransition(m_helper, m_acquisitionState, m_restoreState ));
m_restoreState ->addTransition(new BoardStatusRestoreTransition(m_helper, m_restoreState, m_calculateState));
m_acquisitionState->addTransition(new DataAcquisitionTransition(m_helper, m_acquisitionState, m_restoreState));
m_restoreState->addTransition(new BoardStatusRestoreTransition(m_helper, m_restoreState, m_calculateState));
m_calculateState->addTransition(new CompensationCalculationTransition(m_helper, m_calculateState, m_completedState));
m_abortState->addTransition(new BoardStatusRestoreTransition(m_helper, m_abortState, m_readyState));
m_workingState->addTransition(m_helper, SIGNAL(abort()), m_abortState) ;
m_workingState->addTransition(m_helper, SIGNAL(abort()), m_abortState);
// Ready
}
}

View File

@ -38,7 +38,6 @@
#include "../wizardstate.h"
#include "../wizardmodel.h"
namespace OpenPilot {
class ThermalCalibrationModel : public WizardModel {
Q_PROPERTY(bool startEnable READ startEnabled NOTIFY startEnabledChanged)
Q_PROPERTY(bool endEnable READ endEnabled NOTIFY endEnabledChanged)
@ -195,12 +194,14 @@ public slots:
{
emit abort();
}
void wizardReady(){
void wizardReady()
{
setStartEnabled(true);
setEndEnabled(false);
setCancelEnabled(false);
}
void wizardStarted(){
void wizardStarted()
{
setStartEnabled(false);
setEndEnabled(true);
setCancelEnabled(true);

View File

@ -35,6 +35,7 @@ WizardState *WizardModel::currentState()
{
foreach(QAbstractState * value, this->configuration()) {
WizardState *state = static_cast<WizardState *>(value);
if (state->children().count() <= 1) {
return state;
}