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

Merge remote-tracking branch 'origin/skarlsso/OP-1423_populate_txpid_min_max_fields' into next

This commit is contained in:
Fredrik Arvidsson 2014-08-09 10:28:07 +02:00
commit bc5bf38ec5
2 changed files with 158 additions and 0 deletions

View File

@ -28,6 +28,10 @@
#include "configtxpidwidget.h"
#include "txpidsettings.h"
#include "hwsettings.h"
#include "stabilizationsettings.h"
#include "stabilizationsettingsbank1.h"
#include "stabilizationsettingsbank2.h"
#include "stabilizationsettingsbank3.h"
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/generalsettings.h>
@ -51,6 +55,10 @@ ConfigTxPIDWidget::ConfigTxPIDWidget(QWidget *parent) : ConfigTaskWidget(parent)
connect(m_txpid->Apply, SIGNAL(clicked()), this, SLOT(applySettings()));
connect(m_txpid->Save, SIGNAL(clicked()), this, SLOT(saveSettings()));
connect(m_txpid->PID1, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSpinBoxProperties(int)));
connect(m_txpid->PID2, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSpinBoxProperties(int)));
connect(m_txpid->PID3, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSpinBoxProperties(int)));
addWidgetBinding("TxPIDSettings", "BankNumber", m_txpid->pidBank, 0, 1, true);
addWidgetBinding("TxPIDSettings", "PIDs", m_txpid->PID1, TxPIDSettings::PIDS_INSTANCE1);
@ -88,6 +96,154 @@ ConfigTxPIDWidget::~ConfigTxPIDWidget()
// Do nothing
}
template <class StabilizationSettingsBankX>
static float defaultValueForPidOption(const StabilizationSettingsBankX *bank, int pidOption)
{
switch (pidOption) {
case TxPIDSettings::PIDS_DISABLED:
return 0.0f;
case TxPIDSettings::PIDS_ROLLRATEKP:
return bank->getRollRatePID_Kp();
case TxPIDSettings::PIDS_PITCHRATEKP:
return bank->getPitchRatePID_Kp();
case TxPIDSettings::PIDS_ROLLPITCHRATEKP:
return bank->getRollRatePID_Kp();
case TxPIDSettings::PIDS_YAWRATEKP:
return bank->getYawRatePID_Kp();
case TxPIDSettings::PIDS_ROLLRATEKI:
return bank->getRollRatePID_Ki();
case TxPIDSettings::PIDS_PITCHRATEKI:
return bank->getPitchRatePID_Ki();
case TxPIDSettings::PIDS_ROLLPITCHRATEKI:
return bank->getRollRatePID_Ki();
case TxPIDSettings::PIDS_YAWRATEKI:
return bank->getYawRatePID_Ki();
case TxPIDSettings::PIDS_ROLLRATEKD:
return bank->getRollRatePID_Kd();
case TxPIDSettings::PIDS_PITCHRATEKD:
return bank->getPitchRatePID_Kd();
case TxPIDSettings::PIDS_ROLLPITCHRATEKD:
return bank->getRollRatePID_Kd();
case TxPIDSettings::PIDS_YAWRATEKD:
return bank->getYawRatePID_Kd();
case TxPIDSettings::PIDS_ROLLRATEILIMIT:
return bank->getRollRatePID_ILimit();
case TxPIDSettings::PIDS_PITCHRATEILIMIT:
return bank->getPitchRatePID_ILimit();
case TxPIDSettings::PIDS_ROLLPITCHRATEILIMIT:
return bank->getRollRatePID_ILimit();
case TxPIDSettings::PIDS_YAWRATEILIMIT:
return bank->getYawRatePID_ILimit();
case TxPIDSettings::PIDS_ROLLATTITUDEKP:
return bank->getRollPI_Kp();
case TxPIDSettings::PIDS_PITCHATTITUDEKP:
return bank->getPitchPI_Kp();
case TxPIDSettings::PIDS_ROLLPITCHATTITUDEKP:
return bank->getRollPI_Kp();
case TxPIDSettings::PIDS_YAWATTITUDEKP:
return bank->getYawPI_Kp();
case TxPIDSettings::PIDS_ROLLATTITUDEKI:
return bank->getRollPI_Ki();
case TxPIDSettings::PIDS_PITCHATTITUDEKI:
return bank->getPitchPI_Ki();
case TxPIDSettings::PIDS_ROLLPITCHATTITUDEKI:
return bank->getRollPI_Ki();
case TxPIDSettings::PIDS_YAWATTITUDEKI:
return bank->getYawPI_Ki();
case TxPIDSettings::PIDS_ROLLATTITUDEILIMIT:
return bank->getRollPI_ILimit();
case TxPIDSettings::PIDS_PITCHATTITUDEILIMIT:
return bank->getPitchPI_ILimit();
case TxPIDSettings::PIDS_ROLLPITCHATTITUDEILIMIT:
return bank->getRollPI_ILimit();
case TxPIDSettings::PIDS_YAWATTITUDEILIMIT:
return bank->getYawPI_ILimit();
default:
qDebug() << "getDefaultValueForOption: Incorrect PID option" << pidOption;
return 0.0f;
}
}
float ConfigTxPIDWidget::getDefaultValueForPidOption(int pidOption)
{
if (pidOption == TxPIDSettings::PIDS_GYROTAU) {
StabilizationSettings *stab = qobject_cast<StabilizationSettings *>(getObject(QString("StabilizationSettings")));
return stab->getGyroTau();
}
uint bankNumber = m_txpid->pidBank->currentIndex() + 1;
if (bankNumber == 1) {
StabilizationSettingsBank1 *bank = qobject_cast<StabilizationSettingsBank1 *>(getObject(QString("StabilizationSettingsBank1")));
return defaultValueForPidOption(bank, pidOption);
} else if (bankNumber == 2) {
StabilizationSettingsBank2 *bank = qobject_cast<StabilizationSettingsBank2 *>(getObject(QString("StabilizationSettingsBank2")));
return defaultValueForPidOption(bank, pidOption);
} else if (bankNumber == 3) {
StabilizationSettingsBank3 *bank = qobject_cast<StabilizationSettingsBank3 *>(getObject(QString("StabilizationSettingsBank3")));
return defaultValueForPidOption(bank, pidOption);
} else {
qDebug() << "getDefaultValueForPidOption: Incorrect bank number:" << bankNumber;
return 0.0f;
}
}
void ConfigTxPIDWidget::updateSpinBoxProperties(int selectedPidOption)
{
QObject *PIDx = sender();
QDoubleSpinBox *minPID;
QDoubleSpinBox *maxPID;
if (PIDx == m_txpid->PID1) {
minPID = m_txpid->MinPID1;
maxPID = m_txpid->MaxPID1;
} else if (PIDx == m_txpid->PID2) {
minPID = m_txpid->MinPID2;
maxPID = m_txpid->MaxPID2;
} else if (PIDx == m_txpid->PID3) {
minPID = m_txpid->MinPID3;
maxPID = m_txpid->MaxPID3;
} else {
qDebug() << "updateSpinBoxProperties: Incorrect sender object";
return;
}
float value = getDefaultValueForPidOption(selectedPidOption);
minPID->setValue(value);
maxPID->setValue(value);
}
void ConfigTxPIDWidget::refreshValues()
{
HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager());

View File

@ -40,6 +40,8 @@ private:
Ui_TxPIDWidget *m_txpid;
private slots:
void updateSpinBoxProperties(int selectedPidOption);
float getDefaultValueForPidOption(int pidOption);
void refreshValues();
void applySettings();
void saveSettings();