QGCPX4AirframeConfig.cc 7.86 KB
Newer Older
1 2
#include <QMessageBox>

Lorenz Meier's avatar
Lorenz Meier committed
3 4 5
#include "QGCPX4AirframeConfig.h"
#include "ui_QGCPX4AirframeConfig.h"

6 7 8
#include "UASManager.h"
#include "UAS.h"

Lorenz Meier's avatar
Lorenz Meier committed
9 10
QGCPX4AirframeConfig::QGCPX4AirframeConfig(QWidget *parent) :
    QWidget(parent),
11
    mav(NULL),
12
    selectedId(-1),
Lorenz Meier's avatar
Lorenz Meier committed
13 14 15
    ui(new Ui::QGCPX4AirframeConfig)
{
    ui->setupUi(this);
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

    // Fill the lists here manually in accordance with the list from:
    // https://github.com/PX4/Firmware/blob/master/ROMFS/px4fmu_common/init.d/rcS

    ui->planeComboBox->addItem(tr("Multiplex Easystar 1/2"), 1);
    ui->planeComboBox->addItem(tr("Hobbyking Bixler 1/2"), 10);

    connect(ui->planeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(planeSelected(int)));

    ui->flyingWingComboBox->addItem(tr("Bormatec Camflyer Q"), 1);
    ui->flyingWingComboBox->addItem(tr("Phantom FPV"), 10);

    connect(ui->flyingWingComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(flyingWingSelected(int)));

    ui->quadXComboBox->addItem(tr("Standard 10\" Quad"), 1);
    ui->quadXComboBox->addItem(tr("DJI F330 8\" Quad"), 10);

    connect(ui->quadXComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(quadXSelected(int)));

    connect(ui->quadPlusComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(quadPlusSelected(int)));

    connect(ui->hexaXComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(hexaXSelected(int)));

    connect(ui->hexaPlusComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(hexaPlusSelected(int)));

    connect(ui->octoXComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(octoXSelected(int)));

    connect(ui->octoPlusComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(octoPlusSelected(int)));

    connect(ui->hComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(hSelected(int)));

47 48 49
    ui->hComboBox->addItem(tr("TBS Discovery"), 15);
    ui->hComboBox->addItem(tr("H Custom"), 16);

50 51 52 53 54 55 56
    connect(ui->applyButton, SIGNAL(clicked()), this, SLOT(applyAndReboot()));

    connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS()));

    setActiveUAS(UASManager::instance()->getActiveUAS());
}

Lorenz Meier's avatar
Lorenz Meier committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
void QGCPX4AirframeConfig::parameterChanged(int uas, int component, QString parameterName, QVariant value)
{
    Q_UNUSED(uas);
    Q_UNUSED(component);

    if (parameterName.contains("SYS_AUTOSTART"))
    {
        int index = value.toInt();
        if (index > 0) {
            setAirframeID(index);
            ui->statusLabel->setText(tr("Onboard start script ID: #%1").arg(index));
        } else {
            ui->statusLabel->setText(tr("System not configured for autostart."));
        }
    }
}

74 75
void QGCPX4AirframeConfig::setActiveUAS(UASInterface* uas)
{
Lorenz Meier's avatar
Lorenz Meier committed
76 77 78 79
    if (mav)
    {
        disconnect(mav, SIGNAL(parameterChanged(int,int,QString,QVariant)), this, SLOT(parameterChanged(int,int,QString,QVariant)));
    }
80 81 82 83 84 85

    if (!uas)
        return;

    mav = uas;

Lorenz Meier's avatar
Lorenz Meier committed
86 87
    connect(mav, SIGNAL(parameterChanged(int,int,QString,QVariant)), this, SLOT(parameterChanged(int,int,QString,QVariant)));

88 89 90 91 92
    //connect(uas->getParamManager(), SIGNAL())
}

void QGCPX4AirframeConfig::setAirframeID(int id)
{
93
    selectedId = id;
Lorenz Meier's avatar
Lorenz Meier committed
94 95 96 97 98 99 100 101 102
    ui->statusLabel->setText(tr("Ground start script ID: #%1").arg(selectedId));

    if (id > 0 && id < 10) {
        ui->planePushButton->setChecked(true);
    }
    else if (id > 10 && id < 20)
    {
        ui->quadXPushButton->setChecked(true);
    }
103 104 105 106
}

void QGCPX4AirframeConfig::applyAndReboot()
{
107
    // Guard against the case of an edit where we didn't receive all params yet
Lorenz Meier's avatar
Lorenz Meier committed
108
    if (selectedId <= 0)
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
    {
        QMessageBox msgBox;
        msgBox.setText(tr("No airframe selected"));
        msgBox.setInformativeText(tr("Please select an airframe first."));
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setDefaultButton(QMessageBox::Ok);
        (void)msgBox.exec();

        return;
    }

    if (!mav)
        return;

    if (mav->getParamManager()->countOnboardParams() == 0 &&
            mav->getParamManager()->countPendingParams() == 0)
    {
        mav->getParamManager()->requestParameterListIfEmpty();
        QGC::SLEEP::msleep(100);
    }

    // Guard against the case of an edit where we didn't receive all params yet
    if (mav->getParamManager()->countPendingParams() > 0)
    {
        QMessageBox msgBox;
        msgBox.setText(tr("Parameter sync with UAS not yet complete"));
        msgBox.setInformativeText(tr("Please wait a few moments and retry"));
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setDefaultButton(QMessageBox::Ok);
        (void)msgBox.exec();
139 140

        return;
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    }

    QList<int> components = mav->getParamManager()->getComponentForParam("SYS_AUTOSTART");

    // Guard against multiple components responding - this will never show in practice
    if (components.count() != 1) {
        QMessageBox msgBox;
        msgBox.setText(tr("Invalid system setup detected"));
        msgBox.setInformativeText(tr("None or more than one component advertised to provide the main system configuration option. This is an invalid system setup - please check your autopilot."));
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setDefaultButton(QMessageBox::Ok);
        (void)msgBox.exec();

        return;
    }

    qDebug() << "Setting comp" << components.first() << "SYS_AUTOSTART" << (qint32)selectedId;

Lorenz Meier's avatar
Lorenz Meier committed
159 160 161
    mav->setParameter(components.first(), "SYS_AUTOSTART", (qint32)selectedId);

    //mav->getParamManager()->setParameter(components.first(), "SYS_AUTOSTART", (qint32)selectedId);
162 163

    // Send pending params
164 165
    mav->getParamManager()->sendPendingParameters(true);

166
    // Reboot
167
    mav->executeCommand(MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, 1, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0);
168 169 170 171 172 173 174 175 176 177 178
}

void QGCPX4AirframeConfig::setAutoConfig(bool enabled)
{
    if (!mav)
        return;
    mav->getParamManager()->setParameter(0, "SYS_AUTOCONFIG", (qint32) ((enabled) ? 1 : 0));
}

void QGCPX4AirframeConfig::flyingWingSelected()
{
Lorenz Meier's avatar
Lorenz Meier committed
179
    ui->flyingWingPushButton->setChecked(true);
Lorenz Meier's avatar
Lorenz Meier committed
180 181
}

182 183 184 185 186 187 188 189
void QGCPX4AirframeConfig::flyingWingSelected(int index)
{
    int system_index = ui->flyingWingComboBox->itemData(index).toInt();
    setAirframeID(system_index);
}

void QGCPX4AirframeConfig::planeSelected()
{
Lorenz Meier's avatar
Lorenz Meier committed
190
    ui->planePushButton->setChecked(true);
191 192 193 194 195
}

void QGCPX4AirframeConfig::planeSelected(int index)
{
    int system_index = ui->planeComboBox->itemData(index).toInt();
Lorenz Meier's avatar
Lorenz Meier committed
196
    planeSelected();
197 198 199 200 201 202
    setAirframeID(system_index);
}


void QGCPX4AirframeConfig::quadXSelected()
{
Lorenz Meier's avatar
Lorenz Meier committed
203
    ui->quadXPushButton->setChecked(true);
204 205 206 207 208
}

void QGCPX4AirframeConfig::quadXSelected(int index)
{
    int system_index = ui->quadXComboBox->itemData(index).toInt();
Lorenz Meier's avatar
Lorenz Meier committed
209
    quadXSelected();
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
    setAirframeID(system_index);
}

void QGCPX4AirframeConfig::quadPlusSelected()
{

}

void QGCPX4AirframeConfig::quadPlusSelected(int index)
{
    int system_index = ui->quadPlusComboBox->itemData(index).toInt();
    setAirframeID(system_index);
}

void QGCPX4AirframeConfig::hexaXSelected()
{

}

void QGCPX4AirframeConfig::hexaXSelected(int index)
{
    int system_index = ui->hexaXComboBox->itemData(index).toInt();
    setAirframeID(system_index);
}

void QGCPX4AirframeConfig::hexaPlusSelected()
{

}

void QGCPX4AirframeConfig::hexaPlusSelected(int index)
{
    int system_index = ui->hexaPlusComboBox->itemData(index).toInt();
    setAirframeID(system_index);
}

void QGCPX4AirframeConfig::octoXSelected()
{

}

void QGCPX4AirframeConfig::octoXSelected(int index)
{
    int system_index = ui->octoXComboBox->itemData(index).toInt();
    setAirframeID(system_index);
}

void QGCPX4AirframeConfig::octoPlusSelected()
{

}

void QGCPX4AirframeConfig::octoPlusSelected(int index)
{
    int system_index = ui->octoPlusComboBox->itemData(index).toInt();
    setAirframeID(system_index);
}

void QGCPX4AirframeConfig::hSelected()
{

}

void QGCPX4AirframeConfig::hSelected(int index)
{
    int system_index = ui->hComboBox->itemData(index).toInt();
    setAirframeID(system_index);
}


Lorenz Meier's avatar
Lorenz Meier committed
280 281 282 283
QGCPX4AirframeConfig::~QGCPX4AirframeConfig()
{
    delete ui;
}