From 7f3a810fa605c29d4830ac6281f8d2daa2c096ac Mon Sep 17 00:00:00 2001 From: Mike LaBranche Date: Sat, 30 Jun 2012 14:35:38 -0700 Subject: [PATCH] MixerCurve: alpha version of integrated mixer curve; only in fixedwing config currently. --- .../src/plugins/config/airframe.ui | 60 +--- .../config/configvehicletypewidget.cpp | 21 +- .../plugins/config/configvehicletypewidget.h | 1 - .../uavobjectwidgetutils/mixercurve.cpp | 259 +++++++++++++++- .../plugins/uavobjectwidgetutils/mixercurve.h | 49 ++- .../uavobjectwidgetutils/mixercurve.ui | 284 ++++++++++++++++-- .../uavobjectwidgetutils/mixercurvewidget.cpp | 14 +- .../uavobjectwidgetutils/mixercurvewidget.h | 4 +- 8 files changed, 596 insertions(+), 96 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/airframe.ui b/ground/openpilotgcs/src/plugins/config/airframe.ui index 47006a789..8fd8ce73e 100644 --- a/ground/openpilotgcs/src/plugins/config/airframe.ui +++ b/ground/openpilotgcs/src/plugins/config/airframe.ui @@ -471,23 +471,7 @@ margin:1px; - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - + 0 @@ -496,14 +480,14 @@ margin:1px; - 100 - 100 + 350 + 350 - 200 - 200 + 500 + 500 @@ -514,26 +498,6 @@ margin:1px; - - - - - 200 - 16777215 - - - - Reset - - - - - - - Val: 0.00 - - - @@ -2784,14 +2748,14 @@ p, li { white-space: pre-wrap; } <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Lucida Grande'; font-size:13pt; font-weight:400; font-style:normal;"> +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> <table border="0" style="-qt-table-type: root; margin-top:4px; margin-bottom:4px; margin-left:4px; margin-right:4px;"> <tr> <td style="border: none;"> <p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:14pt; font-weight:600; color:#ff0000;">SETTING UP FEED FORWARD IS DANGEROUS</span></p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:11pt;"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Beware: Feed Forward Tuning will launch all engines around mid-throttle, you have been warned!</p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Remove your props initially, and for fine-tuning, make sure your airframe is safely held in place. Wear glasses and protect your face and body.</p></td></tr></table></body></html> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Lucida Grande'; font-size:13pt;">Beware: Feed Forward Tuning will launch all engines around mid-throttle, you have been warned!</span></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Lucida Grande'; font-size:13pt;">Remove your props initially, and for fine-tuning, make sure your airframe is safely held in place. Wear glasses and protect your face and body.</span></p></td></tr></table></body></html> @@ -2889,7 +2853,7 @@ p, li { white-space: pre-wrap; } MixerCurveWidget QWidget -
mixercurvewidget.h
+
uavobjectwidgetutils/mixercurvewidget.h
1
@@ -2898,6 +2862,12 @@ p, li { white-space: pre-wrap; }
cfg_vehicletypes/configccpmwidget.h
1
+ + MixerCurve + QWidget +
uavobjectwidgetutils/mixercurve.h
+ 1 +
diff --git a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp index 84b531d6b..293821d55 100644 --- a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp @@ -207,7 +207,7 @@ ConfigVehicleTypeWidget::ConfigVehicleTypeWidget(QWidget *parent) : ConfigTaskWi //mdl connect(m_heli->m_ccpm->ccpmType, SIGNAL(currentIndexChanged(QString)), this, SLOT(setupAirframeUI(QString))); //Connect throttle curve reset pushbuttons to reset functions - connect(m_aircraft->fwThrottleReset, SIGNAL(clicked()), this, SLOT(resetFwMixer())); + //connect(m_aircraft->fwThrottleReset, SIGNAL(clicked()), this, SLOT(resetFwMixer())); connect(m_aircraft->mrThrottleCurveReset, SIGNAL(clicked()), this, SLOT(resetMrMixer())); connect(m_aircraft->gvThrottleCurve1Reset, SIGNAL(clicked()), this, SLOT(resetGvFrontMixer())); connect(m_aircraft->gvThrottleCurve2Reset, SIGNAL(clicked()), this, SLOT(resetGvRearMixer())); @@ -487,7 +487,7 @@ void ConfigVehicleTypeWidget::resetFwMixer() { UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); UAVObjectField* field = obj->getField(QString("ThrottleCurve1")); - resetMixer(m_aircraft->fixedWingThrottle, field->getNumElements(),1); + //resetMixer(m_aircraft->fixedWingThrottle, field->getNumElements(),1); } /** @@ -497,7 +497,7 @@ void ConfigVehicleTypeWidget::resetMrMixer() { UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); UAVObjectField* field = obj->getField(QString("ThrottleCurve1")); - resetMixer(m_aircraft->multiThrottleCurve, field->getNumElements(),0.9); + //resetMixer(m_aircraft->multiThrottleCurve, field->getNumElements(),0.9); } /** @@ -507,7 +507,7 @@ void ConfigVehicleTypeWidget::resetGvFrontMixer() { UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); UAVObjectField* field = obj->getField(QString("ThrottleCurve1")); - resetMixer(m_aircraft->groundVehicleThrottle1, field->getNumElements(),1); + //resetMixer(m_aircraft->groundVehicleThrottle1, field->getNumElements(),1); } /** @@ -517,7 +517,7 @@ void ConfigVehicleTypeWidget::resetGvRearMixer() { UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); UAVObjectField* field = obj->getField(QString("ThrottleCurve2")); - resetMixer(m_aircraft->groundVehicleThrottle2, field->getNumElements(),1); + //resetMixer(m_aircraft->groundVehicleThrottle2, field->getNumElements(),1); } /** @@ -537,7 +537,7 @@ void ConfigVehicleTypeWidget::resetCt2Mixer() { UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); UAVObjectField* field = obj->getField(QString("ThrottleCurve2")); - resetMixer(m_aircraft->customThrottle2Curve, field->getNumElements(),1); + //resetMixer(m_aircraft->customThrottle2Curve, field->getNumElements(),1); } @@ -550,15 +550,6 @@ void ConfigVehicleTypeWidget::resetMixer(MixerCurveWidget *mixer, int numElement mixer->initLinearCurve((quint32)numElements,maxvalue); } -/** - Updates the currently moved fixed wing throttle curve item value - */ -void ConfigVehicleTypeWidget::updateFwThrottleCurveValue(QList list, double value) -{ - Q_UNUSED(list); - m_aircraft->fwThrottleCurveItemValue->setText(QString().sprintf("Val: %.2f",value)); -} - /** Updates the currently moved multi-rotor throttle curve item value */ diff --git a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h index 3cca72ba1..fb7571cd2 100644 --- a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h +++ b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h @@ -99,7 +99,6 @@ private slots: void resetGvRearMixer(); void resetCt1Mixer(); void resetCt2Mixer(); - void updateFwThrottleCurveValue(QList list, double value); void updateMrThrottleCurveValue(QList list, double value); void updateGvThrottle1CurveValue(QList list, double value); void updateGvThrottle2CurveValue(QList list, double value); diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurve.cpp b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurve.cpp index 4997f1493..c319138dd 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurve.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurve.cpp @@ -1,14 +1,265 @@ +#include #include "mixercurve.h" -#include "ui_mixercurve.h" MixerCurve::MixerCurve(QWidget *parent) : QFrame(parent), - ui(new Ui::MixerCurve) + m_mixerUI(new Ui::MixerCurve), + m_curveType(MixerCurve::MIXERCURVE_THROTTLE) { - ui->setupUi(this); + m_mixerUI->setupUi(this); + + m_curve = m_mixerUI->CurveWidget; + m_settings = m_mixerUI->CurveSettings; + + UpdateCurveSettings(); + + connect(m_mixerUI->CurveType, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCurveSettings())); + connect(m_mixerUI->ResetCurve, SIGNAL(clicked()), this, SLOT(ResetCurve())); + connect(m_mixerUI->GenerateCurve, SIGNAL(clicked()), this, SLOT(GenerateCurve())); + connect(m_curve, SIGNAL(curveUpdated()), this, SLOT(UpdateSettings())); + + connect(m_mixerUI->CurveMin, SIGNAL(valueChanged(double)), this, SLOT(CurveMinChanged(double))); + connect(m_mixerUI->CurveMax, SIGNAL(valueChanged(double)), this, SLOT(CurveMaxChanged(double))); + connect(m_mixerUI->CurveStep, SIGNAL(valueChanged(double)), this, SLOT(GenerateCurve())); } MixerCurve::~MixerCurve() { - delete ui; + delete m_mixerUI; +} + +void MixerCurve::ResetCurve() +{ + m_curve->setMin((m_curveType == MixerCurve::MIXERCURVE_THROTTLE) ? 0.0 : -1.0); + m_curve->setMax(1.0); + + m_mixerUI->CurveMin->setValue(m_curve->getMin()); + m_mixerUI->CurveMax->setValue(m_curve->getMax()); + + initLinearCurve(MixerCurveWidget::NODE_NUMELEM, m_curve->getMax(), m_curve->getMin()); + + UpdateSettings(); +} + +void MixerCurve::UpdateCurveSettings() +{ + //get the user settings + QString curveType = m_mixerUI->CurveType->currentText(); + + switch (m_curveType) { + case MixerCurve::MIXERCURVE_THROTTLE: + { + m_mixerUI->CurveMin->setMinimum(0.0); + m_mixerUI->CurveMax->setMinimum(0.0); + m_mixerUI->CurveStep->setMinimum(0.0); + break; + } + case MixerCurve::MIXERCURVEPITCH: + { + m_mixerUI->CurveMin->setMinimum(-1.0); + m_mixerUI->CurveMax->setMinimum(-1.0); + m_mixerUI->CurveStep->setMinimum(0.0); + break; + } + } + m_mixerUI->CurveMin->setMaximum(1.0); + m_mixerUI->CurveMax->setMaximum(1.0); + m_mixerUI->CurveStep->setMaximum(100.0); + + //set default visible + m_mixerUI->minLabel->setText("Min"); + m_mixerUI->minLabel->setVisible(true); + m_mixerUI->CurveMin->setVisible(true); + m_mixerUI->maxLabel->setVisible(false); + m_mixerUI->CurveMax->setVisible(false); + m_mixerUI->stepLabel->setVisible(false); + m_mixerUI->CurveStep->setVisible(false); + + if ( curveType.compare("Flat")==0) + { + m_mixerUI->minLabel->setText("Value"); + } + if ( curveType.compare("Linear")==0) + { + m_mixerUI->maxLabel->setVisible(true); + m_mixerUI->CurveMax->setVisible(true); + } + if ( curveType.compare("Step")==0) + { + m_mixerUI->maxLabel->setVisible(true); + m_mixerUI->CurveMax->setVisible(true); + m_mixerUI->stepLabel->setText("Step at"); + m_mixerUI->stepLabel->setVisible(true); + m_mixerUI->CurveStep->setVisible(true); + } + if ( curveType.compare("Exp")==0) + { + m_mixerUI->maxLabel->setVisible(true); + m_mixerUI->CurveMax->setVisible(true); + m_mixerUI->stepLabel->setText("Strength"); + m_mixerUI->stepLabel->setVisible(true); + m_mixerUI->CurveStep->setVisible(true); + } + if ( curveType.compare("Log")==0) + { + m_mixerUI->maxLabel->setVisible(true); + m_mixerUI->CurveMax->setVisible(true); + m_mixerUI->stepLabel->setText("Strength"); + m_mixerUI->stepLabel->setVisible(true); + m_mixerUI->CurveStep->setVisible(true); + } +} + +void MixerCurve::GenerateCurve() +{ + double scale; + double newValue; + + //get the user settings + double value1 = getMin(); + double value2 = getMax(); + double value3 = getStep(); + + QString CurveType = m_mixerUI->CurveType->currentText(); + + QList points; + + for (int i=0; i* points) +{ + m_curve->initCurve(points); + UpdateSettings(); +} + +QList MixerCurve::getCurve() +{ + return m_curve->getCurve(); +} + +void MixerCurve::initLinearCurve(int numPoints, double maxValue, double minValue) +{ + m_curve->initLinearCurve(numPoints, maxValue, minValue); +} + +void MixerCurve::setCurve(const QList* points) +{ + m_curve->setCurve(points); + UpdateSettings(); +} + +void MixerCurve::setMin(double value) +{ + m_curve->setMin(value); +} + +double MixerCurve::getMin() +{ + return m_curve->getMin(); +} + +void MixerCurve::setMax(double value) +{ + m_curve->setMax(value); +} + +double MixerCurve::getMax() +{ + return m_curve->getMax(); +} + +double MixerCurve::getStep() +{ + return m_mixerUI->CurveStep->value(); +} + +void MixerCurve::UpdateSettings() +{ + QList points = m_curve->getCurve(); + + int ptCnt = points.count(); + for (int i=0; iitem((ptCnt - 1) - i, 0); + if (item) + item->setText(QString().sprintf("%.2f",points.at(i))); + } +} + +void MixerCurve::CurveMinChanged(double value) +{ + setMin(value); + + // the min changed so redraw the curve + // mixercurvewidget::setCurve will trim any points below min + QList points = getCurve(); + setCurve(&points); +} + +void MixerCurve::CurveMaxChanged(double value) +{ + setMax(value); + + // the max changed so redraw the curve + // mixercurvewidget::setCurve will trim any points above max + QList points = getCurve(); + setCurve(&points); +} + +double MixerCurve::setRange(double min, double max) +{ + return m_curve->setRange(min, max); +} + +void MixerCurve::showEvent(QShowEvent *event) +{ + Q_UNUSED(event) + // Thit fitInView method should only be called now, once the + // widget is shown, otherwise it cannot compute its values and + // the result is usually a ahrsbargraph that is way too small. + //fitInView(this, Qt::KeepAspectRatio); + +} + +void MixerCurve::resizeEvent(QResizeEvent* event) +{ + Q_UNUSED(event); + //fitInView(this, Qt::KeepAspectRatio); } diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurve.h b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurve.h index a4e7fdf6a..eeebe0d22 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurve.h +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurve.h @@ -2,21 +2,64 @@ #define MIXERCURVE_H #include +#include +#include +#include + +#include "ui_mixercurve.h" +#include "mixercurvewidget.h" +#include "uavobjectwidgetutils_global.h" namespace Ui { class MixerCurve; } -class MixerCurve : public QFrame +class UAVOBJECTWIDGETUTILS_EXPORT MixerCurve : public QFrame { Q_OBJECT public: explicit MixerCurve(QWidget *parent = 0); ~MixerCurve(); - + + + /* Enumeration options for ThrottleCurves */ + typedef enum { MIXERCURVE_THROTTLE=0, MIXERCURVEPITCH=1 } MixerCurveType; + + void initCurve (const QList* points); + QList getCurve(); + void initLinearCurve(int numPoints, double maxValue = 1, double minValue = 0); + void setCurve(const QList* points); + void setMin(double value); + double getMin(); + void setMax(double value); + double getMax(); + double getStep(); + double setRange(double min, double max); + + +signals: + +protected: + void showEvent(QShowEvent *event); + void resizeEvent(QResizeEvent *event); + +public slots: + void ResetCurve(); + void GenerateCurve(); + void UpdateSettings(); + +private slots: + void CurveMinChanged(double value); + void CurveMaxChanged(double value); + void UpdateCurveSettings(); + private: - Ui::MixerCurve *ui; + Ui::MixerCurve* m_mixerUI; + MixerCurveWidget* m_curve; + QTableWidget* m_settings; + MixerCurveType m_curveType; + }; #endif // MIXERCURVE_H diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurve.ui b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurve.ui index 48573bf24..67ad97fe2 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurve.ui +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurve.ui @@ -6,10 +6,28 @@ 0 0 - 322 - 300 + 437 + 317 + + + 365 + 306 + + + + + 500 + 500 + + + + + 300 + 300 + + MixerCurve @@ -19,64 +37,282 @@ QFrame::Raised - + - 80 - 40 - 221 + 140 + 10 + 291 + 300 + + + + + 261 241 - + + + + + 300 + 300 + - + - 20 - 260 + 70 + 240 51 22 + + QAbstractSpinBox::CorrectToNearestValue + + + -1.000000000000000 + + + 1.000000000000000 + + + 0.010000000000000 + + + 0.000000000000000 + - + - 20 + 70 40 51 22 + + QAbstractSpinBox::CorrectToNearestValue + + + 0.000000000000000 + + + 1.000000000000000 + + + 0.010000000000000 + + + 1.000000000000000 + - + - 10 - 70 - 61 - 181 + 20 + 60 + 101 + 171 + + + 8 + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + false + 5 1 - - - - - - + + + 5 + + + + + 4 + + + + + 3 + + + + + 2 + + + + + 1 + + + + + Value + + + + + 1.0 + + + + + .75 + + + + + .50 + + + + + .25 + + + + + .00 + + + + + + + 0 + 10 + 61 + 22 + + + + + Linear + + + + + Log + + + + + Exp + + + + + Flat + + + + + Step + + + + + + + 70 + 10 + 61 + 23 + + + + Generate + + + + + + 20 + 240 + 41 + 16 + + + + Min + + + + + + 20 + 40 + 41 + 16 + + + + Max + + + + + + 20 + 290 + 75 + 23 + + + + Reset + + + + + + 20 + 260 + 41 + 16 + + + + Step + + + + + + 70 + 260 + 51 + 22 + + + + QAbstractSpinBox::CorrectToNearestValue + MixerCurveWidget QWidget -
mixercurvewidget.h
+
uavobjectwidgetutils/mixercurvewidget.h
1
diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvewidget.cpp b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvewidget.cpp index a19692ff9..eea8fef7b 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvewidget.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvewidget.cpp @@ -220,12 +220,13 @@ void MixerCurveWidget::setCurve(const QList* points) Node* node = nodeList.at(i); node->setPos(w*i, h - (val*h)); node->verticalMove(true); + node->update(); } curveUpdating = false; update(); - emit curveUpdated(points, (double)0); + emit curveUpdated(); } @@ -248,19 +249,26 @@ void MixerCurveWidget::resizeEvent(QResizeEvent* event) void MixerCurveWidget::itemMoved(double itemValue) { if (!curveUpdating) { - QList curve = getCurve(); - emit curveUpdated(&curve, itemValue); + emit curveUpdated(); } } void MixerCurveWidget::setMin(double value) { + if (curveMin != value) + emit curveMinChanged(value); + curveMin = value; } + void MixerCurveWidget::setMax(double value) { + if (curveMax != value) + emit curveMaxChanged(value); + curveMax = value; } + double MixerCurveWidget::getMin() { return curveMin; diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvewidget.h b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvewidget.h index 031a70733..e1275a3a5 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvewidget.h +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvewidget.h @@ -57,7 +57,9 @@ public: static const int NODE_NUMELEM = 5; signals: - void curveUpdated(const QList* points, const double value); + void curveUpdated(); + void curveMinChanged(double value); + void curveMaxChanged(double value); private slots: