diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp index a7e46eb83..7f2d235d0 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp @@ -132,16 +132,11 @@ ConfigCcpmWidget::ConfigCcpmWidget(QWidget *parent) : VehicleConfig(parent) } - m_ccpm->PitchCurve->setMin(-1); - - resetMixer(m_ccpm->PitchCurve, 5); - resetMixer(m_ccpm->ThrottleCurve, 5); - - MixerSettings * mixerSettings = MixerSettings::GetInstance(getObjectManager()); - Q_ASSERT(mixerSettings); - UAVObjectField * curve2source = mixerSettings->getField("Curve2Source"); - Q_ASSERT(curve2source); + //initialize our two mixer curves + m_ccpm->PitchCurve->initLinearCurve(5, 1.0, -1.0); + m_ccpm->ThrottleCurve->initLinearCurve(5, 1.0); + //initialize channel names m_ccpm->ccpmEngineChannel->addItems(channelNames); m_ccpm->ccpmEngineChannel->setCurrentIndex(0); m_ccpm->ccpmTailChannel->addItems(channelNames); @@ -474,14 +469,6 @@ void ConfigCcpmWidget::UpdateType() } -/** - Resets a mixer curve - */ -void ConfigCcpmWidget::resetMixer(MixerCurveWidget *mixer, int numElements) -{ - mixer->initLinearCurve(numElements,(double)1); -} - void ConfigCcpmWidget::UpdateCurveWidgets() { int NumCurvePoints,i,Changed; @@ -501,7 +488,8 @@ void ConfigCcpmWidget::UpdateCurveWidgets() if (ThisValue!=OldCurveValues.at(i))Changed=1; } // Setup all Throttle1 curves for all types of airframes - if (Changed==1)m_ccpm->ThrottleCurve->setCurve(curveValues); + if (Changed==1) + m_ccpm->ThrottleCurve->setCurve(curveValues); curveValues.clear(); Changed=0; @@ -513,7 +501,8 @@ void ConfigCcpmWidget::UpdateCurveWidgets() if (ThisValue!=OldCurveValues.at(i))Changed=1; } // Setup all Throttle1 curves for all types of airframes - if (Changed==1)m_ccpm->PitchCurve->setCurve(curveValues); + if (Changed==1) + m_ccpm->PitchCurve->setCurve(curveValues); } void ConfigCcpmWidget::updatePitchCurveValue(QList curveValues0,double Value0) @@ -606,50 +595,40 @@ void ConfigCcpmWidget::UpdateCurveSettings() m_ccpm->CurveValue2->setCorrectionMode(QAbstractSpinBox::CorrectToNearestValue); m_ccpm->CurveValue3->setCorrectionMode(QAbstractSpinBox::CorrectToNearestValue); + //set default visible + m_ccpm->CurveLabel1->setVisible(true); + m_ccpm->CurveValue1->setVisible(true); + m_ccpm->CurveLabel2->setVisible(false); + m_ccpm->CurveValue2->setVisible(false); + m_ccpm->CurveLabel3->setVisible(false); + m_ccpm->CurveValue3->setVisible(false); + m_ccpm->ccpmGenerateCurve->setVisible(true); + m_ccpm->CurveToGenerate->setVisible(true); + if ( CurveType.compare("Flat")==0) { m_ccpm->CurveLabel1->setText("Value"); - m_ccpm->CurveLabel1->setVisible(true); - m_ccpm->CurveValue1->setVisible(true); - m_ccpm->CurveLabel2->setVisible(false); - m_ccpm->CurveValue2->setVisible(false); - m_ccpm->CurveLabel3->setVisible(false); - m_ccpm->CurveValue3->setVisible(false); - m_ccpm->ccpmGenerateCurve->setVisible(true); - m_ccpm->CurveToGenerate->setVisible(true); } if ( CurveType.compare("Linear")==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->setVisible(false); - m_ccpm->CurveValue3->setVisible(false); - m_ccpm->ccpmGenerateCurve->setVisible(true); - m_ccpm->CurveToGenerate->setVisible(true); } if ( CurveType.compare("Step")==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("Step at"); m_ccpm->CurveLabel3->setVisible(true); m_ccpm->CurveValue3->setVisible(true); - m_ccpm->ccpmGenerateCurve->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); @@ -660,14 +639,10 @@ void ConfigCcpmWidget::UpdateCurveSettings() 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); @@ -677,22 +652,17 @@ void ConfigCcpmWidget::UpdateCurveSettings() 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); + m_ccpm->CurveValue3->setCorrectionMode(QAbstractSpinBox::CorrectToNearestValue); } if ( CurveType.compare("Custom")==0) { m_ccpm->CurveLabel1->setVisible(false); m_ccpm->CurveValue1->setVisible(false); - m_ccpm->CurveLabel2->setVisible(false); - m_ccpm->CurveValue2->setVisible(false); - m_ccpm->CurveLabel3->setVisible(false); - m_ccpm->CurveValue3->setVisible(false); m_ccpm->ccpmGenerateCurve->setVisible(false); m_ccpm->CurveToGenerate->setVisible(false); } -UpdateCurveWidgets(); + + UpdateCurveWidgets(); } void ConfigCcpmWidget::GenerateCurve() diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h index 3dceadcda..443663959 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h @@ -103,7 +103,6 @@ private: void GenerateCurve(); void UpdateMixer(); void UpdateType(); - void resetMixer(MixerCurveWidget *mixer, int numElements); void UpdateCurveWidgets(); void updatePitchCurveValue(QList,double); void updateThrottleCurveValue(QList,double); diff --git a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp index 8208710df..068904671 100644 --- a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp @@ -648,9 +648,9 @@ void ConfigVehicleTypeWidget::refreshWidgetsValues(UAVObject * o) } else { // no, init a straight curve - m_aircraft->multiThrottleCurve->initLinearCurve(curveValues.count(),0.9); - m_aircraft->fixedWingThrottle->initLinearCurve(curveValues.count(),(double)1); - m_aircraft->groundVehicleThrottle1->initLinearCurve(curveValues.count(),(double)1); + m_aircraft->multiThrottleCurve->initLinearCurve(curveValues.count(), 0.9); + m_aircraft->fixedWingThrottle->initLinearCurve(curveValues.count(), 1.0); + m_aircraft->groundVehicleThrottle1->initLinearCurve(curveValues.count(), 1.0); } // Setup all Throttle2 curves for all types of airframes //AT THIS MOMENT, THAT MEANS ONLY GROUND VEHICLES @@ -660,7 +660,7 @@ void ConfigVehicleTypeWidget::refreshWidgetsValues(UAVObject * o) m_aircraft->groundVehicleThrottle2->initCurve(curveValues); } else { - m_aircraft->groundVehicleThrottle2->initLinearCurve(curveValues.count(),(double)1); + m_aircraft->groundVehicleThrottle2->initLinearCurve(curveValues.count(), 1.0); } // Load the Settings for fixed wing frames: diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvepoint.cpp b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvepoint.cpp index f474eaea2..5996eb7d3 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvepoint.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvepoint.cpp @@ -103,10 +103,8 @@ void Node::verticalMove(bool flag){ double Node::value() { double h = graph->sceneRect().height(); - double min = graph->getMin(); - double range = graph->getMax() - min; double ratio = (h - pos().y()) / h; - return (range * ratio ) + min; + return ((graph->getMax() - graph->getMin()) * ratio ) + graph->getMin(); } @@ -123,12 +121,14 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &val) // Force node to move vertically newPos.setX(pos().x()); + // Stay inside graph if (newPos.y() < 0) newPos.setY(0); //qDebug() << h << " - " << newPos.y(); if (newPos.y() > h) newPos.setY(h); + return newPos; } case ItemPositionHasChanged: { diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvewidget.cpp b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvewidget.cpp index 71199b04d..2d11df926 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvewidget.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvewidget.cpp @@ -69,6 +69,7 @@ MixerCurveWidget::MixerCurveWidget(QWidget *parent) : QGraphicsView(parent) //plot->setElementId("map"); scene->addItem(plot); plot->setZValue(-1); + scene->setSceneRect(plot->boundingRect()); setScene(scene); @@ -139,12 +140,8 @@ void MixerCurveWidget::initNodes(int numPoints) // First of all, clear any existing list if (nodeList.count()) { foreach (Node *node, nodeList ) { - QList edges = node->edges(); - foreach(Edge *edge, edges) { - if (edge->destNode() == node) { - delete edge; - } - else { + foreach(Edge *edge, node->edges()) { + if (edge->sourceNode() == node) { scene()->removeItem(edge); } } @@ -189,14 +186,13 @@ QList MixerCurveWidget::getCurve() { /** Sets a linear graph */ -void MixerCurveWidget::initLinearCurve(quint32 numPoints, double maxValue, double minValue) +void MixerCurveWidget::initLinearCurve(int numPoints, double maxValue, double minValue) { - Q_UNUSED(maxValue); - Q_UNUSED(minValue); + setRange(minValue, maxValue); QList points; - for (double i=0; i points); QList getCurve(); - void initLinearCurve(quint32 numPoints, double maxValue = 1, double minValue = 0); + void initLinearCurve(int numPoints, double maxValue = 1, double minValue = 0); void setCurve(QList); void setMin(double value); double getMin();