1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

MixerCurveWidget: bugfix- don't delete edges in initNodes, just remove from scene;

simplify and remove unused objects in configccpm;  respect min/max in initLinearCurve.
This commit is contained in:
Mike LaBranche 2012-06-22 17:01:33 -07:00
parent 7eb0105886
commit 9b25f68898
6 changed files with 36 additions and 71 deletions

View File

@ -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<double> 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()

View File

@ -103,7 +103,6 @@ private:
void GenerateCurve();
void UpdateMixer();
void UpdateType();
void resetMixer(MixerCurveWidget *mixer, int numElements);
void UpdateCurveWidgets();
void updatePitchCurveValue(QList<double>,double);
void updateThrottleCurveValue(QList<double>,double);

View File

@ -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:

View File

@ -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: {

View File

@ -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<Edge*> 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<double> 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<double> points;
for (double i=0; i<numPoints;i++) {
double val = ((curveMax - curveMin) * (i/(numPoints-1))) + curveMin;
for (double i=0; i < (double)numPoints; i++) {
double val = ((curveMax - curveMin) * ( i / (double)(numPoints-1) ) ) + curveMin;
points.append(val);
}
initCurve(points);

View File

@ -46,7 +46,7 @@ public:
void itemMoved(double itemValue); // Callback when a point is moved, to be updated
void initCurve (QList<double> points);
QList<double> getCurve();
void initLinearCurve(quint32 numPoints, double maxValue = 1, double minValue = 0);
void initLinearCurve(int numPoints, double maxValue = 1, double minValue = 0);
void setCurve(QList<double>);
void setMin(double value);
double getMin();