1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

Ground/MagicWaypoint: New gadget that controls position desired in a magic waypoint fashion.

Ground/PFD: Update to use velocity actual

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1761 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
peabody124 2010-09-26 03:06:37 +00:00 committed by peabody124
parent 77b68e5169
commit ba0fb92853
18 changed files with 1072 additions and 11 deletions

View File

@ -0,0 +1,11 @@
<plugin name="MagicWaypoint" version="0.0.1" 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>Allows controlling the desired position by clicking on a display</description>
<url>http://www.openpilot.org</url>
<dependencyList>
<dependency name="Core" version="1.0.0"/>
</dependencyList>
</plugin>

View File

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
width="64"
height="64"
id="svg2"
inkscape:version="0.47+devel r9530"
sodipodi:docname="positionfield.svg">
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1680"
inkscape:window-height="920"
id="namedview7"
showgrid="false"
inkscape:zoom="6.4523494"
inkscape:cx="5.6017388"
inkscape:cy="32.074874"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:current-layer="svg2"
showguides="true"
inkscape:guide-bbox="true" />
<defs
id="defs4">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 32 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="64 : 32 : 1"
inkscape:persp3d-origin="32 : 21.333333 : 1"
id="perspective9" />
<inkscape:perspective
id="perspective4576"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3899"
id="linearGradient3820"
gradientUnits="userSpaceOnUse"
x1="337.63348"
y1="371.99725"
x2="729.8302"
y2="676.58545" />
<linearGradient
id="linearGradient3899">
<stop
id="stop3901"
offset="0"
style="stop-color:#9699a3;stop-opacity:1;" />
<stop
style="stop-color:#1f1616;stop-opacity:1;"
offset="0.49412024"
id="stop3903" />
<stop
id="stop3905"
offset="1"
style="stop-color:#9498a5;stop-opacity:0;" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3899"
id="linearGradient4790"
x1="14.99304"
y1="1038.3234"
x2="105.25183"
y2="941.66919"
gradientUnits="userSpaceOnUse" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3899"
id="linearGradient3865"
gradientUnits="userSpaceOnUse"
x1="14.99304"
y1="1038.3234"
x2="105.25183"
y2="941.66919" />
</defs>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="background"
inkscape:label="#g4757"
style="stroke-width:0.3;stroke-miterlimit:4;stroke-dasharray:none">
<g
inkscape:label="#layer1"
id="Baba"
transform="matrix(1.1638314,0,0,-1.1066141,-5.6432489,1159.5817)"
style="fill-opacity:1;fill:url(#linearGradient4790);stroke-width:0.26434927;stroke-miterlimit:4;stroke-dasharray:none">
<rect
style="fill:url(#linearGradient3865);fill-opacity:1;stroke:#202020;stroke-width:0;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="rect2985"
y="990.19446"
x="5.0757694"
ry="28.718821"
rx="0.09363886"
height="57.437641"
width="54.725903" />
</g>
<g
id="g3789"
transform="matrix(0.13698764,0,0,0.13698764,-19.020289,-22.990069)"
style="stroke-width:2.1899786;stroke-miterlimit:4;stroke-dasharray:none" />
</g>
<a
id="a3867"
transform="translate(10,-10)">
<path
transform="matrix(0.88823427,0,0,0.88823427,0.65875236,4.0999609)"
inkscape:label="#path3034"
d="m 26.027397,28.684931 c 0,0.55985 -0.453848,1.013698 -1.013698,1.013698 C 24.453848,29.698629 24,29.244781 24,28.684931 c 0,-0.55985 0.453848,-1.013699 1.013699,-1.013699 0.55985,0 1.013698,0.453849 1.013698,1.013699 z"
sodipodi:ry="1.0136986"
sodipodi:rx="1.0136986"
sodipodi:cy="28.684931"
sodipodi:cx="25.013699"
id="joystickEnd"
style="fill:#ff201d;fill-opacity:1;stroke:#ef7d7d;stroke-width:0.39996386;stroke-miterlimit:4;stroke-opacity:0.59336093;stroke-dasharray:none"
sodipodi:type="arc" />
</a>
</svg>

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -0,0 +1,25 @@
TEMPLATE = lib
TARGET = MagicWaypoint
QT += svg
include(../../openpilotgcsplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(../../plugins/uavobjects/uavobjects.pri)
HEADERS += magicwaypointgadget.h
HEADERS += magicwaypointgadgetwidget.h
HEADERS += magicwaypointgadgetfactory.h
HEADERS += magicwaypointplugin.h
HEADERS += positionfield.h
SOURCES += magicwaypointgadget.cpp
SOURCES += magicwaypointgadgetwidget.cpp
SOURCES += magicwaypointgadgetfactory.cpp
SOURCES += magicwaypointplugin.cpp
SOURCES += positionfield.cpp
OTHER_FILES += MagicWaypoint.pluginspec
FORMS += magicwaypoint.ui
RESOURCES += magicwaypoint.qrc

View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/magicwaypoint">
<file>images/positionfield.svg</file>
</qresource>
</RCC>

View File

@ -0,0 +1,161 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MagicWaypoint</class>
<widget class="QWidget" name="MagicWaypoint">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>653</width>
<height>295</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<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>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>50</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Scale:</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="horizontalSliderScale">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="tickInterval">
<number>10</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<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>
</layout>
</item>
</layout>
</item>
<item>
<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>
<layout class="QGridLayout" name="gridLayout" columnstretch="0">
<property name="horizontalSpacing">
<number>10</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="PositionField" name="widgetPosition" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
<property name="mouseTracking">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>PositionField</class>
<extends>QWidget</extends>
<header>positionfield.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,49 @@
/**
******************************************************************************
*
* @file GCSControlgadget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
* @{
* @brief A gadget to control the UAV, either from the keyboard or a joystick
*****************************************************************************/
/*
* 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 "magicwaypointgadget.h"
#include "magicwaypointgadgetwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjects/uavobjectmanager.h"
#include "uavobjects/uavobject.h"
#include <QDebug>
MagicWaypointGadget::MagicWaypointGadget(QString classId, MagicWaypointGadgetWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent),
m_widget(widget)
{
qDebug() << "Class id" << classId;
}
MagicWaypointGadget::~MagicWaypointGadget()
{
}
void MagicWaypointGadget::loadConfiguration(IUAVGadgetConfiguration* config)
{
Q_UNUSED(config);
}

View File

@ -0,0 +1,60 @@
/**
******************************************************************************
*
* @file GCSControlgadget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
* @{
* @brief A gadget to control the UAV, either from the keyboard or a joystick
*****************************************************************************/
/*
* 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 MagicWaypointGADGET_H_
#define MagicWaypointGADGET_H_
#include <coreplugin/iuavgadget.h>
namespace Core {
class IUAVGadget;
}
//class QWidget;
//class QString;
class MagicWaypointGadgetWidget;
using namespace Core;
class MagicWaypointGadget : public Core::IUAVGadget
{
Q_OBJECT
public:
MagicWaypointGadget(QString classId, MagicWaypointGadgetWidget *widget, QWidget *parent = 0);
~MagicWaypointGadget();
QList<int> context() const { return m_context; }
QWidget *widget() { return m_widget; }
QString contextHelpId() const { return QString(); }
void loadConfiguration(IUAVGadgetConfiguration* config);
private:
QWidget *m_widget;
QList<int> m_context;
};
#endif // MagicWaypointGADGET_H_

View File

@ -0,0 +1,48 @@
/**
******************************************************************************
*
* @file GCSControlgadgetfactory.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
* @{
* @brief A gadget to control the UAV, either from the keyboard or a joystick
*****************************************************************************/
/*
* 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 "magicwaypointgadgetfactory.h"
#include "magicwaypointgadgetwidget.h"
#include "magicwaypointgadget.h"
#include <coreplugin/iuavgadget.h>
#include <QDebug>
MagicWaypointGadgetFactory::MagicWaypointGadgetFactory(QObject *parent) :
IUAVGadgetFactory(QString("MagicWaypointGadget"),
tr("Magic Waypoint"),
parent)
{
}
MagicWaypointGadgetFactory::~MagicWaypointGadgetFactory()
{
}
IUAVGadget* MagicWaypointGadgetFactory::createGadget(QWidget *parent) {
MagicWaypointGadgetWidget* gadgetWidget = new MagicWaypointGadgetWidget(parent);
return new MagicWaypointGadget(QString("MagicWaypointGadget"), gadgetWidget, parent);
}

View File

@ -0,0 +1,50 @@
/**
******************************************************************************
*
* @file GCSControlgadgetfactory.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
* @{
* @brief A gadget to control the UAV, either from the keyboard or a joystick
*****************************************************************************/
/*
* 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 MagicWaypointGADGETFACTORY_H_
#define MagicWaypointGADGETFACTORY_H_
#include <coreplugin/iuavgadgetfactory.h>
namespace Core {
class IUAVGadget;
class IUAVGadgetFactory;
}
using namespace Core;
class MagicWaypointGadgetFactory : public IUAVGadgetFactory
{
Q_OBJECT
public:
MagicWaypointGadgetFactory(QObject *parent = 0);
~MagicWaypointGadgetFactory();
IUAVGadget *createGadget(QWidget *parent);
};
#endif // MagicWaypointGADGETFACTORY_H_

View File

@ -0,0 +1,117 @@
/**
******************************************************************************
*
* @file GCSControlgadgetwidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
* @{
* @brief A gadget to control the UAV, either from the keyboard or a joystick
*****************************************************************************/
/*
* 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 "magicwaypointgadgetwidget.h"
#include "ui_magicwaypoint.h"
#include <QDebug>
#include <QStringList>
#include <QtGui/QWidget>
#include <QtGui/QTextEdit>
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
#include "uavobjects/uavobject.h"
#include "uavobjects/uavobjectmanager.h"
#include "uavobjects/manualcontrolcommand.h"
#include "extensionsystem/pluginmanager.h"
#include "extensionsystem/pluginmanager.h"
MagicWaypointGadgetWidget::MagicWaypointGadgetWidget(QWidget *parent) : QLabel(parent)
{
qDebug() << "MagicWaypointGadgetWidget constructor";
m_magicwaypoint = new Ui_MagicWaypoint();
m_magicwaypoint->setupUi(this);
// Connect object updated event from UAVObject to also update check boxes
connect(getPositionDesired(), SIGNAL(objectUpdated(UAVObject*)), this, SLOT(positionDesiredObjectChanged(UAVObject*)));
// Connect updates from the position widget to this widget
connect(m_magicwaypoint->widgetPosition, SIGNAL(positionClicked(double,double)), this, SLOT(positionSelected(double,double)));
connect(this, SIGNAL(positionObjectChanged(double,double)), m_magicwaypoint->widgetPosition, SLOT(updateIndicator(double,double)));
// Catch changes in scale for visualization
connect(m_magicwaypoint->horizontalSliderScale, SIGNAL(valueChanged(int)), this, SLOT(scaleChanged(double)));
}
MagicWaypointGadgetWidget::~MagicWaypointGadgetWidget()
{
// Do nothing
}
/*!
\brief Returns the ManualControlCommand UAVObject
*/
PositionDesired* MagicWaypointGadgetWidget::getPositionDesired()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
PositionDesired* obj = dynamic_cast<PositionDesired*>( objManager->getObject(QString("PositionDesired")) );
return obj;
}
/**
* Detect changes in scale and update visualization (does not change position)
*/
void MagicWaypointGadgetWidget::scaleChanged(int scale) {
Q_UNUSED(scale);
positionDesiredObjectChanged(getPositionDesired());
}
/**
* Update displayed position when @ref PositionDesired object is changed
*/
void MagicWaypointGadgetWidget::positionDesiredObjectChanged(UAVObject* obj)
{
double north = obj->getField("North")->getDouble();
double east = obj->getField("East")->getDouble();
double scale = m_magicwaypoint->horizontalSliderScale->value();
emit positionObjectChanged(north/scale,east/scale);
}
/**
* Slot called by visualization when a new @ref PositionDesired is requested
*/
void MagicWaypointGadgetWidget::positionSelected(double north, double east) {
double scale = m_magicwaypoint->horizontalSliderScale->value();
PositionDesired * posDesired = getPositionDesired();
if(posDesired) {
UAVObjectField * field = posDesired->getField("North");
if(field)
field->setDouble(north * scale);
field = posDesired->getField("East");
if(field)
field->setDouble(east * scale);
posDesired->updated();
}
}
/**
* @}
* @}
*/

View File

@ -0,0 +1,57 @@
/**
******************************************************************************
*
* @file GCSControlgadgetwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
* @{
* @brief A place holder gadget plugin
*****************************************************************************/
/*
* 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 MagicWaypointGADGETWIDGET_H_
#define MagicWaypointGADGETWIDGET_H_
#include <QtGui/QLabel>
#include "uavobjects/positiondesired.h"
class Ui_MagicWaypoint;
class MagicWaypointGadgetWidget : public QLabel
{
Q_OBJECT
public:
MagicWaypointGadgetWidget(QWidget *parent = 0);
~MagicWaypointGadgetWidget();
signals:
void positionObjectChanged(double north, double east);
protected slots:
void scaleChanged(int scale);
void positionDesiredObjectChanged(UAVObject *);
void positionSelected(double north, double east);
private:
PositionDesired * getPositionDesired();
Ui_MagicWaypoint * m_magicwaypoint;
};
#endif /* MagicWaypointGADGETWIDGET_H_ */

View File

@ -0,0 +1,69 @@
/**
******************************************************************************
*
* @file GCSControlplugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
* @{
* @brief A gadget to control the UAV, either from the keyboard or a joystick
*****************************************************************************/
/*
* 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 "magicwaypointplugin.h"
#include "magicwaypointgadgetfactory.h"
#include <QDebug>
#include <QtPlugin>
#include <QStringList>
#include <extensionsystem/pluginmanager.h>
MagicWaypointPlugin::MagicWaypointPlugin()
{
// Do nothing
}
MagicWaypointPlugin::~MagicWaypointPlugin()
{
// Do nothing
}
bool MagicWaypointPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
mf = new MagicWaypointGadgetFactory(this);
addAutoReleasedObject(mf);
return true;
}
void MagicWaypointPlugin::extensionsInitialized()
{
// Do nothing
}
void MagicWaypointPlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(MagicWaypointPlugin)
/**
* @}
* @}
*/

View File

@ -0,0 +1,47 @@
/**
******************************************************************************
*
* @file GCSControlplugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
* @{
* @brief A gadget to control the UAV, either from the keyboard or a joystick
*****************************************************************************/
/*
* 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 MagicWaypointPLUGIN_H_
#define MagicWaypointPLUGIN_H_
#include <extensionsystem/iplugin.h>
class MagicWaypointGadgetFactory;
class MagicWaypointPlugin : public ExtensionSystem::IPlugin
{
public:
MagicWaypointPlugin();
~MagicWaypointPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
private:
MagicWaypointGadgetFactory *mf;
};
#endif /* GCSControlPLUGIN_H_ */

View File

@ -0,0 +1,134 @@
/**
******************************************************************************
*
* @file joystickcontrol.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
* @{
* @brief A that mimics a transmitter joystick and updates the MCC
*****************************************************************************/
/*
* 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 "positionfield.h"
#include "extensionsystem/pluginmanager.h"
#include <QDebug>
#include <QStringList>
#include <QtGui/QWidget>
#include <QtGui/QTextEdit>
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
#include <QtGui/QMessageBox>
#include <QMouseEvent>
#include <QtGlobal>
/**
* @brief Constructor for JoystickControl widget. Sets up the image of a joystick
*/
PositionField::PositionField(QWidget *parent) :
QGraphicsView(parent)
{
setMinimumSize(64,64);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setScene(new QGraphicsScene(this));
setRenderHints(QPainter::Antialiasing);
m_renderer = new QSvgRenderer();
Q_ASSERT( m_renderer->load(QString(":/magicwaypoint/images/positionfield.svg")) != 0 );
m_background = new QGraphicsSvgItem();
m_background->setSharedRenderer(m_renderer);
m_background->setElementId(QString("background"));
m_position = new QGraphicsSvgItem();
m_position->setSharedRenderer(m_renderer);
m_position->setElementId(QString("joystickEnd"));
m_position->setPos(0,0);
QGraphicsScene *l_scene = scene();
l_scene->clear(); // This also deletes all items contained in the scene.
l_scene->addItem(m_background);
l_scene->addItem(m_position);
l_scene->setSceneRect(m_background->boundingRect());
}
PositionField::~PositionField()
{
}
/**
* @brief Update aircraft position on image (values go from -1 to 1)
*/
void PositionField::updateIndicator(double north, double east)
{
QRectF sceneSize = scene()->sceneRect();
m_position->setPos((east+1)/2*sceneSize.width(),(-north+1)/2*sceneSize.height());
}
/**
* @brief Redirect mouse move events to control position
*/
void PositionField::mouseMoveEvent(QMouseEvent *event)
{
QPointF point = mapToScene(event->pos());
QRectF sceneSize = scene()->sceneRect();
double north = - (point.y() / sceneSize.height() - .5) * 2;
double east = (point.x() / sceneSize.width() - .5) * 2;
emit positionClicked(north, east);
}
/**
* @brief Redirect mouse move clicks to control position
*/
void PositionField::mousePressEvent(QMouseEvent *event)
{
if( event->button() == Qt::LeftButton ) {
mouseMoveEvent(event);
}
}
void PositionField::paint()
{
update();
}
void PositionField::paintEvent(QPaintEvent *event)
{
// Skip painting until the dial file is loaded
if (! m_renderer->isValid()) {
qDebug()<<"Image file not loaded, not rendering";
}
QGraphicsView::paintEvent(event);
}
void PositionField::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
fitInView(m_background, Qt::IgnoreAspectRatio );
}
/**
* @}
* @}
*/

View File

@ -0,0 +1,73 @@
/**
******************************************************************************
*
* @file joystickcontrol.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
* @{
* @brief A that mimics a transmitter joystick and updates the MCC
*****************************************************************************/
/*
* 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 POSITIONFIELD_H
#define POSITIONFIELD_H
#include <QWidget>
#include <QGraphicsView>
#include <QtSvg/QSvgRenderer>
#include <QtSvg/QGraphicsSvgItem>
namespace Ui {
class PositionField;
}
class PositionField : public QGraphicsView
{
Q_OBJECT
public:
explicit PositionField(QWidget *parent = 0);
~PositionField();
void paint();
protected:
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
signals:
void positionClicked(double north, double east);
public slots:
void updateIndicator(double north, double east);
private:
QSvgRenderer *m_renderer;
QGraphicsSvgItem *m_background;
QGraphicsSvgItem *m_position;
};
#endif // POSITIONFIELD_H
/**
* @}
* @}
*/

View File

@ -118,7 +118,7 @@ void PFDGadgetWidget::connectNeedles() {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
airspeedObj = dynamic_cast<UAVDataObject*>(objManager->getObject("PositionActual"));
airspeedObj = dynamic_cast<UAVDataObject*>(objManager->getObject("VelocityActual"));
if (attitudeObj != NULL ) {
connect(airspeedObj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateAirspeed(UAVObject*)));
} else {
@ -288,9 +288,10 @@ void PFDGadgetWidget::updateHeading(UAVObject *object) {
\brief Called by updates to @PositionActual to compute airspeed from velocity
*/
void PFDGadgetWidget::updateAirspeed(UAVObject *object) {
UAVObjectField* velField = object->getField("Vel");
if (velField) {
double val = floor(sqrt(pow(velField->getDouble(0),2) + pow(velField->getDouble(1),2))*10)/10;
UAVObjectField* northField = object->getField("North");
UAVObjectField* eastField = object->getField("East");
if (northField && eastField) {
double val = floor(sqrt(pow(northField->getDouble(),2) + pow(eastField->getDouble(),2))*10)/10;
groundspeedTarget = 3.6*val*speedScaleHeight/30;
} else {
@ -302,10 +303,10 @@ void PFDGadgetWidget::updateAirspeed(UAVObject *object) {
\brief Called by the @ref PositionActual updates to show altitude
*/
void PFDGadgetWidget::updateAltitude(UAVObject *object) {
UAVObjectField* posField = object->getField("NED");
if (posField) {
UAVObjectField* downField = object->getField("Down");
if (downField) {
// The altitude scale represents 30 meters
altitudeTarget = floor(posField->getDouble(3)*10)/10*altitudeScaleHeight/30;
altitudeTarget = -floor(downField->getDouble(3)*10)/10*altitudeScaleHeight/30;
} else {
qDebug() << "Unable to get field for altitude update. Obj: " << object->getName();
}

View File

@ -148,3 +148,8 @@ plugin_gcscontrol.depends = plugin_coreplugin
plugin_gcscontrol.depends += plugin_uavobjects
plugin_gcscontrol.depends += plugin_uavtalk
SUBDIRS += plugin_gcscontrol
# Empty UAVGadget - Default for new splits
plugin_magicwaypoint.subdir = magicwaypoint
plugin_magicwaypoint.depends = plugin_coreplugin
SUBDIRS += plugin_magicwaypoint

View File

@ -42,14 +42,13 @@ HEADERS += uavobjects_global.h \
homelocation.h \
vtolsettings.h \
vtolstatus.h \
attitudesettings.h \
mixersettings.h \
mixerstatus.h \
positiondesired.h \
velocitydesired.h \
velocityactual.h \
vtolstatus.h \
guidancesettings.h \
positiondesired.h \
attitudesettings.h
SOURCES += uavobject.cpp \
uavmetaobject.cpp \
@ -89,12 +88,11 @@ SOURCES += uavobject.cpp \
homelocation.cpp \
vtolsettings.cpp \
vtolstatus.cpp \
attitudesettings.cpp \
mixersettings.cpp \
mixerstatus.cpp \
positiondesired.cpp \
velocitydesired.cpp \
velocityactual.cpp \
guidancesettings.cpp \
positiondesired.cpp \
attitudesettings.cpp
OTHER_FILES += UAVObjects.pluginspec