mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
Make the autotune UI allow recomputing the values based on the measured system
properties.
This commit is contained in:
parent
2ccd6605a4
commit
c3df203d7c
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>443</width>
|
||||
<height>560</height>
|
||||
<height>575</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -26,68 +26,52 @@
|
||||
<string>Tuning Aggressiveness</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="1" column="0">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Rate Tuning:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSlider" name="rateTuning">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="objrelation" stdset="0">
|
||||
<stringlist>
|
||||
<string>obj1name:RelayTuningSettings</string>
|
||||
<string>fieldname:RateGain</string>
|
||||
<string>scale:0.01</string>
|
||||
<string>haslimits:yes</string>
|
||||
</stringlist>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Attitude Tuning:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSlider" name="attitudeTuning">
|
||||
<item row="0" column="1">
|
||||
<widget class="QSlider" name="rateTuning">
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="objrelation" stdset="0">
|
||||
<stringlist>
|
||||
<string>obj1name:RelayTuningSettings</string>
|
||||
<string>fieldname:AttitudeGain</string>
|
||||
<string>elemescale:0.01</string>
|
||||
<string>haslimits:yes</string>
|
||||
<string>objname:RelayTuningSettings</string>
|
||||
<string>fieldname:RateGain</string>
|
||||
<string>scale:0.01</string>
|
||||
<string>haslimits:no</string>
|
||||
</stringlist>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_21">
|
||||
<property name="text">
|
||||
<string>StepSize</string>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSlider" name="attitudeTuning">
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSlider" name="stepSizeSlider">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="objrelation" stdset="0">
|
||||
<stringlist>
|
||||
<string>obj1name:RelatyTuningSettings</string>
|
||||
<string>fieldname:Amplitude</string>
|
||||
<string>objname:RelayTuningSettings</string>
|
||||
<string>fieldname:AttitudeGain</string>
|
||||
<string>scale:0.01</string>
|
||||
<string>haslimits:yes</string>
|
||||
<string>haslimits:no</string>
|
||||
</stringlist>
|
||||
</property>
|
||||
</widget>
|
||||
@ -232,13 +216,33 @@
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="objrelation" stdset="0">
|
||||
<stringlist>
|
||||
<string>objname:RelayTuning</string>
|
||||
<string>fieldname:Period</string>
|
||||
<string>element:Roll</string>
|
||||
</stringlist>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="measuredRollAmplitude">
|
||||
<widget class="QLabel" name="measuredRollGain">
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="objrelation" stdset="0">
|
||||
<stringlist>
|
||||
<string>objname:RelayTuning</string>
|
||||
<string>fieldname:Gain</string>
|
||||
<string>element:Roll</string>
|
||||
</stringlist>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
@ -251,7 +255,7 @@
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Amplitude (deg/s)</string>
|
||||
<string>Gain (deg/s) / output</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -267,13 +271,33 @@
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="objrelation" stdset="0">
|
||||
<stringlist>
|
||||
<string>objname:RelayTuning</string>
|
||||
<string>fieldname:Period</string>
|
||||
<string>element:Pitch</string>
|
||||
</stringlist>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="measuredPitchPeriod_2">
|
||||
<widget class="QLabel" name="measuredPitchGain">
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="objrelation" stdset="0">
|
||||
<stringlist>
|
||||
<string>objname:RelayTuning</string>
|
||||
<string>fieldname:Gain</string>
|
||||
<string>element:Pitch</string>
|
||||
</stringlist>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@ -989,14 +1013,69 @@ will alter thingsfor the next autotuning flight</string>
|
||||
<widget class="QPushButton" name="useComputedValues">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>270</x>
|
||||
<x>250</x>
|
||||
<y>380</y>
|
||||
<width>161</width>
|
||||
<height>24</height>
|
||||
<width>171</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QPushButton {
|
||||
border: 1px outset #999;
|
||||
border-radius: 5;
|
||||
background-color: qlineargradient(spread:pad, x1:0.507, y1:0.869318, x2:0.507, y2:0.0965909, stop:0.28 rgba(236, 236, 236, 255), stop:1 rgba(252, 252, 252, 255));
|
||||
}
|
||||
|
||||
QPushButton:pressed {
|
||||
|
||||
border-style: inset;
|
||||
background-color: qlineargradient(spread:pad, x1:0.502, y1:0.664864, x2:0.502, y2:0.034, stop:0.358209 rgba(250, 250, 250, 255), stop:0.626866 rgba(235, 235, 235, 255));
|
||||
|
||||
}
|
||||
|
||||
|
||||
QPushButton:hover {
|
||||
border: 1px outset #999;
|
||||
border-color: rgb(83, 83, 83);
|
||||
border-radius: 4;
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Apply Computed Values</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_21">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>40</x>
|
||||
<y>410</y>
|
||||
<width>104</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Use Computed Values</string>
|
||||
<string>Step Size</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QSlider" name="stepSizeSlider">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>149</x>
|
||||
<y>410</y>
|
||||
<width>266</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="objrelation" stdset="0">
|
||||
<stringlist>
|
||||
<string>objname:RelayTuningSettings</string>
|
||||
<string>fieldname:Amplitude</string>
|
||||
<string>scale:0.01</string>
|
||||
<string>haslimits:no</string>
|
||||
</stringlist>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
|
@ -10,6 +10,9 @@
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
#include <QList>
|
||||
#include "relaytuningsettings.h"
|
||||
#include "relaytuning.h"
|
||||
#include "stabilizationsettings.h"
|
||||
|
||||
ConfigAutotuneWidget::ConfigAutotuneWidget(QWidget *parent) :
|
||||
ConfigTaskWidget(parent)
|
||||
@ -17,9 +20,117 @@ ConfigAutotuneWidget::ConfigAutotuneWidget(QWidget *parent) :
|
||||
m_autotune = new Ui_AutotuneWidget();
|
||||
m_autotune->setupUi(this);
|
||||
|
||||
// Connect automatic signals
|
||||
autoLoadWidgets();
|
||||
|
||||
disableMouseWheelEvents();
|
||||
|
||||
// Whenever any value changes compute new potential stabilization settings
|
||||
connect(m_autotune->rateTuning, SIGNAL(valueChanged(int)), this, SLOT(recomputeStabilization()));
|
||||
connect(m_autotune->attitudeTuning, SIGNAL(valueChanged(int)), this, SLOT(recomputeStabilization()));
|
||||
|
||||
RelayTuning *relayTuning = RelayTuning::GetInstance(getObjectManager());
|
||||
Q_ASSERT(relayTuning);
|
||||
if(relayTuning)
|
||||
connect(relayTuning, SIGNAL(updateRequested(UAVObject*)), this, SLOT(recomputeStabilization()));
|
||||
|
||||
// Connect the apply button for the stabilization settings
|
||||
connect(m_autotune->useComputedValues, SIGNAL(pressed()), this, SLOT(saveStabilization()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the stabilization settings computed
|
||||
*/
|
||||
void ConfigAutotuneWidget::saveStabilization()
|
||||
{
|
||||
StabilizationSettings *stabilizationSettings = StabilizationSettings::GetInstance(getObjectManager());
|
||||
Q_ASSERT(stabilizationSettings);
|
||||
if(!stabilizationSettings)
|
||||
return;
|
||||
|
||||
// Make sure to recompute in case the other stab settings changed since
|
||||
// the last time
|
||||
recomputeStabilization();
|
||||
|
||||
// Apply this data to the board
|
||||
stabilizationSettings->setData(stabSettings);
|
||||
stabilizationSettings->updated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever the gain ratios or measured values
|
||||
* are changed
|
||||
*/
|
||||
void ConfigAutotuneWidget::recomputeStabilization()
|
||||
{
|
||||
RelayTuningSettings *relayTuningSettings = RelayTuningSettings::GetInstance(getObjectManager());
|
||||
Q_ASSERT(relayTuningSettings);
|
||||
if (!relayTuningSettings)
|
||||
return;
|
||||
|
||||
RelayTuning *relayTuning = RelayTuning::GetInstance(getObjectManager());
|
||||
Q_ASSERT(relayTuning);
|
||||
if(!relayTuning)
|
||||
return;
|
||||
|
||||
StabilizationSettings *stabilizationSettings = StabilizationSettings::GetInstance(getObjectManager());
|
||||
Q_ASSERT(stabilizationSettings);
|
||||
if(!stabilizationSettings)
|
||||
return;
|
||||
|
||||
RelayTuning::DataFields relayTuningData = relayTuning->getData();
|
||||
RelayTuningSettings::DataFields tuningSettingsData = relayTuningSettings->getData();
|
||||
stabSettings = stabilizationSettings->getData();
|
||||
|
||||
// Need to divide these by 100 because that is what the .ui file does
|
||||
// to get the UAVO
|
||||
const double gain_ratio_r = m_autotune->rateTuning->value() / 100.0;
|
||||
const double zero_ratio_r = m_autotune->rateTuning->value() / 100.0;
|
||||
const double gain_ratio_p = m_autotune->attitudeTuning->value() / 100.0;
|
||||
const double zero_ratio_p = m_autotune->attitudeTuning->value() / 100.0;
|
||||
|
||||
// For now just run over roll and pitch
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (relayTuningData.Period[i] == 0 || relayTuningData.Gain[i] == 0)
|
||||
continue;
|
||||
|
||||
double wu = 1000.0 * 2 * M_PI / relayTuningData.Period[i]; // ultimate freq = output osc freq (rad/s)
|
||||
|
||||
double wc = wu * gain_ratio_r; // target openloop crossover frequency (rad/s)
|
||||
double zc = wc * zero_ratio_r; // controller zero location (rad/s)
|
||||
double kpu = 4.0f / M_PI / relayTuningData.Gain[i]; // ultimate gain, i.e. the proportional gain for instablity
|
||||
double kp = kpu * gain_ratio_r; // proportional gain
|
||||
double ki = zc * kp; // integral gain
|
||||
|
||||
// Now calculate gains for the next loop out knowing it is the integral of
|
||||
// the inner loop -- the plant is position/velocity = scale*1/s
|
||||
double wc2 = wc * gain_ratio_p; // crossover of the attitude loop
|
||||
double kp2 = wc2; // kp of attitude
|
||||
double ki2 = wc2 * zero_ratio_p * kp2; // ki of attitude
|
||||
|
||||
switch(i) {
|
||||
case 0: // Roll
|
||||
|
||||
stabSettings.RollRatePID[StabilizationSettings::ROLLRATEPID_KP] = kp;
|
||||
stabSettings.RollRatePID[StabilizationSettings::ROLLRATEPID_KI] = ki;
|
||||
stabSettings.RollPI[StabilizationSettings::ROLLPI_KP] = kp2;
|
||||
stabSettings.RollPI[StabilizationSettings::ROLLPI_KI] = ki2;
|
||||
break;
|
||||
case 1: // Pitch
|
||||
stabSettings.PitchRatePID[StabilizationSettings::PITCHRATEPID_KP] = kp;
|
||||
stabSettings.PitchRatePID[StabilizationSettings::PITCHRATEPID_KI] = ki;
|
||||
stabSettings.PitchPI[StabilizationSettings::PITCHPI_KP] = kp2;
|
||||
stabSettings.PitchPI[StabilizationSettings::PITCHPI_KI] = ki2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Display these computed settings
|
||||
m_autotune->rollRateKp->setText(QString().number(stabSettings.RollRatePID[StabilizationSettings::ROLLRATEPID_KP]));
|
||||
m_autotune->rollRateKi->setText(QString().number(stabSettings.RollRatePID[StabilizationSettings::ROLLRATEPID_KI]));
|
||||
m_autotune->rollAttitudeKp->setText(QString().number(stabSettings.RollPI[StabilizationSettings::ROLLPI_KP]));
|
||||
m_autotune->rollAttitudeKi->setText(QString().number(stabSettings.RollPI[StabilizationSettings::ROLLPI_KI]));
|
||||
m_autotune->pitchRateKp->setText(QString().number(stabSettings.PitchRatePID[StabilizationSettings::PITCHRATEPID_KP]));
|
||||
m_autotune->pitchRateKi->setText(QString().number(stabSettings.PitchRatePID[StabilizationSettings::PITCHRATEPID_KI]));
|
||||
m_autotune->pitchAttitudeKp->setText(QString().number(stabSettings.PitchPI[StabilizationSettings::PITCHPI_KP]));
|
||||
m_autotune->pitchAttitudeKi->setText(QString().number(stabSettings.PitchPI[StabilizationSettings::PITCHPI_KI]));
|
||||
}
|
||||
|
@ -46,10 +46,15 @@ public:
|
||||
|
||||
private:
|
||||
Ui_AutotuneWidget *m_autotune;
|
||||
StabilizationSettings::DataFields stabSettings;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
void recomputeStabilization();
|
||||
void saveStabilization();
|
||||
};
|
||||
|
||||
#endif // CONFIGAUTOTUNE_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user