mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
Can now click two boxes to control manual control settings. Shamelessly ripping off dial code to make pretty SVG joystick (to come).
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1140 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
765d4f729b
commit
64c4534f55
@ -1,11 +1,13 @@
|
||||
TEMPLATE = lib
|
||||
TARGET = GCSControl
|
||||
QT += svg
|
||||
|
||||
include(../../openpilotgcsplugin.pri)
|
||||
include(../../plugins/coreplugin/coreplugin.pri)
|
||||
include(../../plugins/uavobjects/uavobjects.pri)
|
||||
|
||||
HEADERS += gcscontrolgadget.h
|
||||
HEADERS += joystickcontrol.h
|
||||
HEADERS += gcscontrolgadgetwidget.h
|
||||
HEADERS += gcscontrolgadgetfactory.h
|
||||
HEADERS += gcscontrolplugin.h
|
||||
@ -14,7 +16,11 @@ SOURCES += gcscontrolgadget.cpp
|
||||
SOURCES += gcscontrolgadgetwidget.cpp
|
||||
SOURCES += gcscontrolgadgetfactory.cpp
|
||||
SOURCES += gcscontrolplugin.cpp
|
||||
SOURCES += joystickcontrol.cpp
|
||||
|
||||
OTHER_FILES += GCSControl.pluginspec
|
||||
|
||||
FORMS += gcscontrol.ui
|
||||
|
||||
RESOURCES += \
|
||||
gcscontrol.qrc
|
||||
|
5
ground/src/plugins/gcscontrol/gcscontrol.qrc
Normal file
5
ground/src/plugins/gcscontrol/gcscontrol.qrc
Normal file
@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/gsccontrol">
|
||||
<file>images/joystickBackground.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
@ -6,27 +6,113 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>653</width>
|
||||
<height>290</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>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>73</x>
|
||||
<y>61</y>
|
||||
<width>181</width>
|
||||
<height>191</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBoxGcsControl">
|
||||
<property name="text">
|
||||
<string>FlightMode</string>
|
||||
<string>GCS Control</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Flight Mode:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBoxFlightMode"/>
|
||||
</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,0">
|
||||
<property name="horizontalSpacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="JoystickControl" name="widgetLeftStick" 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>
|
||||
<item row="0" column="1">
|
||||
<widget class="JoystickControl" name="widgetRightStick" 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>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>JoystickControl</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>joystickcontrol.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -43,7 +43,16 @@ GCSControlGadgetWidget::GCSControlGadgetWidget(QWidget *parent) : QLabel(parent)
|
||||
{
|
||||
m_gcscontrol = new Ui_GCSControl();
|
||||
m_gcscontrol->setupUi(this);
|
||||
connect(m_gcscontrol->pushButton, SIGNAL(clicked()), this, SLOT(buttonPressed()));
|
||||
|
||||
// Set up the drop down box for the flightmode
|
||||
m_gcscontrol->comboBoxFlightMode->addItem(QString("Manual"));
|
||||
m_gcscontrol->comboBoxFlightMode->addItem(QString("Stabilized"));
|
||||
m_gcscontrol->comboBoxFlightMode->addItem(QString("Auto"));
|
||||
|
||||
// Set up slots and signals
|
||||
connect(m_gcscontrol->checkBoxGcsControl, SIGNAL(stateChanged(int)), this, SLOT(gcsControlToggle(int)));
|
||||
connect(m_gcscontrol->comboBoxFlightMode, SIGNAL(currentIndexChanged(int)), this, SLOT(flightModeChanged(int)));
|
||||
|
||||
}
|
||||
|
||||
GCSControlGadgetWidget::~GCSControlGadgetWidget()
|
||||
@ -51,31 +60,55 @@ GCSControlGadgetWidget::~GCSControlGadgetWidget()
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void GCSControlGadgetWidget::buttonPressed()
|
||||
/*!
|
||||
\brief Returns the ManualControlCommand UAVObject
|
||||
*/
|
||||
|
||||
ManualControlCommand* GCSControlGadgetWidget::getMCC()
|
||||
{
|
||||
// Get access to the ManualControlObject
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
ManualControlCommand* obj = dynamic_cast<ManualControlCommand*>( objManager->getObject(QString("ManualControlCommand")) );
|
||||
|
||||
// Need to set the metadata to let GCS override OpenPilot
|
||||
UAVObject::Metadata mdata = obj->getMetadata();
|
||||
mdata.gcsAccess = UAVObject::ACCESS_READWRITE;
|
||||
mdata.flightAccess = UAVObject::ACCESS_READONLY;
|
||||
obj->setMetadata(mdata);
|
||||
|
||||
// Set values to some constants for now
|
||||
ManualControlCommand::DataFields data = obj->getData();
|
||||
data.FlightMode = ManualControlCommand::FLIGHTMODE_STABILIZED;
|
||||
data.Pitch = .5;
|
||||
data.Roll = .3;
|
||||
data.Throttle = .2;
|
||||
data.Yaw = .3;
|
||||
obj->setData(data);
|
||||
|
||||
// Visual confirmation
|
||||
m_gcscontrol->pushButton->setText(obj->toString());
|
||||
|
||||
//Q_ASSERT( 0 );
|
||||
return obj;
|
||||
}
|
||||
|
||||
/*!
|
||||
\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();
|
||||
if (state)
|
||||
{
|
||||
mdata.flightAccess = UAVObject::ACCESS_READONLY;
|
||||
}
|
||||
else
|
||||
{
|
||||
mdata.flightAccess = UAVObject::ACCESS_READWRITE;
|
||||
}
|
||||
getMCC()->setMetadata(mdata);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Called when the flight mode drop down is changed and sets the ManualControlCommand->FlightMode accordingly
|
||||
*/
|
||||
void GCSControlGadgetWidget::flightModeChanged(int state)
|
||||
{
|
||||
ManualControlCommand::DataFields data = getMCC()->getData();
|
||||
if( state == 0 )
|
||||
{
|
||||
data.FlightMode = ManualControlCommand::FLIGHTMODE_MANUAL;
|
||||
}
|
||||
else if ( state == 1 )
|
||||
{
|
||||
data.FlightMode = ManualControlCommand::FLIGHTMODE_STABILIZED;
|
||||
}
|
||||
else if ( state == 2 )
|
||||
{
|
||||
data.FlightMode = ManualControlCommand::FLIGHTMODE_AUTO;
|
||||
}
|
||||
getMCC()->setData(data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
#define GCSControlGADGETWIDGET_H_
|
||||
|
||||
#include <QtGui/QLabel>
|
||||
#include "uavobjects/manualcontrolcommand.h"
|
||||
|
||||
class Ui_GCSControl;
|
||||
|
||||
@ -41,10 +42,12 @@ public:
|
||||
~GCSControlGadgetWidget();
|
||||
|
||||
private slots:
|
||||
void buttonPressed();
|
||||
void gcsControlToggle(int state);
|
||||
void flightModeChanged(int state);
|
||||
|
||||
private:
|
||||
Ui_GCSControl *m_gcscontrol;
|
||||
ManualControlCommand* getMCC();
|
||||
};
|
||||
|
||||
#endif /* GCSControlGADGETWIDGET_H_ */
|
||||
|
41
ground/src/plugins/gcscontrol/images/joystickBackground.svg
Normal file
41
ground/src/plugins/gcscontrol/images/joystickBackground.svg
Normal file
@ -0,0 +1,41 @@
|
||||
<?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>
|
After Width: | Height: | Size: 1.1 KiB |
90
ground/src/plugins/gcscontrol/joystickcontrol.cpp
Normal file
90
ground/src/plugins/gcscontrol/joystickcontrol.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
#include "joystickcontrol.h"
|
||||
#include "ui_joystickcontrol.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>
|
||||
|
||||
JoystickControl::JoystickControl(QWidget *parent) :
|
||||
QGraphicsView(parent)
|
||||
{
|
||||
setMinimumSize(64,64);
|
||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
setScene(new QGraphicsScene(this));
|
||||
setRenderHints(QPainter::Antialiasing);
|
||||
|
||||
m_renderer = new QSvgRenderer();
|
||||
m_renderer->load(QString(":/gcscontrol/images/joystickBackground.svg"));
|
||||
m_background = new QGraphicsSvgItem();
|
||||
m_background->setSharedRenderer(m_renderer);
|
||||
|
||||
QGraphicsScene *l_scene = scene();
|
||||
l_scene->clear(); // This also deletes all items contained in the scene.
|
||||
l_scene->addItem(m_background);
|
||||
|
||||
}
|
||||
|
||||
JoystickControl::~JoystickControl()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ManualControlCommand* JoystickControl::getMCC()
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
ManualControlCommand* obj = dynamic_cast<ManualControlCommand*>( objManager->getObject(QString("ManualControlCommand")) );
|
||||
return obj;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void JoystickControl::paint()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
void JoystickControl::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
// Skip painting until the dial file is loaded
|
||||
if (! m_renderer->isValid()) {
|
||||
qDebug()<<"Dial file not loaded, not rendering";
|
||||
// return;
|
||||
}
|
||||
QGraphicsView::paintEvent(event);
|
||||
}
|
||||
|
||||
void JoystickControl::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
fitInView(m_background, Qt::KeepAspectRatio );
|
||||
}
|
33
ground/src/plugins/gcscontrol/joystickcontrol.h
Normal file
33
ground/src/plugins/gcscontrol/joystickcontrol.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef JOYSTICKCONTROL_H
|
||||
#define JOYSTICKCONTROL_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QGraphicsView>
|
||||
#include <QtSvg/QSvgRenderer>
|
||||
#include <QtSvg/QGraphicsSvgItem>
|
||||
#include "uavobjects/manualcontrolcommand.h"
|
||||
|
||||
namespace Ui {
|
||||
class JoystickControl;
|
||||
}
|
||||
|
||||
class JoystickControl : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit JoystickControl(QWidget *parent = 0);
|
||||
~JoystickControl();
|
||||
void paint();
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
private:
|
||||
ManualControlCommand* getMCC();
|
||||
QSvgRenderer *m_renderer;
|
||||
QGraphicsSvgItem *m_background;
|
||||
};
|
||||
|
||||
#endif // JOYSTICKCONTROL_H
|
Loading…
x
Reference in New Issue
Block a user