RadioCalibrationWindow.cc 4.91 KB
Newer Older
1 2 3
#include "RadioCalibrationWindow.h"

RadioCalibrationWindow::RadioCalibrationWindow(QWidget *parent) :
4 5
        QWidget(parent, Qt::Window),
        radio(new RadioCalibrationData())
6
{
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    QGridLayout *grid = new QGridLayout();

    aileron = new AirfoilServoCalibrator(AirfoilServoCalibrator::AILERON);
    grid->addWidget(aileron, 0, 0, 1, 1, Qt::AlignTop);

    elevator = new AirfoilServoCalibrator(AirfoilServoCalibrator::ELEVATOR);
    grid->addWidget(elevator, 0, 1, 1, 1, Qt::AlignTop);

    rudder = new AirfoilServoCalibrator(AirfoilServoCalibrator::RUDDER);
    grid->addWidget(rudder, 0, 2, 1, 1, Qt::AlignTop);

    gyro = new SwitchCalibrator(tr("Gyro Mode/Gain"));
    grid->addWidget(gyro, 0, 3, 1, 1, Qt::AlignTop);


    pitch = new CurveCalibrator(tr("Collective Pitch"));
    grid->addWidget(pitch, 1, 0, 1, 2);

    throttle = new CurveCalibrator(tr("Throttle"));
    grid->addWidget(throttle, 1, 2, 1, 2);

28 29
    /* Buttons for loading/transmitting calibration data */
    QHBoxLayout *hbox = new QHBoxLayout();
30 31 32 33 34 35 36 37 38
    QPushButton *load = new QPushButton(tr("Load File"));
    QPushButton *save = new QPushButton(tr("Save File"));
    QPushButton *transmit = new QPushButton(tr("Transmit to UAV"));
    QPushButton *get = new QPushButton(tr("Get from UAV"));
    hbox->addWidget(load);
    hbox->addWidget(save);
    hbox->addWidget(transmit);
    hbox->addWidget(get);
    grid->addLayout(hbox, 2, 0, 1, 4);
39
    this->setLayout(grid);
40 41 42 43 44 45 46

    connect(load, SIGNAL(clicked()), this, SLOT(loadFile()));
    connect(save, SIGNAL(clicked()), this, SLOT(saveFile()));
    connect(transmit, SIGNAL(clicked()), this, SLOT(send()));
    connect(get, SIGNAL(clicked()), this, SLOT(receive()));

    setUASId(0);
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
}

void RadioCalibrationWindow::setChannel(int ch, float raw, float normalized)
{
    /** this expects a particular channel to function mapping
       \todo allow run-time channel mapping
       */
    switch (ch)
    {
    case 0:
        aileron->channelChanged(raw);
        break;
    case 1:
        elevator->channelChanged(raw);
        break;
    case 2:
        throttle->channelChanged(raw);
        break;
    case 3:
        rudder->channelChanged(raw);
        break;
    case 4:
        gyro->channelChanged(raw);
        break;
    case 5:
        pitch->channelChanged(raw);
        break;


    }
77
}
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115


/*
  ** RadioCalibrationData Function Definitions **
*/

RadioCalibrationWindow::RadioCalibrationData::RadioCalibrationData(RadioCalibrationWindow *parent)
    :parent(parent)
{
    data = new QVector<QVector<float> >();
}

RadioCalibrationWindow::RadioCalibrationData::RadioCalibrationData(const QVector<float> &aileron,
                                                                   const QVector<float> &elevator,
                                                                   const QVector<float> &rudder,
                                                                   const QVector<float> &gyro,
                                                                   const QVector<float> &pitch,
                                                                   const QVector<float> &throttle,
                                                                   RadioCalibrationWindow *parent)
                                                                       :parent(parent)
{
    data = new QVector<QVector<float> >();
    (*data) << aileron
            << elevator
            << rudder
            << gyro
            << pitch
            << throttle;
}

RadioCalibrationWindow::RadioCalibrationData::RadioCalibrationData(RadioCalibrationData &other)
    :parent(other.parent)
{
    data = new QVector<QVector<float> >(*other.data);
}

void RadioCalibrationWindow::RadioCalibrationData::saveFile()
{
116
    qDebug() << __FILE__ << __LINE__ << "SAVE TO FILE";
117 118 119 120
}

void RadioCalibrationWindow::RadioCalibrationData::loadFile()
{
121
    qDebug() << __FILE__ << __LINE__ << "LOAD FROM FILE";
122 123 124 125
}

void RadioCalibrationWindow::RadioCalibrationData::send()
{    
126 127 128
    qDebug() << __FILE__ << __LINE__ << "uasId = " << uasId;
#ifdef MAVLINK_ENABLED_UALBERTA_MESSAGES
    UAS *uas = dynamic_cast<UAS*>(UASManager::instance()->getUASForId(uasId));
129 130 131 132 133 134 135 136 137 138 139
    if (uas)
    {
        qDebug()<< "we have a uas";
        mavlink_message_t msg;
        mavlink_msg_radio_calibration_pack(uasId, 0, &msg,
                                           (*data)[AILERON].constData(),
                                           (*data)[ELEVATOR].constData(),
                                           (*data)[RUDDER].constData(),
                                           (*data)[GYRO].constData(),
                                           (*data)[PITCH].constData(),
                                           (*data)[THROTTLE].constData());
140
        uas->sendMessage(msg);
141 142 143 144 145 146 147

    }
#endif
}

void RadioCalibrationWindow::RadioCalibrationData::receive()
{
148
    qDebug() << __FILE__ << __LINE__ << "READ FROM UAV";
149 150 151 152
}

void RadioCalibrationWindow::RadioCalibrationData::setUASId(int id)
{
153
    this->uasId = id;
154
}