From f0d818665320d6b7a2f312673317c521e37b55c5 Mon Sep 17 00:00:00 2001 From: pixhawk Date: Sun, 25 Apr 2010 15:38:05 +0200 Subject: [PATCH] Pushed implementation of parameter settings, almost done. Added many new MAVLink messages needed for interaction with IMU --- qgroundcontrol.pro | 26 ++--- src/ui/HDDisplay.cc | 13 ++- src/ui/HDDisplay.h | 3 +- src/ui/MainWindow.cc | 8 +- src/ui/ParameterInterface.cc | 16 +++ src/ui/ParameterInterface.ui | 74 ++++++------- src/ui/param/ParamTreeItem.cc | 82 +++++++++++++++ src/ui/param/ParamTreeItem.h | 61 +++++++++++ src/ui/param/ParamTreeModel.cc | 183 +++++++++++++++++++++++++++++++++ src/ui/param/ParamTreeModel.h | 63 ++++++++++++ 10 files changed, 464 insertions(+), 65 deletions(-) create mode 100644 src/ui/param/ParamTreeItem.cc create mode 100644 src/ui/param/ParamTreeItem.h create mode 100644 src/ui/param/ParamTreeModel.cc create mode 100644 src/ui/param/ParamTreeModel.h diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index f83d0db64..039068c37 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -1,30 +1,25 @@ # Include QMapControl map library - # prefer version from external directory / # from http://github.com/pixhawk/qmapcontrol/ # over bundled version in lib directory - # Version from GIT repository is preferred -#include ( "../qmapcontrol/QMapControl/QMapControl.pri" ) #{ - # Include bundled version if necessary - include(lib/QMapControl/QMapControl.pri) - message("Including bundled QMapControl version as FALLBACK. This is fine on Linux and MacOS, but not the best choice in Windows") -#} +# include ( "../qmapcontrol/QMapControl/QMapControl.pri" ) #{ +# Include bundled version if necessary +include(lib/QMapControl/QMapControl.pri) +message("Including bundled QMapControl version as FALLBACK. This is fine on Linux and MacOS, but not the best choice in Windows") +# } # Include general settings for MAVGround # necessary as last include to override any non-acceptable settings # done by the plugins above include(qgroundcontrol.pri) - # QWT plot and QExtSerial depend on paths set by qgroundcontrol.pri - # Include serial port library include(src/lib/qextserialport/qextserialport.pri) # Include QWT plotting library include(src/lib/qwt/qwt.pri) - DEPENDPATH += . \ lib/QMapControl \ lib/QMapControl/src @@ -64,7 +59,8 @@ INCLUDEPATH += src \ include/ui \ src/input \ src/lib/qmapcontrol \ - src/ui/mavlink + src/ui/mavlink \ + src/ui/param HEADERS += src/MG.h \ src/Core.h \ src/uas/UASInterface.h \ @@ -114,7 +110,9 @@ HEADERS += src/MG.h \ src/ui/MAVLinkSettingsWidget.h \ src/ui/AudioOutputWidget.h \ src/GAudioOutput.h \ - src/LogCompressor.h + src/LogCompressor.h \ + src/ui/param/ParamTreeItem.h \ + src/ui/param/ParamTreeModel.h SOURCES += src/main.cc \ src/Core.cc \ src/uas/UASManager.cc \ @@ -159,5 +157,7 @@ SOURCES += src/main.cc \ src/ui/MAVLinkSettingsWidget.cc \ src/ui/AudioOutputWidget.cc \ src/GAudioOutput.cc \ - src/LogCompressor.cc + src/LogCompressor.cc \ + src/ui/param/ParamTreeItem.cc \ + src/ui/param/ParamTreeModel.cc RESOURCES = mavground.qrc diff --git a/src/ui/HDDisplay.cc b/src/ui/HDDisplay.cc index f47b29a45..f9e326fdc 100644 --- a/src/ui/HDDisplay.cc +++ b/src/ui/HDDisplay.cc @@ -78,8 +78,8 @@ HDDisplay::HDDisplay(QStringList* plotList, QWidget *parent) : this->setMinimumWidth(100); // Refresh timer - refreshTimer->setInterval(100); - connect(refreshTimer, SIGNAL(timeout()), this, SLOT(update())); + refreshTimer->setInterval(150); // 200 Hz/5 ms + connect(refreshTimer, SIGNAL(timeout()), this, SLOT(triggerUpdate())); //connect(refreshTimer, SIGNAL(timeout()), this, SLOT(paintGL())); fontDatabase = QFontDatabase(); @@ -101,11 +101,18 @@ HDDisplay::~HDDisplay() delete m_ui; } +void HDDisplay::triggerUpdate() +{ + // Only repaint the regions necessary + QRect r = geometry(); + update(r); +} + void HDDisplay::paintEvent(QPaintEvent * event) { //paintGL(); static quint64 interval = 0; - //qDebug() << "INTERVAL:" << MG::TIME::getGroundTimeNow() - interval << __FILE__ << __LINE__; + qDebug() << "INTERVAL:" << MG::TIME::getGroundTimeNow() - interval << __FILE__ << __LINE__; interval = MG::TIME::getGroundTimeNow(); paintDisplay(); } diff --git a/src/ui/HDDisplay.h b/src/ui/HDDisplay.h index 319d38c46..65d13c522 100644 --- a/src/ui/HDDisplay.h +++ b/src/ui/HDDisplay.h @@ -59,9 +59,10 @@ public slots: void stop(); void setActiveUAS(UASInterface* uas); - protected slots: +protected slots: void paintGL(); void paintDisplay(); + void triggerUpdate(); protected: void changeEvent(QEvent *e); diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 5525d67ce..f21232ae4 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -23,7 +23,7 @@ This file is part of the PIXHAWK project /** * @file - * @brief Implementation of main application window + * @brief Implementation of class MainWindow * @author Lorenz Meier * */ @@ -208,8 +208,9 @@ void MainWindow::startVideoCapture() .arg(format)); delete videoTimer; videoTimer = new QTimer(this); - videoTimer->setInterval(40); - connect(videoTimer, SIGNAL(timeout()), this, SLOT(saveScreen())); + //videoTimer->setInterval(40); + //connect(videoTimer, SIGNAL(timeout()), this, SLOT(saveScreen())); + //videoTimer->stop(); } void MainWindow::stopVideoCapture() @@ -391,7 +392,6 @@ void MainWindow::loadPilotView() headDown1->start(); headDown2->start(); - this->show(); } diff --git a/src/ui/ParameterInterface.cc b/src/ui/ParameterInterface.cc index cdf35699d..6c16499b9 100644 --- a/src/ui/ParameterInterface.cc +++ b/src/ui/ParameterInterface.cc @@ -1,4 +1,7 @@ +#include + #include "ParameterInterface.h" +#include "ParamTreeModel.h" #include "UASManager.h" #include "ui_ParameterInterface.h" @@ -8,6 +11,19 @@ ParameterInterface::ParameterInterface(QWidget *parent) : { m_ui->setupUi(this); connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*))); + + // FIXME Testing TODO + + QString testData = "IMU\n ROLL_K_P\t0.527\n ROLL_K_I\t1.255\n PITCH_K_P\t0.621\n PITCH_K_I\t2.5545\n"; + + ParamTreeModel* model = new ParamTreeModel(testData); + + QTreeView* tree = new QTreeView(); + tree->setModel(model); + + QStackedWidget* stack = m_ui->stackedWidget; + stack->addWidget(tree); + stack->setCurrentWidget(tree); } ParameterInterface::~ParameterInterface() diff --git a/src/ui/ParameterInterface.ui b/src/ui/ParameterInterface.ui index 5661898b4..a48cac827 100644 --- a/src/ui/ParameterInterface.ui +++ b/src/ui/ParameterInterface.ui @@ -6,7 +6,7 @@ 0 0 - 349 + 350 545 @@ -17,7 +17,7 @@ - Extended Output + Activate Extended Output @@ -37,13 +37,27 @@ + + + + Send RC-values + + + + + + + Send raw controller outputs + + + - Calibration + Calibration Wizards @@ -52,7 +66,7 @@ - Start gyro calibration + Start dynamic calibration @@ -66,7 +80,7 @@ - Start mag. calibration + Start static calibration @@ -77,20 +91,6 @@ - - - - Start ACC calibration - - - - - - - Date unknown - - - @@ -113,49 +113,35 @@ - - - - Component - - - - - - - - - - - - - - - - - - - + Read - + Write permanently - + Backup + + + + + + + + diff --git a/src/ui/param/ParamTreeItem.cc b/src/ui/param/ParamTreeItem.cc new file mode 100644 index 000000000..1f42a4d3f --- /dev/null +++ b/src/ui/param/ParamTreeItem.cc @@ -0,0 +1,82 @@ +/*===================================================================== + +PIXHAWK Micro Air Vehicle Flying Robotics Toolkit + +(c) 2009, 2010 PIXHAWK PROJECT + +This file is part of the PIXHAWK project + + PIXHAWK is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + PIXHAWK is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with PIXHAWK. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Implementation of class MainWindow + * @author Lorenz Meier + * + */ + +#include + +#include "ParamTreeItem.h" + +ParamTreeItem::ParamTreeItem(const QList &data, ParamTreeItem *parent) +{ + parentItem = parent; + itemData = data; +} + +ParamTreeItem::~ParamTreeItem() +{ + qDeleteAll(childItems); +} + +void ParamTreeItem::appendChild(ParamTreeItem *item) +{ + childItems.append(item); +} + +ParamTreeItem *ParamTreeItem::child(int row) +{ + return childItems.value(row); +} + +int ParamTreeItem::childCount() const +{ + return childItems.count(); +} + +int ParamTreeItem::columnCount() const +{ + return itemData.count(); +} + +QVariant ParamTreeItem::data(int column) const +{ + return itemData.value(column); +} + +ParamTreeItem *ParamTreeItem::parent() +{ + return parentItem; +} + +int ParamTreeItem::row() const +{ + if (parentItem) + return parentItem->childItems.indexOf(const_cast(this)); + + return 0; +} diff --git a/src/ui/param/ParamTreeItem.h b/src/ui/param/ParamTreeItem.h new file mode 100644 index 000000000..db9c9a418 --- /dev/null +++ b/src/ui/param/ParamTreeItem.h @@ -0,0 +1,61 @@ +/*===================================================================== + +PIXHAWK Micro Air Vehicle Flying Robotics Toolkit + +(c) 2009, 2010 PIXHAWK PROJECT + +This file is part of the PIXHAWK project + + PIXHAWK is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + PIXHAWK is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with PIXHAWK. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Definition of class ParamTreeItem + * @author Lorenz Meier + * + */ + +#ifndef PARAMTREEITEM_H +#define PARAMTREEITEM_H + +#include +#include + +/** + * @brief One item in the onboard parameter tree + */ +class ParamTreeItem +{ +public: + ParamTreeItem(const QList &data, ParamTreeItem *parent = 0); + ~ParamTreeItem(); + + void appendChild(ParamTreeItem *child); + + ParamTreeItem *child(int row); + int childCount() const; + int columnCount() const; + QVariant data(int column) const; + int row() const; + ParamTreeItem *parent(); + +private: + QList childItems; + QList itemData; + ParamTreeItem *parentItem; +}; + +#endif // PARAMTREEITEM_H diff --git a/src/ui/param/ParamTreeModel.cc b/src/ui/param/ParamTreeModel.cc new file mode 100644 index 000000000..06762c06b --- /dev/null +++ b/src/ui/param/ParamTreeModel.cc @@ -0,0 +1,183 @@ +/*===================================================================== + +PIXHAWK Micro Air Vehicle Flying Robotics Toolkit + +(c) 2009, 2010 PIXHAWK PROJECT + +This file is part of the PIXHAWK project + + PIXHAWK is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + PIXHAWK is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with PIXHAWK. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Implementation of class ParamTreeModel + * @author Lorenz Meier + * + */ + +#include + +#include "ParamTreeItem.h" +#include "ParamTreeModel.h" + +ParamTreeModel::ParamTreeModel(const QString &data, QObject *parent) + : QAbstractItemModel(parent) +{ + QList rootData; + rootData << tr("Parameter") << tr("Value"); + rootItem = new ParamTreeItem(rootData); + setupModelData(data.split(QString("\n")), rootItem); +} + +ParamTreeModel::~ParamTreeModel() +{ + delete rootItem; +} + +int ParamTreeModel::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return static_cast(parent.internalPointer())->columnCount(); + else + return rootItem->columnCount(); +} + +QVariant ParamTreeModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role != Qt::DisplayRole) + return QVariant(); + + ParamTreeItem *item = static_cast(index.internalPointer()); + + return item->data(index.column()); +} + +Qt::ItemFlags ParamTreeModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return 0; + + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +QVariant ParamTreeModel::headerData(int section, Qt::Orientation orientation, + int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + return rootItem->data(section); + + return QVariant(); +} + +QModelIndex ParamTreeModel::index(int row, int column, const QModelIndex &parent) + const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + ParamTreeItem *parentItem; + + if (!parent.isValid()) + parentItem = rootItem; + else + parentItem = static_cast(parent.internalPointer()); + + ParamTreeItem *childItem = parentItem->child(row); + if (childItem) + return createIndex(row, column, childItem); + else + return QModelIndex(); +} + +QModelIndex ParamTreeModel::parent(const QModelIndex &index) const +{ + if (!index.isValid()) + return QModelIndex(); + + ParamTreeItem *childItem = static_cast(index.internalPointer()); + ParamTreeItem *parentItem = childItem->parent(); + + if (parentItem == rootItem) + return QModelIndex(); + + return createIndex(parentItem->row(), 0, parentItem); +} + +int ParamTreeModel::rowCount(const QModelIndex &parent) const +{ + ParamTreeItem *parentItem; + if (parent.column() > 0) + return 0; + + if (!parent.isValid()) + parentItem = rootItem; + else + parentItem = static_cast(parent.internalPointer()); + + return parentItem->childCount(); +} + +void ParamTreeModel::setupModelData(const QStringList &lines, ParamTreeItem *parent) +{ + QList parents; + QList indentations; + parents << parent; + indentations << 0; + + int number = 0; + + while (number < lines.count()) { + int position = 0; + while (position < lines[number].length()) { + if (lines[number].mid(position, 1) != " ") + break; + position++; + } + + QString lineData = lines[number].mid(position).trimmed(); + + if (!lineData.isEmpty()) { + // Read the column data from the rest of the line. + QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts); + QList columnData; + for (int column = 0; column < columnStrings.count(); ++column) + columnData << columnStrings[column]; + + if (position > indentations.last()) { + // The last child of the current parent is now the new parent + // unless the current parent has no children. + + if (parents.last()->childCount() > 0) { + parents << parents.last()->child(parents.last()->childCount()-1); + indentations << position; + } + } else { + while (position < indentations.last() && parents.count() > 0) { + parents.pop_back(); + indentations.pop_back(); + } + } + + // Append a new item to the current parent's list of children. + parents.last()->appendChild(new ParamTreeItem(columnData, parents.last())); + } + + number++; + } +} diff --git a/src/ui/param/ParamTreeModel.h b/src/ui/param/ParamTreeModel.h new file mode 100644 index 000000000..17902ec4a --- /dev/null +++ b/src/ui/param/ParamTreeModel.h @@ -0,0 +1,63 @@ +/*===================================================================== + +PIXHAWK Micro Air Vehicle Flying Robotics Toolkit + +(c) 2009, 2010 PIXHAWK PROJECT + +This file is part of the PIXHAWK project + + PIXHAWK is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + PIXHAWK is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with PIXHAWK. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Definition of class ParamParamTreeModel + * @author Lorenz Meier + * + */ + +#ifndef PARAMTREEMODEL_H +#define PARAMTREEMODEL_H + +#include +#include +#include + +class ParamTreeItem; + +class ParamTreeModel : public QAbstractItemModel +{ + Q_OBJECT + +public: + ParamTreeModel(const QString &data, QObject *parent = 0); + ~ParamTreeModel(); + + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + +private: + void setupModelData(const QStringList &lines, ParamTreeItem *parent); + + ParamTreeItem *rootItem; +}; +#endif // PARAMParamTreeModel_H -- 2.22.0