diff --git a/flight/Modules/GPS/inc/GPS.h b/flight/Modules/GPS/inc/GPS.h index 250565e0a..fad5e8eed 100644 --- a/flight/Modules/GPS/inc/GPS.h +++ b/flight/Modules/GPS/inc/GPS.h @@ -1,55 +1,55 @@ -/** - ****************************************************************************** - * @addtogroup OpenPilotModules OpenPilot Modules - * @{ - * @addtogroup GSPModule GPS Module - * @brief Process GPS information - * @{ - * - * @file GPS.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Include file of the GPS module. - * As with all modules only the initialize function is exposed all other - * interactions with the module take place through the event queue and - * objects. - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * 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 GPS_H -#define GPS_H - -#include "gpsvelocity.h" -#include "gpssatellites.h" -#include "gpsposition.h" -#include "gpstime.h" - -#define NO_PARSER -3 // no parser available -#define PARSER_OVERRUN -2 // message buffer overrun before completing the message -#define PARSER_ERROR -1 // message unparsable by this parser -#define PARSER_INCOMPLETE 0 // parser needs more data to complete the message -#define PARSER_COMPLETE 1 // parser has received a complete message and finished processing - -int32_t GPSInitialize(void); - -#endif // GPS_H - -/** - * @} - * @} - */ +/** + ****************************************************************************** + * @addtogroup OpenPilotModules OpenPilot Modules + * @{ + * @addtogroup GSPModule GPS Module + * @brief Process GPS information + * @{ + * + * @file GPS.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Include file of the GPS module. + * As with all modules only the initialize function is exposed all other + * interactions with the module take place through the event queue and + * objects. + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * 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 GPS_H +#define GPS_H + +#include "gpsvelocity.h" +#include "gpssatellites.h" +#include "gpsposition.h" +#include "gpstime.h" + +#define NO_PARSER -3 // no parser available +#define PARSER_OVERRUN -2 // message buffer overrun before completing the message +#define PARSER_ERROR -1 // message unparsable by this parser +#define PARSER_INCOMPLETE 0 // parser needs more data to complete the message +#define PARSER_COMPLETE 1 // parser has received a complete message and finished processing + +int32_t GPSInitialize(void); + +#endif // GPS_H + +/** + * @} + * @} + */ diff --git a/ground/openpilotgcs/src/plugins/gpsdisplay/gpsconstellationwidget.cpp b/ground/openpilotgcs/src/plugins/gpsdisplay/gpsconstellationwidget.cpp index 8ae569095..e70f2ed72 100644 --- a/ground/openpilotgcs/src/plugins/gpsdisplay/gpsconstellationwidget.cpp +++ b/ground/openpilotgcs/src/plugins/gpsdisplay/gpsconstellationwidget.cpp @@ -1,184 +1,184 @@ -/** - ****************************************************************************** - * - * @file gpsconstellationwidget.cpp - * @author Edouard Lafargue Copyright (C) 2010. - * @addtogroup GCSPlugins GCS Plugins - * @{ - * @addtogroup GPSGadgetPlugin GPS Gadget Plugin - * @{ - * @brief A widget which displays the GPS constellation - *****************************************************************************/ -/* - * 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 "gpsconstellationwidget.h" - -#include -#include - -/* - * Initialize the widget - */ -GpsConstellationWidget::GpsConstellationWidget(QWidget *parent) : QGraphicsView(parent) -{ - - // Create a layout, add a QGraphicsView and put the SVG inside. - // The constellation widget looks like this: - // |--------------------| - // | | - // | | - // | Constellation | - // | | - // | | - // | | - // |--------------------| - - - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - - QSvgRenderer *renderer = new QSvgRenderer(); - renderer->load(QString(":/gpsgadget/images/gpsEarth.svg")); - - world = new QGraphicsSvgItem(); - world->setSharedRenderer(renderer); - world->setElementId("map"); - - scene = new QGraphicsScene(this); - scene->addItem(world); - scene->setSceneRect(world->boundingRect()); - setScene(scene); - - // Now create 'maxSatellites' satellite icons which we will move around on the map: - for (int i=0; i < MAX_SATTELITES;i++) { - satellites[i][0] = 0; - satellites[i][1] = 0; - satellites[i][2] = 0; - satellites[i][3] = 0; - - satIcons[i] = new QGraphicsSvgItem(world); - satIcons[i]->setSharedRenderer(renderer); - satIcons[i]->setElementId("sat-notSeen"); - satIcons[i]->hide(); - - satTexts[i] = new QGraphicsSimpleTextItem("##",satIcons[i]); - satTexts[i]->setBrush(QColor("Black")); - satTexts[i]->setFont(QFont("Courier")); - } -} - -GpsConstellationWidget::~GpsConstellationWidget() -{ - delete scene; - scene = 0; - - //delete renderer; - //renderer = 0; -} - -void GpsConstellationWidget::showEvent(QShowEvent *event) -{ - Q_UNUSED(event) - // Thit fitInView method should only be called now, once the - // widget is shown, otherwise it cannot compute its values and - // the result is usually a ahrsbargraph that is way too small. - fitInView(world, Qt::KeepAspectRatio); - // Scale, can't use fitInView since that doesn't work until we're shown. - // qreal factor = height()/world->boundingRect().height(); -// world->setScale(factor); - // setSceneRect(world->boundingRect()); - -} - -void GpsConstellationWidget::resizeEvent(QResizeEvent* event) -{ - Q_UNUSED(event); - fitInView(world, Qt::KeepAspectRatio); -} - -void GpsConstellationWidget::updateSat(int index, int prn, int elevation, int azimuth, int snr) -{ - if (index >= MAX_SATTELITES) { - // A bit of error checking never hurts. - return; - } - - // TODO: add range checking - satellites[index][0] = prn; - satellites[index][1] = elevation; - satellites[index][2] = azimuth; - satellites[index][3] = snr; - - if (prn && elevation >= 0) { - QPointF opd = polarToCoord(elevation,azimuth); - opd += QPointF(-satIcons[index]->boundingRect().center().x(), - -satIcons[index]->boundingRect().center().y()); - satIcons[index]->setTransform(QTransform::fromTranslate(opd.x(),opd.y()), false); - if (snr) { - satIcons[index]->setElementId("satellite"); - } else { - satIcons[index]->setElementId("sat-notSeen"); - } - satIcons[index]->show(); - - QRectF iconRect = satIcons[index]->boundingRect(); - QString prnString = QString().number(prn); - if(prnString.length() == 1) { - prnString = "0" + prnString; - } - satTexts[index]->setText(prnString); - QRectF textRect = satTexts[index]->boundingRect(); - - QTransform matrix; - qreal scale = 0.70 * (iconRect.width() / textRect.width()); - matrix.translate(iconRect.width()/2, iconRect.height()/2); - matrix.scale(scale,scale); - matrix.translate(-textRect.width()/2,-textRect.height()/2); - satTexts[index]->setTransform(matrix,false); - } else { - satIcons[index]->hide(); - } - -} - -/** - Converts the elevation/azimuth to X/Y coordinates on the map - - */ -QPointF GpsConstellationWidget::polarToCoord(int elevation, int azimuth) -{ - double x; - double y; - double rad_elevation; - double rad_azimuth; - - - rad_elevation = M_PI*elevation/180; - rad_azimuth = M_PI*azimuth/180; - - x = cos(rad_elevation)*sin(rad_azimuth); - y = -cos(rad_elevation)*cos(rad_azimuth); - - x = world->boundingRect().width()/2 * x; - y = world->boundingRect().height()/2 * y; - - x = (world->boundingRect().width() / 2) + x; - y = (world->boundingRect().height() / 2) + y; - - return QPointF(x,y); - -} +/** + ****************************************************************************** + * + * @file gpsconstellationwidget.cpp + * @author Edouard Lafargue Copyright (C) 2010. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup GPSGadgetPlugin GPS Gadget Plugin + * @{ + * @brief A widget which displays the GPS constellation + *****************************************************************************/ +/* + * 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 "gpsconstellationwidget.h" + +#include +#include + +/* + * Initialize the widget + */ +GpsConstellationWidget::GpsConstellationWidget(QWidget *parent) : QGraphicsView(parent) +{ + + // Create a layout, add a QGraphicsView and put the SVG inside. + // The constellation widget looks like this: + // |--------------------| + // | | + // | | + // | Constellation | + // | | + // | | + // | | + // |--------------------| + + + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + QSvgRenderer *renderer = new QSvgRenderer(); + renderer->load(QString(":/gpsgadget/images/gpsEarth.svg")); + + world = new QGraphicsSvgItem(); + world->setSharedRenderer(renderer); + world->setElementId("map"); + + scene = new QGraphicsScene(this); + scene->addItem(world); + scene->setSceneRect(world->boundingRect()); + setScene(scene); + + // Now create 'maxSatellites' satellite icons which we will move around on the map: + for (int i=0; i < MAX_SATTELITES;i++) { + satellites[i][0] = 0; + satellites[i][1] = 0; + satellites[i][2] = 0; + satellites[i][3] = 0; + + satIcons[i] = new QGraphicsSvgItem(world); + satIcons[i]->setSharedRenderer(renderer); + satIcons[i]->setElementId("sat-notSeen"); + satIcons[i]->hide(); + + satTexts[i] = new QGraphicsSimpleTextItem("##",satIcons[i]); + satTexts[i]->setBrush(QColor("Black")); + satTexts[i]->setFont(QFont("Courier")); + } +} + +GpsConstellationWidget::~GpsConstellationWidget() +{ + delete scene; + scene = 0; + + //delete renderer; + //renderer = 0; +} + +void GpsConstellationWidget::showEvent(QShowEvent *event) +{ + Q_UNUSED(event) + // Thit fitInView method should only be called now, once the + // widget is shown, otherwise it cannot compute its values and + // the result is usually a ahrsbargraph that is way too small. + fitInView(world, Qt::KeepAspectRatio); + // Scale, can't use fitInView since that doesn't work until we're shown. + // qreal factor = height()/world->boundingRect().height(); +// world->setScale(factor); + // setSceneRect(world->boundingRect()); + +} + +void GpsConstellationWidget::resizeEvent(QResizeEvent* event) +{ + Q_UNUSED(event); + fitInView(world, Qt::KeepAspectRatio); +} + +void GpsConstellationWidget::updateSat(int index, int prn, int elevation, int azimuth, int snr) +{ + if (index >= MAX_SATTELITES) { + // A bit of error checking never hurts. + return; + } + + // TODO: add range checking + satellites[index][0] = prn; + satellites[index][1] = elevation; + satellites[index][2] = azimuth; + satellites[index][3] = snr; + + if (prn && elevation >= 0) { + QPointF opd = polarToCoord(elevation,azimuth); + opd += QPointF(-satIcons[index]->boundingRect().center().x(), + -satIcons[index]->boundingRect().center().y()); + satIcons[index]->setTransform(QTransform::fromTranslate(opd.x(),opd.y()), false); + if (snr) { + satIcons[index]->setElementId("satellite"); + } else { + satIcons[index]->setElementId("sat-notSeen"); + } + satIcons[index]->show(); + + QRectF iconRect = satIcons[index]->boundingRect(); + QString prnString = QString().number(prn); + if(prnString.length() == 1) { + prnString = "0" + prnString; + } + satTexts[index]->setText(prnString); + QRectF textRect = satTexts[index]->boundingRect(); + + QTransform matrix; + qreal scale = 0.70 * (iconRect.width() / textRect.width()); + matrix.translate(iconRect.width()/2, iconRect.height()/2); + matrix.scale(scale,scale); + matrix.translate(-textRect.width()/2,-textRect.height()/2); + satTexts[index]->setTransform(matrix,false); + } else { + satIcons[index]->hide(); + } + +} + +/** + Converts the elevation/azimuth to X/Y coordinates on the map + + */ +QPointF GpsConstellationWidget::polarToCoord(int elevation, int azimuth) +{ + double x; + double y; + double rad_elevation; + double rad_azimuth; + + + rad_elevation = M_PI*elevation/180; + rad_azimuth = M_PI*azimuth/180; + + x = cos(rad_elevation)*sin(rad_azimuth); + y = -cos(rad_elevation)*cos(rad_azimuth); + + x = world->boundingRect().width()/2 * x; + y = world->boundingRect().height()/2 * y; + + x = (world->boundingRect().width() / 2) + x; + y = (world->boundingRect().height() / 2) + y; + + return QPointF(x,y); + +}