mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-15 07:29:15 +01:00
Draw joystick end to indicate position
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1148 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
9410aa80fa
commit
7f7b54d812
@ -22,5 +22,4 @@ OTHER_FILES += GCSControl.pluginspec
|
||||
|
||||
FORMS += gcscontrol.ui
|
||||
|
||||
RESOURCES += \
|
||||
gcscontrol.qrc
|
||||
RESOURCES += gcscontrol.qrc
|
||||
|
@ -1,5 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/gcscontrol">
|
||||
<file>images/joystickBackground.svg</file>
|
||||
<file>images/joystick.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -63,7 +63,6 @@ GCSControlGadgetWidget::~GCSControlGadgetWidget()
|
||||
/*!
|
||||
\brief Returns the ManualControlCommand UAVObject
|
||||
*/
|
||||
|
||||
ManualControlCommand* GCSControlGadgetWidget::getMCC()
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
@ -75,7 +74,6 @@ ManualControlCommand* GCSControlGadgetWidget::getMCC()
|
||||
/*!
|
||||
\brief Called when the gcs control is toggled and enabled or disables flight write access to manual control command
|
||||
*/
|
||||
|
||||
void GCSControlGadgetWidget::gcsControlToggle(int state)
|
||||
{
|
||||
UAVObject::Metadata mdata = getMCC()->getMetadata();
|
||||
@ -111,4 +109,7 @@ void GCSControlGadgetWidget::flightModeChanged(int state)
|
||||
getMCC()->setData(data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
@ -63,3 +63,7 @@ void GCSControlPlugin::shutdown()
|
||||
}
|
||||
Q_EXPORT_PLUGIN(GCSControlPlugin)
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
76
ground/src/plugins/gcscontrol/images/joystick.svg
Normal file
76
ground/src/plugins/gcscontrol/images/joystick.svg
Normal file
@ -0,0 +1,76 @@
|
||||
<?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: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="joystickBackground.svg">
|
||||
<sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="870"
|
||||
inkscape:window-height="739"
|
||||
id="namedview7"
|
||||
showgrid="false"
|
||||
inkscape:zoom="18.25"
|
||||
inkscape:cx="32"
|
||||
inkscape:cy="32"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="22"
|
||||
inkscape:window-maximized="0"
|
||||
inkscape:current-layer="svg2" />
|
||||
<defs
|
||||
id="defs4" />
|
||||
<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
|
||||
transform="matrix(1.1638314,0,0,-1.1066141,-5.6432489,1159.6292)"
|
||||
id="background"
|
||||
inkscape:label="#layer1">
|
||||
<rect
|
||||
width="54.725903"
|
||||
height="57.437641"
|
||||
rx="0.09363886"
|
||||
ry="28.718821"
|
||||
x="5.0757694"
|
||||
y="990.19446"
|
||||
id="rect2985"
|
||||
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.10537914;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
|
||||
</g>
|
||||
<path
|
||||
sodipodi:type="arc"
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#998ad7;stroke-width:0.4;stroke-miterlimit:4;stroke-opacity:0.59336102000000002;stroke-dasharray:none"
|
||||
id="joystickEnd"
|
||||
sodipodi:cx="25.013699"
|
||||
sodipodi:cy="28.684931"
|
||||
sodipodi:rx="1.0136986"
|
||||
sodipodi:ry="1.0136986"
|
||||
d="m 26.027397,28.684931 a 1.0136986,1.0136986 0 1 1 -2.027397,0 1.0136986,1.0136986 0 1 1 2.027397,0 z"
|
||||
inkscape:label="#path3034" />
|
||||
</svg>
|
After Width: | Height: | Size: 2.3 KiB |
@ -1,41 +0,0 @@
|
||||
<?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"
|
||||
version="1.1"
|
||||
width="64"
|
||||
height="64"
|
||||
id="svg2">
|
||||
<defs
|
||||
id="defs4" />
|
||||
<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></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
transform="translate(0,-988.36218)"
|
||||
id="layer1">
|
||||
<rect
|
||||
width="54.725903"
|
||||
height="57.437641"
|
||||
rx="0.09363886"
|
||||
ry="28.718821"
|
||||
x="5.0757694"
|
||||
y="990.19446"
|
||||
id="rect2985"
|
||||
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.10537914;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 1.1 KiB |
@ -1,3 +1,30 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @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 "joystickcontrol.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include <QDebug>
|
||||
@ -10,6 +37,9 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QtGlobal>
|
||||
|
||||
/**
|
||||
* @brief Constructor for JoystickControl widget. Sets up the image of a joystick
|
||||
*/
|
||||
JoystickControl::JoystickControl(QWidget *parent) :
|
||||
QGraphicsView(parent)
|
||||
{
|
||||
@ -18,15 +48,26 @@ JoystickControl::JoystickControl(QWidget *parent) :
|
||||
setScene(new QGraphicsScene(this));
|
||||
setRenderHints(QPainter::Antialiasing);
|
||||
|
||||
m_renderer = new QSvgRenderer();
|
||||
Q_ASSERT( m_renderer->load(QString(":/gcscontrol/images/joystickBackground.svg")) );
|
||||
// Connect object updated event from UAVObject to also animate sticks
|
||||
connect(getMCC(), SIGNAL(objectUpdated(UAVObject*)), this, SLOT(mccChanged(UAVObject*)));
|
||||
|
||||
m_background = new QGraphicsSvgItem(QString(":/gcscontrol/images/joystickBackground.svg"));
|
||||
|
||||
m_renderer = new QSvgRenderer();
|
||||
Q_ASSERT( m_renderer->load(QString(":/gcscontrol/images/joystick.svg")) );
|
||||
|
||||
m_background = new QGraphicsSvgItem();
|
||||
m_background->setSharedRenderer(m_renderer);
|
||||
m_background->setElementId(QString("background"));
|
||||
|
||||
m_joystickEnd = new QGraphicsSvgItem();
|
||||
m_joystickEnd->setSharedRenderer(m_renderer);
|
||||
m_joystickEnd->setElementId(QString("joystickEnd"));
|
||||
m_joystickEnd->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_joystickEnd);
|
||||
l_scene->setSceneRect(m_background->boundingRect());
|
||||
}
|
||||
|
||||
@ -35,6 +76,37 @@ JoystickControl::~JoystickControl()
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Draw stick positions when ManualControlCommand gets updated
|
||||
*/
|
||||
void JoystickControl::mccChanged(UAVObject*)
|
||||
{
|
||||
QPen pen;
|
||||
pen.setColor(QColor(Qt::white));
|
||||
pen.setWidth(2);
|
||||
|
||||
// draw stick positions
|
||||
if( this->objectName() == QString("widgetLeftStick"))
|
||||
{
|
||||
ManualControlCommand::DataFields data = getMCC()->getData();
|
||||
double x = (data.Yaw + 1) / 2 * scene()->sceneRect().width();
|
||||
double y = (data.Pitch + 1) / 2 * scene()->sceneRect().height();
|
||||
m_joystickEnd->setPos(x,y);
|
||||
}
|
||||
else if( this->objectName() == QString("widgetRightStick"))
|
||||
{
|
||||
ManualControlCommand::DataFields data = getMCC()->getData();
|
||||
double x = (data.Roll + 1) / 2 * scene()->sceneRect().width();
|
||||
double y = (data.Throttle + 1) / 2 * scene()->sceneRect().height();
|
||||
|
||||
m_joystickEnd->setPos(x,y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the Manual Control Command UAV Object
|
||||
*/
|
||||
ManualControlCommand* JoystickControl::getMCC()
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
@ -43,32 +115,21 @@ ManualControlCommand* JoystickControl::getMCC()
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Redirect mouse move events to control joystick position
|
||||
*/
|
||||
void JoystickControl::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
updateMCC(mapToScene(event->pos()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Redirect mouse move clicks to control joystick position
|
||||
*/
|
||||
void JoystickControl::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
Qt::MouseButton button = event->button();
|
||||
QPoint point = event->pos();
|
||||
QSize widgetSize = this->size();
|
||||
|
||||
double x = 2 * ( ((double)point.x()) / ((double)widgetSize.width()) - .5 );
|
||||
double y = 2 * ( ((double)point.y()) / ((double)widgetSize.height()) - .5);
|
||||
|
||||
if( button == Qt::LeftButton && this->objectName() == QString("widgetLeftStick"))
|
||||
{
|
||||
|
||||
ManualControlCommand::DataFields data = getMCC()->getData();
|
||||
data.Pitch = x;
|
||||
data.Yaw = y;
|
||||
getMCC()->setData(data);
|
||||
}
|
||||
|
||||
if( button == Qt::LeftButton && this->objectName() == QString("widgetRightStick"))
|
||||
{
|
||||
|
||||
ManualControlCommand::DataFields data = getMCC()->getData();
|
||||
data.Throttle = x;
|
||||
data.Roll = y;
|
||||
getMCC()->setData(data);
|
||||
}
|
||||
if( event->button() == Qt::LeftButton )
|
||||
updateMCC(mapToScene(event->pos()));
|
||||
}
|
||||
|
||||
void JoystickControl::paint()
|
||||
@ -91,3 +152,37 @@ void JoystickControl::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
fitInView(m_background, Qt::KeepAspectRatio );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update the roll,pitch,yaw,throttle for the Manual Control Command based on stick position (from mouse event)
|
||||
*/
|
||||
void JoystickControl::updateMCC(QPointF point)
|
||||
{
|
||||
QRectF sceneSize = scene()->sceneRect();
|
||||
|
||||
double x = 2 * ( point.x() / sceneSize.width() - .5 );
|
||||
double y = 2 * ( point.y() / sceneSize.height() - .5);
|
||||
|
||||
if( this->objectName() == QString("widgetLeftStick"))
|
||||
{
|
||||
|
||||
ManualControlCommand::DataFields data = getMCC()->getData();
|
||||
data.Pitch = y;
|
||||
data.Yaw = x;
|
||||
getMCC()->setData(data);
|
||||
}
|
||||
|
||||
if( this->objectName() == QString("widgetRightStick"))
|
||||
{
|
||||
|
||||
ManualControlCommand::DataFields data = getMCC()->getData();
|
||||
data.Throttle = y;
|
||||
data.Roll = x;
|
||||
getMCC()->setData(data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
@ -1,3 +1,31 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @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 JOYSTICKCONTROL_H
|
||||
#define JOYSTICKCONTROL_H
|
||||
|
||||
@ -19,15 +47,28 @@ public:
|
||||
explicit JoystickControl(QWidget *parent = 0);
|
||||
~JoystickControl();
|
||||
void paint();
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
private:
|
||||
void updateMCC(QPointF);
|
||||
ManualControlCommand* getMCC();
|
||||
|
||||
protected slots:
|
||||
void mccChanged(UAVObject*);
|
||||
|
||||
private:
|
||||
QSvgRenderer *m_renderer;
|
||||
QGraphicsSvgItem *m_background;
|
||||
};
|
||||
QGraphicsSvgItem *m_joystickEnd;
|
||||
};
|
||||
|
||||
#endif // JOYSTICKCONTROL_H
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user