Skip to content
Snippets Groups Projects
QGCVehicleConfig.cc 51 KiB
Newer Older
  • Learn to ignore specific revisions
  •         //Param recieved that we have no metadata for. Search to see if it belongs in a
            //group with some other params
    
            bool found = false;
            for (int i=0;i<toolWidgets.size();i++)
            {
                if (parameterName.startsWith(toolWidgets[i]->objectName()))
                {
    
                    //It should be grouped with this one, add it.
    
                    toolWidgets[i]->addParam(uas,component,parameterName,value);
    
                    libParamToWidgetMap->insert(parameterName,toolWidgets[i]);
    
                //New param type, create a QGroupBox for it.
    
                QGCToolWidget *tool = new QGCToolWidget("", this);
                QString tooltitle = parameterName;
                if (parameterName.split("_").size() > 1)
                {
                    tooltitle = parameterName.split("_")[0] + "_";
                }
                tool->setTitle(tooltitle);
                tool->setObjectName(tooltitle);
                //tool->setSettings(set);
                tool->addParam(uas,component,parameterName,value);
    
                libParamToWidgetMap->insert(parameterName,tool);
    
                toolWidgets.append(tool);
                QGroupBox *box = new QGroupBox(this);
                box->setTitle(tool->objectName());
                box->setLayout(new QVBoxLayout());
                box->layout()->addWidget(tool);
    
    
    
                //Make sure we have similar number of widgets on each side.
                if (ui->leftAdvancedLayout->count() > ui->rightAdvancedLayout->count())
    
                    ui->rightAdvancedLayout->addWidget(box);
    
                    ui->leftAdvancedLayout->addWidget(box);
    
    
        // Channel calibration values
        QRegExp minTpl("RC?_MIN");
        minTpl.setPatternSyntax(QRegExp::Wildcard);
        QRegExp maxTpl("RC?_MAX");
        maxTpl.setPatternSyntax(QRegExp::Wildcard);
        QRegExp trimTpl("RC?_TRIM");
        trimTpl.setPatternSyntax(QRegExp::Wildcard);
        QRegExp revTpl("RC?_REV");
        revTpl.setPatternSyntax(QRegExp::Wildcard);
    
        // Do not write the RC type, as these values depend on this
        // active onboard parameter
    
        if (minTpl.exactMatch(parameterName)) {
            bool ok;
    
            unsigned int index = parameterName.mid(2, 1).toInt(&ok) - 1;
    
            //qDebug() << "PARAM:" << parameterName << "index:" << index;
    
            {
                rcMin[index] = value.toInt();
            }
        }
    
        if (maxTpl.exactMatch(parameterName)) {
            bool ok;
    
            unsigned int index = parameterName.mid(2, 1).toInt(&ok) - 1;
            if (ok && index < chanMax)
    
            {
                rcMax[index] = value.toInt();
            }
        }
    
        if (trimTpl.exactMatch(parameterName)) {
            bool ok;
    
            unsigned int index = parameterName.mid(2, 1).toInt(&ok) - 1;
            if (ok && index < chanMax)
    
            {
                rcTrim[index] = value.toInt();
            }
        }
    
        if (revTpl.exactMatch(parameterName)) {
            bool ok;
    
            unsigned int index = parameterName.mid(2, 1).toInt(&ok) - 1;
            if (ok && index < chanMax)
    
            {
                rcRev[index] = (value.toInt() == -1) ? true : false;
    
                updateInvertedCheckboxes(index);
    
            }
        }
    
    //        mav->setParameter(0, trimTpl.arg(i), rcTrim[i]);
    //        mav->setParameter(0, maxTpl.arg(i), rcMax[i]);
    //        mav->setParameter(0, revTpl.arg(i), (rcRev[i]) ? -1 : 1);
    //    }
    
    
        if (rcTypeUpdateRequested > 0 && parameterName == QString("RC_TYPE"))
        {
            rcTypeUpdateRequested = 0;
            updateStatus(tr("Received RC type update, setting parameters based on model."));
            rcType = value.toInt();
            // Request all other parameters as well
            requestCalibrationRC();
        }
    
    
        // Order is: roll, pitch, yaw, throttle, mode sw, aux 1-3
    
        if (parameterName.contains("RC_MAP_ROLL")) {
    
            rcMapping[0] = value.toInt() - 1;
            ui->rollSpinBox->setValue(rcMapping[0]+1);
    
            rcMapping[1] = value.toInt() - 1;
            ui->pitchSpinBox->setValue(rcMapping[1]+1);
    
            rcMapping[2] = value.toInt() - 1;
            ui->yawSpinBox->setValue(rcMapping[2]+1);
    
            rcMapping[3] = value.toInt() - 1;
            ui->throttleSpinBox->setValue(rcMapping[3]+1);
    
            rcMapping[4] = value.toInt() - 1;
            ui->modeSpinBox->setValue(rcMapping[4]+1);
    
            rcMapping[5] = value.toInt() - 1;
            ui->aux1SpinBox->setValue(rcMapping[5]+1);
    
            rcMapping[6] = value.toInt() - 1;
    
            ui->aux2SpinBox->setValue(rcMapping[6]+1);
    
            rcMapping[7] = value.toInt() - 1;
    
            ui->aux3SpinBox->setValue(rcMapping[7]+1);
    
    }
    
    void QGCVehicleConfig::updateStatus(const QString& str)
    {
        ui->statusLabel->setText(str);
        ui->statusLabel->setStyleSheet("");
    }
    
    void QGCVehicleConfig::updateError(const QString& str)
    {
        ui->statusLabel->setText(str);
        ui->statusLabel->setStyleSheet(QString("QLabel { margin: 0px 2px; font: 14px; color: %1; background-color: %2; }").arg(QGC::colorDarkWhite.name()).arg(QGC::colorMagenta.name()));
    }
    
    void QGCVehicleConfig::setRCType(int type)
    {
        if (!mav) return;
    
        // XXX TODO Add handling of RC_TYPE vs non-RC_TYPE here
    
        mav->setParameter(0, "RC_TYPE", type);
        rcTypeUpdateRequested = QGC::groundTimeMilliseconds();
        QTimer::singleShot(rcTypeTimeout+100, this, SLOT(checktimeOuts()));
    }
    
    void QGCVehicleConfig::checktimeOuts()
    {
        if (rcTypeUpdateRequested > 0)
        {
            if (QGC::groundTimeMilliseconds() - rcTypeUpdateRequested > rcTypeTimeout)
            {
                updateError(tr("Setting remote control timed out - is the system connected?"));
            }
        }
    }
    
    void QGCVehicleConfig::updateView()
    {
        if (changed)
        {
    
                ui->rollSlider->setValue(rcRoll * 50 + 50);
                ui->pitchSlider->setValue(rcThrottle * 100);
                ui->yawSlider->setValue(rcYaw * 50 + 50);
                ui->throttleSlider->setValue(rcPitch * 50 + 50);
    
                ui->rollSlider->setValue(rcRoll * 50 + 50);
                ui->pitchSlider->setValue(rcPitch * 50 + 50);
                ui->yawSlider->setValue(rcYaw * 50 + 50);
                ui->throttleSlider->setValue(rcThrottle * 100);
    
                ui->rollSlider->setValue(rcYaw * 50 + 50);
                ui->pitchSlider->setValue(rcThrottle * 100);
                ui->yawSlider->setValue(rcRoll * 50 + 50);
                ui->throttleSlider->setValue(rcPitch * 50 + 50);
    
                ui->rollSlider->setValue(rcYaw * 50 + 50);
                ui->pitchSlider->setValue(rcPitch * 50 + 50);
                ui->yawSlider->setValue(rcRoll * 50 + 50);
                ui->throttleSlider->setValue(rcThrottle * 100);
            }
    
    
            ui->chanLabel->setText(QString("%1/%2").arg(rcValue[rcMapping[0]]).arg(rcRoll, 5, 'f', 2, QChar(' ')));
            ui->chanLabel_2->setText(QString("%1/%2").arg(rcValue[rcMapping[1]]).arg(rcPitch, 5, 'f', 2, QChar(' ')));
            ui->chanLabel_3->setText(QString("%1/%2").arg(rcValue[rcMapping[2]]).arg(rcYaw, 5, 'f', 2, QChar(' ')));
            ui->chanLabel_4->setText(QString("%1/%2").arg(rcValue[rcMapping[3]]).arg(rcThrottle, 5, 'f', 2, QChar(' ')));
    
    
            ui->modeSwitchSlider->setValue(rcMode * 50 + 50);
    
            ui->chanLabel_5->setText(QString("%1/%2").arg(rcValue[rcMapping[4]]).arg(rcMode, 5, 'f', 2, QChar(' ')));
    
            if (rcValue[rcMapping[5]] != UINT16_MAX) {
    
                ui->aux1Slider->setValue(rcAux1 * 50 + 50);
    
                ui->chanLabel_6->setText(QString("%1/%2").arg(rcValue[rcMapping[5]]).arg(rcAux1, 5, 'f', 2, QChar(' ')));
    
            if (rcValue[rcMapping[6]] != UINT16_MAX) {
    
                ui->aux2Slider->setValue(rcAux2 * 50 + 50);
    
                ui->chanLabel_7->setText(QString("%1/%2").arg(rcValue[rcMapping[6]]).arg(rcAux2, 5, 'f', 2, QChar(' ')));
    
            if (rcValue[rcMapping[7]] != UINT16_MAX) {
    
                ui->aux3Slider->setValue(rcAux3 * 50 + 50);
    
                ui->chanLabel_8->setText(QString("%1/%2").arg(rcValue[rcMapping[7]]).arg(rcAux3, 5, 'f', 2, QChar(' ')));
    
            } else {
                ui->chanLabel_8->setText(tr("---"));