From b285df98c7495061954287e2c9c1b08a20c99902 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 1 Aug 2014 13:36:22 +0200 Subject: [PATCH 1/2] OP-1423 Populate TxPID Min/Max fields with the current values from the Stabilization page --- .../src/plugins/config/configtxpidwidget.cpp | 126 ++++++++++++++++++ .../src/plugins/config/configtxpidwidget.h | 2 + 2 files changed, 128 insertions(+) diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp index 85657e0f3..5447f3ec1 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp @@ -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 #include @@ -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(currentTextChanged(QString)), this, SLOT(updateSpinBoxProperties(const QString &))); + connect(m_txpid->PID2, SIGNAL(currentTextChanged(QString)), this, SLOT(updateSpinBoxProperties(const QString &))); + connect(m_txpid->PID3, SIGNAL(currentTextChanged(QString)), this, SLOT(updateSpinBoxProperties(const QString &))); + addWidgetBinding("TxPIDSettings", "BankNumber", m_txpid->pidBank, 0, 1, true); addWidgetBinding("TxPIDSettings", "PIDs", m_txpid->PID1, TxPIDSettings::PIDS_INSTANCE1); @@ -88,6 +96,124 @@ ConfigTxPIDWidget::~ConfigTxPIDWidget() // Do nothing } +template +static float defaultValueForPidOption(const StabilizationSettingsBankX *bank, const QString & pidOption) +{ + if (pidOption == "Disabled") { + return 0.0f; + } else if (pidOption == "Roll Rate.Kp") { + return bank->getRollRatePID_Kp(); + } else if (pidOption == "Pitch Rate.Kp") { + return bank->getPitchRatePID_Kp(); + } else if (pidOption == "Roll+Pitch Rate.Kp") { + return bank->getRollRatePID_Kp(); + } else if (pidOption == "Yaw Rate.Kp") { + return bank->getYawRatePID_Kp(); + } else if (pidOption == "Roll Rate.Ki") { + return bank->getRollRatePID_Ki(); + } else if (pidOption == "Pitch Rate.Ki") { + return bank->getPitchRatePID_Ki(); + } else if (pidOption == "Roll+Pitch Rate.Ki") { + return bank->getRollRatePID_Ki(); + } else if (pidOption == "Yaw Rate.Ki") { + return bank->getYawRatePID_Ki(); + } else if (pidOption == "Roll Rate.Kd") { + return bank->getRollRatePID_Kd(); + } else if (pidOption == "Pitch Rate.Kd") { + return bank->getPitchRatePID_Kd(); + } else if (pidOption == "Roll+Pitch Rate.Kd") { + return bank->getRollRatePID_Kd(); + } else if (pidOption == "Yaw Rate.Kd") { + return bank->getYawRatePID_Kd(); + } else if (pidOption == "Roll Rate.ILimit") { + return bank->getRollRatePID_ILimit(); + } else if (pidOption == "Pitch Rate.ILimit") { + return bank->getPitchRatePID_ILimit(); + } else if (pidOption == "Roll+Pitch Rate.ILimit") { + return bank->getRollRatePID_ILimit(); + } else if (pidOption == "Yaw Rate.ILimit") { + return bank->getYawRatePID_ILimit(); + } else if (pidOption == "Roll Attitude.Kp") { + return bank->getRollPI_Kp(); + } else if (pidOption == "Pitch Attitude.Kp") { + return bank->getPitchPI_Kp(); + } else if (pidOption == "Roll+Pitch Attitude.Kp") { + return bank->getRollPI_Kp(); + } else if (pidOption == "Yaw Attitude.Kp") { + return bank->getYawPI_Kp(); + } else if (pidOption == "Roll Attitude.Ki") { + return bank->getRollPI_Ki(); + } else if (pidOption == "Pitch Attitude.Ki") { + return bank->getPitchPI_Ki(); + } else if (pidOption == "Roll+Pitch Attitude.Ki") { + return bank->getRollPI_Ki(); + } else if (pidOption == "Yaw Attitude.Ki") { + return bank->getYawPI_Ki(); + } else if (pidOption == "Roll Attitude.ILimit") { + return bank->getRollPI_ILimit(); + } else if (pidOption == "Pitch Attitude.ILimit") { + return bank->getPitchPI_ILimit(); + } else if (pidOption == "Roll+Pitch Attitude.ILimit") { + return bank->getRollPI_ILimit(); + } else if (pidOption == "Yaw Attitude.ILimit") { + return bank->getYawPI_ILimit(); + } + + qDebug() << "getDefaultValueForOption: Incorrect PID option" << pidOption; + return 0.0f; +} + +float ConfigTxPIDWidget::getDefaultValueForPidOption(const QString & pidOption) +{ + if (pidOption == "GyroTau") { + StabilizationSettings *stab = qobject_cast(getObject(QString("StabilizationSettings"))); + return stab->getGyroTau(); + } + + uint bankNumber = m_txpid->pidBank->currentIndex() + 1; + + if (bankNumber == 1) { + StabilizationSettingsBank1 *bank = qobject_cast(getObject(QString("StabilizationSettingsBank1"))); + return defaultValueForPidOption(bank, pidOption); + } else if (bankNumber == 2) { + StabilizationSettingsBank2 *bank = qobject_cast(getObject(QString("StabilizationSettingsBank2"))); + return defaultValueForPidOption(bank, pidOption); + } else if (bankNumber == 3) { + StabilizationSettingsBank3 *bank = qobject_cast(getObject(QString("StabilizationSettingsBank3"))); + return defaultValueForPidOption(bank, pidOption); + } else { + qDebug() << "getDefaultValueForPidOption: Incorrect bank number:" << bankNumber; + return 0.0f; + } +} + +void ConfigTxPIDWidget::updateSpinBoxProperties(const QString & 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()); diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h index 38d2aa318..34a50c413 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h @@ -40,6 +40,8 @@ private: Ui_TxPIDWidget *m_txpid; private slots: + void updateSpinBoxProperties(const QString & selectedPidOption); + float getDefaultValueForPidOption(const QString & pidOption); void refreshValues(); void applySettings(); void saveSettings(); From 4754e62a8ef45cca29e92463218b58e209da03f7 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Tue, 5 Aug 2014 19:31:26 +0200 Subject: [PATCH 2/2] OP-1423 Use the TxPIDSettings::PIDsOptions enum instead of string comparisons --- .../src/plugins/config/configtxpidwidget.cpp | 164 +++++++++++------- .../src/plugins/config/configtxpidwidget.h | 4 +- 2 files changed, 99 insertions(+), 69 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp index 5447f3ec1..3facff7fa 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp @@ -55,9 +55,9 @@ 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(currentTextChanged(QString)), this, SLOT(updateSpinBoxProperties(const QString &))); - connect(m_txpid->PID2, SIGNAL(currentTextChanged(QString)), this, SLOT(updateSpinBoxProperties(const QString &))); - connect(m_txpid->PID3, SIGNAL(currentTextChanged(QString)), this, SLOT(updateSpinBoxProperties(const QString &))); + 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); @@ -97,75 +97,105 @@ ConfigTxPIDWidget::~ConfigTxPIDWidget() } template -static float defaultValueForPidOption(const StabilizationSettingsBankX *bank, const QString & pidOption) +static float defaultValueForPidOption(const StabilizationSettingsBankX *bank, int pidOption) { - if (pidOption == "Disabled") { + switch (pidOption) { + case TxPIDSettings::PIDS_DISABLED: return 0.0f; - } else if (pidOption == "Roll Rate.Kp") { - return bank->getRollRatePID_Kp(); - } else if (pidOption == "Pitch Rate.Kp") { - return bank->getPitchRatePID_Kp(); - } else if (pidOption == "Roll+Pitch Rate.Kp") { - return bank->getRollRatePID_Kp(); - } else if (pidOption == "Yaw Rate.Kp") { - return bank->getYawRatePID_Kp(); - } else if (pidOption == "Roll Rate.Ki") { - return bank->getRollRatePID_Ki(); - } else if (pidOption == "Pitch Rate.Ki") { - return bank->getPitchRatePID_Ki(); - } else if (pidOption == "Roll+Pitch Rate.Ki") { - return bank->getRollRatePID_Ki(); - } else if (pidOption == "Yaw Rate.Ki") { - return bank->getYawRatePID_Ki(); - } else if (pidOption == "Roll Rate.Kd") { - return bank->getRollRatePID_Kd(); - } else if (pidOption == "Pitch Rate.Kd") { - return bank->getPitchRatePID_Kd(); - } else if (pidOption == "Roll+Pitch Rate.Kd") { - return bank->getRollRatePID_Kd(); - } else if (pidOption == "Yaw Rate.Kd") { - return bank->getYawRatePID_Kd(); - } else if (pidOption == "Roll Rate.ILimit") { - return bank->getRollRatePID_ILimit(); - } else if (pidOption == "Pitch Rate.ILimit") { - return bank->getPitchRatePID_ILimit(); - } else if (pidOption == "Roll+Pitch Rate.ILimit") { - return bank->getRollRatePID_ILimit(); - } else if (pidOption == "Yaw Rate.ILimit") { - return bank->getYawRatePID_ILimit(); - } else if (pidOption == "Roll Attitude.Kp") { - return bank->getRollPI_Kp(); - } else if (pidOption == "Pitch Attitude.Kp") { - return bank->getPitchPI_Kp(); - } else if (pidOption == "Roll+Pitch Attitude.Kp") { - return bank->getRollPI_Kp(); - } else if (pidOption == "Yaw Attitude.Kp") { - return bank->getYawPI_Kp(); - } else if (pidOption == "Roll Attitude.Ki") { - return bank->getRollPI_Ki(); - } else if (pidOption == "Pitch Attitude.Ki") { - return bank->getPitchPI_Ki(); - } else if (pidOption == "Roll+Pitch Attitude.Ki") { - return bank->getRollPI_Ki(); - } else if (pidOption == "Yaw Attitude.Ki") { - return bank->getYawPI_Ki(); - } else if (pidOption == "Roll Attitude.ILimit") { - return bank->getRollPI_ILimit(); - } else if (pidOption == "Pitch Attitude.ILimit") { - return bank->getPitchPI_ILimit(); - } else if (pidOption == "Roll+Pitch Attitude.ILimit") { - return bank->getRollPI_ILimit(); - } else if (pidOption == "Yaw Attitude.ILimit") { - return bank->getYawPI_ILimit(); - } - qDebug() << "getDefaultValueForOption: Incorrect PID option" << pidOption; - 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(const QString & pidOption) +float ConfigTxPIDWidget::getDefaultValueForPidOption(int pidOption) { - if (pidOption == "GyroTau") { + if (pidOption == TxPIDSettings::PIDS_GYROTAU) { StabilizationSettings *stab = qobject_cast(getObject(QString("StabilizationSettings"))); return stab->getGyroTau(); } @@ -187,7 +217,7 @@ float ConfigTxPIDWidget::getDefaultValueForPidOption(const QString & pidOption) } } -void ConfigTxPIDWidget::updateSpinBoxProperties(const QString & selectedPidOption) +void ConfigTxPIDWidget::updateSpinBoxProperties(int selectedPidOption) { QObject *PIDx = sender(); diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h index 34a50c413..afb148119 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h @@ -40,8 +40,8 @@ private: Ui_TxPIDWidget *m_txpid; private slots: - void updateSpinBoxProperties(const QString & selectedPidOption); - float getDefaultValueForPidOption(const QString & pidOption); + void updateSpinBoxProperties(int selectedPidOption); + float getDefaultValueForPidOption(int pidOption); void refreshValues(); void applySettings(); void saveSettings();