HDDisplay.h 6.21 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/*=====================================================================

PIXHAWK Micro Air Vehicle Flying Robotics Toolkit

(c) 2009, 2010 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 Definition of Head Down Display (HDD)
 *
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
 *
 */

#ifndef HDDISPLAY_H
#define HDDISPLAY_H

#include <QtGui/QWidget>
#include <QColor>
#include <QTimer>
#include <QFontDatabase>
pixhawk's avatar
pixhawk committed
39 40
#include <QMap>
#include <QPair>
pixhawk's avatar
pixhawk committed
41 42 43 44 45 46 47 48 49 50 51
#include <cmath>

#include "UASInterface.h"

namespace Ui {
    class HDDisplay;
}

class HDDisplay : public QWidget {
    Q_OBJECT
public:
pixhawk's avatar
pixhawk committed
52
    HDDisplay(QStringList* plotList, QWidget *parent = 0);
pixhawk's avatar
pixhawk committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    ~HDDisplay();

public slots:
    /** @brief Update a HDD value */
    void updateValue(UASInterface* uas, QString name, double value, quint64 msec);
    void start();
    void stop();
    void setActiveUAS(UASInterface* uas);

    protected slots:
    void paintGL();

protected:
    void changeEvent(QEvent *e);
    void paintEvent(QPaintEvent * event);
    float refLineWidthToPen(float line);
    float refToScreenX(float x);
    float refToScreenY(float y);
    void rotatePolygonClockWiseRad(QPolygonF& p, float angle, QPointF origin);
    void drawPolygon(QPolygonF refPolygon, QPainter* painter);
    void drawLine(float refX1, float refY1, float refX2, float refY2, float width, const QColor& color, QPainter* painter);
    void drawEllipse(float refX, float refY, float radiusX, float radiusY, float startDeg, float endDeg, float lineWidth, const QColor& color, QPainter* painter);
    void drawCircle(float refX, float refY, float radius, float startDeg, float endDeg, float lineWidth, const QColor& color, QPainter* painter);

    void drawChangeRateStrip(float xRef, float yRef, float height, float minRate, float maxRate, float value, QPainter* painter);
    void drawChangeIndicatorGauge(float xRef, float yRef, float radius, float expectedMaxChange, float value, const QColor& color, QPainter* painter, bool solid=true);
    void drawGauge(float xRef, float yRef, float radius, float min, float max, const QString name, float value, const QColor& color, QPainter* painter, QPair<float, float> goodRange, QPair<float, float> criticalRange, bool solid=true);
    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);

    UASInterface* uas; ///< The uas currently monitored
    QMap<QString, float> values; ///< The variables this HUD displays
    QMap<QString, float> valuesDot; ///< First derivative of the variable
    QMap<QString, float> valuesMean; ///< Mean since system startup for this variable
    QMap<QString, int> valuesCount; ///< Number of values received so far
    QMap<QString, quint64> lastUpdate; ///< The last update time for this variable
pixhawk's avatar
pixhawk committed
89 90 91 92
    QMap<QString, float> minValues; ///< The minimum value this variable is assumed to have
    QMap<QString, float> maxValues; ///< The maximum value this variable is assumed to have
    QMap<QString, QPair<float, float> > goodRanges; ///< The range of good values
    QMap<QString, QPair<float, float> > critRanges; ///< The range of critical values
pixhawk's avatar
pixhawk committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
    double scalingFactor; ///< Factor used to scale all absolute values to screen coordinates
    float xCenterOffset, yCenterOffset; ///< Offset from center of window in mm coordinates
    float vwidth; ///< Virtual width of this window, 200 mm per default. This allows to hardcode positions and aspect ratios. This virtual image plane is then scaled to the window size.
    float vheight; ///< Virtual height of this window, 150 mm per default

    int xCenter; ///< Center of the HUD instrument in pixel coordinates. Allows to off-center the whole instrument in its OpenGL window, e.g. to fit another instrument
    int yCenter; ///< Center of the HUD instrument in pixel coordinates. Allows to off-center the whole instrument in its OpenGL window, e.g. to fit another instrument

    // HUD colors
    QColor backgroundColor;    ///< Background color
    QColor defaultColor;       ///< Color for most HUD elements, e.g. pitch lines, center cross, change rate gauges
    QColor setPointColor;      ///< Color for the current control set point, e.g. yaw desired
    QColor warningColor;       ///< Color for warning messages
    QColor criticalColor;      ///< Color for caution messages
    QColor infoColor;          ///< Color for normal/default messages
    QColor fuelColor;          ///< Current color for the fuel message, can be info, warning or critical color

    // Blink rates
    int warningBlinkRate;      ///< Blink rate of warning messages, will be rounded to the refresh rate

    QTimer* refreshTimer;      ///< The main timer, controls the update rate
    QPainter* hudPainter;
    QFont font;                ///< The HUD font, per default the free Bitstream Vera SANS, which is very close to actual HUD fonts
    QFontDatabase fontDatabase;///< Font database, only used to load the TrueType font file (the HUD font is directly loaded from file rather than from the system)
    bool hardwareAcceleration; ///< Enable hardware acceleration

    float strongStrokeWidth;   ///< Strong line stroke width, used throughout the HUD
    float normalStrokeWidth;   ///< Normal line stroke width, used throughout the HUD
    float fineStrokeWidth;     ///< Fine line stroke width, used throughout the HUD

pixhawk's avatar
pixhawk committed
123 124
    QStringList* acceptList;   ///< Variable names to plot

pixhawk's avatar
pixhawk committed
125 126 127 128 129
private:
    Ui::HDDisplay *m_ui;
};

#endif // HDDISPLAY_H