From 2113e1a2e1ab0cee6284638298861cc13522ffee Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 11 Jul 2014 23:11:45 +0200 Subject: [PATCH 01/10] OP-1397 Add initial support for attitude mode response (deg) --- flight/modules/TxPID/txpid.c | 30 ++++++++++++++++++++ shared/uavobjectdefinition/txpidsettings.xml | 1 + 2 files changed, 31 insertions(+) diff --git a/flight/modules/TxPID/txpid.c b/flight/modules/TxPID/txpid.c index a48a20967..85a65172e 100644 --- a/flight/modules/TxPID/txpid.c +++ b/flight/modules/TxPID/txpid.c @@ -83,6 +83,7 @@ // Private functions static void updatePIDs(UAVObjEvent *ev); static uint8_t update(float *var, float val); +static uint8_t updateResponsiveness(uint8_t *var, float val); static float scale(float val, float inMin, float inMax, float outMin, float outMax); /** @@ -235,6 +236,9 @@ static void updatePIDs(UAVObjEvent *ev) case TXPIDSETTINGS_PIDS_ROLLATTITUDEILIMIT: needsUpdateBank |= update(&bank.RollPI.ILimit, value); break; + case TXPIDSETTINGS_PIDS_ROLLATTITUDERESP: + needsUpdateBank |= updateResponsiveness(&bank.RollMax, value); + break; case TXPIDSETTINGS_PIDS_PITCHRATEKP: needsUpdateBank |= update(&bank.PitchRatePID.Kp, value); break; @@ -256,6 +260,9 @@ static void updatePIDs(UAVObjEvent *ev) case TXPIDSETTINGS_PIDS_PITCHATTITUDEILIMIT: needsUpdateBank |= update(&bank.PitchPI.ILimit, value); break; + case TXPIDSETTINGS_PIDS_PITCHATTITUDERESP: + needsUpdateBank |= updateResponsiveness(&bank.PitchMax, value); + break; case TXPIDSETTINGS_PIDS_ROLLPITCHRATEKP: needsUpdateBank |= update(&bank.RollRatePID.Kp, value); needsUpdateBank |= update(&bank.PitchRatePID.Kp, value); @@ -284,6 +291,10 @@ static void updatePIDs(UAVObjEvent *ev) needsUpdateBank |= update(&bank.RollPI.ILimit, value); needsUpdateBank |= update(&bank.PitchPI.ILimit, value); break; + case TXPIDSETTINGS_PIDS_ROLLPITCHATTITUDERESP: + needsUpdateBank |= updateResponsiveness(&bank.RollMax, value); + needsUpdateBank |= updateResponsiveness(&bank.PitchMax, value); + break; case TXPIDSETTINGS_PIDS_YAWRATEKP: needsUpdateBank |= update(&bank.YawRatePID.Kp, value); break; @@ -305,6 +316,9 @@ static void updatePIDs(UAVObjEvent *ev) case TXPIDSETTINGS_PIDS_YAWATTITUDEILIMIT: needsUpdateBank |= update(&bank.YawPI.ILimit, value); break; + case TXPIDSETTINGS_PIDS_YAWATTITUDERESP: + needsUpdateBank |= updateResponsiveness(&bank.YawMax, value); + break; case TXPIDSETTINGS_PIDS_GYROTAU: needsUpdateStab |= update(&stab.GyroTau, value); break; @@ -389,6 +403,22 @@ static uint8_t update(float *var, float val) return 0; } +/** + * Updates var using val if needed. + * \returns 1 if updated, 0 otherwise + */ +static uint8_t updateResponsiveness(uint8_t *var, float val) +{ + // Just floor it for now. + uint8_t roundedVal = (uint8_t)val; + + if (*var != roundedVal) { + *var = roundedVal; + return 1; + } + return 0; +} + /** * @} */ diff --git a/shared/uavobjectdefinition/txpidsettings.xml b/shared/uavobjectdefinition/txpidsettings.xml index 9f1a91579..174ca840c 100644 --- a/shared/uavobjectdefinition/txpidsettings.xml +++ b/shared/uavobjectdefinition/txpidsettings.xml @@ -18,6 +18,7 @@ Roll Attitude.Kp, Pitch Attitude.Kp, Roll+Pitch Attitude.Kp, Yaw Attitude.Kp, Roll Attitude.Ki, Pitch Attitude.Ki, Roll+Pitch Attitude.Ki, Yaw Attitude.Ki, Roll Attitude.ILimit, Pitch Attitude.ILimit, Roll+Pitch Attitude.ILimit, Yaw Attitude.ILimit, + Roll Attitude.Resp, Pitch Attitude.Resp, Roll+Pitch Attitude.Resp, Yaw Attitude.Resp, GyroTau" defaultvalue="Disabled"/> From a7ee6fa7642d92cb2cc4182cde9874d8ad9884da Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 11 Jul 2014 23:29:36 +0200 Subject: [PATCH 02/10] OP-1397 Add initial support for rate mode response (deg/s) --- flight/modules/TxPID/txpid.c | 13 +++++++++++++ shared/uavobjectdefinition/txpidsettings.xml | 1 + 2 files changed, 14 insertions(+) diff --git a/flight/modules/TxPID/txpid.c b/flight/modules/TxPID/txpid.c index 85a65172e..c49ed49d7 100644 --- a/flight/modules/TxPID/txpid.c +++ b/flight/modules/TxPID/txpid.c @@ -227,6 +227,9 @@ static void updatePIDs(UAVObjEvent *ev) case TXPIDSETTINGS_PIDS_ROLLRATEILIMIT: needsUpdateBank |= update(&bank.RollRatePID.ILimit, value); break; + case TXPIDSETTINGS_PIDS_ROLLRATERESP: + needsUpdateBank |= update(&bank.ManualRate.Roll, value); + break; case TXPIDSETTINGS_PIDS_ROLLATTITUDEKP: needsUpdateBank |= update(&bank.RollPI.Kp, value); break; @@ -251,6 +254,9 @@ static void updatePIDs(UAVObjEvent *ev) case TXPIDSETTINGS_PIDS_PITCHRATEILIMIT: needsUpdateBank |= update(&bank.PitchRatePID.ILimit, value); break; + case TXPIDSETTINGS_PIDS_PITCHRATERESP: + needsUpdateBank |= update(&bank.ManualRate.Pitch, value); + break; case TXPIDSETTINGS_PIDS_PITCHATTITUDEKP: needsUpdateBank |= update(&bank.PitchPI.Kp, value); break; @@ -279,6 +285,10 @@ static void updatePIDs(UAVObjEvent *ev) needsUpdateBank |= update(&bank.RollRatePID.ILimit, value); needsUpdateBank |= update(&bank.PitchRatePID.ILimit, value); break; + case TXPIDSETTINGS_PIDS_ROLLPITCHRATERESP: + needsUpdateBank |= update(&bank.ManualRate.Roll, value); + needsUpdateBank |= update(&bank.ManualRate.Pitch, value); + break; case TXPIDSETTINGS_PIDS_ROLLPITCHATTITUDEKP: needsUpdateBank |= update(&bank.RollPI.Kp, value); needsUpdateBank |= update(&bank.PitchPI.Kp, value); @@ -307,6 +317,9 @@ static void updatePIDs(UAVObjEvent *ev) case TXPIDSETTINGS_PIDS_YAWRATEILIMIT: needsUpdateBank |= update(&bank.YawRatePID.ILimit, value); break; + case TXPIDSETTINGS_PIDS_YAWRATERESP: + needsUpdateBank |= update(&bank.ManualRate.Yaw, value); + break; case TXPIDSETTINGS_PIDS_YAWATTITUDEKP: needsUpdateBank |= update(&bank.YawPI.Kp, value); break; diff --git a/shared/uavobjectdefinition/txpidsettings.xml b/shared/uavobjectdefinition/txpidsettings.xml index 174ca840c..e85774e9b 100644 --- a/shared/uavobjectdefinition/txpidsettings.xml +++ b/shared/uavobjectdefinition/txpidsettings.xml @@ -15,6 +15,7 @@ Roll Rate.Ki, Pitch Rate.Ki, Roll+Pitch Rate.Ki, Yaw Rate.Ki, Roll Rate.Kd, Pitch Rate.Kd, Roll+Pitch Rate.Kd, Yaw Rate.Kd, Roll Rate.ILimit, Pitch Rate.ILimit, Roll+Pitch Rate.ILimit, Yaw Rate.ILimit, + Roll Rate.Resp, Pitch Rate.Resp, Roll+Pitch Rate.Resp, Yaw Rate.Resp, Roll Attitude.Kp, Pitch Attitude.Kp, Roll+Pitch Attitude.Kp, Yaw Attitude.Kp, Roll Attitude.Ki, Pitch Attitude.Ki, Roll+Pitch Attitude.Ki, Yaw Attitude.Ki, Roll Attitude.ILimit, Pitch Attitude.ILimit, Roll+Pitch Attitude.ILimit, Yaw Attitude.ILimit, From 14770876cd747a63e5fbb08daadd68e855a36fce Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Tue, 15 Jul 2014 00:19:28 +0200 Subject: [PATCH 03/10] OP-1397 Change spinbox properties when a Responsiveness item is selected --- .../src/plugins/config/configtxpidwidget.cpp | 43 +++++++++++++++++++ .../src/plugins/config/configtxpidwidget.h | 1 + 2 files changed, 44 insertions(+) diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp index 85657e0f3..4e58d2357 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp @@ -51,6 +51,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(activated(QString)), this, SLOT(updateSpinBoxProperties(const QString &))); + connect(m_txpid->PID2, SIGNAL(activated(QString)), this, SLOT(updateSpinBoxProperties(const QString &))); + connect(m_txpid->PID3, SIGNAL(activated(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 +92,45 @@ ConfigTxPIDWidget::~ConfigTxPIDWidget() // Do nothing } +void ConfigTxPIDWidget::updateSpinBoxProperties(const QString & selected_pid_type) +{ + QDoubleSpinBox *minPID; + QDoubleSpinBox *maxPID; + + qDebug() << "ConfigTxPIDWidget::updateSpinBoxProperties(" << selected_pid_type << ")"; + + QObject *obj = sender(); + if (obj == m_txpid->PID1) { + minPID = m_txpid->MinPID1; + maxPID = m_txpid->MaxPID1; + } else if (obj == m_txpid->PID2) { + minPID = m_txpid->MinPID2; + maxPID = m_txpid->MaxPID2; + } else if (obj == m_txpid->PID3) { + minPID = m_txpid->MinPID3; + maxPID = m_txpid->MaxPID3; + } else { + qDebug() << "updateSpinBoxProperties: Incorrect sender object"; + return; + } + + if (selected_pid_type.endsWith(".Resp")) { + minPID->setRange(0, 999); + maxPID->setRange(0, 999); + minPID->setSingleStep(1); + maxPID->setSingleStep(1); + minPID->setDecimals(0); + maxPID->setDecimals(0); + } else { + minPID->setRange(0, 99.99); + maxPID->setRange(0, 99.99); + minPID->setSingleStep(0.000100); + maxPID->setSingleStep(0.000100); + minPID->setDecimals(6); + maxPID->setDecimals(6); + } +} + 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..212bc2880 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h @@ -40,6 +40,7 @@ private: Ui_TxPIDWidget *m_txpid; private slots: + void updateSpinBoxProperties(const QString & selected_pid_type); void refreshValues(); void applySettings(); void saveSettings(); From 0416c39cdb505f7cf00b768824a51a0d84bfaac9 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Thu, 17 Jul 2014 12:21:12 +0200 Subject: [PATCH 04/10] OP-1397 Limit the Attitude Responsiveness values to 180 degrees --- .../src/plugins/config/configtxpidwidget.cpp | 26 +++++++++++++++---- .../src/plugins/config/configtxpidwidget.h | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp index 4e58d2357..01930f17a 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp @@ -92,12 +92,22 @@ ConfigTxPIDWidget::~ConfigTxPIDWidget() // Do nothing } -void ConfigTxPIDWidget::updateSpinBoxProperties(const QString & selected_pid_type) +static bool isResponsivenessType(const QString & pidType) +{ + return pidType.endsWith(".Resp"); +} + +static bool isAttitudeType(const QString & pidType) +{ + return pidType.contains("Attitude"); +} + +void ConfigTxPIDWidget::updateSpinBoxProperties(const QString & selectedPidType) { QDoubleSpinBox *minPID; QDoubleSpinBox *maxPID; - qDebug() << "ConfigTxPIDWidget::updateSpinBoxProperties(" << selected_pid_type << ")"; + qDebug() << "ConfigTxPIDWidget::updateSpinBoxProperties(" << selectedPidType << ")"; QObject *obj = sender(); if (obj == m_txpid->PID1) { @@ -114,9 +124,15 @@ void ConfigTxPIDWidget::updateSpinBoxProperties(const QString & selected_pid_typ return; } - if (selected_pid_type.endsWith(".Resp")) { - minPID->setRange(0, 999); - maxPID->setRange(0, 999); + if (isResponsivenessType(selectedPidType)) { + if (isAttitudeType(selectedPidType)) { + // Limit to 180 degrees. + minPID->setRange(0, 180); + maxPID->setRange(0, 180); + } else { + minPID->setRange(0, 999); + maxPID->setRange(0, 999); + } minPID->setSingleStep(1); maxPID->setSingleStep(1); minPID->setDecimals(0); diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h index 212bc2880..ca4c61d55 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h @@ -40,7 +40,7 @@ private: Ui_TxPIDWidget *m_txpid; private slots: - void updateSpinBoxProperties(const QString & selected_pid_type); + void updateSpinBoxProperties(const QString & selectedPidType); void refreshValues(); void applySettings(); void saveSettings(); From 3e4737949ab0cd3f9df7f90a923bb1f8bbf8bb4e Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Mon, 21 Jul 2014 10:37:09 +0200 Subject: [PATCH 05/10] OP-1397 Make sure the Min/MaxPIDx widgit limits get set before the values are populated --- .../src/plugins/config/configtxpidwidget.cpp | 36 ++++++++++--------- .../src/plugins/config/configtxpidwidget.h | 2 +- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp index 01930f17a..d69f594a3 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp @@ -51,20 +51,21 @@ 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(activated(QString)), this, SLOT(updateSpinBoxProperties(const QString &))); - connect(m_txpid->PID2, SIGNAL(activated(QString)), this, SLOT(updateSpinBoxProperties(const QString &))); - connect(m_txpid->PID3, SIGNAL(activated(QString)), this, SLOT(updateSpinBoxProperties(const QString &))); + 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); - addWidgetBinding("TxPIDSettings", "PIDs", m_txpid->PID2, TxPIDSettings::PIDS_INSTANCE2); - addWidgetBinding("TxPIDSettings", "PIDs", m_txpid->PID3, TxPIDSettings::PIDS_INSTANCE3); - addWidgetBinding("TxPIDSettings", "Inputs", m_txpid->Input1, TxPIDSettings::INPUTS_INSTANCE1); addWidgetBinding("TxPIDSettings", "Inputs", m_txpid->Input2, TxPIDSettings::INPUTS_INSTANCE2); addWidgetBinding("TxPIDSettings", "Inputs", m_txpid->Input3, TxPIDSettings::INPUTS_INSTANCE3); + // It's important that the PIDx values are populated before the MinPIDx and MaxPIDx, + // otherwise the MinPIDx and MaxPIDx will be capped by the old spin box limits. The correct limits + // are set when updateSpinBoxProperties is called when the PIDx->currentTextChanged signal is sent. + // The binding order is reversed because the values are populated in reverse. + addWidgetBinding("TxPIDSettings", "MinPID", m_txpid->MinPID1, TxPIDSettings::MINPID_INSTANCE1); addWidgetBinding("TxPIDSettings", "MinPID", m_txpid->MinPID2, TxPIDSettings::MINPID_INSTANCE2); addWidgetBinding("TxPIDSettings", "MinPID", m_txpid->MinPID3, TxPIDSettings::MINPID_INSTANCE3); @@ -73,6 +74,10 @@ ConfigTxPIDWidget::ConfigTxPIDWidget(QWidget *parent) : ConfigTaskWidget(parent) addWidgetBinding("TxPIDSettings", "MaxPID", m_txpid->MaxPID2, TxPIDSettings::MAXPID_INSTANCE2); addWidgetBinding("TxPIDSettings", "MaxPID", m_txpid->MaxPID3, TxPIDSettings::MAXPID_INSTANCE3); + addWidgetBinding("TxPIDSettings", "PIDs", m_txpid->PID1, TxPIDSettings::PIDS_INSTANCE1); + addWidgetBinding("TxPIDSettings", "PIDs", m_txpid->PID2, TxPIDSettings::PIDS_INSTANCE2); + addWidgetBinding("TxPIDSettings", "PIDs", m_txpid->PID3, TxPIDSettings::PIDS_INSTANCE3); + addWidgetBinding("TxPIDSettings", "ThrottleRange", m_txpid->ThrottleMin, TxPIDSettings::THROTTLERANGE_MIN); addWidgetBinding("TxPIDSettings", "ThrottleRange", m_txpid->ThrottleMax, TxPIDSettings::THROTTLERANGE_MAX); @@ -92,24 +97,23 @@ ConfigTxPIDWidget::~ConfigTxPIDWidget() // Do nothing } -static bool isResponsivenessType(const QString & pidType) +static bool isResponsivenessOption(const QString & pidOption) { - return pidType.endsWith(".Resp"); + return pidOption.endsWith(".Resp"); } -static bool isAttitudeType(const QString & pidType) +static bool isAttitudeOption(const QString & pidOption) { - return pidType.contains("Attitude"); + return pidOption.contains("Attitude"); } -void ConfigTxPIDWidget::updateSpinBoxProperties(const QString & selectedPidType) +void ConfigTxPIDWidget::updateSpinBoxProperties(const QString & selectedPidOption) { QDoubleSpinBox *minPID; QDoubleSpinBox *maxPID; - qDebug() << "ConfigTxPIDWidget::updateSpinBoxProperties(" << selectedPidType << ")"; - QObject *obj = sender(); + if (obj == m_txpid->PID1) { minPID = m_txpid->MinPID1; maxPID = m_txpid->MaxPID1; @@ -124,8 +128,8 @@ void ConfigTxPIDWidget::updateSpinBoxProperties(const QString & selectedPidType) return; } - if (isResponsivenessType(selectedPidType)) { - if (isAttitudeType(selectedPidType)) { + if (isResponsivenessOption(selectedPidOption)) { + if (isAttitudeOption(selectedPidOption)) { // Limit to 180 degrees. minPID->setRange(0, 180); maxPID->setRange(0, 180); diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h index ca4c61d55..67c700867 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h @@ -40,7 +40,7 @@ private: Ui_TxPIDWidget *m_txpid; private slots: - void updateSpinBoxProperties(const QString & selectedPidType); + void updateSpinBoxProperties(const QString & selectedPidOption); void refreshValues(); void applySettings(); void saveSettings(); From 12589abe7e4994a9c80bc6490ad127530bd8d1d2 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Mon, 21 Jul 2014 15:38:28 +0200 Subject: [PATCH 06/10] OP-1397 Read default values for selected PID option from StabilizationSettingsBankX --- .../src/plugins/config/configtxpidwidget.cpp | 128 +++++++++++++++++- .../src/plugins/config/configtxpidwidget.h | 1 + 2 files changed, 124 insertions(+), 5 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp index d69f594a3..fce1984a2 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp @@ -28,6 +28,9 @@ #include "configtxpidwidget.h" #include "txpidsettings.h" #include "hwsettings.h" +#include "stabilizationsettingsbank1.h" +#include "stabilizationsettingsbank2.h" +#include "stabilizationsettingsbank3.h" #include #include @@ -107,20 +110,127 @@ static bool isAttitudeOption(const QString & pidOption) return pidOption.contains("Attitude"); } +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 Rate.Resp") { + return bank->getManualRate_Roll(); + } else if (pidOption == "Pitch Rate.Resp") { + return bank->getManualRate_Pitch(); + } else if (pidOption == "Roll+Pitch Rate.Resp") { + return bank->getManualRate_Roll(); + } else if (pidOption == "Yaw Rate.Resp") { + return bank->getManualRate_Yaw(); + } 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(); + } else if (pidOption == "Roll Attitude.Resp") { + return (float)bank->getRollMax(); + } else if (pidOption == "Pitch Attitude.Resp") { + return (float)bank->getPitchMax(); + } else if (pidOption == "Roll+Pitch Attitude.Resp") { + return (float)bank->getRollMax(); + } else if (pidOption == "Yaw Attitude.Resp") { + return bank->getYawMax(); + } + + qDebug() << "getDefaultValueForOption: Incorrect PID option" << pidOption; + return 0.0f; +} + +float ConfigTxPIDWidget::getDefaultValueForPidOption(const QString & pidOption) +{ + if (pidOption == "GyroTau") { + // TODO: Implement + return 0.0f; + } + + 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; - QObject *obj = sender(); - - if (obj == m_txpid->PID1) { + if (PIDx == m_txpid->PID1) { minPID = m_txpid->MinPID1; maxPID = m_txpid->MaxPID1; - } else if (obj == m_txpid->PID2) { + } else if (PIDx == m_txpid->PID2) { minPID = m_txpid->MinPID2; maxPID = m_txpid->MaxPID2; - } else if (obj == m_txpid->PID3) { + } else if (PIDx == m_txpid->PID3) { minPID = m_txpid->MinPID3; maxPID = m_txpid->MaxPID3; } else { @@ -128,6 +238,9 @@ void ConfigTxPIDWidget::updateSpinBoxProperties(const QString & selectedPidOptio return; } + // The ranges need to be setup before the values can be set, + // otherwise the value might be incorrectly capped. + if (isResponsivenessOption(selectedPidOption)) { if (isAttitudeOption(selectedPidOption)) { // Limit to 180 degrees. @@ -149,6 +262,11 @@ void ConfigTxPIDWidget::updateSpinBoxProperties(const QString & selectedPidOptio minPID->setDecimals(6); maxPID->setDecimals(6); } + + float value = getDefaultValueForPidOption(selectedPidOption); + + minPID->setValue(value); + maxPID->setValue(value); } void ConfigTxPIDWidget::refreshValues() diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h index 67c700867..34a50c413 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h @@ -41,6 +41,7 @@ private: private slots: void updateSpinBoxProperties(const QString & selectedPidOption); + float getDefaultValueForPidOption(const QString & pidOption); void refreshValues(); void applySettings(); void saveSettings(); From f9343d9959a2f9fd45068a5c2752a58ce6815db3 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 1 Aug 2014 09:41:13 +0200 Subject: [PATCH 07/10] OP-1397 Fetch default values for GyroTau --- ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp index fce1984a2..ad8db8cd9 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp @@ -28,6 +28,7 @@ #include "configtxpidwidget.h" #include "txpidsettings.h" #include "hwsettings.h" +#include "stabilizationsettings.h" #include "stabilizationsettingsbank1.h" #include "stabilizationsettingsbank2.h" #include "stabilizationsettingsbank3.h" @@ -196,8 +197,8 @@ static float defaultValueForPidOption(const StabilizationSettingsBankX & bank, c float ConfigTxPIDWidget::getDefaultValueForPidOption(const QString & pidOption) { if (pidOption == "GyroTau") { - // TODO: Implement - return 0.0f; + StabilizationSettings *stab = qobject_cast(getObject(QString("StabilizationSettings"))); + return stab->getGyroTau(); } uint bankNumber = m_txpid->pidBank->currentIndex() + 1; From 04d9d3191dab5ea562868c3779849738be4212b0 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 1 Aug 2014 10:50:52 +0200 Subject: [PATCH 08/10] OP-1397 Fix StabilizationSettingsBankX type for defaultValueForPidOption --- ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp index ad8db8cd9..9672bac11 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp @@ -112,7 +112,7 @@ static bool isAttitudeOption(const QString & pidOption) } template -static float defaultValueForPidOption(const StabilizationSettingsBankX & bank, const QString & pidOption) +static float defaultValueForPidOption(const StabilizationSettingsBankX *bank, const QString & pidOption) { if (pidOption == "Disabled") { return 0.0f; From 7f344da9778ae6b615e45dd846dadaca6f6b3690 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 1 Aug 2014 14:51:39 +0200 Subject: [PATCH 09/10] OP-1397 Round to instead of floor to uint8_t values in txpid.c --- flight/modules/TxPID/txpid.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/flight/modules/TxPID/txpid.c b/flight/modules/TxPID/txpid.c index c49ed49d7..f356558e8 100644 --- a/flight/modules/TxPID/txpid.c +++ b/flight/modules/TxPID/txpid.c @@ -83,7 +83,7 @@ // Private functions static void updatePIDs(UAVObjEvent *ev); static uint8_t update(float *var, float val); -static uint8_t updateResponsiveness(uint8_t *var, float val); +static uint8_t updateUint8(uint8_t *var, float val); static float scale(float val, float inMin, float inMax, float outMin, float outMax); /** @@ -240,7 +240,7 @@ static void updatePIDs(UAVObjEvent *ev) needsUpdateBank |= update(&bank.RollPI.ILimit, value); break; case TXPIDSETTINGS_PIDS_ROLLATTITUDERESP: - needsUpdateBank |= updateResponsiveness(&bank.RollMax, value); + needsUpdateBank |= updateUint8(&bank.RollMax, value); break; case TXPIDSETTINGS_PIDS_PITCHRATEKP: needsUpdateBank |= update(&bank.PitchRatePID.Kp, value); @@ -267,7 +267,7 @@ static void updatePIDs(UAVObjEvent *ev) needsUpdateBank |= update(&bank.PitchPI.ILimit, value); break; case TXPIDSETTINGS_PIDS_PITCHATTITUDERESP: - needsUpdateBank |= updateResponsiveness(&bank.PitchMax, value); + needsUpdateBank |= updateUint8(&bank.PitchMax, value); break; case TXPIDSETTINGS_PIDS_ROLLPITCHRATEKP: needsUpdateBank |= update(&bank.RollRatePID.Kp, value); @@ -302,8 +302,8 @@ static void updatePIDs(UAVObjEvent *ev) needsUpdateBank |= update(&bank.PitchPI.ILimit, value); break; case TXPIDSETTINGS_PIDS_ROLLPITCHATTITUDERESP: - needsUpdateBank |= updateResponsiveness(&bank.RollMax, value); - needsUpdateBank |= updateResponsiveness(&bank.PitchMax, value); + needsUpdateBank |= updateUint8(&bank.RollMax, value); + needsUpdateBank |= updateUint8(&bank.PitchMax, value); break; case TXPIDSETTINGS_PIDS_YAWRATEKP: needsUpdateBank |= update(&bank.YawRatePID.Kp, value); @@ -330,7 +330,7 @@ static void updatePIDs(UAVObjEvent *ev) needsUpdateBank |= update(&bank.YawPI.ILimit, value); break; case TXPIDSETTINGS_PIDS_YAWATTITUDERESP: - needsUpdateBank |= updateResponsiveness(&bank.YawMax, value); + needsUpdateBank |= updateUint8(&bank.YawMax, value); break; case TXPIDSETTINGS_PIDS_GYROTAU: needsUpdateStab |= update(&stab.GyroTau, value); @@ -420,10 +420,9 @@ static uint8_t update(float *var, float val) * Updates var using val if needed. * \returns 1 if updated, 0 otherwise */ -static uint8_t updateResponsiveness(uint8_t *var, float val) +static uint8_t updateUint8(uint8_t *var, float val) { - // Just floor it for now. - uint8_t roundedVal = (uint8_t)val; + uint8_t roundedVal = (uint8_t)roundf(val); if (*var != roundedVal) { *var = roundedVal; From f569a9d8cbb53e72b3ad4f450ebc20f1aa9637ff Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Sun, 10 Aug 2014 20:19:29 +0200 Subject: [PATCH 10/10] OP-1397 Filter out unnecessary debug messages and use asserts instead. --- .../src/plugins/config/configtxpidwidget.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp index af3112385..0f0e7fa87 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp @@ -260,8 +260,11 @@ static float defaultValueForPidOption(const StabilizationSettingsBankX *bank, in case TxPIDSettings::PIDS_YAWATTITUDERESP: return bank->getYawMax(); + case -1: // The PID Option field was uninitialized. + return 0.0f; + default: - qDebug() << "getDefaultValueForOption: Incorrect PID option" << pidOption; + Q_ASSERT_X(false, "getDefaultValueForOption", "Incorrect PID option"); return 0.0f; } } @@ -273,7 +276,14 @@ float ConfigTxPIDWidget::getDefaultValueForPidOption(int pidOption) return stab->getGyroTau(); } - uint bankNumber = m_txpid->pidBank->currentIndex() + 1; + int pidBankIndex = m_txpid->pidBank->currentIndex(); + + if (pidBankIndex == -1) { + // The pidBank field was uninitilized. + return 0.0f; + } + + int bankNumber = pidBankIndex + 1; if (bankNumber == 1) { StabilizationSettingsBank1 *bank = qobject_cast(getObject(QString("StabilizationSettingsBank1"))); @@ -285,7 +295,7 @@ float ConfigTxPIDWidget::getDefaultValueForPidOption(int pidOption) StabilizationSettingsBank3 *bank = qobject_cast(getObject(QString("StabilizationSettingsBank3"))); return defaultValueForPidOption(bank, pidOption); } else { - qDebug() << "getDefaultValueForPidOption: Incorrect bank number:" << bankNumber; + Q_ASSERT_X(false, "getDefaultValueForPidOption", "Incorrect bank number"); return 0.0f; } } @@ -307,7 +317,7 @@ void ConfigTxPIDWidget::updateSpinBoxProperties(int selectedPidOption) minPID = m_txpid->MinPID3; maxPID = m_txpid->MaxPID3; } else { - qDebug() << "updateSpinBoxProperties: Incorrect sender object"; + Q_ASSERT_X(false, "updateSpinBoxProperties", "Incorrect sender object"); return; }