mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-22 12:54:14 +01:00
Updated MixerCurveWidget so that it can have ranges other than 0 to 1.
Default behaviour not changed. New functions allow the setting of the max and min values for the curve. 0 to 1 range is needed when output is used for motors. -1 to 1 range is needed when output is used for a servo. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2060 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
7180c4fe2d
commit
0a2cfbacc7
@ -56,6 +56,11 @@ MixerCurveWidget::MixerCurveWidget(QWidget *parent) : QGraphicsView(parent)
|
|||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
setRenderHint(QPainter::Antialiasing);
|
setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
|
curveMin=0.0;
|
||||||
|
curveMax=1.0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QGraphicsScene *scene = new QGraphicsScene(this);
|
QGraphicsScene *scene = new QGraphicsScene(this);
|
||||||
QSvgRenderer *renderer = new QSvgRenderer();
|
QSvgRenderer *renderer = new QSvgRenderer();
|
||||||
plot = new QGraphicsSvgItem();
|
plot = new QGraphicsSvgItem();
|
||||||
@ -109,10 +114,12 @@ void MixerCurveWidget::initCurve(QList<double> points)
|
|||||||
scene()->addItem(node);
|
scene()->addItem(node);
|
||||||
nodeList.append(node);
|
nodeList.append(node);
|
||||||
double val = points.at(i);
|
double val = points.at(i);
|
||||||
if (val>1)
|
if (val>curveMax)
|
||||||
val=1;
|
val=curveMax;
|
||||||
if (val<0)
|
if (val<curveMin)
|
||||||
val=0;
|
val=curveMin;
|
||||||
|
val+=curveMin;
|
||||||
|
val/=(curveMax-curveMin);
|
||||||
node->setPos(w*i,h-val*h);
|
node->setPos(w*i,h-val*h);
|
||||||
node->verticalMove(true);
|
node->verticalMove(true);
|
||||||
}
|
}
|
||||||
@ -133,7 +140,7 @@ QList<double> MixerCurveWidget::getCurve() {
|
|||||||
|
|
||||||
qreal h = plot->boundingRect().height();
|
qreal h = plot->boundingRect().height();
|
||||||
foreach(Node *node, nodeList) {
|
foreach(Node *node, nodeList) {
|
||||||
list.append((h-node->pos().y())/h);
|
list.append(((curveMax-curveMin)*(h-node->pos().y())/h)+curveMin);
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
@ -154,10 +161,12 @@ void MixerCurveWidget::setCurve(QList<double> points)
|
|||||||
qreal h = plot->boundingRect().height();
|
qreal h = plot->boundingRect().height();
|
||||||
for (int i=0; i<points.length(); i++) {
|
for (int i=0; i<points.length(); i++) {
|
||||||
double val = points.at(i);
|
double val = points.at(i);
|
||||||
if (val>1)
|
if (val>curveMax)
|
||||||
val=1;
|
val=curveMax;
|
||||||
if (val<0)
|
if (val<curveMin)
|
||||||
val=0;
|
val=curveMin;
|
||||||
|
val-=curveMin;
|
||||||
|
val/=(curveMax-curveMin);
|
||||||
nodeList.at(i)->setPos(w*i,h-val*h);
|
nodeList.at(i)->setPos(w*i,h-val*h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -187,3 +196,17 @@ void MixerCurveWidget::itemMoved(double itemValue)
|
|||||||
QList<double> list = getCurve();
|
QList<double> list = getCurve();
|
||||||
emit curveUpdated(list, itemValue);
|
emit curveUpdated(list, itemValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MixerCurveWidget::setMin(double value)
|
||||||
|
{
|
||||||
|
curveMin = value;
|
||||||
|
}
|
||||||
|
void MixerCurveWidget::setMax(double value)
|
||||||
|
{
|
||||||
|
curveMax = value;
|
||||||
|
}
|
||||||
|
void MixerCurveWidget::setRange(double min, double max)
|
||||||
|
{
|
||||||
|
curveMin = min;
|
||||||
|
curveMax = max;
|
||||||
|
}
|
||||||
|
@ -46,6 +46,9 @@ public:
|
|||||||
void initCurve (QList<double> points);
|
void initCurve (QList<double> points);
|
||||||
QList<double> getCurve();
|
QList<double> getCurve();
|
||||||
void setCurve(QList<double>);
|
void setCurve(QList<double>);
|
||||||
|
void setMin(double value);
|
||||||
|
void setMax(double value);
|
||||||
|
void setRange(double min, double max);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void curveUpdated(QList<double>, double );
|
void curveUpdated(QList<double>, double );
|
||||||
@ -55,6 +58,8 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QGraphicsSvgItem *plot;
|
QGraphicsSvgItem *plot;
|
||||||
QList<Node*> nodeList;
|
QList<Node*> nodeList;
|
||||||
|
double curveMin;
|
||||||
|
double curveMax;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent *event);
|
void showEvent(QShowEvent *event);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user