AirfoilServoCalibrator.cc 3.41 KB
Newer Older
1 2 3
#include "AirfoilServoCalibrator.h"

AirfoilServoCalibrator::AirfoilServoCalibrator(AirfoilType type, QWidget *parent) :
4 5 6 7
    AbstractCalibrator(parent),    
    highPulseWidth(new QLabel()),
    centerPulseWidth(new QLabel()),
    lowPulseWidth(new QLabel())
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
{
    QGridLayout *grid = new QGridLayout(this);

    /* Add title */
    QHBoxLayout *titleLayout = new QHBoxLayout();
    QLabel *title;
    if (type == AILERON)
    {
        title = new QLabel(tr("Aileron"));
    }
    else if (type == ELEVATOR)
    {
        title = new QLabel(tr("Elevator"));
    }
    else if (type == RUDDER)
    {
        title = new QLabel(tr("Rudder"));
    }

    titleLayout->addWidget(title);
    grid->addLayout(titleLayout, 0, 0, 1, 3, Qt::AlignHCenter);

    /* Add current Pulse Width Display */
    QLabel *pulseWidthTitle = new QLabel(tr("Pulse Width (us)"));
    QHBoxLayout *pulseLayout = new QHBoxLayout();
    pulseLayout->addWidget(pulseWidthTitle);
    pulseLayout->addWidget(pulseWidth);
    grid->addLayout(pulseLayout, 1, 0, 1, 3);

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    QLabel *highPulseString;
    QLabel *centerPulseString;
    QLabel *lowPulseString;
    if (type == AILERON)
    {
        highPulseString = new QLabel(tr("Bank Left"));
        centerPulseString = new QLabel(tr("Center"));
        lowPulseString = new QLabel(tr("Bank Right"));
    }
    else if (type == ELEVATOR)
    {
        highPulseString = new QLabel(tr("Nose Down"));
        centerPulseString = new QLabel(tr("Center"));
        lowPulseString = new QLabel(tr("Nose Up"));
    }
    else if (type == RUDDER)
    {
        highPulseString = new QLabel(tr("Nose Left"));
        centerPulseString = new QLabel(tr("Center"));
        lowPulseString = new QLabel(tr("Nose Right"));
    }
    else
    {
        highPulseString = new QLabel(tr("High"));
        centerPulseString = new QLabel(tr("Center"));
        lowPulseString = new QLabel(tr("Low"));
    }


    QPushButton *highButton = new QPushButton(tr("Set"));
    QPushButton *centerButton = new QPushButton(tr("Set"));
    QPushButton *lowButton = new QPushButton(tr("Set"));

    grid->addWidget(highPulseString, 2, 0);
    grid->addWidget(highPulseWidth, 2, 1);
    grid->addWidget(highButton, 2, 2);

    grid->addWidget(centerPulseString, 3, 0);
    grid->addWidget(centerPulseWidth, 3, 1);
    grid->addWidget(centerButton, 3, 2);

    grid->addWidget(lowPulseString, 4, 0);
    grid->addWidget(lowPulseWidth, 4, 1);
    grid->addWidget(lowButton, 4, 2);

82
    this->setLayout(grid);
83 84 85 86 87 88 89 90 91 92 93

    connect(highButton, SIGNAL(clicked()), this, SLOT(setHigh()));
    connect(centerButton, SIGNAL(clicked()), this, SLOT(setCenter()));
    connect(lowButton, SIGNAL(clicked()), this, SLOT(setLow()));
}



void AirfoilServoCalibrator::setHigh()
{
    highPulseWidth->setText(QString::number(static_cast<double>(logExtrema())));
94
    emit setpointChanged(2, logExtrema());
95 96 97 98 99
}

void AirfoilServoCalibrator::setCenter()
{
    centerPulseWidth->setText(QString::number(static_cast<double>(logAverage())));
100
    emit setpointChanged(1, logAverage());
101 102
}

103
void AirfoilServoCalibrator::setLow()
104
{
105
    lowPulseWidth->setText(QString::number(static_cast<double>(logExtrema())));
106
    emit setpointChanged(0, logExtrema());
107
}
108 109 110 111 112 113 114 115 116 117

void AirfoilServoCalibrator::set(const QVector<float> &data)
{
    if (data.size() == 3)
    {
        lowPulseWidth->setText(QString::number(data[0]));
        centerPulseWidth->setText(QString::number(data[1]));
        highPulseWidth->setText(QString::number(data[2]));
    }
}