mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-15 07:29:15 +01:00
OP-1397 Read default values for selected PID option from StabilizationSettingsBankX
This commit is contained in:
parent
3e4737949a
commit
12589abe7e
@ -28,6 +28,9 @@
|
||||
#include "configtxpidwidget.h"
|
||||
#include "txpidsettings.h"
|
||||
#include "hwsettings.h"
|
||||
#include "stabilizationsettingsbank1.h"
|
||||
#include "stabilizationsettingsbank2.h"
|
||||
#include "stabilizationsettingsbank3.h"
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <coreplugin/generalsettings.h>
|
||||
|
||||
@ -107,20 +110,127 @@ static bool isAttitudeOption(const QString & pidOption)
|
||||
return pidOption.contains("Attitude");
|
||||
}
|
||||
|
||||
template <class StabilizationSettingsBankX>
|
||||
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<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(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()
|
||||
|
@ -41,6 +41,7 @@ private:
|
||||
|
||||
private slots:
|
||||
void updateSpinBoxProperties(const QString & selectedPidOption);
|
||||
float getDefaultValueForPidOption(const QString & pidOption);
|
||||
void refreshValues();
|
||||
void applySettings();
|
||||
void saveSettings();
|
||||
|
Loading…
x
Reference in New Issue
Block a user