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

AirfoilServoCalibrator::AirfoilServoCalibrator(AirfoilType type, QWidget *parent) :
4
    AbstractCalibrator(parent),
5 6 7
    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
    if (type == AILERON) {
15
        title = new QLabel(tr("Aileron"));
16
    } else if (type == ELEVATOR) {
17
        title = new QLabel(tr("Elevator"));
18
    } else if (type == RUDDER) {
19
        title = new QLabel(tr("Rudder"));
20
    } else {
pixhawk's avatar
pixhawk committed
21 22
        title = new QLabel(tr("Unknown"));
    }
23 24 25 26 27 28 29 30 31 32 33

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

34 35 36
    QLabel *highPulseString;
    QLabel *centerPulseString;
    QLabel *lowPulseString;
37
    if (type == AILERON) {
38
        highPulseString = new QLabel(tr("Bank Right"));
39
        centerPulseString = new QLabel(tr("Center"));
40
        lowPulseString = new QLabel(tr("Bank Left"));
41
    } else if (type == ELEVATOR) {
42
        highPulseString = new QLabel(tr("Nose Up"));
43
        centerPulseString = new QLabel(tr("Center"));
44
        lowPulseString = new QLabel(tr("Nose Down"));
45
    } else if (type == RUDDER) {
46
        highPulseString = new QLabel(tr("Nose Right"));
47
        centerPulseString = new QLabel(tr("Center"));
48
        lowPulseString = new QLabel(tr("Nose Left"));
49
    } else {
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
        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);

72
    this->setLayout(grid);
73 74 75 76 77 78 79 80

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

void AirfoilServoCalibrator::setHigh()
{
81
    highPulseWidth->setText(QString::number(logExtrema()));
82
    emit setpointChanged(2, logExtrema());
83 84 85 86
}

void AirfoilServoCalibrator::setCenter()
{
87
    centerPulseWidth->setText(QString::number(logAverage()));
88
    emit setpointChanged(1, logAverage());
89 90
}

91
void AirfoilServoCalibrator::setLow()
92
{
93
    lowPulseWidth->setText(QString::number(logExtrema()));
94
    emit setpointChanged(0, logExtrema());
95
}
96

97
void AirfoilServoCalibrator::set(const QVector<uint16_t> &data)
98
{
99
    if (data.size() == 3) {
100 101 102 103 104
        lowPulseWidth->setText(QString::number(data[0]));
        centerPulseWidth->setText(QString::number(data[1]));
        highPulseWidth->setText(QString::number(data[2]));
    }
}