Newer
Older
// On Windows (for VS2010) stdint.h contains the limits normally contained in limits.h
// It also needs the __STDC_LIMIT_MACROS macro defined in order to include them (done
// in qgroundcontrol.pri).
#ifdef WIN32
#include <stdint.h>
#else
#include <limits.h>
#endif
#include <QTimer>
#include <QDir>
#include <QXmlStreamReader>
#include <QMessageBox>
#include "QGCPX4VehicleConfig.h"
#include "QGC.h"
#include "QGCToolWidget.h"
#include "ui_QGCPX4VehicleConfig.h"
#include "px4_configuration/QGCPX4AirframeConfig.h"
#include "px4_configuration/QGCPX4SensorCalibration.h"
#include "px4_configuration/PX4RCCalibration.h"
#define WIDGET_INDEX_FIRMWARE 0
#define WIDGET_INDEX_RC 1
#define WIDGET_INDEX_SENSOR_CAL 2
#define WIDGET_INDEX_AIRFRAME_CONFIG 3
#define WIDGET_INDEX_GENERAL_CONFIG 4
#define WIDGET_INDEX_ADV_CONFIG 5
#define MIN_PWM_VAL 800
#define MAX_PWM_VAL 2200
QGCPX4VehicleConfig::QGCPX4VehicleConfig(QWidget *parent) :
QWidget(parent),
mav(NULL),
px4AirframeConfig(NULL),
planeBack(":/files/images/px4/rc/cessna_back.png"),
planeSide(":/files/images/px4/rc/cessna_side.png"),
ui(new Ui::QGCPX4VehicleConfig)
{
doneLoadingConfig = false;
setObjectName("QGC_VEHICLECONFIG");
ui->setupUi(this);
Lorenz Meier
committed
ui->advancedMenuButton->setEnabled(false);
ui->airframeMenuButton->setEnabled(false);
ui->sensorMenuButton->setEnabled(false);
ui->rcMenuButton->setEnabled(false);
px4AirframeConfig = new QGCPX4AirframeConfig(this);
ui->airframeLayout->addWidget(px4AirframeConfig);
px4SensorCalibration = new QGCPX4SensorCalibration(this);
ui->sensorLayout->addWidget(px4SensorCalibration);
px4RCCalibration = new PX4RCCalibration(this);
ui->rcLayout->addWidget(px4RCCalibration);
PX4FirmwareUpgrade* firmwareUpgrade = new PX4FirmwareUpgrade(this);
ui->firmwareLayout->addWidget(firmwareUpgrade);
connect(ui->rcMenuButton,SIGNAL(clicked()),
this,SLOT(rcMenuButtonClicked()));
connect(ui->sensorMenuButton,SIGNAL(clicked()),
this,SLOT(sensorMenuButtonClicked()));
Lorenz Meier
committed
connect(ui->flightModeMenuButton, SIGNAL(clicked()),
this, SLOT(flightModeMenuButtonClicked()));
connect(ui->safetyConfigButton, SIGNAL(clicked()),
this, SLOT(safetyConfigMenuButtonClicked()));
connect(ui->tuningMenuButton,SIGNAL(clicked()),
this,SLOT(tuningMenuButtonClicked()));
connect(ui->advancedMenuButton,SIGNAL(clicked()),
this,SLOT(advancedMenuButtonClicked()));
connect(ui->airframeMenuButton, SIGNAL(clicked()),
this, SLOT(airframeMenuButtonClicked()));
connect(ui->firmwareMenuButton, SIGNAL(clicked()),
this, SLOT(firmwareMenuButtonClicked()));
//TODO connect buttons here to save/clear actions?
UASInterface* tmpMav = UASManager::instance()->getActiveUAS();
if (tmpMav) {
ui->pendingCommitsWidget->initWithUAS(tmpMav);
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)),
this, SLOT(setActiveUAS(UASInterface*)));
QGCPX4VehicleConfig::~QGCPX4VehicleConfig()
{
delete ui;
}
void QGCPX4VehicleConfig::rcMenuButtonClicked()
{
Lorenz Meier
committed
ui->stackedWidget->setCurrentWidget(ui->rcTab);
}
void QGCPX4VehicleConfig::sensorMenuButtonClicked()
{
Lorenz Meier
committed
ui->stackedWidget->setCurrentWidget(ui->sensorTab);
Lorenz Meier
committed
void QGCPX4VehicleConfig::tuningMenuButtonClicked()
{
Lorenz Meier
committed
ui->tabTitleLabel->setText(tr("Controller Tuning"));
}
void QGCPX4VehicleConfig::flightModeMenuButtonClicked()
{
ui->stackedWidget->setCurrentWidget(ui->flightModeTab);
ui->tabTitleLabel->setText(tr("Flight Mode Configuration"));
}
void QGCPX4VehicleConfig::safetyConfigMenuButtonClicked()
Lorenz Meier
committed
ui->stackedWidget->setCurrentWidget(ui->safetyConfigTab);
ui->tabTitleLabel->setText(tr("Safety Feature Configuration"));
}
void QGCPX4VehicleConfig::advancedMenuButtonClicked()
{
Lorenz Meier
committed
ui->stackedWidget->setCurrentWidget(ui->advancedTab);
ui->tabTitleLabel->setText(tr("Advanced Configuration Options"));
void QGCPX4VehicleConfig::airframeMenuButtonClicked()
{
Lorenz Meier
committed
ui->stackedWidget->setCurrentWidget(ui->airframeTab);
ui->tabTitleLabel->setText(tr("Airframe Configuration"));
}
void QGCPX4VehicleConfig::firmwareMenuButtonClicked()
{
Lorenz Meier
committed
ui->stackedWidget->setCurrentWidget(ui->firmwareTab);
void QGCPX4VehicleConfig::toggleSpektrumPairing(bool enabled)
{
Don Gagne
committed
Q_UNUSED(enabled);
if (!ui->dsm2RadioButton->isChecked() && !ui->dsmxRadioButton->isChecked()
&& !ui->dsmx8RadioButton->isChecked()) {
// Reject
QMessageBox warnMsgBox;
warnMsgBox.setText(tr("Please select a Spektrum Protocol Version"));
warnMsgBox.setInformativeText(tr("Please select either DSM2 or DSM-X\ndirectly below the pair button,\nbased on the receiver type."));
warnMsgBox.setStandardButtons(QMessageBox::Ok);
warnMsgBox.setDefaultButton(QMessageBox::Ok);
(void)warnMsgBox.exec();
UASInterface* mav = UASManager::instance()->getActiveUAS();
if (mav) {
int rxSubType;
if (ui->dsm2RadioButton->isChecked())
rxSubType = 0;
else if (ui->dsmxRadioButton->isChecked())
rxSubType = 1;
else // if (ui->dsmx8RadioButton->isChecked())
rxSubType = 2;
mav->pairRX(0, rxSubType);
}
void QGCPX4VehicleConfig::menuButtonClicked()
{
QPushButton *button = qobject_cast<QPushButton*>(sender());
if (!button)
{
return;
}
if (buttonToWidgetMap.contains(button))
{
ui->stackedWidget->setCurrentWidget(buttonToWidgetMap[button]);
}
}
void QGCPX4VehicleConfig::setActiveUAS(UASInterface* active)
{
// Hide items if NULL and abort
if (!active) {
return;
}
// Do nothing if UAS is already visible
if (mav == active)
return;
disconnect(mav, SIGNAL(parameterChanged(int,int,QString,QVariant)), this,
SLOT(parameterChanged(int,int,QString,QVariant)));
foreach(QWidget* child, ui->airframeLayout->findChildren<QWidget*>())
{
child->deleteLater();
}
// And then delete any custom tabs
foreach(QWidget* child, additionalTabs) {
child->deleteLater();
}
additionalTabs.clear();
toolWidgets.clear();
paramToWidgetMap.clear();
libParamToWidgetMap.clear();
systemTypeToParamMap.clear();
toolToBoxMap.clear();
paramTooltips.clear();
}
// Connect new system
mav = active;
paramMgr = mav->getParamManager();
ui->paramTreeWidget->setUAS(mav);
//TODO eliminate the separate RC_TYPE call
mav->requestParameter(0, "RC_TYPE");
// Connect new system
connect(mav, SIGNAL(parameterChanged(int,int,QString,QVariant)), this,
SLOT(parameterChanged(int,int,QString,QVariant)));
if (systemTypeToParamMap.contains(mav->getSystemTypeName())) {
paramToWidgetMap = systemTypeToParamMap[mav->getSystemTypeName()];
}
//Indication that we have no meta data for this system type.
qDebug() << "No parameters defined for system type:" << mav->getSystemTypeName();
paramToWidgetMap = systemTypeToParamMap[mav->getSystemTypeName()];
}
mav->getParamManager()->setParamDescriptions(paramTooltips);
}
qDebug() << "CALIBRATION!! System Type Name:" << mav->getSystemTypeName();
updateStatus(QString("Reading from system %1").arg(mav->getUASName()));
// Since a system is now connected, enable the VehicleConfig UI.
Lorenz Meier
committed
// Enable buttons
bool px4Firmware = mav->getAutopilotType() == MAV_AUTOPILOT_PX4;
ui->airframeMenuButton->setEnabled(px4Firmware);
ui->sensorMenuButton->setEnabled(px4Firmware);
ui->rcMenuButton->setEnabled(px4Firmware);
Lorenz Meier
committed
ui->advancedMenuButton->setEnabled(true);
void QGCPX4VehicleConfig::parameterChanged(int uas, int component, QString parameterName, QVariant value)
{
//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.
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();
}
qCritical() << "Widget with no box, possible memory corruption for param:" << parameterName;
}
}
else if (libParamToWidgetMap.contains(parameterName)) {
//All the library parameters
libParamToWidgetMap.value(parameterName)->setParameterValue(uas,component,parameterName,value);
if (toolToBoxMap.contains(libParamToWidgetMap.value(parameterName))) {
toolToBoxMap[libParamToWidgetMap.value(parameterName)]->show();
}
qCritical() << "Widget with no box, possible memory corruption for param:" << parameterName;
}
}
//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]);
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
// if (!found) {
// //New param type, create a QGroupBox for it.
// QWidget* parent = ui->advanceColumnContents;
// // Create the tool, attaching it to the QGroupBox
// QGCToolWidget *tool = new QGCToolWidget("", parent);
// QString tooltitle = parameterName;
// if (parameterName.split("_").size() > 1) {
// tooltitle = parameterName.split("_")[0] + "_";
// }
// tool->setTitle(tooltitle);
// tool->setObjectName(tooltitle);
// //tool->setSettings(set);
// libParamToWidgetMap.insert(parameterName,tool);
// toolWidgets.append(tool);
// tool->addParam(uas, component, parameterName, value);
// QGroupBox *box = new QGroupBox(parent);
// box->setTitle(tool->objectName());
// box->setLayout(new QVBoxLayout(box));
// box->layout()->addWidget(tool);
// libParamToWidgetMap.insert(parameterName,tool);
// toolWidgets.append(tool);
// ui->advancedColumnLayout->addWidget(box);
// toolToBoxMap[tool] = box;
// }
}
}
void QGCPX4VehicleConfig::updateStatus(const QString& str)
{
ui->advancedStatusLabel->setText(str);
ui->advancedStatusLabel->setStyleSheet("");
}
void QGCPX4VehicleConfig::updateError(const QString& str)
{
ui->advancedStatusLabel->setText(str);
ui->advancedStatusLabel->setStyleSheet(QString("QLabel { margin: 0px 2px; font: 14px; color: %1; background-color: %2; }").arg(QGC::colorDarkWhite.name()).arg(QGC::colorMagenta.name()));