Browse Source

Currently testing parameter write, close to completely working, created beta release binary from this state

QGC4.4
pixhawk 15 years ago
parent
commit
f80441e4a7
  1. 7
      mavground.qrc
  2. 9
      src/Core.cc
  3. 3
      src/comm/MAVLinkSimulationLink.cc
  4. 4
      src/comm/MAVLinkXMLParser.cc
  5. 29
      src/uas/UAS.cc
  6. 9
      src/uas/UAS.h
  7. 9
      src/uas/UASInterface.h
  8. 71
      src/ui/ParameterInterface.cc
  9. 9
      src/ui/ParameterInterface.h
  10. 25
      src/ui/ParameterInterface.ui
  11. 86
      src/ui/QGCParamWidget.cc
  12. 27
      src/ui/QGCParamWidget.h

7
mavground.qrc

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/" >
<qresource prefix="/">
<file>images/control/launch.svg</file>
<file>images/status/dialog-error.svg</file>
<file>images/status/dialog-warning.svg</file>
@ -78,8 +78,9 @@ @@ -78,8 +78,9 @@
<file>images/style-mission.css</file>
<file>images/splash.png</file>
<file>audio/alert.wav</file>
<file>demo-log.txt</file>
</qresource>
<qresource prefix="/general" >
<file alias="vera.ttf" >images/Vera.ttf</file>
<qresource prefix="/general">
<file alias="vera.ttf">images/Vera.ttf</file>
</qresource>
</RCC>

9
src/Core.cc

@ -132,14 +132,9 @@ Core::Core(int &argc, char* argv[]) : QApplication(argc, argv) @@ -132,14 +132,9 @@ Core::Core(int &argc, char* argv[]) : QApplication(argc, argv)
}
}
MAVLinkSimulationLink* simulationLink = new MAVLinkSimulationLink(MG::DIR::getSupportFilesDirectory() + "/demo-log.txt");
// MAVLinkSimulationLink* simulationLink = new MAVLinkSimulationLink(MG::DIR::getSupportFilesDirectory() + "/demo-log.txt");
MAVLinkSimulationLink* simulationLink = new MAVLinkSimulationLink(":/demo-log.txt");
mainWindow->addLink(simulationLink);
//CommConfigurationWindow* simulationWidget = new CommConfigurationWindow(simulationLink, mavlink, this);
//ui.menuNetwork->addAction(commWidget->getAction());
//simulationLink->connect();
}
/**

3
src/comm/MAVLinkSimulationLink.cc

@ -550,6 +550,7 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size) @@ -550,6 +550,7 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size)
break;
case MAVLINK_MSG_ID_PARAM_REQUEST_LIST:
{
qDebug() << "GCS REQUESTED PARAM LIST FROM SIMULATION";
mavlink_param_request_list_t read;
mavlink_msg_param_request_list_decode(&msg, &read);
if (read.target_system == systemId)
@ -579,6 +580,8 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size) @@ -579,6 +580,8 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size)
//add data into datastream
memcpy(stream+streampointer,buffer, bufferlength);
streampointer+=bufferlength;
qDebug() << "SIMULATION SENT PARAMETERS TO GCS";
}
}
}

4
src/comm/MAVLinkXMLParser.cc

@ -91,6 +91,7 @@ bool MAVLinkXMLParser::generate() @@ -91,6 +91,7 @@ bool MAVLinkXMLParser::generate()
QString commentContainer = "/**\n * @brief Send a %1 message\n *\n%2 * @return length of the message in bytes (excluding serial stream start sign)\n */\n";
QString commentEntry = " * @param %1 %2\n";
QString idDefine = QString("#define MAVLINK_MSG_ID_%1 %2").arg(messageName.toUpper(), QString::number(messageId));
QString arrayDefines = "";
QString cStructName = QString("mavlink_%1_t").arg(messageName);
QString cStruct = "typedef struct __%1 \n{\n%2\n} %1;";
QString cStructLines = "";
@ -137,6 +138,7 @@ bool MAVLinkXMLParser::generate() @@ -137,6 +138,7 @@ bool MAVLinkXMLParser::generate()
packLines += QString("\ti += put_%1_by_index(%2, %3, i, msg->payload); //%4\n").arg(arrayType, fieldName, QString::number(arrayLength), e2.text());
// Add decode function for this type
decodeLines += QString("\tmavlink_msg_%1_get_%2(msg, %1->%2);\n").arg(messageName, fieldName);
arrayDefines += QString("#define MAVLINK_MSG_%1_FIELD_%2_LEN %3").arg(messageName.toUpper(), fieldName.toUpper(), QString::number(arrayLength));
}
else
// Handle simple types like integers and floats
@ -206,7 +208,7 @@ bool MAVLinkXMLParser::generate() @@ -206,7 +208,7 @@ bool MAVLinkXMLParser::generate()
encode = encode.arg(messageName).arg(cStructName).arg(packArguments);
decode = decode.arg(messageName).arg(cStructName).arg(decodeLines);
compactSend = compactSend.arg(channelType, messageType, messageName, sendArguments, packParameters);
QString cFile = "// MESSAGE " + messageName.toUpper() + " PACKING\n\n" + idDefine + "\n\n" + cStruct + "\n\n" + commentContainer.arg(messageName.toLower(), commentLines) + pack + encode + "\n" + compactSend + "\n" + "// MESSAGE " + messageName.toUpper() + " UNPACKING\n\n" + unpacking + decode;
QString cFile = "// MESSAGE " + messageName.toUpper() + " PACKING\n\n" + idDefine + "\n\n" + cStruct + "\n\n" + arrayDefines + "\n\n" + commentContainer.arg(messageName.toLower(), commentLines) + pack + encode + "\n" + compactSend + "\n" + "// MESSAGE " + messageName.toUpper() + " UNPACKING\n\n" + unpacking + decode;
cFiles.append(qMakePair(QString("mavlink_msg_%1.h").arg(messageName), cFile));
}
}

29
src/uas/UAS.cc

@ -154,6 +154,9 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) @@ -154,6 +154,9 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message)
case MAV_MODE_AUTO:
mode = "AUTO MODE";
break;
case MAV_MODE_GUIDED:
mode = "GUIDED MODE";
break;
case MAV_MODE_READY:
mode = "READY";
break;
@ -547,7 +550,31 @@ void UAS::requestWaypoints() @@ -547,7 +550,31 @@ void UAS::requestWaypoints()
void UAS::requestParameters()
{
mavlink_message_t msg;
mavlink_msg_param_request_list_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg);
mavlink_msg_param_request_list_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, this->getUASID(), 0);
sendMessage(msg);
}
void UAS::writeParameters()
{
mavlink_message_t msg;
}
void UAS::setParameter(int component, QString id, float value)
{
mavlink_message_t msg;
mavlink_param_set_t p;
p.param_value = value;
p.target_system = uasId;
p.target_component = component;
// Copy string into buffer, ensuring not to exceed the buffer size
char* s = (char*)id.toStdString().c_str();
for (int i = 0; (i < id.length() && i < sizeof(p.param_id)); i++)
{
p.param_id[i] = *s;
}
mavlink_msg_param_set_encode(mavlink->getSystemId(), mavlink->getComponentId(), &msg, &p);
sendMessage(msg);
}

9
src/uas/UAS.h

@ -51,7 +51,8 @@ public: @@ -51,7 +51,8 @@ public:
UAS(MAVLinkProtocol* protocol, int id = 0);
~UAS();
enum BatteryType {
enum BatteryType
{
NICD = 0,
NIMH = 1,
LIION = 2,
@ -187,6 +188,12 @@ public slots: @@ -187,6 +188,12 @@ public slots:
/** @brief Set current mode of operation, e.g. auto or manual */
void setMode(int mode);
/** @brief Set a system parameter */
void setParameter(int component, QString id, float value);
/** @brief Write parameters to permanent storage */
void writeParameters();
signals:
/** @brief The main/battery voltage has changed/was updated */

9
src/uas/UASInterface.h

@ -173,6 +173,15 @@ public slots: @@ -173,6 +173,15 @@ public slots:
virtual void clearWaypointList() = 0;
/** @brief Request all onboard parameters of all components */
virtual void requestParameters() = 0;
/** @brief Write parameter to permanent storage */
virtual void writeParameters() = 0;
/** @brief Set a system parameter
* @param component ID of the system component to write the parameter to
* @param id String identifying the parameter
* @warning The length of the ID string is limited by the MAVLink format! Take care to not exceed it
* @param value Value of the parameter, IEEE 754 single precision floating point
*/
virtual void setParameter(int component, QString id, float value) = 0;
/**
* @brief Add a link to the list of current links

71
src/ui/ParameterInterface.cc

@ -17,7 +17,6 @@ ParameterInterface::ParameterInterface(QWidget *parent) : @@ -17,7 +17,6 @@ ParameterInterface::ParameterInterface(QWidget *parent) :
// Setup UI connections
connect(m_ui->vehicleComboBox, SIGNAL(activated(int)), this, SLOT(selectUAS(int)));
connect(m_ui->readParamsButton, SIGNAL(clicked()), this, SLOT(requestParameterList()));
// Setup MAV connections
connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*)));
@ -51,78 +50,8 @@ void ParameterInterface::addUAS(UASInterface* uas) @@ -51,78 +50,8 @@ void ParameterInterface::addUAS(UASInterface* uas)
curr = uas->getUASID();
qDebug() << "first widget";
}
// Connect signals
connect(uas, SIGNAL(parameterChanged(int,int,QString,float)), this, SLOT(addParameter(int,int,QString,float)));
}
void ParameterInterface::requestParameterList()
{
UASInterface* mav;
QGCParamWidget* widget = paramWidgets->value(curr);
if (widget != NULL)
{
mav = widget->getUAS();
mav->requestParameters();
// Clear view
widget->clear();
}
}
/**
*
* @param uas System which has the component
* @param component id of the component
* @param componentName human friendly name of the component
*/
void ParameterInterface::addComponent(int uas, int component, QString componentName)
{
QGCParamWidget* widget = paramWidgets->value(uas);
if (widget != NULL)
{
widget->addComponent(component, componentName);
}
}
void ParameterInterface::addParameter(int uas, int component, QString parameterName, float value)
{
QGCParamWidget* widget = paramWidgets->value(uas);
if (widget != NULL)
{
widget->addParameter(component, parameterName, value);
}
}
/**
* @param uas system
* @param component the subsystem which has the parameter
* @param parameterName name of the parameter, as delivered by the system
* @param value value of the parameter
*/
void ParameterInterface::setParameter(UASInterface* uas, int component, QString parameterName, float value)
{
Q_UNUSED(uas);
}
/**
* @param
*/
void ParameterInterface::commitParameter(UASInterface* uas, int component, QString parameterName, float value)
{
}
/*
void ParameterInterface::commitParameters(UASInterface* uas)
{
}*/
/**
*
*/
void ParameterInterface::changeEvent(QEvent *e)
{
switch (e->type()) {

9
src/ui/ParameterInterface.h

@ -2,9 +2,7 @@ @@ -2,9 +2,7 @@
#define PARAMETERINTERFACE_H
#include <QtGui/QWidget>
#include <QtGui/QTreeView>
#include <QtGui/QTreeWidget>
#include <QtGui/QTreeWidgetItem>
#include "ui_ParameterInterface.h"
#include "UASInterface.h"
#include "ParamTreeModel.h"
@ -23,11 +21,6 @@ public: @@ -23,11 +21,6 @@ public:
public slots:
void addUAS(UASInterface* uas);
void selectUAS(int index);
void addComponent(int uas, int component, QString componentName);
void addParameter(int uas, int component, QString parameterName, float value);
void requestParameterList();
void setParameter(UASInterface* uas, int component, QString parameterName, float value);
void commitParameter(UASInterface* uas, int component, QString parameterName, float value);
protected:
virtual void changeEvent(QEvent *e);

25
src/ui/ParameterInterface.ui

@ -110,31 +110,10 @@ @@ -110,31 +110,10 @@
</property>
</widget>
</item>
<item row="0" column="2" colspan="2">
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="vehicleComboBox"/>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="readParamsButton">
<property name="text">
<string>Read</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QPushButton" name="writeParamsButton">
<property name="text">
<string>Write permanently</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="backupParamsButton">
<property name="text">
<string>Backup</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<item row="1" column="0" colspan="3">
<widget class="QStackedWidget" name="stackedWidget">
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout"/>

86
src/ui/QGCParamWidget.cc

@ -1,26 +1,41 @@ @@ -1,26 +1,41 @@
#include <QHBoxLayout>
#include <QGridLayout>
#include <QPushButton>
#include "QGCParamWidget.h"
#include "UASInterface.h"
#include <QDebug>
QGCParamWidget::QGCParamWidget(UASInterface* uas, QWidget *parent) :
QWidget(parent),
mav(uas),
components(new QMap<int, QTreeWidgetItem*>())
QWidget(parent),
mav(uas),
components(new QMap<int, QTreeWidgetItem*>())
{
// Create tree widget
tree = new QTreeWidget(this);
tree->setColumnWidth(0, 150);
// Set tree widget as widget onto this component
QHBoxLayout* horizontalLayout;
QGridLayout* horizontalLayout;
//form->setAutoFillBackground(false);
horizontalLayout = new QHBoxLayout(this);
horizontalLayout->setSpacing(0);
horizontalLayout = new QGridLayout(this);
horizontalLayout->setSpacing(6);
horizontalLayout->setMargin(0);
horizontalLayout->setSizeConstraint(QLayout::SetMinimumSize);
horizontalLayout->addWidget(tree);
horizontalLayout->addWidget(tree, 0, 0, 1, 3);
QPushButton* readButton = new QPushButton(tr("Read"));
connect(readButton, SIGNAL(clicked()), this, SLOT(requestParameterList()));
horizontalLayout->addWidget(readButton, 1, 0);
QPushButton* setButton = new QPushButton(tr("Set (RAM)"));
connect(setButton, SIGNAL(clicked()), this, SLOT(setParameters()));
horizontalLayout->addWidget(setButton, 1, 1);
QPushButton* writeButton = new QPushButton(tr("Write (Disk)"));
connect(writeButton, SIGNAL(clicked()), this, SLOT(writeParameters()));
horizontalLayout->addWidget(writeButton, 1, 2);
// Set layout
this->setLayout(horizontalLayout);
// Set header
@ -29,6 +44,11 @@ QGCParamWidget::QGCParamWidget(UASInterface* uas, QWidget *parent) : @@ -29,6 +44,11 @@ QGCParamWidget::QGCParamWidget(UASInterface* uas, QWidget *parent) :
headerItems.append("Value");
tree->setHeaderLabels(headerItems);
tree->setColumnCount(2);
// Connect signals/slots
connect(this, SIGNAL(parameterChanged(int,QString,float)), mav, SLOT(setParameter(int,QString,float)));
// New parameters from UAS
connect(uas, SIGNAL(parameterChanged(int,int,QString,float)), this, SLOT(addParameter(int,int,QString,float)));
}
UASInterface* QGCParamWidget::getUAS()
@ -42,8 +62,9 @@ UASInterface* QGCParamWidget::getUAS() @@ -42,8 +62,9 @@ UASInterface* QGCParamWidget::getUAS()
* @param component id of the component
* @param componentName human friendly name of the component
*/
void QGCParamWidget::addComponent(int component, QString componentName)
void QGCParamWidget::addComponent(int uas, int component, QString componentName)
{
Q_UNUSED(uas);
QStringList list;
list.append(componentName);
list.append(QString::number(component));
@ -58,8 +79,14 @@ void QGCParamWidget::addComponent(int component, QString componentName) @@ -58,8 +79,14 @@ void QGCParamWidget::addComponent(int component, QString componentName)
}
}
void QGCParamWidget::addParameter(int component, QString parameterName, float value)
/**
* @param uas System which has the component
* @param component id of the component
* @param parameterName human friendly name of the parameter
*/
void QGCParamWidget::addParameter(int uas, int component, QString parameterName, float value)
{
Q_UNUSED(uas);
// Insert parameter into map
//tree->appendParam(component, parameterName, value);
QStringList plist;
@ -70,12 +97,49 @@ void QGCParamWidget::addParameter(int component, QString parameterName, float va @@ -70,12 +97,49 @@ void QGCParamWidget::addParameter(int component, QString parameterName, float va
// Get component
if (!components->contains(component))
{
addComponent(component, "Component #" + QString::number(component));
addComponent(uas, component, "Component #" + QString::number(component));
}
components->value(component)->addChild(item);
item->setFlags(item->flags() | Qt::ItemIsEditable);
//connect(item, SIGNAL())
tree->expandAll();
tree->update();
}
void QGCParamWidget::requestParameterList()
{
mav->requestParameters();
// Clear view
clear();
}
/**
* @param component the subsystem which has the parameter
* @param parameterName name of the parameter, as delivered by the system
* @param value value of the parameter
*/
void QGCParamWidget::setParameter(int component, QString parameterName, float value)
{
}
void QGCParamWidget::setParameters()
{
//mav->setParameter(component, parameterName, value);
// Iterate through all components, through all parameters and emit them
/*QMap<int, QTreeWidgetItem>::iterator i;
for (i = components->begin(); i != components->end(); ++i)
{
int compid = i.key();
i.value()->children();
}*/
}
void QGCParamWidget::writeParameters()
{
mav->writeParameters();
}
void QGCParamWidget::clear()
{
tree->clear();

27
src/ui/QGCParamWidget.h

@ -8,22 +8,37 @@ @@ -8,22 +8,37 @@
#include "UASInterface.h"
/**
* @brief Widget to read/set onboard parameters
*/
class QGCParamWidget : public QWidget
{
Q_OBJECT
public:
explicit QGCParamWidget(UASInterface* uas, QWidget *parent = 0);
/** @brief Get the UAS of this widget */
UASInterface* getUAS();
signals:
void parameterChanged(int component, QString parametername, float value);
public slots:
void addComponent(int component, QString componentName);
void addParameter(int component, QString parameterName, float value);
/** @brief Add a component to the list */
void addComponent(int uas, int component, QString componentName);
/** @brief Add a parameter to the list */
void addParameter(int uas, int component, QString parameterName, float value);
/** @brief Request list of parameters from MAV */
void requestParameterList();
/** @brief Set one parameter, changes value in RAM of MAV */
void setParameter(int component, QString parameterName, float value);
/** @brief Set all parameters, changes the value in RAM of MAV */
void setParameters();
/** @brief Write the current parameters to permanent storage (EEPROM/HDD) */
void writeParameters();
/** @brief Clear the parameter list */
void clear();
protected:
UASInterface* mav;
QTreeWidget* tree;
QMap<int, QTreeWidgetItem*>* components;
UASInterface* mav; ///< The MAV this widget is controlling
QTreeWidget* tree; ///< The parameter tree
QMap<int, QTreeWidgetItem*>* components; ///< The list of components
};

Loading…
Cancel
Save