1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-27 16:54:15 +01:00

Improvements to the ccpm curve mixing UI

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2035 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
andrew 2010-10-30 05:15:39 +00:00 committed by andrew
parent dbe20a7eab
commit c7b6341b21
3 changed files with 274 additions and 177 deletions

View File

@ -873,68 +873,82 @@
<widget class="QWidget" name="layoutWidget"> <widget class="QWidget" name="layoutWidget">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>22</x> <x>10</x>
<y>11</y> <y>10</y>
<width>661</width> <width>670</width>
<height>501</height> <height>390</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item row="0" column="0"> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QComboBox" name="CurveType"> <layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="toolTip">
<string>Select aircraft type here</string>
</property>
<item> <item>
<property name="text"> <widget class="QComboBox" name="CurveType">
<string>Linear</string> <property name="font">
</property> <font>
</item> <pointsize>10</pointsize>
<item> </font>
<property name="text">
<string>Flat</string>
</property>
</item>
<item>
<property name="text">
<string>Step</string>
</property>
</item>
<item>
<property name="text">
<string>Custom</string>
</property>
</item>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Number of points</string>
</property> </property>
<property name="toolTip">
<string>Select aircraft type here</string>
</property>
<item>
<property name="text">
<string>Linear</string>
</property>
</item>
<item>
<property name="text">
<string>Flat</string>
</property>
</item>
<item>
<property name="text">
<string>Step</string>
</property>
</item>
<item>
<property name="text">
<string>Exp</string>
</property>
</item>
<item>
<property name="text">
<string>Log</string>
</property>
</item>
<item>
<property name="text">
<string>Custom</string>
</property>
</item>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item>
<widget class="QSpinBox" name="NumCurvePoints"> <layout class="QGridLayout" name="gridLayout_4">
<property name="minimum"> <item row="0" column="1">
<number>2</number> <widget class="QSpinBox" name="NumCurvePoints">
</property> <property name="minimum">
<property name="maximum"> <number>2</number>
<number>10</number> </property>
</property> <property name="maximum">
<property name="value"> <number>10</number>
<number>5</number> </property>
</property> <property name="value">
</widget> <number>5</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Number of points</string>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </item>
@ -1037,101 +1051,9 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="0" column="1" rowspan="2"> <item>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_21">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_18">
<item>
<widget class="QLabel" name="label_41">
<property name="text">
<string>Blade Pitch Curve</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="MixerCurveWidget" name="widget_2" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>150</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="customThrottleCurve2Value">
<property name="text">
<string>Val: 0.00</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_20">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_17">
<item>
<widget class="QLabel" name="label_39">
<property name="text">
<string>Throttle Curve</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="MixerCurveWidget" name="widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>150</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="customThrottleCurve1Value">
<property name="text">
<string>Val: 0.00</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item row="1" column="0">
<layout class="QFormLayout" name="formLayout_5">
<item row="0" column="0">
<widget class="QTableWidget" name="CurveSettings"> <widget class="QTableWidget" name="CurveSettings">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
@ -1402,31 +1324,93 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item>
<spacer name="horizontalSpacer"> <layout class="QVBoxLayout" name="verticalLayout_20">
<property name="orientation"> <item>
<enum>Qt::Horizontal</enum> <layout class="QHBoxLayout" name="horizontalLayout_17">
</property> <item>
<property name="sizeHint" stdset="0"> <widget class="QLabel" name="label_39">
<size> <property name="text">
<width>40</width> <string>Throttle Curve</string>
<height>10</height> </property>
</size> </widget>
</property> </item>
</spacer> </layout>
</item>
<item>
<widget class="MixerCurveWidget" name="ThrottleCurve" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>150</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="customThrottleCurve1Value">
<property name="text">
<string>Val: 0.00</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item row="1" column="0"> <item>
<spacer name="verticalSpacer"> <layout class="QVBoxLayout" name="verticalLayout_21">
<property name="orientation"> <item>
<enum>Qt::Vertical</enum> <layout class="QHBoxLayout" name="horizontalLayout_18">
</property> <item>
<property name="sizeHint" stdset="0"> <widget class="QLabel" name="label_41">
<size> <property name="text">
<width>20</width> <string>Blade Pitch Curve</string>
<height>10</height> </property>
</size> </widget>
</property> </item>
</spacer> </layout>
</item>
<item>
<widget class="MixerCurveWidget" name="PitchCurve" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>150</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="customThrottleCurve2Value">
<property name="text">
<string>Val: 0.00</string>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </item>

View File

@ -109,6 +109,10 @@ ConfigccpmWidget::ConfigccpmWidget(QWidget *parent) : ConfigTaskWidget(parent)
m_ccpm->SwashplateImage->scene()->addItem(ServoZText); m_ccpm->SwashplateImage->scene()->addItem(ServoZText);
resetMixer(m_ccpm->PitchCurve, 5);
resetMixer(m_ccpm->ThrottleCurve, 5);
@ -145,6 +149,7 @@ ConfigccpmWidget::ConfigccpmWidget(QWidget *parent) : ConfigTaskWidget(parent)
//connect(m_ccpm->getccpmCurrent, SIGNAL(clicked()), this, SLOT(requestccpmUpdate())); //connect(m_ccpm->getccpmCurrent, SIGNAL(clicked()), this, SLOT(requestccpmUpdate()));
connect(m_ccpm->ccpmGenerateCurve, SIGNAL(clicked()), this, SLOT(GenerateCurve())); connect(m_ccpm->ccpmGenerateCurve, SIGNAL(clicked()), this, SLOT(GenerateCurve()));
connect(m_ccpm->NumCurvePoints, SIGNAL(valueChanged(int)), this, SLOT(UpdateCurveSettings())); connect(m_ccpm->NumCurvePoints, SIGNAL(valueChanged(int)), this, SLOT(UpdateCurveSettings()));
connect(m_ccpm->CurveToGenerate, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCurveSettings()));
connect(m_ccpm->CurveType, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCurveSettings())); connect(m_ccpm->CurveType, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCurveSettings()));
connect(m_ccpm->ccpmAngleW, SIGNAL(valueChanged(double)), this, SLOT(ccpmSwashplateUpdate())); connect(m_ccpm->ccpmAngleW, SIGNAL(valueChanged(double)), this, SLOT(ccpmSwashplateUpdate()));
connect(m_ccpm->ccpmAngleX, SIGNAL(valueChanged(double)), this, SLOT(ccpmSwashplateUpdate())); connect(m_ccpm->ccpmAngleX, SIGNAL(valueChanged(double)), this, SLOT(ccpmSwashplateUpdate()));
@ -163,12 +168,14 @@ ConfigccpmWidget::ConfigccpmWidget(QWidget *parent) : ConfigTaskWidget(parent)
connect(m_ccpm->ccpmCollectivespinBox, SIGNAL(valueChanged(int)), this, SLOT(UpdateMixer())); connect(m_ccpm->ccpmCollectivespinBox, SIGNAL(valueChanged(int)), this, SLOT(UpdateMixer()));
connect(m_ccpm->ccpmType, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateType())); connect(m_ccpm->ccpmType, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateType()));
connect(m_ccpm->ccpmSingleServo, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateType())); connect(m_ccpm->ccpmSingleServo, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateType()));
connect(m_ccpm->CurveSettings, SIGNAL(cellChanged (int, int)), this, SLOT(UpdateCurveWidgets()));
connect(parent, SIGNAL(autopilotConnected()),this, SLOT(requestccpmUpdate()));
// connect(parent, SIGNAL(autopilotConnected()),this, SLOT(requestccpmUpdate()));
} }
@ -215,7 +222,7 @@ void ConfigccpmWidget::UpdateType()
m_ccpm->CurveToGenerate->setEnabled(1); m_ccpm->CurveToGenerate->setEnabled(1);
m_ccpm->CurveSettings->setColumnHidden(1,0); m_ccpm->CurveSettings->setColumnHidden(1,0);
m_ccpm->widget_2->setVisible(1); m_ccpm->PitchCurve->setVisible(1);
m_ccpm->customThrottleCurve2Value->setVisible(1); m_ccpm->customThrottleCurve2Value->setVisible(1);
m_ccpm->label_41->setVisible(1); m_ccpm->label_41->setVisible(1);
@ -280,7 +287,7 @@ void ConfigccpmWidget::UpdateType()
m_ccpm->CurveToGenerate->setCurrentIndex(0); m_ccpm->CurveToGenerate->setCurrentIndex(0);
m_ccpm->CurveToGenerate->setEnabled(0); m_ccpm->CurveToGenerate->setEnabled(0);
m_ccpm->CurveSettings->setColumnHidden(1,1); m_ccpm->CurveSettings->setColumnHidden(1,1);
m_ccpm->widget_2->setVisible(0); m_ccpm->PitchCurve->setVisible(0);
m_ccpm->customThrottleCurve2Value->setVisible(0); m_ccpm->customThrottleCurve2Value->setVisible(0);
m_ccpm->label_41->setVisible(0); m_ccpm->label_41->setVisible(0);
} }
@ -292,6 +299,43 @@ void ConfigccpmWidget::UpdateType()
} }
/**
Resets a mixer curve
*/
void ConfigccpmWidget::resetMixer(MixerCurveWidget *mixer, int numElements)
{
QList<double> curveValues;
for (double i=0; i<numElements; i++) {
curveValues.append(i/(numElements-1));
}
// Setup all Throttle1 curves for all types of airframes
mixer->initCurve(curveValues);
}
void ConfigccpmWidget::UpdateCurveWidgets()
{
int NumCurvePoints,i;
QList<double> curveValues;
//get the user settings
NumCurvePoints=m_ccpm->NumCurvePoints->value();
curveValues.clear();
for (i=0; i<NumCurvePoints; i++)
{
curveValues.append(m_ccpm->CurveSettings->item(i, 0 )->text().toDouble());
}
// Setup all Throttle1 curves for all types of airframes
m_ccpm->ThrottleCurve->initCurve(curveValues);
curveValues.clear();
for (i=0; i<NumCurvePoints; i++)
{
curveValues.append(m_ccpm->CurveSettings->item(i, 1 )->text().toDouble());
}
// Setup all Throttle1 curves for all types of airframes
m_ccpm->PitchCurve->initCurve(curveValues);
}
@ -314,6 +358,28 @@ void ConfigccpmWidget::UpdateCurveSettings()
} }
m_ccpm->CurveSettings->setVerticalHeaderLabels( vertHeaders ); m_ccpm->CurveSettings->setVerticalHeaderLabels( vertHeaders );
if (m_ccpm->CurveToGenerate->currentIndex()==0)
{
m_ccpm->CurveValue1->setMinimum(0.0);
m_ccpm->CurveValue2->setMinimum(0.0);
m_ccpm->CurveValue3->setMinimum(0.0);
}
else
{
m_ccpm->CurveValue1->setMinimum(-1.0);
m_ccpm->CurveValue2->setMinimum(-1.0);
m_ccpm->CurveValue3->setMinimum(0.0);
}
m_ccpm->CurveValue1->setMaximum(1.0);
m_ccpm->CurveValue2->setMaximum(1.0);
m_ccpm->CurveValue3->setMaximum(100.0);
m_ccpm->CurveValue1->setSingleStep(0.1);
m_ccpm->CurveValue2->setSingleStep(0.1);
m_ccpm->CurveValue3->setSingleStep(1.0);
m_ccpm->CurveValue1->setCorrectionMode(QAbstractSpinBox::CorrectToNearestValue);;
m_ccpm->CurveValue2->setCorrectionMode(QAbstractSpinBox::CorrectToNearestValue);
m_ccpm->CurveValue3->setCorrectionMode(QAbstractSpinBox::CorrectToNearestValue);
if ( CurveType.compare("Flat")==0) if ( CurveType.compare("Flat")==0)
{ {
m_ccpm->CurveLabel1->setText("Value"); m_ccpm->CurveLabel1->setText("Value");
@ -353,6 +419,42 @@ void ConfigccpmWidget::UpdateCurveSettings()
m_ccpm->ccpmGenerateCurve->setVisible(true); m_ccpm->ccpmGenerateCurve->setVisible(true);
m_ccpm->CurveToGenerate->setVisible(true); m_ccpm->CurveToGenerate->setVisible(true);
} }
if ( CurveType.compare("Exp")==0)
{
m_ccpm->CurveLabel1->setText("Min");
m_ccpm->CurveLabel1->setVisible(true);
m_ccpm->CurveValue1->setVisible(true);
m_ccpm->CurveLabel2->setText("Max");
m_ccpm->CurveLabel2->setVisible(true);
m_ccpm->CurveValue2->setVisible(true);
m_ccpm->CurveLabel3->setText("Strength");
m_ccpm->CurveLabel3->setVisible(true);
m_ccpm->CurveValue3->setVisible(true);
m_ccpm->CurveValue3->setMinimum(1.0);
m_ccpm->CurveValue3->setMaximum(100.0);
m_ccpm->CurveValue3->setSingleStep(1.0);
m_ccpm->CurveValue3->setCorrectionMode(QAbstractSpinBox::CorrectToNearestValue);;
m_ccpm->ccpmGenerateCurve->setVisible(true);
m_ccpm->CurveToGenerate->setVisible(true);
}
if ( CurveType.compare("Log")==0)
{
m_ccpm->CurveLabel1->setText("Min");
m_ccpm->CurveLabel1->setVisible(true);
m_ccpm->CurveValue1->setVisible(true);
m_ccpm->CurveLabel2->setText("Max");
m_ccpm->CurveLabel2->setVisible(true);
m_ccpm->CurveValue2->setVisible(true);
m_ccpm->CurveLabel3->setText("Strength");
m_ccpm->CurveLabel3->setVisible(true);
m_ccpm->CurveValue3->setVisible(true);
m_ccpm->CurveValue3->setMinimum(1.0);
m_ccpm->CurveValue3->setMaximum(100.0);
m_ccpm->CurveValue3->setSingleStep(1.0);
m_ccpm->CurveValue3->setCorrectionMode(QAbstractSpinBox::CorrectToNearestValue);;
m_ccpm->ccpmGenerateCurve->setVisible(true);
m_ccpm->CurveToGenerate->setVisible(true);
}
if ( CurveType.compare("Custom")==0) if ( CurveType.compare("Custom")==0)
{ {
m_ccpm->CurveLabel1->setVisible(false); m_ccpm->CurveLabel1->setVisible(false);
@ -365,6 +467,7 @@ void ConfigccpmWidget::UpdateCurveSettings()
m_ccpm->CurveToGenerate->setVisible(false); m_ccpm->CurveToGenerate->setVisible(false);
} }
} }
void ConfigccpmWidget::GenerateCurve() void ConfigccpmWidget::GenerateCurve()
{ {
@ -408,13 +511,21 @@ void ConfigccpmWidget::GenerateCurve()
item->setText( tr( "%1" ).arg(value2) ); item->setText( tr( "%1" ).arg(value2) );
} }
} }
if ( CurveType.compare("Exp")==0)
{
item->setText( tr( "%1" ).arg(value1 +(((exp(scale*(value3/10))-1))/(exp((value3/10))-1)*(value2-value1))) );
}
if ( CurveType.compare("Log")==0)
{
item->setText( tr( "%1" ).arg(value1 +(((log(scale*(value3*2)+1))/(log(1+(value3*2))))*(value2-value1))) );
}
} }
for (i=NumCurvePoints;i<10;i++) for (i=NumCurvePoints;i<10;i++)
{ {
item =m_ccpm->CurveSettings->item(i, CurveToGenerate ); item =m_ccpm->CurveSettings->item(i, CurveToGenerate );
item->setText( tr( "" ) ); item->setText( tr( "" ) );
} }
UpdateCurveWidgets();
} }

View File

@ -68,6 +68,8 @@ private:
void GenerateCurve(); void GenerateCurve();
void UpdateMixer(); void UpdateMixer();
void UpdateType(); void UpdateType();
void resetMixer(MixerCurveWidget *mixer, int numElements);
void UpdateCurveWidgets();
public slots: public slots:
void requestccpmUpdate(); void requestccpmUpdate();
void sendccpmUpdate(); void sendccpmUpdate();