1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-27 16:54:15 +01:00
HiTL plugin tree copied and adapted for IL2 specific configuration.
The actual data bridge between IL2 and UAVObjects is still missing



git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@908 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
corvus 2010-06-27 19:18:48 +00:00 committed by corvus
parent 82aa515a52
commit 2e8271bb0f
19 changed files with 1540 additions and 0 deletions

View File

@ -0,0 +1,12 @@
<plugin name="HITLIL2" version="1.0.0" compatVersion="1.0.0">
<vendor>The OpenPilot Project</vendor>
<copyright>(C) 2010 OpenPilot Project</copyright>
<license>The GNU Public License (GPL) Version 3</license>
<description>Hardware In The Loop Simulation with IL2</description>
<url>http://www.openpilot.org</url>
<dependencyList>
<dependency name="Core" version="1.0.0"/>
<dependency name="UAVObjects" version="1.0.0"/>
<dependency name="UAVTalk" version="1.0.0"/>
</dependencyList>
</plugin>

View File

@ -0,0 +1,52 @@
/**
******************************************************************************
*
* @file hitlil2factory.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup hitlil2plugin
* @{
*
*****************************************************************************/
/*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef HITLIL2FACTORY_H
#define HITLIL2FACTORY_H
#include <coreplugin/iuavgadgetfactory.h>
namespace Core {
class IUAVGadget;
class IUAVGadgetFactory;
}
using namespace Core;
class HITLIL2Factory : public Core::IUAVGadgetFactory
{
Q_OBJECT
public:
HITLIL2Factory(QObject *parent = 0);
~HITLIL2Factory();
Core::IUAVGadget *createGadget(QWidget *parent);
IUAVGadgetConfiguration *createConfiguration(const QByteArray &state);
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
};
#endif // HITLIL2FACTORY_H

View File

@ -0,0 +1,49 @@
/**
******************************************************************************
*
* @file hitlil2.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup hitlil2plugin
* @{
*
*****************************************************************************/
/*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "hitlil2.h"
#include "hitlil2widget.h"
#include "hitlil2configuration.h"
HITLIL2::HITLIL2(QString classId, HITLIL2Widget *widget, QWidget *parent) :
IUAVGadget(classId, parent),
m_widget(widget)
{
}
HITLIL2::~HITLIL2()
{
}
void HITLIL2::loadConfiguration(IUAVGadgetConfiguration* config)
{
HITLIL2Configuration *m = qobject_cast<HITLIL2Configuration*>(config);
m_widget->setIlHostName( m->il2HostName() );
m_widget->setIl2Port( m->il2Port() );
m_widget->setIl2ManualControl( m->il2ManualControl() );
}

View File

@ -0,0 +1,56 @@
/**
******************************************************************************
*
* @file hitlil2.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup hitlil2plugin
* @{
*
*****************************************************************************/
/*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef HITLIL2_H
#define HITLIL2_H
#include <coreplugin/iuavgadget.h>
#include "hitlil2widget.h"
class IUAVGadget;
class QWidget;
class QString;
class HITLIL2Widget;
using namespace Core;
class HITLIL2 : public Core::IUAVGadget
{
Q_OBJECT
public:
HITLIL2(QString classId, HITLIL2Widget *widget, QWidget *parent = 0);
~HITLIL2();
QWidget *widget() { return m_widget; }
void loadConfiguration(IUAVGadgetConfiguration* config);
private:
HITLIL2Widget *m_widget;
};
#endif // HITLIL2_H

View File

@ -0,0 +1,22 @@
TEMPLATE = lib
TARGET = HITLIL2
QT += network
include(../../openpilotgcsplugin.pri)
include(hitlil2_dependencies.pri)
HEADERS += hitlil2plugin.h \
hitlil2widget.h \
hitlil2optionspage.h \
hitlil2factory.h \
hitlil2configuration.h \
hitlil2.h \
il2bridge.h
SOURCES += hitlil2plugin.cpp \
hitlil2widget.cpp \
hitlil2optionspage.cpp \
hitlil2factory.cpp \
hitlil2configuration.cpp \
hitlil2.cpp \
il2bridge.cpp
OTHER_FILES += HITLIL2.pluginspec
FORMS += hitlil2optionspage.ui \
hitlil2widget.ui

View File

@ -0,0 +1,4 @@
include(../../plugins/uavobjects/uavobjects.pri)
include(../../plugins/uavtalk/uavtalk.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(../../libs/utils/utils.pri)

View File

@ -0,0 +1,67 @@
/**
******************************************************************************
*
* @file hitlil2configuration.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup hitlil2plugin
* @{
*
*****************************************************************************/
/*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "hitlil2configuration.h"
#include <QtCore/QDataStream>
HITLIL2Configuration::HITLIL2Configuration(QString classId, const QByteArray &state, QObject *parent) :
IUAVGadgetConfiguration(classId, parent),
m_fgPathBin(""), m_fgPathData(""), m_fgManualControl(false)
{
if (state.count() > 0) {
QDataStream stream(state);
QString il2HostName;
int il2Port;
bool il2ManualControl;
stream >> il2HostName;
m_il2HostName = il2HostName;
stream >> il2Port;
m_il2Port = il2Port;
stream >> il2ManualControl;
m_il2ManualControl = fgManualControl;
}
}
IUAVGadgetConfiguration *HITLIL2Configuration::clone()
{
HITLIL2Configuration *m = new HITLIL2Configuration(this->classId());
m->m_il2HostName = m_il2HostName;
m->m_il2Port = m_il2Port;
m->m_il2ManualControl = m_il2ManualControl;
return m;
}
QByteArray HITLIL2Configuration::saveState() const
{
QByteArray bytes;
QDataStream stream(&bytes, QIODevice::WriteOnly);
stream << m_il2HostName;
stream << m_il2Port;
stream << m_il2ManualControl;
return bytes;
}

View File

@ -0,0 +1,68 @@
/**
******************************************************************************
*
* @file hitlil2configuration.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup hitlil2plugin
* @{
*
*****************************************************************************/
/*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef HITLIL2CONFIGURATION_H
#define HITLIL2CONFIGURATION_H
#include <coreplugin/iuavgadgetconfiguration.h>
#include <QtGui/QColor>
#include <QString>
using namespace Core;
class HITLIL2Configuration : public IUAVGadgetConfiguration
{
Q_OBJECT
Q_PROPERTY(QString m_il2HostName READ il2HostName WRITE setIl2HostName)
Q_PROPERTY(int m_il2Port READ il2Port WRITE setIl2Port)
Q_PROPERTY(bool m_il2ManualControl READ il2ManualControl WRITE setIl2ManualControl)
public:
explicit HITLIL2Configuration(QString classId, const QByteArray &state = 0, QObject *parent = 0);
QByteArray saveState() const;
IUAVGadgetConfiguration *clone();
QString il2HostName() const { return m_il2HostName; }
int il2Port() const { return m_il2Port; }
bool il2ManualControl() const { return m_il2ManualControl; }
signals:
public slots:
void setIl2HostName(QString HostName) { m_il2HostName = iHostName; }
void setIl2Port(int Port) { m_il2Port = Port; }
void setIl2ManualControl(bool val) { m_il2ManualControl = val; }
private:
QString m_il2HostName;
int m_il2Port;
bool m_il2ManualControl;
};
#endif // HITLIL2CONFIGURATION_H

View File

@ -0,0 +1,58 @@
/**
******************************************************************************
*
* @file hitlil2factory.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup hitlil2plugin
* @{
*
*****************************************************************************/
/*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "hitlil2factory.h"
#include "hitlil2widget.h"
#include "hitlil2.h"
#include "hitlil2configuration.h"
#include "hitlil2optionspage.h"
#include <coreplugin/iuavgadget.h>
HITLIL2Factory::HITLIL2Factory(QObject *parent) :
IUAVGadgetFactory(QString("HITLIL2"), tr("HITL Simulation with IL2"), parent)
{
}
HITLIL2Factory::~HITLIL2Factory()
{
}
Core::IUAVGadget* HITLIL2Factory::createGadget(QWidget *parent)
{
HITLIL2Widget* gadgetWidget = new HITLIL2Widget(parent);
return new HITLIL2(QString("HITLIL2"), gadgetWidget, parent);
}
IUAVGadgetConfiguration *HITLIL2Factory::createConfiguration(const QByteArray &state)
{
return new HITLIL2Configuration(QString("HITLIL2"), state);
}
IOptionsPage *HITLIL2Factory::createOptionsPage(IUAVGadgetConfiguration *config)
{
return new HITLIL2OptionsPage(qobject_cast<HITLIL2Configuration*>(config));
}

View File

@ -0,0 +1,66 @@
/**
******************************************************************************
*
* @file hitlil2optionspage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup hitlil2plugin
* @{
*
*****************************************************************************/
/*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "hitlil2optionspage.h"
#include "hitlil2configuration.h"
#include "ui_hitlil2optionspage.h"
HITLIL2OptionsPage::HITLIL2OptionsPage(HITLIL2Configuration *config, QObject *parent) :
IOptionsPage(parent),
m_config(config)
{
}
QWidget *HITLIL2OptionsPage::createPage(QWidget *parent)
{
// Create page
m_optionsPage = new Ui::HITLIL2OptionsPage();
QWidget* optionsPageWidget = new QWidget;
m_optionsPage->setupUi(optionsPageWidget);
// Restore the contents from the settings:
m_optionsPage->Il2Port->setValue(m_config->Il2Port());
m_optionsPage->Il2HostName->setText(m_config->Il2HostName());
m_optionsPage->il2ManualControl->setChecked(m_config->il2ManualControl());
return optionsPageWidget;
}
void HITLIL2OptionsPage::apply()
{
m_config->setIl2Port( m_optionsPage->Il2Port->value());
m_config->setIl2HostName( m_optionsPage->Il2HostName->text());
m_config->setIl2ManualControl( m_optionsPage->il2ManualControl->isChecked());
}
void HITLIL2OptionsPage::finish()
{
delete m_optionsPage;
}

View File

@ -0,0 +1,65 @@
/**
******************************************************************************
*
* @file hitlil2optionspage.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup hitlil2plugin
* @{
*
*****************************************************************************/
/*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef HITLIL2OPTIONSPAGE_H
#define HITLIL2OPTIONSPAGE_H
#include "coreplugin/dialogs/ioptionspage.h"
namespace Core {
class IUAVGadgetConfiguration;
}
class HITLIL2Configuration;
using namespace Core;
namespace Ui {
class HITLIL2OptionsPage;
}
class HITLIL2OptionsPage : public IOptionsPage
{
Q_OBJECT
public:
explicit HITLIL2OptionsPage(HITLIL2Configuration *config, QObject *parent = 0);
QWidget *createPage(QWidget *parent);
void apply();
void finish();
signals:
private slots:
private:
HITLIL2Configuration* m_config;
Ui::HITLIL2OptionsPage* m_optionsPage;
};
#endif // HITLIL2OPTIONSPAGE_H

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HITLIL2OptionsPage</class>
<widget class="QWidget" name="HITLIL2OptionsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>388</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="il2ManualControl">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Manual aircraft control (can be used when hardware is not available)</string>
</property>
<property name="text">
<string>Manual aircraft control (can be used when hardware is not available)</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QSpinBox" name="Il2Port">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999999</number>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>IL2 DeviceLink Port</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="Il2HostName"/>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>IL2 Host Name/Number</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,63 @@
/**
******************************************************************************
*
* @file hitlil2plugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup hitlil2plugin
* @{
*
*****************************************************************************/
/*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "hitlil2plugin.h"
#include "hitlil2factory.h"
#include <QtPlugin>
#include <QStringList>
#include <extensionsystem/pluginmanager.h>
HITLIL2Plugin::HITLIL2Plugin()
{
// Do nothing
}
HITLIL2Plugin::~HITLIL2Plugin()
{
// Do nothing
}
bool HITLIL2Plugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
mf = new HITLIL2Factory(this);
addAutoReleasedObject(mf);
return true;
}
void HITLIL2Plugin::extensionsInitialized()
{
// Do nothing
}
void HITLIL2Plugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(HITLIL2Plugin)

View File

@ -0,0 +1,47 @@
/**
******************************************************************************
*
* @file hitlil2plugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup hitlil2plugin
* @{
*
*****************************************************************************/
/*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef HITLIL2PLUGIN_H
#define HITLIL2PLUGIN_H
#include <extensionsystem/iplugin.h>
class HITLIL2Factory;
class HITLIL2Plugin : public ExtensionSystem::IPlugin
{
public:
HITLIL2Plugin();
~HITLIL2Plugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
private:
HITLIL2Factory *mf;
};
#endif /* HITLIL2PLUGIN_H */

View File

@ -0,0 +1,164 @@
/**
******************************************************************************
*
* @file hitlil2widget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup hitlil2plugin
* @{
*
*****************************************************************************/
/*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "hitlil2widget.h"
#include "ui_hitlil2widget.h"
#include "qxtlogger.h"
#include <QDebug>
#include "uavobjects/uavobjectmanager.h"
HITLIL2Widget::HITLIL2Widget(QWidget *parent) : QWidget(parent)
{
il2Process = NULL;
widget = new Ui_HITLIL2Widget();
widget->setupUi(this);
connect(widget->startButton, SIGNAL(clicked()), this, SLOT(startButtonClicked()));
connect(widget->stopButton, SIGNAL(clicked()), this, SLOT(stopButtonClicked()));
}
HITLIL2Widget::~HITLIL2Widget()
{
delete widget;
}
void HITLIL2Widget::startButtonClicked()
{
// Stop running process if one is active
if (il2Process != NULL)
{
stopButtonClicked();
}
// Setup process
widget->textBrowser->append(QString("Connecting to IL2 ...\n"));
// Start bridge
qxtLog->info("HITLIL2: Starting bridge, initializing IL2 and Autopilot connections");
il2Bridge = new IL2Bridge(il2HostName,il2Port);
connect(il2Bridge, SIGNAL(autopilotConnected()), this, SLOT(onAutopilotConnect()));
connect(il2Bridge, SIGNAL(autopilotDisconnected()), this, SLOT(onAutopilotDisconnect()));
connect(il2Bridge, SIGNAL(il2Connected()), this, SLOT(onFGConnect()));
connect(il2Bridge, SIGNAL(il2Disconnected()), this, SLOT(onFGDisconnect()));
// Initialize connection status
if ( il2Bridge->isAutopilotConnected() )
{
onAutopilotConnect();
}
else
{
onAutopilotDisconnect();
}
if ( il2Bridge->isFGConnected() )
{
onFGConnect();
}
else
{
onFGDisconnect();
}
}
void HITLIL2Widget::stopButtonClicked()
{
// NOTE: Does not currently work, may need to send control+c to through the terminal
if (il2Process != NULL)
{
il2Process->disconnect(this);
il2Process->kill();
delete il2Process;
il2Bridge->disconnect(this);
delete il2Bridge;
il2Process = NULL;
}
}
void HITLIL2Widget::setIl2HostName(QString il2HostName)
{
this->il2HostName = il2HostName;
}
void HITLIL2Widget::setIl2Port(int il2Port)
{
this->il2Port = il2Port;
}
void HITLIL2Widget::setFGManualControl(bool val)
{
this->il2ManualControl = val;
}
void HITLIL2Widget::processReadyRead()
{
QByteArray bytes = il2Process->readAllStandardOutput();
QString str(bytes);
if ( !str.contains("Error reading data") ) // ignore error
{
widget->textBrowser->append(str);
}
}
void HITLIL2Widget::onAutopilotConnect()
{
QPalette pal(widget->apLabel->palette());
pal.setColor(QPalette::Window, Qt::green);
widget->apLabel->setPalette(pal);
widget->apLabel->setAutoFillBackground(true);
widget->apLabel->setText("AutoPilot Connected");
qxtLog->info("HITL-IL2: Autopilot connected, initializing for HITL simulation");
}
void HITLIL2Widget::onAutopilotDisconnect()
{
QPalette pal(widget->apLabel->palette());
pal.setColor(QPalette::Window, Qt::red);
widget->apLabel->setPalette(pal);
widget->apLabel->setAutoFillBackground(true);
widget->apLabel->setText("AutoPilot Disconnected");
qxtLog->info("HITL-IL2: Autopilot disconnected");
}
void HITLIL2Widget::onIl2Connect()
{
QPalette pal(widget->il2Label->palette());
pal.setColor(QPalette::Window, Qt::green);
widget->il2Label->setPalette(pal);
widget->il2Label->setAutoFillBackground(true);
widget->il2Label->setText("IL2 Connected");
qxtLog->info("HITL-IL2: IL2 connected");
}
void HITLIL2Widget::onFGDisconnect()
{
QPalette pal(widget->il2Label->palette());
pal.setColor(QPalette::Window, Qt::red);
widget->il2Label->setPalette(pal);
widget->il2Label->setAutoFillBackground(true);
widget->il2Label->setText("IL2 Disconnected");
qxtLog->info("HITL-IL2: IL2 disconnected");
}

View File

@ -0,0 +1,67 @@
/**
******************************************************************************
*
* @file hitlwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup hitlplugin
* @{
*
*****************************************************************************/
/*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef HITLIL2WIDGET_H
#define HITLIL2WIDGET_H
#include <QtGui/QWidget>
#include "il2bridge.h"
class Ui_HITLIL2Widget;
class HITLIL2Widget : public QWidget
{
Q_OBJECT
public:
HITLIL2Widget(QWidget *parent = 0);
~HITLIL2Widget();
void setIl2HostName(QString il2HostName);
void setIl2Port(int il2Port);
void setIl2ManualControl(bool val);
public slots:
private slots:
void startButtonClicked();
void stopButtonClicked();
void processReadyRead();
void onAutopilotConnect();
void onAutopilotDisconnect();
void onIl2Connect();
void onIl2Disconnect();
private:
Ui_HITLIL2Widget* widget;
Il2Bridge* il2Bridge;
QString il2HostName;
int il2Port;
bool il2ManualControl;
};
#endif /* HITLIL2WIDGET_H */

View File

@ -0,0 +1,210 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HITLIL2Widget</class>
<widget class="QWidget" name="HITLIL2Widget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>786</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="startButton">
<property name="toolTip">
<string>Request update</string>
</property>
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="stopButton">
<property name="toolTip">
<string>Send update</string>
</property>
<property name="text">
<string>Stop</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>5</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>5</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="apLabel">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="text">
<string>AutoPilot Disconnected</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="fgLabel">
<property name="text">
<string>IL2 Disconnected</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>5</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>5</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QTextBrowser" name="textBrowser"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,294 @@
/**
******************************************************************************
*
* @file il2bridge.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup hitlplugin
* @{
*
*****************************************************************************/
/*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "il2bridge.h"
#include "extensionsystem/pluginmanager.h"
Il2Bridge::Il2Bridge(QString il2HostName, int il2Port)
{
// Init fields
il2Host = QHostAddress(il2HostName);
inPort = 0;
outPort = il2Port;
updatePeriod = 50;
il2Timeout = 2000;
autopilotConnectionStatus = false;
fgConnectionStatus = false;
// Get required UAVObjects
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager* objManager = pm->getObject<UAVObjectManager>();
actDesired = ActuatorDesired::GetInstance(objManager);
altActual = AltitudeActual::GetInstance(objManager);
attActual = AttitudeActual::GetInstance(objManager);
posActual = PositionActual::GetInstance(objManager);
telStats = GCSTelemetryStats::GetInstance(objManager);
// Listen to autopilot connection events
TelemetryManager* telMngr = pm->getObject<TelemetryManager>();
connect(telMngr, SIGNAL(connected()), this, SLOT(onAutopilotConnect()));
connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect()));
//connect(telStats, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(telStatsUpdated(UAVObject*)));
// If already connect setup autopilot
GCSTelemetryStats::DataFields stats = telStats->getData();
if ( stats.Status == GCSTelemetryStats::STATUS_CONNECTED )
{
onAutopilotConnect();
}
// Setup local ports
inSocket = new QUdpSocket(this);
outSocket = new QUdpSocket(this);
inSocket->bind(QHostAddress::Any, inPort);
connect(inSocket, SIGNAL(readyRead()), this, SLOT(receiveUpdate()));
// Setup transmit timer
txTimer = new QTimer(this);
connect(txTimer, SIGNAL(timeout()), this, SLOT(transmitUpdate()));
txTimer->setInterval(updatePeriod);
txTimer->start();
// Setup FG connection timer
fgTimer = new QTimer(this);
connect(fgTimer, SIGNAL(timeout()), this, SLOT(onFGConnectionTimeout()));
fgTimer->setInterval(fgTimeout);
fgTimer->start();
}
Il2Bridge::~Il2Bridge()
{
delete inSocket;
delete outSocket;
delete txTimer;
delete fgTimer;
}
bool Il2Bridge::isAutopilotConnected()
{
return autopilotConnectionStatus;
}
bool Il2Bridge::isFGConnected()
{
return fgConnectionStatus;
}
void Il2Bridge::transmitUpdate()
{
// Read ActuatorDesired from autopilot
ActuatorDesired::DataFields actData = actDesired->getData();
float ailerons = actData.Roll;
float elevator = -actData.Pitch;
float rudder = actData.Yaw;
float throttle = actData.Throttle;
// Send update to Il2
QString cmd;
cmd = QString("%1,%2,%3,%4\n")
.arg(ailerons)
.arg(elevator)
.arg(rudder)
.arg(throttle);
QByteArray data = cmd.toAscii();
outSocket->writeDatagram(data, fgHost, outPort);
}
void Il2Bridge::receiveUpdate()
{
// Update connection timer and status
fgTimer->setInterval(fgTimeout);
fgTimer->stop();
fgTimer->start();
if ( !fgConnectionStatus )
{
fgConnectionStatus = true;
emit fgConnected();
}
// Process data
while ( inSocket->bytesAvailable() > 0 )
{
// Receive datagram
QByteArray datagram;
datagram.resize(inSocket->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
inSocket->readDatagram(datagram.data(), datagram.size(),
&sender, &senderPort);
QString datastr(datagram);
// Process incomming data
processUpdate(datastr);
}
}
void Il2Bridge::setupObjects()
{
setupInputObject(actDesired, 75);
setupOutputObject(altActual, 250);
setupOutputObject(attActual, 75);
setupOutputObject(posActual, 250);
}
void Il2Bridge::setupInputObject(UAVObject* obj, int updatePeriod)
{
UAVObject::Metadata mdata;
mdata = obj->getDefaultMetadata();
mdata.flightAccess = UAVObject::ACCESS_READWRITE;
mdata.gcsAccess = UAVObject::ACCESS_READWRITE;
mdata.flightTelemetryAcked = false;
mdata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC;
mdata.flightTelemetryUpdatePeriod = updatePeriod;
mdata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_MANUAL;
obj->setMetadata(mdata);
}
void Il2Bridge::setupOutputObject(UAVObject* obj, int updatePeriod)
{
UAVObject::Metadata mdata;
mdata = obj->getDefaultMetadata();
mdata.flightAccess = UAVObject::ACCESS_READONLY;
mdata.gcsAccess = UAVObject::ACCESS_READWRITE;
mdata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_NEVER;
mdata.gcsTelemetryAcked = false;
mdata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC;
mdata.gcsTelemetryUpdatePeriod = updatePeriod;
obj->setMetadata(mdata);
}
void Il2Bridge::onAutopilotConnect()
{
autopilotConnectionStatus = true;
setupObjects();
emit autopilotConnected();
}
void Il2Bridge::onAutopilotDisconnect()
{
autopilotConnectionStatus = false;
emit autopilotDisconnected();
}
void Il2Bridge::onFGConnectionTimeout()
{
if ( fgConnectionStatus )
{
fgConnectionStatus = false;
emit fgDisconnected();
}
}
void Il2Bridge::processUpdate(QString& data)
{
// Split
QStringList fields = data.split(",");
// Get xRate (deg/s)
float xRate = fields[0].toFloat() * 180.0/M_PI;
// Get yRate (deg/s)
float yRate = fields[1].toFloat() * 180.0/M_PI;
// Get zRate (deg/s)
float zRate = fields[2].toFloat() * 180.0/M_PI;
// Get xAccel (m/s^2)
float xAccel = fields[3].toFloat() * FT2M;
// Get yAccel (m/s^2)
float yAccel = fields[4].toFloat() * FT2M;
// Get xAccel (m/s^2)
float zAccel = fields[5].toFloat() * FT2M;
// Get pitch (deg)
float pitch = fields[6].toFloat();
// Get pitchRate (deg/s)
float pitchRate = fields[7].toFloat();
// Get roll (deg)
float roll = fields[8].toFloat();
// Get rollRate (deg/s)
float rollRate = fields[9].toFloat();
// Get yaw (deg)
float yaw = fields[10].toFloat();
// Get yawRate (deg/s)
float yawRate = fields[11].toFloat();
// Get latitude (deg)
float latitude = fields[12].toFloat();
// Get longitude (deg)
float longitude = fields[13].toFloat();
// Get heading (deg)
float heading = fields[14].toFloat();
// Get altitude (m)
float altitude = fields[15].toFloat() * FT2M;
// Get altitudeAGL (m)
float altitudeAGL = fields[16].toFloat() * FT2M;
// Get groundspeed (m/s)
float groundspeed = fields[17].toFloat() * KT2MPS;
// Get airspeed (m/s)
float airspeed = fields[18].toFloat() * KT2MPS;
// Get temperature (degC)
float temperature = fields[19].toFloat();
// Get pressure (kpa)
float pressure = fields[20].toFloat() * INHG2KPA;
// Update AltitudeActual object
AltitudeActual::DataFields altActualData;
altActualData.Altitude = altitudeAGL;
altActualData.Temperature = temperature;
altActualData.Pressure = pressure;
altActual->setData(altActualData);
// Update attActual object
AttitudeActual::DataFields attActualData;
attActualData.Roll = roll;
attActualData.Pitch = pitch;
attActualData.Yaw = yaw;
attActualData.q1 = 0;
attActualData.q2 = 0;
attActualData.q3 = 0;
attActualData.q4 = 0;
attActualData.seq = 0;
attActual->setData(attActualData);
// Update gps objects
PositionActual::DataFields gpsData;
gpsData.Altitude = altitude;
gpsData.Heading = heading;
gpsData.Groundspeed = groundspeed;
gpsData.Latitude = latitude;
gpsData.Longitude = longitude;
gpsData.Satellites = 10;
gpsData.Status = PositionActual::STATUS_FIX3D;
posActual->setData(gpsData);
}
void Il2Bridge::telStatsUpdated(UAVObject* obj)
{
GCSTelemetryStats::DataFields stats = telStats->getData();
if ( !autopilotConnectionStatus && stats.Status == GCSTelemetryStats::STATUS_CONNECTED )
{
onAutopilotConnect();
}
else if ( autopilotConnectionStatus && stats.Status != GCSTelemetryStats::STATUS_CONNECTED )
{
onAutopilotDisconnect();
}
}

View File

@ -0,0 +1,96 @@
/**
******************************************************************************
*
* @file il2bridge.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup hitlplugin
* @{
*
*****************************************************************************/
/*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef FLIGHTGEARBRIDGE_H
#define FLIGHTGEARBRIDGE_H
#include <QObject>
#include <QUdpSocket>
#include <QTimer>
#include <math.h>
#include "uavtalk/telemetrymanager.h"
#include "uavobjects/uavobjectmanager.h"
#include "uavobjects/actuatordesired.h"
#include "uavobjects/altitudeactual.h"
#include "uavobjects/attitudeactual.h"
#include "uavobjects/positionactual.h"
#include "uavobjects/gcstelemetrystats.h"
class Il2Bridge: public QObject
{
Q_OBJECT
public:
Il2Bridge(QString il2HostName, int il2Port);
~Il2Bridge();
bool isAutopilotConnected();
bool isIl2Connected();
signals:
void autopilotConnected();
void autopilotDisconnected();
void il2Connected();
void il2Disconnected();
private slots:
void transmitUpdate();
void receiveUpdate();
void onAutopilotConnect();
void onAutopilotDisconnect();
void onIl2ConnectionTimeout();
void telStatsUpdated(UAVObject* obj);
private:
static const float FT2M = 0.3048;
static const float KT2MPS = 0.514444444;
static const float INHG2KPA = 3.386;
QUdpSocket* inSocket;
QUdpSocket* outSocket;
ActuatorDesired* actDesired;
AltitudeActual* altActual;
AttitudeActual* attActual;
PositionActual* posActual;
GCSTelemetryStats* telStats;
QHostAddress il2Host;
int inPort;
int outPort;
int updatePeriod;
QTimer* txTimer;
QTimer* fgTimer;
bool autopilotConnectionStatus;
bool il2ConnectionStatus;
int il2Timeout;
void processUpdate(QString& data);
void setupOutputObject(UAVObject* obj, int updatePeriod);
void setupInputObject(UAVObject* obj, int updatePeriod);
void setupObjects();
};
#endif // FLIGHTGEARBRIDGE_H