Commit e0085289 authored by pixhawk's avatar pixhawk

Working on QGraphicsView-based local waypoints interface supporting...

Working on QGraphicsView-based local waypoints interface supporting drag-and-drop, commented code, fixed Google Maps interface, added mouse and SpinBox zoom to HSIWidget, fixed MAV-based coloring and stylesheets - MEGA COMMIT
parent 937caddc
......@@ -101,8 +101,46 @@ QSeparator {
QSpinBox {
min-height: 12 px;
}
min-height: 14px;
max-height: 18px;
border: 1px solid #4A4A4F;
border-radius: 5px;
}
QSpinBox::up-button {
subcontrol-origin: border;
subcontrol-position: top right; /* position at the top right corner */
border-image: url(:/images/actions/go-up.svg) 1;
border-width: 1px;
}
QSpinBox::down-button {
subcontrol-origin: border;
subcontrol-position: bottom right; /* position at the top right corner */
border-image: url(:/images/actions/go-down.svg) 1;
border-width: 1px;
}
QDoubleSpinBox {
min-height: 14px;
max-height: 18px;
border: 1px solid #4A4A4F;
border-radius: 5px;
}
QDoubleSpinBox::up-button {
subcontrol-origin: border;
subcontrol-position: top right; /* position at the top right corner */
border-image: url(:/images/actions/go-up.svg) 1;
border-width: 1px;
max-width: 5px;
}
QDoubleSpinBox::down-button {
subcontrol-origin: border;
subcontrol-position: bottom right; /* position at the top right corner */
border-image: url(:/images/actions/go-down.svg) 1;
border-width: 1px;
max-width: 5px;
}
QPushButton {
font-weight: bold;
......
......@@ -27,8 +27,7 @@
namespace qmapcontrol
{
GoogleMapAdapter::GoogleMapAdapter()
: TileMapAdapter("mt2.google.com", "/mt?n=404&x=%2&y=%3&zoom=%1", 256, 17, 0)
//: TileMapAdapter("tile.openstreetmap.org", "/%1/%2/%3.png", 256, 0, 17)
: TileMapAdapter("mt0.google.com", "/vt/lyrs=&x=%2&s=&y=%3&z=%1", 256, 0, 17)
{
}
......
......@@ -29,155 +29,155 @@
namespace qmapcontrol
{
GoogleSatMapAdapter::GoogleSatMapAdapter()
: TileMapAdapter("kh2.google.com", "/kh?n=404&v=8&t=trtqtt", 256, 0, 19)
: TileMapAdapter("khm.google.com", "/kh?v=51&x=%2&s=&y=%3&z=%1", 256, 0, 17)
{
// name = "googlesat";
numberOfTiles = pow(2, current_zoom+0.0);
coord_per_x_tile = 360. / numberOfTiles;
coord_per_y_tile = 180. / numberOfTiles;
// // name = "googlesat";
//
// numberOfTiles = pow(2, current_zoom+0.0);
// coord_per_x_tile = 360. / numberOfTiles;
// coord_per_y_tile = 180. / numberOfTiles;
}
GoogleSatMapAdapter::~GoogleSatMapAdapter()
{
}
QString GoogleSatMapAdapter::getHost() const
{
int random = qrand() % 4;
return QString("kh%1.google.com").arg(random);
}
QPoint GoogleSatMapAdapter::coordinateToDisplay(const QPointF& coordinate) const
{
//double x = ((coordinate.x()+180)*(tilesize*numberOfTiles/360));
//double y = (((coordinate.y()*-1)+90)*(tilesize*numberOfTiles/180));
qreal x = (coordinate.x()+180.) * (numberOfTiles*mytilesize)/360.; // coord to pixel!
//double y = -1*(coordinate.y()-90) * (numberOfTiles*tilesize)/180.; // coord to pixel!
qreal y = (getMercatorYCoord(coordinate.y())-M_PI) * -1 * (numberOfTiles*mytilesize)/(2*M_PI); // coord to pixel!
return QPoint(int(x), int(y));
}
QPointF GoogleSatMapAdapter::displayToCoordinate(const QPoint& point) const
{
//double lon = ((point.x()/tilesize*numberOfTiles)*360)-180;
//double lat = (((point.y()/tilesize*numberOfTiles)*180)-90)*-1;
qreal lon = (point.x()*(360.0/(numberOfTiles*mytilesize)))-180.0;
// qreal lat = -(point.y()*(180.0/(numberOfTiles*mytilesize)))+90.0;
// FIXME Looks buggy
qreal lat = getMercatorLatitude(point.y()*-1*(2*M_PI/(numberOfTiles*mytilesize)) + M_PI);
//qreal lat = lat *180./M_PI;
return QPointF(lon, lat);
}
qreal GoogleSatMapAdapter::getMercatorLatitude(qreal YCoord) const
{
//http://welcome.warnercnr.colostate.edu/class_info/nr502/lg4/projection_mathematics/converting.html
if (YCoord > M_PI) return 9999.;
if (YCoord < -M_PI) return -9999.;
qreal t = atan(exp(YCoord));
qreal res = (2.*(t))-(M_PI/2.);
return res;
}
qreal GoogleSatMapAdapter::getMercatorYCoord(qreal lati) const
{
qreal lat = lati;
// conversion degre=>radians
qreal phi = M_PI * lat / 180;
qreal res;
//double temp = Math.Tan(Math.PI / 4 - phi / 2);
//res = Math.Log(temp);
res = 0.5 * log((1 + sin(phi)) / (1 - sin(phi)));
return res;
}
void GoogleSatMapAdapter::zoom_in()
{
current_zoom+=1;
numberOfTiles = pow(2, current_zoom+0.0);
coord_per_x_tile = 360. / numberOfTiles;
coord_per_y_tile = 180. / numberOfTiles;
}
void GoogleSatMapAdapter::zoom_out()
{
current_zoom-=1;
numberOfTiles = pow(2, current_zoom+0.0);
coord_per_x_tile = 360. / numberOfTiles;
coord_per_y_tile = 180. / numberOfTiles;
}
bool GoogleSatMapAdapter::isValid(int x, int y, int z) const
{
if ((x>=0 && x < numberOfTiles) && (y>=0 && y < numberOfTiles) && z>=0)
{
return true;
}
return false;
}
QString GoogleSatMapAdapter::query(int i, int j, int z) const
{
return getQ(-180+i*coord_per_x_tile,
90-(j+1)*coord_per_y_tile, z);
}
QString GoogleSatMapAdapter::getQ(qreal longitude, qreal latitude, int zoom) const
{
qreal xmin=-180;
qreal xmax=180;
qreal ymin=-90;
qreal ymax=90;
qreal xmoy=0;
qreal ymoy=0;
QString location="t";
//Google uses a latitude divided by 2;
qreal halflat = latitude;
for (int i = 0; i < zoom; i++)
{
xmoy = (xmax + xmin) / 2;
ymoy = (ymax + ymin) / 2;
if (halflat >= ymoy) //upper part (q or r)
{
ymin = ymoy;
if (longitude < xmoy)
{ /*q*/
location+= "q";
xmax = xmoy;
}
else
{/*r*/
location+= "r";
xmin = xmoy;
}
}
else //lower part (t or s)
{
ymax = ymoy;
if (longitude < xmoy)
{ /*t*/
location+= "t";
xmax = xmoy;
}
else
{/*s*/
location+= "s";
xmin = xmoy;
}
}
}
return QString("/kh?n=404&v=24&t=%1").arg(location);
}
//
// QString GoogleSatMapAdapter::getHost() const
// {
// int random = qrand() % 4;
// return QString("kh%1.google.com").arg(random);
// }
//
// QPoint GoogleSatMapAdapter::coordinateToDisplay(const QPointF& coordinate) const
// {
// //double x = ((coordinate.x()+180)*(tilesize*numberOfTiles/360));
// //double y = (((coordinate.y()*-1)+90)*(tilesize*numberOfTiles/180));
//
// qreal x = (coordinate.x()+180.) * (numberOfTiles*mytilesize)/360.; // coord to pixel!
// //double y = -1*(coordinate.y()-90) * (numberOfTiles*tilesize)/180.; // coord to pixel!
// qreal y = (getMercatorYCoord(coordinate.y())-M_PI) * -1 * (numberOfTiles*mytilesize)/(2*M_PI); // coord to pixel!
// return QPoint(int(x), int(y));
// }
//
// QPointF GoogleSatMapAdapter::displayToCoordinate(const QPoint& point) const
// {
// //double lon = ((point.x()/tilesize*numberOfTiles)*360)-180;
// //double lat = (((point.y()/tilesize*numberOfTiles)*180)-90)*-1;
//
// qreal lon = (point.x()*(360.0/(numberOfTiles*mytilesize)))-180.0;
// // qreal lat = -(point.y()*(180.0/(numberOfTiles*mytilesize)))+90.0;
// // FIXME Looks buggy
//
// qreal lat = getMercatorLatitude(point.y()*-1*(2*M_PI/(numberOfTiles*mytilesize)) + M_PI);
// //qreal lat = lat *180./M_PI;
// return QPointF(lon, lat);
// }
//
// qreal GoogleSatMapAdapter::getMercatorLatitude(qreal YCoord) const
// {
// //http://welcome.warnercnr.colostate.edu/class_info/nr502/lg4/projection_mathematics/converting.html
// if (YCoord > M_PI) return 9999.;
// if (YCoord < -M_PI) return -9999.;
//
// qreal t = atan(exp(YCoord));
// qreal res = (2.*(t))-(M_PI/2.);
// return res;
// }
//
// qreal GoogleSatMapAdapter::getMercatorYCoord(qreal lati) const
// {
// qreal lat = lati;
//
// // conversion degre=>radians
// qreal phi = M_PI * lat / 180;
//
// qreal res;
// //double temp = Math.Tan(Math.PI / 4 - phi / 2);
// //res = Math.Log(temp);
// res = 0.5 * log((1 + sin(phi)) / (1 - sin(phi)));
//
// return res;
// }
//
// void GoogleSatMapAdapter::zoom_in()
// {
// current_zoom+=1;
// numberOfTiles = pow(2, current_zoom+0.0);
// coord_per_x_tile = 360. / numberOfTiles;
// coord_per_y_tile = 180. / numberOfTiles;
// }
//
// void GoogleSatMapAdapter::zoom_out()
// {
// current_zoom-=1;
// numberOfTiles = pow(2, current_zoom+0.0);
// coord_per_x_tile = 360. / numberOfTiles;
// coord_per_y_tile = 180. / numberOfTiles;
// }
//
// bool GoogleSatMapAdapter::isValid(int x, int y, int z) const
// {
// if ((x>=0 && x < numberOfTiles) && (y>=0 && y < numberOfTiles) && z>=0)
// {
// return true;
// }
// return false;
// }
// QString GoogleSatMapAdapter::query(int i, int j, int z) const
// {
// return getQ(-180+i*coord_per_x_tile,
// 90-(j+1)*coord_per_y_tile, z);
// }
//
// QString GoogleSatMapAdapter::getQ(qreal longitude, qreal latitude, int zoom) const
// {
// qreal xmin=-180;
// qreal xmax=180;
// qreal ymin=-90;
// qreal ymax=90;
//
// qreal xmoy=0;
// qreal ymoy=0;
// QString location="t";
//
// //Google uses a latitude divided by 2;
// qreal halflat = latitude;
//
// for (int i = 0; i < zoom; i++)
// {
// xmoy = (xmax + xmin) / 2;
// ymoy = (ymax + ymin) / 2;
// if (halflat >= ymoy) //upper part (q or r)
// {
// ymin = ymoy;
// if (longitude < xmoy)
// { /*q*/
// location+= "q";
// xmax = xmoy;
// }
// else
// {/*r*/
// location+= "r";
// xmin = xmoy;
// }
// }
// else //lower part (t or s)
// {
// ymax = ymoy;
// if (longitude < xmoy)
// { /*t*/
//
// location+= "t";
// xmax = xmoy;
// }
// else
// {/*s*/
// location+= "s";
// xmin = xmoy;
// }
// }
// }
// return QString("/kh?n=404&v=24&t=%1").arg(location);
// }
}
......@@ -44,31 +44,31 @@ namespace qmapcontrol
*/
GoogleSatMapAdapter();
virtual ~GoogleSatMapAdapter();
virtual QPoint coordinateToDisplay(const QPointF&) const;
virtual QPointF displayToCoordinate(const QPoint&) const;
//! returns the host of this MapAdapter
/*!
* @return the host of this MapAdapter
*/
QString getHost () const;
protected:
virtual void zoom_in();
virtual void zoom_out();
virtual QString query(int x, int y, int z) const;
virtual bool isValid(int x, int y, int z) const;
private:
virtual QString getQ(qreal longitude, qreal latitude, int zoom) const;
qreal getMercatorLatitude(qreal YCoord) const;
qreal getMercatorYCoord(qreal lati) const;
qreal coord_per_x_tile;
qreal coord_per_y_tile;
int srvNum;
//
// virtual QPoint coordinateToDisplay(const QPointF&) const;
// virtual QPointF displayToCoordinate(const QPoint&) const;
//
// //! returns the host of this MapAdapter
// /*!
// * @return the host of this MapAdapter
// */
// QString getHost () const;
//
//
// protected:
// virtual void zoom_in();
// virtual void zoom_out();
// virtual QString query(int x, int y, int z) const;
// virtual bool isValid(int x, int y, int z) const;
//
// private:
// virtual QString getQ(qreal longitude, qreal latitude, int zoom) const;
// qreal getMercatorLatitude(qreal YCoord) const;
// qreal getMercatorYCoord(qreal lati) const;
//
// qreal coord_per_x_tile;
// qreal coord_per_y_tile;
// int srvNum;
};
}
#endif
......@@ -31,7 +31,10 @@
message(Qt version $$[QT_VERSION])
release {
# DEFINES += QT_NO_DEBUG_OUTPUT
# DEFINES += QT_NO_WARNING_OUTPUT
}
# MAC OS X
macx {
......
......@@ -152,7 +152,10 @@ HEADERS += src/MG.h \
src/ui/QGCPxImuFirmwareUpdate.h \
src/comm/MAVLinkLightProtocol.h \
src/ui/QGCDataPlot2D.h \
src/ui/linechart/IncrementalPlot.h
src/ui/linechart/IncrementalPlot.h \
src/ui/map/Waypoint2DIcon.h \
src/ui/map/MAV2DIcon.h \
src/ui/map/QGC2DIcon.h
SOURCES += src/main.cc \
src/Core.cc \
src/uas/UASManager.cc \
......@@ -212,7 +215,10 @@ SOURCES += src/main.cc \
src/ui/QGCPxImuFirmwareUpdate.cc \
src/comm/MAVLinkLightProtocol.cc \
src/ui/QGCDataPlot2D.cc \
src/ui/linechart/IncrementalPlot.cc
src/ui/linechart/IncrementalPlot.cc \
src/ui/map/Waypoint2DIcon.cc \
src/ui/map/MAV2DIcon.cc \
src/ui/map/QGC2DIcon.cc
RESOURCES = mavground.qrc
# Include RT-LAB Library
......
......@@ -258,7 +258,7 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b)
//if ()
// If a new loss was detected or we just hit one 128th packet step
if (lastLoss != totalLossCounter || (totalReceiveCounter & 0x7F) == 0)
if (lastLoss != totalLossCounter || (totalReceiveCounter == 128))
{
// Calculate new loss ratio
// Receive loss
......
......@@ -40,6 +40,7 @@ This file is part of the QGROUNDCONTROL project
#include "ProtocolInterface.h"
#include "LinkInterface.h"
#include "protocol.h"
#include "mavlink.h"
/**
* @brief MAVLink micro air vehicle protocol reference implementation.
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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.
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
#ifndef ARDUPILOTMAV_H
#define ARDUPILOTMAV_H
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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.
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
#ifndef PXQUADMAV_H
#define PXQUADMAV_H
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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.
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
#ifndef SLUGSMAV_H
#define SLUGSMAV_H
......
......@@ -1038,6 +1038,11 @@ void UAS::setManualControlCommands(double roll, double pitch, double yaw, double
}
}
int UAS::getSystemType()
{
return this->type;
}
void UAS::receiveButton(int buttonIndex)
{
switch (buttonIndex)
......
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the PIXHAWK project
This file is part of the QGROUNDCONTROL project
PIXHAWK is free software: you can redistribute it and/or modify
QGROUNDCONTROL 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.
PIXHAWK is distributed in the hope that it will be useful,
QGROUNDCONTROL 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
......@@ -142,6 +142,7 @@ protected:
public:
UASWaypointManager &getWaypointManager(void) { return waypointManager; }
int getSystemType();
public slots:
/** @brief Launches the system **/
......
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the PIXHAWK project
This file is part of the QGROUNDCONTROL project
PIXHAWK is free software: you can redistribute it and/or modify
QGROUNDCONTROL 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.
PIXHAWK is distributed in the hope that it will be useful,
QGROUNDCONTROL 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
......@@ -135,6 +135,9 @@ public:
return colors[nextColor++];
}
/** @brief Get the type of the system (airplane, quadrotor, helicopter,..)*/
virtual int getSystemType() = 0;
QColor getColor()
{
return color;
......
......@@ -23,7 +23,7 @@ This file is part of the PIXHAWK project
/**
* @file
* @brief Implementation of central manager for all connected aerial vehicles
* @brief Implementation of class UASManager
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
......@@ -81,9 +81,7 @@ void UASManager::addUAS(UASInterface* uas)
// If there is no active UAS yet, set the first one as the active UAS
if (activeUAS == NULL)
{
activeUAS = uas;
emit activeUASSet(uas);
emit activeUASSet(uas->getUASID());
setActiveUAS(uas);
}
}
......@@ -165,6 +163,11 @@ void UASManager::setActiveUAS(UASInterface* uas)
if (uas != NULL)
{
activeUASMutex.lock();
if (activeUAS != NULL)
{
emit activeUASStatusChanged(activeUAS, false);
emit activeUASStatusChanged(activeUAS->getUASID(), false);
}
activeUAS = uas;
activeUASMutex.unlock();
......@@ -172,6 +175,8 @@ void UASManager::setActiveUAS(UASInterface* uas)
emit activeUASSet(uas);
emit activeUASSet(uas->getUASID());
emit activeUASStatusChanged(uas, true);
emit activeUASStatusChanged(uas->getUASID(), true);
}
}
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
QGroundControl Open Source Ground Control Station
(c) 2009 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the PIXHAWK project
This file is part of the QGROUNDCONTROL project
PIXHAWK is free software: you can redistribute it and/or modify
QGROUNDCONTROL 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.
PIXHAWK is distributed in the hope that it will be useful,
QGROUNDCONTROL 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Definition of central manager for all connected aerial vehicles
* @brief Definition of class UASManager
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
......@@ -37,7 +37,7 @@ This file is part of the PIXHAWK project
#include <UASInterface.h>
/**
* @brief Manager class for the UASs
* @brief Central manager for all connected aerial vehicles
*
* This class keeps a list of all connected / configured UASs. It also stores which
* UAS is currently select with respect to user input or manual controls.
......@@ -165,8 +165,14 @@ protected:
signals:
void UASCreated(UASInterface* UAS);
/** @brief The UAS currently under main operator control changed */
void activeUASSet(UASInterface* UAS);
/** @brief The UAS currently under main operator control changed */
void activeUASSet(int systemId);
/** @brief The UAS currently under main operator control changed */
void activeUASStatusChanged(UASInterface* UAS, bool active);
/** @brief The UAS currently under main operator control changed */
void activeUASStatusChanged(int systemId, bool active);
};
......
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the PIXHAWK project
This file is part of the QGROUNDCONTROL project
PIXHAWK is free software: you can redistribute it and/or modify
QGROUNDCONTROL 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.
PIXHAWK is distributed in the hope that it will be useful,
QGROUNDCONTROL 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
......
......@@ -32,6 +32,8 @@ This file is part of the PIXHAWK project
#include <QFile>
#include <QGLWidget>
#include <QStringList>
#include <QGraphicsTextItem>
#include <QMouseEvent>
#include "UASManager.h"
#include "HDDisplay.h"
#include "ui_HDDisplay.h"
......@@ -80,11 +82,47 @@ HDDisplay::HDDisplay(QStringList* plotList, QWidget *parent) :
acceptList = new QStringList();
}
// setBackgroundBrush(QBrush(backgroundColor));
// setDragMode(QGraphicsView::ScrollHandDrag);
// setCacheMode(QGraphicsView::CacheBackground);
// // FIXME Handle full update with care - ressource intensive
// setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
//
// setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
//
// //Set-up the scene
// QGraphicsScene* Scene = new QGraphicsScene(this);
// setScene(Scene);
//
// //Populate the scene
// for(int x = 0; x < 1000; x = x + 25) {
// for(int y = 0; y < 1000; y = y + 25) {
//
// if(x % 100 == 0 && y % 100 == 0) {
// Scene->addRect(x, y, 2, 2);
//
// QString pointString;
// QTextStream stream(&pointString);
// stream << "(" << x << "," << y << ")";
// QGraphicsTextItem* item = Scene->addText(pointString);
// item->setPos(x, y);
// } else {
// Scene->addRect(x, y, 1, 1);
// }
// }
// }
//
// //Set-up the view
// setSceneRect(0, 0, 1000, 1000);
// setCenter(QPointF(500.0, 500.0)); //A modified version of centerOn(), handles special cases
// setCursor(Qt::OpenHandCursor);
this->setMinimumHeight(125);
this->setMinimumWidth(100);
// Refresh timer
refreshTimer->setInterval(150); // 200 Hz/5 ms
refreshTimer->setInterval(180); //
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(triggerUpdate()));
//connect(refreshTimer, SIGNAL(timeout()), this, SLOT(paintGL()));
......@@ -117,14 +155,12 @@ void HDDisplay::enableGLRendering(bool enable)
void HDDisplay::triggerUpdate()
{
// Only repaint the regions necessary
QRect r = geometry();
update(r);
update(this->geometry());
}
void HDDisplay::paintEvent(QPaintEvent * event)
{
Q_UNUSED(event);
//paintGL();
static quint64 interval = 0;
//qDebug() << "INTERVAL:" << MG::TIME::getGroundTimeNow() - interval << __FILE__ << __LINE__;
interval = MG::TIME::getGroundTimeNow();
......@@ -152,7 +188,7 @@ void HDDisplay::renderOverlay()
QPainter painter(viewport());
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
painter.fillRect(QRect(0, 0, width(), height()), backgroundColor);
//painter.fillRect(QRect(0, 0, width(), height()), backgroundColor);
const int columns = 3;
const float spacing = 0.4f; // 40% of width
const float gaugeWidth = vwidth / (((float)columns) + (((float)columns+1) * spacing + spacing * 0.5f));
......@@ -629,3 +665,138 @@ void HDDisplay::changeEvent(QEvent *e)
break;
}
}
///**
// * Sets the current centerpoint. Also updates the scene's center point.
// * Unlike centerOn, which has no way of getting the floating point center
// * back, SetCenter() stores the center point. It also handles the special
// * sidebar case. This function will claim the centerPoint to sceneRec ie.
// * the centerPoint must be within the sceneRec.
// */
////Set the current centerpoint in the
//void HDDisplay::setCenter(const QPointF& centerPoint) {
// //Get the rectangle of the visible area in scene coords
// QRectF visibleArea = mapToScene(rect()).boundingRect();
//
// //Get the scene area
// QRectF sceneBounds = sceneRect();
//
// double boundX = visibleArea.width() / 2.0;
// double boundY = visibleArea.height() / 2.0;
// double boundWidth = sceneBounds.width() - 2.0 * boundX;
// double boundHeight = sceneBounds.height() - 2.0 * boundY;
//
// //The max boundary that the centerPoint can be to
// QRectF bounds(boundX, boundY, boundWidth, boundHeight);
//
// if(bounds.contains(centerPoint)) {
// //We are within the bounds
// currentCenterPoint = centerPoint;
// } else {
// //We need to clamp or use the center of the screen
// if(visibleArea.contains(sceneBounds)) {
// //Use the center of scene ie. we can see the whole scene
// currentCenterPoint = sceneBounds.center();
// } else {
//
// currentCenterPoint = centerPoint;
//
// //We need to clamp the center. The centerPoint is too large
// if(centerPoint.x() > bounds.x() + bounds.width()) {
// currentCenterPoint.setX(bounds.x() + bounds.width());
// } else if(centerPoint.x() < bounds.x()) {
// currentCenterPoint.setX(bounds.x());
// }
//
// if(centerPoint.y() > bounds.y() + bounds.height()) {
// currentCenterPoint.setY(bounds.y() + bounds.height());
// } else if(centerPoint.y() < bounds.y()) {
// currentCenterPoint.setY(bounds.y());
// }
//
// }
// }
//
// //Update the scrollbars
// centerOn(currentCenterPoint);
//}
//
///**
// * Handles when the mouse button is pressed
// */
//void HDDisplay::mousePressEvent(QMouseEvent* event) {
// //For panning the view
// lastPanPoint = event->pos();
// setCursor(Qt::ClosedHandCursor);
//}
//
///**
// * Handles when the mouse button is released
// */
//void HDDisplay::mouseReleaseEvent(QMouseEvent* event) {
// setCursor(Qt::OpenHandCursor);
// lastPanPoint = QPoint();
//}
//
///**
//*Handles the mouse move event
//*/
//void HDDisplay::mouseMoveEvent(QMouseEvent* event) {
// if(!lastPanPoint.isNull()) {
// //Get how much we panned
// QPointF delta = mapToScene(lastPanPoint) - mapToScene(event->pos());
// lastPanPoint = event->pos();
//
// //Update the center ie. do the pan
// setCenter(getCenter() + delta);
// }
//}
//
///**
// * Zoom the view in and out.
// */
//void HDDisplay::wheelEvent(QWheelEvent* event) {
//
// //Get the position of the mouse before scaling, in scene coords
// QPointF pointBeforeScale(mapToScene(event->pos()));
//
// //Get the original screen centerpoint
// QPointF screenCenter = getCenter(); //CurrentCenterPoint; //(visRect.center());
//
// //Scale the view ie. do the zoom
// double scaleFactor = 1.15; //How fast we zoom
// if(event->delta() > 0) {
// //Zoom in
// scale(scaleFactor, scaleFactor);
// } else {
// //Zooming out
// scale(1.0 / scaleFactor, 1.0 / scaleFactor);
// }
//
// //Get the position after scaling, in scene coords
// QPointF pointAfterScale(mapToScene(event->pos()));
//
// //Get the offset of how the screen moved
// QPointF offset = pointBeforeScale - pointAfterScale;
//
// //Adjust to the new center for correct zooming
// QPointF newCenter = screenCenter + offset;
// setCenter(newCenter);
//}
//
///**
// * Need to update the center so there is no jolt in the
// * interaction after resizing the widget.
// */
//void HDDisplay::resizeEvent(QResizeEvent* event) {
// //Get the rectangle of the visible area in scene coords
// QRectF visibleArea = mapToScene(rect()).boundingRect();
// setCenter(visibleArea.center());
//
// //Call the subclass resize so the scrollbars are updated correctly
// QGraphicsView::resizeEvent(event);
//}
......@@ -94,6 +94,23 @@ protected:
void drawSystemIndicator(float xRef, float yRef, int maxNum, float maxWidth, float maxHeight, QPainter* painter);
void paintText(QString text, QColor color, float fontSize, float refX, float refY, QPainter* painter);
// //Holds the current centerpoint for the view, used for panning and zooming
// QPointF currentCenterPoint;
//
// //From panning the view
// QPoint lastPanPoint;
//
// //Set the current centerpoint in the
// void setCenter(const QPointF& centerPoint);
// QPointF getCenter() { return currentCenterPoint; }
//
// //Take over the interaction
// virtual void mousePressEvent(QMouseEvent* event);
// virtual void mouseReleaseEvent(QMouseEvent* event);
// virtual void mouseMoveEvent(QMouseEvent* event);
// virtual void wheelEvent(QWheelEvent* event);
// virtual void resizeEvent(QResizeEvent* event);
UASInterface* uas; ///< The uas currently monitored
QMap<QString, float> values; ///< The variables this HUD displays
QMap<QString, float> valuesDot; ///< First derivative of the variable
......
......@@ -32,12 +32,16 @@ This file is part of the QGROUNDCONTROL project
#include <QFile>
#include <QStringList>
#include <QPainter>
#include <QGraphicsScene>
#include <QHBoxLayout>
#include <QDoubleSpinBox>
#include "UASManager.h"
#include "HSIDisplay.h"
#include "MG.h"
#include "QGC.h"
#include "Waypoint.h"
#include "UASWaypointManager.h"
#include "Waypoint2DIcon.h"
#include <QDebug>
......@@ -98,9 +102,28 @@ HSIDisplay::HSIDisplay(QWidget *parent) :
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*)));
refreshTimer->setInterval(60);
// this->setScene(new QGraphicsScene(-metricWidth/2.0f, -metricWidth/2.0f, metricWidth, metricWidth, this));
xCenterPos = vwidth/2.0f;
yCenterPos = vheight/2.0f + topMargin - bottomMargin;
// Add interaction elements
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setMargin(2);
layout->setSpacing(0);
QDoubleSpinBox* spinBox = new QDoubleSpinBox(this);
spinBox->setMinimum(0.1);
spinBox->setMaximum(9999);
connect(spinBox, SIGNAL(valueChanged(double)), this, SLOT(setMetricWidth(double)));
connect(this, SIGNAL(metricWidthChanged(double)), spinBox, SLOT(setValue(double)));
layout->addWidget(spinBox);
layout->setAlignment(spinBox, Qt::AlignBottom | Qt::AlignLeft);
this->setLayout(layout);
this->setVisible(false);
// Do first update
setMetricWidth(metricWidth);
}
void HSIDisplay::paintEvent(QPaintEvent * event)
......@@ -136,7 +159,8 @@ void HSIDisplay::renderOverlay()
painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
// Draw background
painter.fillRect(QRect(0, 0, width(), height()), backgroundColor);
//painter.fillRect(QRect(0, 0, width(), height()), backgroundColor);
// Draw base instrument
// ----------------------
......@@ -393,6 +417,15 @@ void HSIDisplay::mouseDoubleClickEvent(QMouseEvent * event)
}
}
void HSIDisplay::setMetricWidth(double width)
{
if (width != metricWidth)
{
metricWidth = width;
emit metricWidthChanged(metricWidth);
}
}
/**
*
* @param uas the UAS/MAV to monitor/display with the HUD
......@@ -634,6 +667,18 @@ void HSIDisplay::drawWaypoints(QPainter& painter)
if (uas)
{
const QVector<Waypoint*>& list = uas->getWaypointManager().getWaypointList();
// for (int i = 0; i < list.size(); i++)
// {
// QPointF in(list.at(i)->getX(), list.at(i)->getY());
// // Transform from world to body coordinates
// in = metricWorldToBody(in);
// // Scale from metric to screen reference coordinates
// QPointF p = metricBodyToRef(in);
// Waypoint2DIcon* wp = new Waypoint2DIcon();
// wp->setLocalPosition(list.at(i)->getX(), list.at(i)->getY());
// wp->setPos(0, 0);
// scene()->addItem(wp);
// }
QColor color;
painter.setBrush(Qt::NoBrush);
......@@ -863,18 +908,22 @@ void HSIDisplay::drawAltitudeSetpoint(float xRef, float yRef, float radius, cons
// paintText(label, color, 4.5f, xRef-7.5f, yRef-2.0f, painter);
}
/**
* @param fix 0: lost, 1: 2D local position hold, 2: 2D localization, 3: 3D localization
*/
void localizationChanged(UASInterface* uas, int fix);
/**
* @param fix 0: lost, 1: at least one satellite, but no GPS fix, 2: 2D localization, 3: 3D localization
*/
void gpsLocalizationChanged(UASInterface* uas, int fix);
/**
* @param fix 0: lost, 1: 2D local position hold, 2: 2D localization, 3: 3D localization
*/
void visionLocalizationChanged(UASInterface* uas, int fix);
void HSIDisplay::wheelEvent(QWheelEvent* event)
{
double zoomScale = 0.005; // Scaling of zoom value
if(event->delta() > 0)
{
// Reduce width -> Zoom in
metricWidth -= event->delta() * zoomScale;
}
else
{
// Increase width -> Zoom out
metricWidth -= event->delta() * zoomScale;
}
metricWidth = qBound(0.1, metricWidth, 9999.0);
emit metricWidthChanged(metricWidth);
}
void HSIDisplay::updateJoystick(double roll, double pitch, double yaw, double thrust, int xHat, int yHat)
{
......
......@@ -51,6 +51,8 @@ public:
public slots:
void setActiveUAS(UASInterface* uas);
/** @brief Set the width in meters this widget shows from top */
void setMetricWidth(double width);
void updateSatellite(int uasid, int satid, float azimuth, float direction, float snr, bool used);
void updateAttitudeSetpoints(UASInterface*, double rollDesired, double pitchDesired, double yawDesired, double thrustDesired, quint64 usec);
void updateAttitude(UASInterface* uas, double roll, double pitch, double yaw, quint64 time);
......@@ -80,6 +82,9 @@ public slots:
void updateJoystick(double roll, double pitch, double yaw, double thrust, int xHat, int yHat);
void pressKey(int key);
signals:
void metricWidthChanged(double width);
protected slots:
void renderOverlay();
void drawGPS(QPainter &painter);
......@@ -101,6 +106,8 @@ protected slots:
void drawSafetyArea(const QPointF &topLeft, const QPointF &bottomRight, const QColor &color, QPainter &painter);
/** @brief Receive mouse clicks */
void mouseDoubleClickEvent(QMouseEvent* event);
/** @brief Receive mouse wheel events */
void wheelEvent(QWheelEvent* event);
protected:
......@@ -202,7 +209,7 @@ protected:
float uiYSetCoordinate; ///< Y Setpoint coordinate wanted by the UI
float uiZSetCoordinate; ///< Z Setpoint coordinate wanted by the UI
float uiYawSet; ///< Yaw Setpoint wanted by the UI
float metricWidth; ///< Width the instrument represents in meters (the width of the ground shown by the widget)
double metricWidth; ///< Width the instrument represents in meters (the width of the ground shown by the widget)
//
float xCenterPos; ///< X center of instrument in virtual coordinates
......
......@@ -391,29 +391,61 @@ void MainWindow::addLink(LinkInterface *link)
void MainWindow::UASCreated(UASInterface* uas)
{
// Connect the UAS to the full user interface
ui.menuConnected_Systems->addAction(QIcon(":/images/mavs/generic.svg"), tr("View ") + uas->getUASName(), uas, SLOT(setSelected()));
// FIXME Should be not inside the mainwindow
connect(uas, SIGNAL(textMessageReceived(int,int,int,QString)), debugConsole, SLOT(receiveTextMessage(int,int,int,QString)));
if (uas != NULL)
{
QIcon icon;
// Set matching icon
switch (uas->getSystemType())
{
case 0:
icon = QIcon(":/images/mavs/generic.svg");
break;
case 1:
icon = QIcon(":/images/mavs/fixed-wing.svg");
break;
case 2:
icon = QIcon(":/images/mavs/quadrotor.svg");
break;
case 3:
icon = QIcon(":/images/mavs/coaxial.svg");
break;
case 4:
icon = QIcon(":/images/mavs/helicopter.svg");
break;
case 5:
icon = QIcon(":/images/mavs/groundstation.svg");
break;
default:
icon = QIcon(":/images/mavs/unknown.svg");
break;
}
// Health / System status indicator
info->addUAS(uas);
ui.menuConnected_Systems->addAction(icon, tr("Select %1 for control").arg(uas->getUASName()), uas, SLOT(setSelected()));
// UAS List
list->addUAS(uas);
// FIXME Should be not inside the mainwindow
connect(uas, SIGNAL(textMessageReceived(int,int,int,QString)), debugConsole, SLOT(receiveTextMessage(int,int,int,QString)));
// Camera view
//camera->addUAS(uas);
// Health / System status indicator
info->addUAS(uas);
// Revalidate UI
// TODO Stylesheet reloading should in theory not be necessary
reloadStylesheet();
// UAS List
list->addUAS(uas);
// Check which type this UAS is of
PxQuadMAV* mav = dynamic_cast<PxQuadMAV*>(uas);
if (mav) loadPixhawkView();
SlugsMAV* mav2 = dynamic_cast<SlugsMAV*>(uas);
if (mav2) loadSlugsView();
// Camera view
//camera->addUAS(uas);
// Revalidate UI
// TODO Stylesheet reloading should in theory not be necessary
reloadStylesheet();
// Check which type this UAS is of
PxQuadMAV* mav = dynamic_cast<PxQuadMAV*>(uas);
if (mav) loadPixhawkView();
SlugsMAV* mav2 = dynamic_cast<SlugsMAV*>(uas);
if (mav2) loadSlugsView();
}
}
/**
......
......@@ -89,7 +89,7 @@
</widget>
<widget class="QMenu" name="menuConnected_Systems">
<property name="title">
<string>Connected Systems</string>
<string>Select System</string>
</property>
</widget>
<addaction name="menuMGround"/>
......
......@@ -64,7 +64,10 @@ MapWidget::MapWidget(QWidget *parent) :
geomLayer = new Layer("Geom Layer", osmAdapter, Layer::GeometryLayer);
// add Layers to the MapControl and set zoom level
mc->addLayer(osmLayer);
//mc->addLayer(osmLayer);
GoogleSatMapAdapter* gsat = new GoogleSatMapAdapter();
Layer* gsatLayer = new Layer("Google Satellite", gsat, Layer::MapLayer);
mc->addLayer(gsatLayer);
mc->addLayer(geomLayer);
mc->setZoom(3);
......
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
(c) 2009 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
This file is part of the PIXHAWK project
PIXHAWK 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.
PIXHAWK 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Head Down Display / Primary Flight Display
*
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
#include "PFD.h"
PFD::PFD(int width, int height, QWidget* parent)
: HUD(width, height, parent)
{
vGaugeSpacing = 70.0f;
vwidth = 200.0f;
vheight = 200.0f;
}
// xCenterOffset(0.0f),
// yCenterOffset(0.0f),
// vwidth(200.0f),
// vheight(150.0f),
// vGaugeSpacing(50.0f),
// vPitchPerDeg(6.0f), ///< 4 mm y translation per degree)
// noCamera(true),
// hardwareAcceleration(true),
// strongStrokeWidth(1.5f),
// normalStrokeWidth(1.0f),
// fineStrokeWidth(0.5f)
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
(c) 2009 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
This file is part of the PIXHAWK project
PIXHAWK 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.
PIXHAWK 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Head Down Display / Primary Flight Display
*
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
#ifndef PFD_H
#define PFD_H
#include "HUD.h"
class PFD : public HUD
{
public:
PFD(int width, int height, QWidget* parent);
};
#endif // PFD_H
......@@ -6,20 +6,20 @@
<rect>
<x>0</x>
<y>0</y>
<width>280</width>
<height>164</height>
<width>287</width>
<height>354</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>280</width>
<height>130</height>
<height>170</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout" rowminimumheight="5,10,10,0,10,5,0">
<layout class="QGridLayout" name="gridLayout" rowminimumheight="10,20,0,10,10,10,300">
<property name="leftMargin">
<number>6</number>
</property>
......@@ -60,7 +60,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
<height>2</height>
</size>
</property>
</spacer>
......
......@@ -299,14 +299,17 @@ void IncrementalPlot::updateScale()
if (xRange > yRange)
{
double yCenter = yMinRange + yRange/2.0;
double xCenter = xMinRange + xRange/2.0;
yMinRange = yCenter - xRange/2.0;
yMaxRange = yCenter + xRange/2.0;
xMinRange = xCenter - (xRange*aspectRatio)/2.0;
xMaxRange = xCenter + (xRange*aspectRatio)/2.0;
}
else
{
double xCenter = xMinRange + xRange/2.0;
xMinRange = xCenter - yRange/2.0;
xMaxRange = xCenter + yRange/2.0;
xMinRange = xCenter - (yRange*aspectRatio)/2.0;
xMaxRange = xCenter + (yRange*aspectRatio)/2.0;
}
}
setAxisScale(xBottom, xMinRange, xMaxRange);
......
......@@ -214,7 +214,7 @@ public:
static const int SCALE_LOGARITHMIC = 2;
static const int DEFAULT_REFRESH_RATE = 40; ///< The default refresh rate is 25 Hz / every 100 ms
static const int DEFAULT_PLOT_INTERVAL = 1000 * 10; ///< The default plot interval is 10 seconds
static const int DEFAULT_PLOT_INTERVAL = 1000 * 15; ///< The default plot interval is 15 seconds
static const int DEFAULT_SCALE_INTERVAL = 1000 * 5;
public slots:
......
#include "MAV2DIcon.h"
#include <QPainter>
MAV2DIcon::MAV2DIcon(QGraphicsItem* parent) :
QGC2DIcon(parent)
{
}
/**
* @return the bounding rectangle of the icon
*/
QRectF MAV2DIcon::boundingRect() const
{
qreal penWidth = 1;
return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,
20 + penWidth, 20 + penWidth);
}
/**
* @param painter QPainter to draw with
* @param option Visual style
* @param widget Parent widget
*/
void MAV2DIcon::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
}
#ifndef MAV2DICON_H
#define MAV2DICON_H
#include "QGC2DIcon.h"
class MAV2DIcon : public QGC2DIcon
{
public:
explicit MAV2DIcon(QGraphicsItem* parent = 0);
QRectF boundingRect() const;
void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*);
};
#endif // MAV2DICON_H
#include "QGC2DIcon.h"
QGC2DIcon::QGC2DIcon(QPointF localOriginInGlobalCoords, bool onlyLocal, QGraphicsItem* parent) :
QGraphicsItem(parent),
localOriginInGlobalCoords(localOriginInGlobalCoords),
local(onlyLocal)
{
}
QGC2DIcon::QGC2DIcon(bool onlyLocal, QGraphicsItem* parent) :
QGraphicsItem(parent),
localOriginInGlobalCoords(QPointF(0, 0)),
local(onlyLocal)
{
}
QGC2DIcon::QGC2DIcon(QGraphicsItem* parent) :
QGraphicsItem(parent),
localOriginInGlobalCoords(QPointF(0, 0)),
local(false)
{
}
QGC2DIcon::~QGC2DIcon()
{
}
QPointF QGC2DIcon::getGlobalPosition()
{
}
QPointF QGC2DIcon::getLocalPosition()
{
}
void QGC2DIcon::setGlobalPosition(QPointF pos)
{
}
void QGC2DIcon::setLocalPosition(QPointF pos)
{
}
void QGC2DIcon::setLocalPosition(float x, float y)
{
}
bool QGC2DIcon::isLocal()
{
return local;
}
#ifndef QGC2DICON_H
#define QGC2DICON_H
#include <QGraphicsItem>
#include <QPointF>
class QGC2DIcon : public QGraphicsItem
{
public:
QGC2DIcon(QPointF localOriginInGlobalCoords, bool onlyLocal=false, QGraphicsItem* parent = 0);
QGC2DIcon(bool onlyLocal=false, QGraphicsItem* parent = 0);
explicit QGC2DIcon(QGraphicsItem* parent = 0);
~QGC2DIcon();
QPointF getGlobalPosition();
QPointF getLocalPosition();
void setGlobalPosition(QPointF pos);
void setLocalPosition(QPointF pos);
void setLocalPosition(float x, float y);
bool isLocal();
virtual QRectF boundingRect() const = 0;
virtual void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) = 0;
signals:
public slots:
protected:
QPointF localOriginInGlobalCoords;
QPointF globalPosition;
QPointF localPosition;
bool local;
};
#endif // QGC2DICON_H
#include "Waypoint2DIcon.h"
#include <QPainter>
#include <QDebug>
Waypoint2DIcon::Waypoint2DIcon(QGraphicsItem* parent) :
QGC2DIcon(parent)
{
}
/**
* @return the bounding rectangle of the icon
*/
QRectF Waypoint2DIcon::boundingRect() const
{
qreal penWidth = 1;
return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,
20 + penWidth, 20 + penWidth);
}
/**
* @param painter QPainter to draw with
* @param option Visual style
* @param widget Parent widget
*/
void Waypoint2DIcon::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
qDebug() << __FILE__ << __LINE__ << "DRAWING";
painter->setPen(QPen(Qt::red));
painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
}
#ifndef WAYPOINT2DICON_H
#define WAYPOINT2DICON_H
#include <QGraphicsItem>
#include "QGC2DIcon.h"
class Waypoint2DIcon : public QGC2DIcon
{
public:
explicit Waypoint2DIcon(QGraphicsItem* parent = 0);
QRectF boundingRect() const;
void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*);
};
#endif // WAYPOINT2DICON_H
......@@ -35,6 +35,7 @@ This file is part of the PIXHAWK project
#include <QFileDialog>
#include <QDebug>
#include <QProcess>
#include <QPalette>
#include <MG.h>
#include "UASControlWidget.h"
......@@ -59,7 +60,7 @@ This file is part of the PIXHAWK project
#define CONTROL_MODE_TEST3_INDEX 8
UASControlWidget::UASControlWidget(QWidget *parent) : QWidget(parent),
uas(NULL),
uas(0),
engineOn(false)
{
ui.setupUi(this);
......@@ -74,22 +75,21 @@ engineOn(false)
ui.modeComboBox->insertItem(CONTROL_MODE_TEST1_INDEX, CONTROL_MODE_TEST1);
ui.modeComboBox->insertItem(CONTROL_MODE_TEST2_INDEX, CONTROL_MODE_TEST2);
ui.modeComboBox->insertItem(CONTROL_MODE_TEST3_INDEX, CONTROL_MODE_TEST3);
connect(ui.modeComboBox, SIGNAL(activated(int)), this, SLOT(setMode(int)));
connect(ui.setModeButton, SIGNAL(clicked()), this, SLOT(transmitMode()));
ui.modeComboBox->setCurrentIndex(0);
}
void UASControlWidget::setUAS(UASInterface* uas)
{
if (this->uas != NULL)
if (this->uas != 0)
{
disconnect(ui.controlButton, SIGNAL(clicked()), uas, SLOT(enable_motors()));
disconnect(ui.liftoffButton, SIGNAL(clicked()), uas, SLOT(launch()));
disconnect(ui.landButton, SIGNAL(clicked()), uas, SLOT(home()));
disconnect(ui.shutdownButton, SIGNAL(clicked()), uas, SLOT(shutdown()));
disconnect(ui.modeComboBox, SIGNAL(activated(int)), this, SLOT(setMode(int)));
disconnect(ui.setModeButton, SIGNAL(clicked()), this, SLOT(transmitMode()));
ui.modeComboBox->clear();
UASInterface* oldUAS = UASManager::instance()->getUASForId(this->uas);
disconnect(ui.controlButton, SIGNAL(clicked()), oldUAS, SLOT(enable_motors()));
disconnect(ui.liftoffButton, SIGNAL(clicked()), oldUAS, SLOT(launch()));
disconnect(ui.landButton, SIGNAL(clicked()), oldUAS, SLOT(home()));
disconnect(ui.shutdownButton, SIGNAL(clicked()), oldUAS, SLOT(shutdown()));
disconnect(uas, SIGNAL(modeChanged(int,QString,QString)), this, SLOT(updateMode(int,QString,QString)));
disconnect(uas, SIGNAL(statusChanged(int)), this, SLOT(updateState(int)));
}
......@@ -99,22 +99,42 @@ void UASControlWidget::setUAS(UASInterface* uas)
connect(ui.liftoffButton, SIGNAL(clicked()), uas, SLOT(launch()));
connect(ui.landButton, SIGNAL(clicked()), uas, SLOT(home()));
connect(ui.shutdownButton, SIGNAL(clicked()), uas, SLOT(shutdown()));
connect(ui.modeComboBox, SIGNAL(activated(int)), this, SLOT(setMode(int)));
connect(ui.setModeButton, SIGNAL(clicked()), this, SLOT(transmitMode()));
ui.modeComboBox->insertItem(0, "Select..");
ui.controlStatusLabel->setText(tr("Connected to ") + uas->getUASName());
connect(uas, SIGNAL(modeChanged(int,QString,QString)), this, SLOT(updateMode(int,QString,QString)));
connect(uas, SIGNAL(statusChanged(int)), this, SLOT(updateState(int)));
this->uas = uas;
ui.controlStatusLabel->setText(tr("Connected to ") + uas->getUASName());
this->uas = uas->getUASID();
setBackgroundColor(uas->getColor());
}
UASControlWidget::~UASControlWidget() {
UASControlWidget::~UASControlWidget()
{
}
/**
* Set the background color based on the MAV color. If the MAV is selected as the
* currently actively controlled system, the frame color is highlighted
*/
void UASControlWidget::setBackgroundColor(QColor color)
{
// UAS color
QColor uasColor = color;
QString colorstyle;
QString borderColor = "#4A4A4F";
borderColor = "#FA4A4F";
uasColor = uasColor.darker(900);
colorstyle = colorstyle.sprintf("QLabel { border-radius: 3px; padding: 0px; margin: 0px; background-color: #%02X%02X%02X; border: 0px solid %s; }",
uasColor.red(), uasColor.green(), uasColor.blue(), borderColor.toStdString().c_str());
setStyleSheet(colorstyle);
QPalette palette = this->palette();
palette.setBrush(QPalette::Window, QBrush(uasColor));
setPalette(palette);
setAutoFillBackground(true);
}
void UASControlWidget::updateMode(int uas,QString mode,QString description)
{
Q_UNUSED(uas);
......@@ -189,14 +209,14 @@ void UASControlWidget::transmitMode()
{
if (uasMode != 0)
{
this->uas->setMode(uasMode);
ui.lastActionLabel->setText(QString("Set new mode for system %1").arg(uas->getUASName()));
UASManager::instance()->getUASForId(this->uas)->setMode(uasMode);
ui.lastActionLabel->setText(QString("Set new mode for system %1").arg(UASManager::instance()->getUASForId(uas)->getUASName()));
}
}
void UASControlWidget::cycleContextButton()
{
UAS* mav = dynamic_cast<UAS*>(this->uas);
UAS* mav = dynamic_cast<UAS*>(UASManager::instance()->getUASForId(this->uas));
if (mav)
{
......@@ -204,13 +224,13 @@ void UASControlWidget::cycleContextButton()
{
ui.controlButton->setText(tr("Stop Engine"));
mav->enable_motors();
ui.lastActionLabel->setText(QString("Attempted to enable motors on %1").arg(uas->getUASName()));
ui.lastActionLabel->setText(QString("Attempted to enable motors on %1").arg(mav->getUASName()));
}
else
{
ui.controlButton->setText(tr("Activate Engine"));
mav->disable_motors();
ui.lastActionLabel->setText(QString("Attempted to disable motors on %1").arg(uas->getUASName()));
ui.lastActionLabel->setText(QString("Attempted to disable motors on %1").arg(mav->getUASName()));
}
//ui.controlButton->setText(tr("Force Landing"));
//ui.controlButton->setText(tr("KILL VEHICLE"));
......
......@@ -64,10 +64,14 @@ public slots:
/** @brief Update state */
void updateState(int state);
protected slots:
/** @brief Set the background color for the widget */
void setBackgroundColor(QColor color);
protected:
UASInterface* uas;
unsigned int uasMode;
bool engineOn;
int uas; ///< Reference to the current uas
unsigned int uasMode; ///< Current uas mode
bool engineOn; ///< Engine state
private:
Ui::uasControl ui;
......
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
(c) 2009 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
This file is part of the PIXHAWK project
PIXHAWK is free software: you can redistribute it and/or modify
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL 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.
PIXHAWK is distributed in the hope that it will be useful,
QGROUNDCONTROL 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
......
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
QGroundControl Open Source Ground Control Station
(c) 2009, 2010 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the PIXHAWK project
This file is part of the QGROUNDCONTROL project
PIXHAWK is free software: you can redistribute it and/or modify
QGROUNDCONTROL 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.
PIXHAWK is distributed in the hope that it will be useful,
QGROUNDCONTROL 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
......
......@@ -78,6 +78,7 @@ UASView::UASView(UASInterface* uas, QWidget *parent) :
connect(uas, SIGNAL(waypointSelected(int,int)), this, SLOT(selectWaypoint(int,int)));
connect(&(uas->getWaypointManager()), SIGNAL(currentWaypointChanged(quint16)), this, SLOT(currentWaypointUpdated(quint16)));
connect(uas, SIGNAL(systemTypeSet(UASInterface*,uint)), this, SLOT(setSystemType(UASInterface*,uint)));
connect(UASManager::instance(), SIGNAL(activeUASStatusChanged(UASInterface*,bool)), this, SLOT(updateActiveUAS(UASInterface*,bool)));
// Setup UAS selection
connect(m_ui->uasViewFrame, SIGNAL(clicked(bool)), this, SLOT(setUASasActive(bool)));
......@@ -108,7 +109,7 @@ UASView::UASView(UASInterface* uas, QWidget *parent) :
// Heartbeat fade
refreshTimer = new QTimer(this);
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
refreshTimer->start(100);
refreshTimer->start(180);
}
UASView::~UASView()
......@@ -142,9 +143,19 @@ void UASView::setBackgroundColor()
void UASView::setUASasActive(bool active)
{
UASManager::instance()->setActiveUAS(this->uas);
this->isActive = active;
setBackgroundColor();
if (active)
{
UASManager::instance()->setActiveUAS(this->uas);
}
}
void UASView::updateActiveUAS(UASInterface* uas, bool active)
{
if (uas == this->uas)
{
this->isActive = active;
setBackgroundColor();
}
}
void UASView::updateMode(int sysId, QString status, QString description)
......
/*=====================================================================
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
QGroundControl Open Source Ground Control Station
(c) 2009 PIXHAWK PROJECT <http://pixhawk.ethz.ch>
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the PIXHAWK project
This file is part of the QGROUNDCONTROL project
PIXHAWK is free software: you can redistribute it and/or modify
QGROUNDCONTROL 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.
PIXHAWK is distributed in the hope that it will be useful,
QGROUNDCONTROL 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
......@@ -42,7 +42,8 @@ namespace Ui {
class UASView;
}
class UASView : public QWidget {
class UASView : public QWidget
{
Q_OBJECT
public:
UASView(UASInterface* uas, QWidget *parent = 0);
......@@ -71,6 +72,8 @@ public slots:
void setSystemType(UASInterface* uas, unsigned int systemType);
/** @brief Set the current UAS as the globally active system */
void setUASasActive(bool);
/** @brief Update the view if an UAS has been set to active */
void updateActiveUAS(UASInterface* uas, bool active);
/** @brief Set the background color for the widget */
void setBackgroundColor();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment