Newer
Older
if (calibrationEnabled) {
if (val < rcMin[chan])
{
rcMin[chan] = val;
}
if (val > rcMax[chan])
{
rcMax[chan] = val;
}
Lorenz Meier
committed
}
// Raw value
rcValue[chan] = val;
// Normalized value
float normalized;
normalized = (val - rcTrim[chan])/(rcMax[chan] - rcTrim[chan]);
Lorenz Meier
committed
}
normalized = -(rcTrim[chan] - val)/(rcTrim[chan] - rcMin[chan]);
}
// Bound
normalized = qBound(-1.0f, normalized, 1.0f);
// Invert
normalized = (rcRev[chan]) ? -1.0f*normalized : normalized;
Lorenz Meier
committed
rcRoll = normalized;
rcPitch = normalized;
rcYaw = normalized;
// THROTTLE
if (rcRev[chan]) {
rcThrottle = 1.0f + normalized;
} else {
rcThrottle = normalized;
rcThrottle = qBound(0.0f, rcThrottle, 1.0f);
// MODE SWITCH
rcMode = normalized;
rcAux1 = normalized;
rcAux2 = normalized;
rcAux3 = normalized;
}
changed = true;
//qDebug() << "RC CHAN:" << chan << "PPM:" << val << "NORMALIZED:" << normalized;
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
void QGCVehicleConfig::updateInvertedCheckboxes(int index)
{
unsigned int mapindex = rcMapping[index];
switch (mapindex)
{
case 0:
ui->invertCheckBox->setChecked(rcRev[index]);
break;
case 1:
ui->invertCheckBox_2->setChecked(rcRev[index]);
break;
case 2:
ui->invertCheckBox_3->setChecked(rcRev[index]);
break;
case 3:
ui->invertCheckBox_4->setChecked(rcRev[index]);
break;
case 4:
ui->invertCheckBox_5->setChecked(rcRev[index]);
break;
case 5:
ui->invertCheckBox_6->setChecked(rcRev[index]);
break;
case 6:
ui->invertCheckBox_7->setChecked(rcRev[index]);
break;
case 7:
ui->invertCheckBox_8->setChecked(rcRev[index]);
break;
}
}
void QGCVehicleConfig::parameterChanged(int uas, int component, QString parameterName, QVariant value)
{
Q_UNUSED(uas);
Q_UNUSED(component);
Michael Carpenter
committed
if (!doneLoadingConfig)
{
//We do not want to attempt to generate any UI elements until loading of the config file is complete.
//We should re-request params later if needed, that is not implemented yet.
Michael Carpenter
committed
return;
}
if (paramToWidgetMap.contains(parameterName))
{
//Main group of parameters of the selected airframe
paramToWidgetMap.value(parameterName)->setParameterValue(uas,component,parameterName,value);
if (toolToBoxMap.contains(paramToWidgetMap.value(parameterName)))
{
toolToBoxMap[paramToWidgetMap.value(parameterName)]->show();
}
else
{
qCritical() << "Widget with no box, possible memory corruption for param:" << parameterName;
}
}
else if (libParamToWidgetMap.contains(parameterName))
Michael Carpenter
committed
{
//All the library parameters
libParamToWidgetMap.value(parameterName)->setParameterValue(uas,component,parameterName,value);
if (toolToBoxMap.contains(libParamToWidgetMap.value(parameterName)))
Michael Carpenter
committed
{
toolToBoxMap[libParamToWidgetMap.value(parameterName)]->show();
Michael Carpenter
committed
}
else
{
qCritical() << "Widget with no box, possible memory corruption for param:" << parameterName;
Michael Carpenter
committed
}
}
else
{
//Param recieved that we have no metadata for. Search to see if it belongs in a
//group with some other params
Michael Carpenter
committed
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.
Michael Carpenter
committed
toolWidgets[i]->addParam(uas,component,parameterName,value);
libParamToWidgetMap.insert(parameterName,toolWidgets[i]);
Michael Carpenter
committed
found = true;
break;
}
}
if (!found)
{
//New param type, create a QGroupBox for it.
QWidget* parent;
if (ui->advancedLeftLayout->count() > ui->advancedRightLayout->count())
{
parent = ui->advancedRightContents;
}
else
{
parent = ui->advancedLeftContents;
}
// Create the tool, attaching it to the QGroupBox
Michael Carpenter
committed
QString tooltitle = parameterName;
if (parameterName.split("_").size() > 1)
{
tooltitle = parameterName.split("_")[0] + "_";
}
John Tapsell
committed
QGCToolWidget *tool = new QGCToolWidget(tooltitle, tooltitle, parent);
Michael Carpenter
committed
//tool->setSettings(set);
libParamToWidgetMap.insert(parameterName,tool);
Michael Carpenter
committed
toolWidgets.append(tool);
tool->addParam(uas, component, parameterName, value);
QGroupBox *box = new QGroupBox(parent);
Michael Carpenter
committed
box->setTitle(tool->objectName());
box->setLayout(new QVBoxLayout(box));
Michael Carpenter
committed
box->layout()->addWidget(tool);
libParamToWidgetMap.insert(parameterName,tool);
toolWidgets.append(tool);
// Make sure we have similar number of widgets on each side.
if (ui->advancedLeftLayout->count() > ui->advancedRightLayout->count())
Michael Carpenter
committed
{
ui->advancedRightLayout->addWidget(box);
Michael Carpenter
committed
}
else
{
ui->advancedLeftLayout->addWidget(box);
Michael Carpenter
committed
}
toolToBoxMap[tool] = box;
}
Michael Carpenter
committed
}
Lorenz Meier
committed
// 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;
Bryant
committed
unsigned int index = parameterName.mid(2, 1).toInt(&ok) - 1;
//qDebug() << "PARAM:" << parameterName << "index:" << index;
Bryant
committed
if (ok && index < chanMax)
Lorenz Meier
committed
{
rcMin[index] = value.toInt();
Michael Carpenter
committed
updateMinMax();
Lorenz Meier
committed
}
}
if (maxTpl.exactMatch(parameterName)) {
bool ok;
Bryant
committed
unsigned int index = parameterName.mid(2, 1).toInt(&ok) - 1;
if (ok && index < chanMax)
Lorenz Meier
committed
{
rcMax[index] = value.toInt();
Michael Carpenter
committed
updateMinMax();
Lorenz Meier
committed
}
}
if (trimTpl.exactMatch(parameterName)) {
bool ok;
Bryant
committed
unsigned int index = parameterName.mid(2, 1).toInt(&ok) - 1;
if (ok && index < chanMax)
Lorenz Meier
committed
{
rcTrim[index] = value.toInt();
}
}
if (revTpl.exactMatch(parameterName)) {
bool ok;
Bryant
committed
unsigned int index = parameterName.mid(2, 1).toInt(&ok) - 1;
if (ok && index < chanMax)
Lorenz Meier
committed
{
rcRev[index] = (value.toInt() == -1) ? true : false;
Lorenz Meier
committed
}
}
// 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();
}
Lorenz Meier
committed
// 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);
Michael Carpenter
committed
ui->rollSpinBox->setEnabled(true);
Lorenz Meier
committed
}
if (parameterName.contains("RC_MAP_PITCH")) {
rcMapping[1] = value.toInt() - 1;
ui->pitchSpinBox->setValue(rcMapping[1]+1);
Michael Carpenter
committed
ui->pitchSpinBox->setEnabled(true);
Lorenz Meier
committed
}
if (parameterName.contains("RC_MAP_YAW")) {
rcMapping[2] = value.toInt() - 1;
ui->yawSpinBox->setValue(rcMapping[2]+1);
Michael Carpenter
committed
ui->yawSpinBox->setEnabled(true);
Lorenz Meier
committed
}
if (parameterName.contains("RC_MAP_THROTTLE")) {
rcMapping[3] = value.toInt() - 1;
ui->throttleSpinBox->setValue(rcMapping[3]+1);
Michael Carpenter
committed
ui->throttleSpinBox->setEnabled(true);
Lorenz Meier
committed
}
if (parameterName.contains("RC_MAP_MODE_SW")) {
rcMapping[4] = value.toInt() - 1;
ui->modeSpinBox->setValue(rcMapping[4]+1);
Michael Carpenter
committed
ui->modeSpinBox->setEnabled(true);
Lorenz Meier
committed
}
if (parameterName.contains("RC_MAP_AUX1")) {
rcMapping[5] = value.toInt() - 1;
ui->aux1SpinBox->setValue(rcMapping[5]+1);
Michael Carpenter
committed
ui->aux1SpinBox->setEnabled(true);
Lorenz Meier
committed
}
if (parameterName.contains("RC_MAP_AUX2")) {
rcMapping[6] = value.toInt() - 1;
ui->aux2SpinBox->setValue(rcMapping[6]+1);
Michael Carpenter
committed
ui->aux2SpinBox->setEnabled(true);
Lorenz Meier
committed
}
if (parameterName.contains("RC_MAP_AUX3")) {
rcMapping[7] = value.toInt() - 1;
ui->aux3SpinBox->setValue(rcMapping[7]+1);
Michael Carpenter
committed
ui->aux3SpinBox->setEnabled(true);
Lorenz Meier
committed
}
// Scaling
if (parameterName.contains("RC_SCALE_ROLL")) {
rcScaling[0] = value.toFloat();
Lorenz Meier
committed
}
if (parameterName.contains("RC_SCALE_PITCH")) {
rcScaling[1] = value.toFloat();
Lorenz Meier
committed
}
if (parameterName.contains("RC_SCALE_YAW")) {
rcScaling[2] = value.toFloat();
Lorenz Meier
committed
}
if (parameterName.contains("RC_SCALE_THROTTLE")) {
rcScaling[3] = value.toFloat();
Lorenz Meier
committed
}
if (parameterName.contains("RC_SCALE_MODE_SW")) {
rcScaling[4] = value.toFloat();
Lorenz Meier
committed
}
if (parameterName.contains("RC_SCALE_AUX1")) {
rcScaling[5] = value.toFloat();
Lorenz Meier
committed
}
if (parameterName.contains("RC_SCALE_AUX2")) {
rcScaling[6] = value.toFloat();
Lorenz Meier
committed
}
if (parameterName.contains("RC_SCALE_AUX3")) {
rcScaling[7] = value.toFloat();
Lorenz Meier
committed
}
}
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()));
}
Michael Carpenter
committed
void QGCVehicleConfig::updateMinMax()
{
// Order is: roll, pitch, yaw, throttle, mode sw, aux 1-3
/*ui->rollWidget->setMin(rcMin[0]);
ui->rollWidget->setMax(rcMax[0]);
ui->pitchWidget->setMin(rcMin[1]);
ui->pitchWidget->setMax(rcMax[1]);
ui->yawWidget->setMin(rcMin[2]);
ui->yawWidget->setMax(rcMax[2]);
ui->throttleWidget->setMin(rcMin[3]);
ui->throttleWidget->setMax(rcMax[3]);
ui->radio5Widget->setMin(rcMin[4]);
ui->radio5Widget->setMax(rcMax[4]);
ui->radio6Widget->setMin(rcMin[5]);
ui->radio6Widget->setMax(rcMax[5]);
ui->radio7Widget->setMin(rcMin[6]);
ui->radio7Widget->setMax(rcMax[6]);
ui->radio8Widget->setMin(rcMin[7]);
ui->radio8Widget->setMax(rcMax[7]);*/
}
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
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)
{
Lorenz Meier
committed
if (rc_mode == RC_MODE_1)
{
Michael Carpenter
committed
//ui->rollSlider->setValue(rcRoll * 50 + 50);
//ui->pitchSlider->setValue(rcThrottle * 100);
//ui->yawSlider->setValue(rcYaw * 50 + 50);
//ui->throttleSlider->setValue(rcPitch * 50 + 50);
Michael Carpenter
committed
ui->rollWidget->setValue(rcValue[0]);
ui->throttleWidget->setValue(rcValue[1]);
ui->yawWidget->setValue(rcValue[2]);
ui->pitchWidget->setValue(rcValue[3]);
ui->rollWidget->setMin(rcMin[0]);
ui->rollWidget->setMax(rcMax[0]);
ui->throttleWidget->setMin(rcMin[1]);
ui->throttleWidget->setMax(rcMax[1]);
ui->yawWidget->setMin(rcMin[2]);
ui->yawWidget->setMax(rcMax[2]);
ui->pitchWidget->setMin(rcMin[3]);
ui->pitchWidget->setMax(rcMax[3]);
Lorenz Meier
committed
}
else if (rc_mode == RC_MODE_2)
{
Michael Carpenter
committed
//ui->rollSlider->setValue(rcRoll * 50 + 50);
//ui->pitchSlider->setValue(rcPitch * 50 + 50);
//ui->yawSlider->setValue(rcYaw * 50 + 50);
//ui->throttleSlider->setValue(rcThrottle * 100);
Michael Carpenter
committed
ui->rollWidget->setValue(rcValue[0]);
ui->pitchWidget->setValue(rcValue[1]);
ui->yawWidget->setValue(rcValue[2]);
ui->throttleWidget->setValue(rcValue[3]);
ui->rollWidget->setMin(rcMin[0]);
ui->rollWidget->setMax(rcMax[0]);
ui->pitchWidget->setMin(rcMin[1]);
ui->pitchWidget->setMax(rcMax[1]);
ui->yawWidget->setMin(rcMin[2]);
ui->yawWidget->setMax(rcMax[2]);
ui->throttleWidget->setMin(rcMin[3]);
ui->throttleWidget->setMax(rcMax[3]);
Lorenz Meier
committed
}
else if (rc_mode == RC_MODE_3)
{
Michael Carpenter
committed
//ui->rollSlider->setValue(rcYaw * 50 + 50);
//ui->pitchSlider->setValue(rcThrottle * 100);
//ui->yawSlider->setValue(rcRoll * 50 + 50);
//ui->throttleSlider->setValue(rcPitch * 50 + 50);
Michael Carpenter
committed
ui->yawWidget->setValue(rcValue[0]);
ui->throttleWidget->setValue(rcValue[1]);
ui->rollWidget->setValue(rcValue[2]);
ui->pitchWidget->setValue(rcValue[3]);
ui->yawWidget->setMin(rcMin[0]);
ui->yawWidget->setMax(rcMax[0]);
ui->throttleWidget->setMin(rcMin[1]);
ui->throttleWidget->setMax(rcMax[1]);
ui->rollWidget->setMin(rcMin[2]);
ui->rollWidget->setMax(rcMax[2]);
ui->pitchWidget->setMin(rcMin[3]);
ui->pitchWidget->setMax(rcMax[3]);
Lorenz Meier
committed
}
else if (rc_mode == RC_MODE_4)
{
Michael Carpenter
committed
//ui->rollSlider->setValue(rcYaw * 50 + 50);
//ui->pitchSlider->setValue(rcPitch * 50 + 50);
//ui->yawSlider->setValue(rcRoll * 50 + 50);
//ui->throttleSlider->setValue(rcThrottle * 100);
Michael Carpenter
committed
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
ui->yawWidget->setValue(rcValue[0]);
ui->pitchWidget->setValue(rcValue[1]);
ui->rollWidget->setValue(rcValue[2]);
ui->throttleWidget->setValue(rcValue[3]);
ui->yawWidget->setMin(rcMin[0]);
ui->yawWidget->setMax(rcMax[0]);
ui->pitchWidget->setMin(rcMin[1]);
ui->pitchWidget->setMax(rcMax[1]);
ui->rollWidget->setMin(rcMin[2]);
ui->rollWidget->setMax(rcMax[2]);
ui->throttleWidget->setMin(rcMin[3]);
ui->throttleWidget->setMax(rcMax[3]);
}
else if (rc_mode == RC_MODE_NONE)
{
ui->rollWidget->setValue(rcValue[0]);
ui->pitchWidget->setValue(rcValue[1]);
ui->throttleWidget->setValue(rcValue[2]);
ui->yawWidget->setValue(rcValue[3]);
Michael Carpenter
committed
ui->rollWidget->setMin(800);
ui->rollWidget->setMax(2200);
ui->pitchWidget->setMin(800);
ui->pitchWidget->setMax(2200);
ui->throttleWidget->setMin(800);
ui->throttleWidget->setMax(2200);
ui->yawWidget->setMin(800);
ui->yawWidget->setMax(2200);
}
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(' ')));
Michael Carpenter
committed
//ui->modeSwitchSlider->setValue(rcMode * 50 + 50);
ui->chanLabel_5->setText(QString("%1/%2").arg(rcValue[rcMapping[4]]).arg(rcMode, 5, 'f', 2, QChar(' ')));
Michael Carpenter
committed
if (rcValue[rcMapping[4] != UINT16_MAX]) {
ui->radio5Widget->setValue(rcValue[4]);
ui->chanLabel_5->setText(QString("%1/%2").arg(rcValue[rcMapping[5]]).arg(rcAux1, 5, 'f', 2, QChar(' ')));
} else {
ui->chanLabel_5->setText(tr("---"));
}
if (rcValue[rcMapping[5]] != UINT16_MAX) {
Michael Carpenter
committed
//ui->aux1Slider->setValue(rcAux1 * 50 + 50);
Michael Carpenter
committed
ui->radio6Widget->setValue(rcValue[5]);
ui->chanLabel_6->setText(QString("%1/%2").arg(rcValue[rcMapping[5]]).arg(rcAux1, 5, 'f', 2, QChar(' ')));
} else {
ui->chanLabel_6->setText(tr("---"));
}
if (rcValue[rcMapping[6]] != UINT16_MAX) {
Michael Carpenter
committed
//ui->aux2Slider->setValue(rcAux2 * 50 + 50);
Michael Carpenter
committed
ui->radio7Widget->setValue(rcValue[6]);
ui->chanLabel_7->setText(QString("%1/%2").arg(rcValue[rcMapping[6]]).arg(rcAux2, 5, 'f', 2, QChar(' ')));
} else {
ui->chanLabel_7->setText(tr("---"));
}
if (rcValue[rcMapping[7]] != UINT16_MAX) {
Michael Carpenter
committed
//ui->aux3Slider->setValue(rcAux3 * 50 + 50);
Michael Carpenter
committed
ui->radio8Widget->setValue(rcValue[7]);
ui->chanLabel_8->setText(QString("%1/%2").arg(rcValue[rcMapping[7]]).arg(rcAux3, 5, 'f', 2, QChar(' ')));
} else {
ui->chanLabel_8->setText(tr("---"));
Lorenz Meier
committed
}
changed = false;
}
}