AirfoilServoCalibrator.cc 3.47 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
{
    QGridLayout *grid = new QGridLayout(this);

    /* Add title */
    QHBoxLayout *titleLayout = new QHBoxLayout();
pixhawk's avatar
pixhawk committed
13
    QLabel* title;
14 15 16 17 18 19 20 21 22 23 24 25
    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"));
    }
pixhawk's avatar
pixhawk committed
26 27 28 29
    else
    {
        title = new QLabel(tr("Unknown"));
    }
30 31 32 33 34 35 36 37 38 39 40

    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);

41 42 43 44 45
    QLabel *highPulseString;
    QLabel *centerPulseString;
    QLabel *lowPulseString;
    if (type == AILERON)
    {
46
        highPulseString = new QLabel(tr("Bank Right"));
47
        centerPulseString = new QLabel(tr("Center"));
48
        lowPulseString = new QLabel(tr("Bank Left"));
49 50 51
    }
    else if (type == ELEVATOR)
    {
52
        highPulseString = new QLabel(tr("Nose Up"));
53
        centerPulseString = new QLabel(tr("Center"));
54
        lowPulseString = new QLabel(tr("Nose Down"));
55 56 57
    }
    else if (type == RUDDER)
    {
58
        highPulseString = new QLabel(tr("Nose Right"));
59
        centerPulseString = new QLabel(tr("Center"));
60
        lowPulseString = new QLabel(tr("Nose Left"));
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    }
    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);

86
    this->setLayout(grid);
87 88 89 90 91 92 93 94 95

    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())));
96
    emit setpointChanged(2, logExtrema());
97 98 99 100 101
}

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

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

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]));
    }
}