1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

OP-1474 Moved TPS settings to PID banks. Rearranged GUI.

This commit is contained in:
m_thread 2014-09-20 17:30:19 +02:00
parent 226fe186c4
commit e4d6171f2c
3 changed files with 62 additions and 33 deletions

View File

@ -125,6 +125,9 @@ ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTa
connect(ui->advancedResponsivenessCheckBox, SIGNAL(toggled(bool)), this, SLOT(linkCheckBoxes(bool)));
connect(ui->defaultThrottleCurveButton, SIGNAL(clicked()), this, SLOT(resetThrottleCurveToDefault()));
connect(ui->enableThrustPIDScalingCheckBox, SIGNAL(toggled(bool)), ui->ThrustPIDSource, SLOT(setEnabled(bool)));
connect(ui->enableThrustPIDScalingCheckBox, SIGNAL(toggled(bool)), ui->ThrustPIDTarget, SLOT(setEnabled(bool)));
connect(ui->enableThrustPIDScalingCheckBox, SIGNAL(toggled(bool)), ui->ThrustPIDAxis, SLOT(setEnabled(bool)));
connect(ui->enableThrustPIDScalingCheckBox, SIGNAL(toggled(bool)), ui->thrustPIDScalingCurve, SLOT(setEnabled(bool)));
ui->thrustPIDScalingCurve->setMixerType(MixerCurve::MIXERCURVE_TPA);
ui->thrustPIDScalingCurve->setMin(-1);
@ -134,7 +137,6 @@ ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTa
addWidget(ui->enableThrustPIDScalingCheckBox);
addWidget(ui->thrustPIDScalingCurve);
addWidget(ui->thrustPIDScalingCurve->getCurveWidget());
connect(this, SIGNAL(widgetContentsChanged(QWidget *)), this, SLOT(processLinkedWidgets(QWidget *)));
connect(this, SIGNAL(autoPilotConnected()), this, SLOT(onBoardConnected()));
@ -166,45 +168,73 @@ void ConfigStabilizationWidget::updateObjectsFromWidgets()
void ConfigStabilizationWidget::updateThrottleCurveFromObject()
{
StabilizationSettings *stabSettings = dynamic_cast<StabilizationSettings *>(getObjectManager()->getObject(QString("StabilizationSettings")));
UAVObject *stabBank = getObjectManager()->getObject(QString(m_pidTabBars.at(0)->tabData(m_currentPIDBank).toString()));
Q_ASSERT(stabBank);
qDebug() << "updatingCurveFromObject" << stabBank->getName();
Q_ASSERT(stabSettings);
UAVObjectField *field = stabBank->getField("ThrustPIDScaleCurve");
Q_ASSERT(field);
QList<double> curve;
for (quint32 i = 0; i < StabilizationSettings::THRUSTPIDSCALECURVE_NUMELEM; i++) {
curve.append(stabSettings->getThrustPIDScaleCurve(i));
for (quint32 i = 0; i < field->getNumElements(); i++) {
qDebug() << field->getName() << field->getElementNames().at(i) << "=>" << field->getValue(i);
curve.append(field->getValue(i).toDouble());
}
ui->thrustPIDScalingCurve->setCurve(&curve);
ui->enableThrustPIDScalingCheckBox->setChecked(stabSettings->getEnableThrustPIDScaling() == StabilizationSettings::ENABLETHRUSTPIDSCALING_TRUE);
ui->thrustPIDScalingCurve->setEnabled(stabSettings->getEnableThrustPIDScaling() == StabilizationSettings::ENABLETHRUSTPIDSCALING_TRUE);
field = stabBank->getField("EnableThrustPIDScaling");
Q_ASSERT(field);
bool enabled = field->getValue() == "TRUE";
ui->enableThrustPIDScalingCheckBox->setChecked(enabled);
ui->thrustPIDScalingCurve->setEnabled(enabled);
}
void ConfigStabilizationWidget::updateObjectFromThrottleCurve()
{
StabilizationSettings *stabSettings = dynamic_cast<StabilizationSettings *>(getObjectManager()->getObject(QString("StabilizationSettings")));
UAVObject *stabBank = getObjectManager()->getObject(QString(m_pidTabBars.at(0)->tabData(m_currentPIDBank).toString()));
Q_ASSERT(stabBank);
qDebug() << "updatingObjectFromCurve" << stabBank->getName();
Q_ASSERT(stabSettings);
UAVObjectField *field = stabBank->getField("ThrustPIDScaleCurve");
Q_ASSERT(field);
QList<double> curve = ui->thrustPIDScalingCurve->getCurve();
for (quint32 i = 0; i < StabilizationSettings::THRUSTPIDSCALECURVE_NUMELEM; i++) {
stabSettings->setThrustPIDScaleCurve(i, curve.at(i));
for (quint32 i = 0; i < field->getNumElements(); i++) {
field->setValue(curve.at(i), i);
qDebug() << field->getName() << field->getElementNames().at(i) << "<=" << curve.at(i);
}
stabSettings->setEnableThrustPIDScaling(ui->enableThrustPIDScalingCheckBox->isChecked() ?
StabilizationSettings::ENABLETHRUSTPIDSCALING_TRUE : StabilizationSettings::ENABLETHRUSTPIDSCALING_FALSE);
field = stabBank->getField("EnableThrustPIDScaling");
Q_ASSERT(field);
field->setValue(ui->enableThrustPIDScalingCheckBox->isChecked() ? "TRUE" : "FALSE");
}
void ConfigStabilizationWidget::resetThrottleCurveToDefault()
{
StabilizationSettings defaultSettings;
UAVDataObject *defaultStabBank = (UAVDataObject*)getObjectManager()->getObject(QString(m_pidTabBars.at(0)->tabData(m_currentPIDBank).toString()));
Q_ASSERT(defaultStabBank);
defaultStabBank = defaultStabBank->dirtyClone();
UAVObjectField *field = defaultStabBank->getField("ThrustPIDScaleCurve");
Q_ASSERT(field);
QList<double> curve;
for (quint32 i = 0; i < StabilizationSettings::THRUSTPIDSCALECURVE_NUMELEM; i++) {
curve.append(defaultSettings.getThrustPIDScaleCurve(i));
for (quint32 i = 0; i < field->getNumElements(); i++) {
curve.append(field->getValue(i).toDouble());
}
ui->thrustPIDScalingCurve->setCurve(&curve);
field = defaultStabBank->getField("EnableThrustPIDScaling");
Q_ASSERT(field);
bool enabled = field->getValue() == "TRUE";
ui->enableThrustPIDScalingCheckBox->setChecked(enabled);
ui->thrustPIDScalingCurve->setEnabled(enabled);
delete defaultStabBank;
}
void ConfigStabilizationWidget::realtimeUpdatesSlot(bool value)
@ -300,6 +330,7 @@ void ConfigStabilizationWidget::onBoardConnected()
void ConfigStabilizationWidget::pidBankChanged(int index)
{
updateObjectFromThrottleCurve();
foreach(QTabBar * tabBar, m_pidTabBars) {
disconnect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(pidBankChanged(int)));
tabBar->setCurrentIndex(index);
@ -313,6 +344,8 @@ void ConfigStabilizationWidget::pidBankChanged(int index)
setWidgetBindingObjectEnabled(m_pidTabBars.at(0)->tabData(index).toString(), true);
m_currentPIDBank = index;
qDebug() << "current bank:" << m_currentPIDBank;
updateThrottleCurveFromObject();
}
bool ConfigStabilizationWidget::shouldObjectBeSaved(UAVObject *object)

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>839</width>
<height>785</height>
<width>882</width>
<height>789</height>
</rect>
</property>
<property name="sizePolicy">
@ -136,8 +136,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>801</width>
<height>726</height>
<width>860</width>
<height>703</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
@ -7836,8 +7836,8 @@ border-radius: 5;</string>
<property name="geometry">
<rect>
<x>0</x>
<y>-299</y>
<width>801</width>
<y>0</y>
<width>844</width>
<height>998</height>
</rect>
</property>
@ -16207,7 +16207,7 @@ border-radius: 5;</string>
</property>
</widget>
</item>
<item row="0" column="3" rowspan="3">
<item row="0" column="3" rowspan="3" alignment="Qt::AlignTop">
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
@ -16836,7 +16836,7 @@ border-radius: 5;</string>
</item>
<item>
<widget class="QComboBox" name="ThrustPIDSource">
<property name="Objrelation" stdset="0">
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:StabilizationSettingsBankX</string>
<string>fieldname:ThrustPIDScaleSource</string>
@ -17961,7 +17961,7 @@ border-radius: 5;</string>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:StabilizationSettingsBankX</string>
<string>fieldname:ThrustPIDScaleAxis</string>
<string>fieldname:ThrustPIDScaleAxes</string>
<string>buttongroup:99</string>
</stringlist>
</property>
@ -18103,8 +18103,8 @@ border-radius: 5;</string>
<rect>
<x>0</x>
<y>0</y>
<width>817</width>
<height>699</height>
<width>860</width>
<height>703</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8" stretch="0,0,0,0,0,0">
@ -24046,8 +24046,8 @@ font:bold;</string>
<rect>
<x>0</x>
<y>0</y>
<width>817</width>
<height>699</height>
<width>860</width>
<height>703</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_18">

View File

@ -47,10 +47,6 @@
<field name="ScaleToAirspeed" units="m/s" type="float" elements="1" defaultvalue="0"/>
<field name="ScaleToAirspeedLimits" units="" type="float" elementnames="Min,Max" defaultvalue="0.05,3"/>
<field name="EnableThrustPIDScaling" units="" type="enum" elements="1" options="FALSE,TRUE" defaultvalue="FALSE"/>
<field name="ThrustPIDScaleCurve" units="percent" type="float" elementnames="0,25,50,75,100" defaultvalue="0.3,0.15,0,-0.15,-0.3"/>
<field name="ThrustPIDScaleSource" units="" type="enum" elements="1" options="ManualControlThrottle,StabilizationDesiredThrust,ActuatorDesiredThrust" defaultvalue="ActuatorDesiredThrust" />
<access gcs="readwrite" flight="readwrite"/>
<telemetrygcs acked="true" updatemode="onchange" period="0"/>
<telemetryflight acked="true" updatemode="onchange" period="0"/>