HSIDisplay.h 10.1 KB
Newer Older
1 2
/*=====================================================================

3
QGroundControl Open Source Ground Control Station
4

5
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
6

7
This file is part of the QGROUNDCONTROL project
8

9
    QGROUNDCONTROL is free software: you can redistribute it and/or modify
10 11 12 13
    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.

14
    QGROUNDCONTROL is distributed in the hope that it will be useful,
15 16 17 18 19
    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
20
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

======================================================================*/

/**
 * @file
 *   @brief Definition of of Horizontal Situation Indicator class
 *
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
 *
 */

#ifndef HSIDISPLAY_H
#define HSIDISPLAY_H

#include <QtGui/QWidget>
#include <QColor>
#include <QTimer>
#include <QMap>
#include <QPair>
40
#include <QMouseEvent>
41 42 43
#include <cmath>

#include "HDDisplay.h"
lm's avatar
lm committed
44
#include "MG.h"
45 46 47 48

class HSIDisplay : public HDDisplay {
    Q_OBJECT
public:
49
    HSIDisplay(QWidget *parent = 0);
lm's avatar
lm committed
50
    // ~HSIDisplay();
51 52 53

public slots:
    void setActiveUAS(UASInterface* uas);
54 55
    /** @brief Set the width in meters this widget shows from top */
    void setMetricWidth(double width);
lm's avatar
lm committed
56
    void updateSatellite(int uasid, int satid, float azimuth, float direction, float snr, bool used);
57
    void updateAttitudeSetpoints(UASInterface*, double rollDesired, double pitchDesired, double yawDesired, double thrustDesired, quint64 usec);
lm's avatar
lm committed
58
    void updateAttitude(UASInterface* uas, double roll, double pitch, double yaw, quint64 time);
lm's avatar
lm committed
59
    void updatePositionSetpoints(int uasid, float xDesired, float yDesired, float zDesired, float yawDesired, quint64 usec);
60 61
    void updateLocalPosition(UASInterface*, double x, double y, double z, quint64 usec);
    void updateGlobalPosition(UASInterface*, double lat, double lon, double alt, quint64 usec);
62
    void updateSpeed(UASInterface* uas, double vx, double vy, double vz, quint64 time);
lm's avatar
lm committed
63
    void updatePositionLock(UASInterface* uas, bool lock);
pixhawk's avatar
pixhawk committed
64 65 66
    void updateAttitudeControllerEnabled(bool enabled);
    void updatePositionXYControllerEnabled(bool enabled);
    void updatePositionZControllerEnabled(bool enabled);
pixhawk's avatar
pixhawk committed
67
    /** @brief Heading control enabled/disabled */
68
    void updatePositionYawControllerEnabled(bool enabled);
pixhawk's avatar
pixhawk committed
69

70
    /** @brief Localization quality changed */
pixhawk's avatar
pixhawk committed
71
    void updateLocalization(UASInterface* uas, int localization);
72
    /** @brief GPS localization quality changed */
pixhawk's avatar
pixhawk committed
73
    void updateGpsLocalization(UASInterface* uas, int localization);
74
    /** @brief Vision localization quality changed */
pixhawk's avatar
pixhawk committed
75 76
    void updateVisionLocalization(UASInterface* uas, int localization);

77 78 79
    /** @brief Ultrasound/Infrared localization changed */
    void updateInfraredUltrasoundLocalization(UASInterface* uas, int fix);

lm's avatar
lm committed
80
    void paintEvent(QPaintEvent * event);
81 82 83
    /** @brief Update state from joystick */
    void updateJoystick(double roll, double pitch, double yaw, double thrust, int xHat, int yHat);
    void pressKey(int key);
84 85
    /** @brief Reset the state of the view */
    void resetMAVState();
86

87 88 89
signals:
    void metricWidthChanged(double width);

90
protected slots:
91
    void renderOverlay();
92 93 94 95
    void drawGPS(QPainter &painter);
    void drawObjects(QPainter &painter);
    void drawPositionDirection(float xRef, float yRef, float radius, const QColor& color, QPainter* painter);
    void drawAttitudeDirection(float xRef, float yRef, float radius, const QColor& color, QPainter* painter);
96
    void drawAltitudeSetpoint(float xRef, float yRef, float radius, const QColor& color, QPainter* painter);
97 98 99 100
    /** @brief Draw a status flag indicator */
    void drawStatusFlag(float x, float y, QString label, bool status, bool known, QPainter& painter);
    /** @brief Draw a position lock indicator */
    void drawPositionLock(float x, float y, QString label, int status, bool known, QPainter& painter);
101 102 103 104 105 106
    void setBodySetpointCoordinateXY(double x, double y);
    void setBodySetpointCoordinateZ(double z);
    /** @brief Send the current ui setpoint coordinates as new setpoint to the MAV */
    void sendBodySetPointCoordinates();
    /** @brief Draw one setpoint */
    void drawSetpointXY(float x, float y, float yaw, const QColor &color, QPainter &painter);
107 108
    /** @brief Draw waypoints of this system */
    void drawWaypoints(QPainter& painter);
109 110
    /** @brief Draw the limiting safety area */
    void drawSafetyArea(const QPointF &topLeft, const QPointF &bottomRight,  const QColor &color, QPainter &painter);
pixhawk's avatar
pixhawk committed
111
    /** @brief Receive mouse clicks */
112
    void mouseDoubleClickEvent(QMouseEvent* event);
113 114
    /** @brief Receive mouse wheel events */
    void wheelEvent(QWheelEvent* event);
115 116

protected:
117

118
    void showEvent(QShowEvent* event);
119
    void hideEvent(QHideEvent* event);
pixhawk's avatar
pixhawk committed
120
    /** @brief Get color from GPS signal-to-noise colormap */
lm's avatar
lm committed
121
    static QColor getColorForSNR(float snr);
pixhawk's avatar
pixhawk committed
122 123 124 125
    /** @brief Metric world coordinates to metric body coordinates */
    QPointF metricWorldToBody(QPointF world);
    /** @brief Metric body coordinates to metric world coordinates */
    QPointF metricBodyToWorld(QPointF body);
126 127 128 129 130
    /** @brief Screen coordinates of widget to metric coordinates in body frame */
    QPointF screenToMetricBody(QPointF ref);
    /** @brief Reference coordinates to metric coordinates */
    QPointF refToMetricBody(QPointF &ref);
    /** @brief Metric coordinates to reference coordinates */
131 132 133
    QPointF metricBodyToRef(QPointF &metric);
    /** @brief Metric body coordinates to screen coordinates */
    QPointF metricBodyToScreen(QPointF metric);
lm's avatar
lm committed
134 135 136 137 138 139 140

    /**
     * @brief Private data container class to be used within the HSI widget
     */
    class GPSSatellite
    {
    public:
lm's avatar
lm committed
141
        GPSSatellite(int id, float elevation, float azimuth, float snr, bool used) :
lm's avatar
lm committed
142
                id(id),
lm's avatar
lm committed
143
                elevation(elevation),
lm's avatar
lm committed
144 145
                azimuth(azimuth),
                snr(snr),
lm's avatar
lm committed
146 147
                used(used),
                lastUpdate(MG::TIME::getGroundTimeNowUsecs())
lm's avatar
lm committed
148 149 150 151
        {

        }

lm's avatar
lm committed
152
        void update(int id, float elevation, float azimuth, float snr, bool used)
lm's avatar
lm committed
153 154
        {
            this->id = id;
lm's avatar
lm committed
155
            this->elevation = elevation;
lm's avatar
lm committed
156 157 158
            this->azimuth = azimuth;
            this->snr = snr;
            this->used = used;
lm's avatar
lm committed
159
            this->lastUpdate = MG::TIME::getGroundTimeNowUsecs();
lm's avatar
lm committed
160 161 162
        }

        int id;
lm's avatar
lm committed
163
        float elevation;
lm's avatar
lm committed
164 165 166
        float azimuth;
        float snr;
        bool used;
lm's avatar
lm committed
167
        quint64 lastUpdate;
lm's avatar
lm committed
168 169 170 171

        friend class HSIDisplay;
    };

lm's avatar
lm committed
172
    QMap<int, GPSSatellite*> gpsSatellites;
pixhawk's avatar
pixhawk committed
173
    unsigned int satellitesUsed;
174

175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    // Current controller values
    float attXSet;
    float attYSet;
    float attYawSet;
    float altitudeSet;

    float posXSet;
    float posYSet;
    float posZSet;

    // Controller saturation values
    float attXSaturation;
    float attYSaturation;
    float attYawSaturation;

    float posXSaturation;
    float posYSaturation;
    float altitudeSaturation;

    // Position
    float lat;
    float lon;
    float alt;
198
    quint64 globalAvailable;   ///< Last global position update time
199 200 201
    float x;
    float y;
    float z;
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
    float vx;
    float vy;
    float vz;
    float speed;
    quint64 localAvailable;    ///< Last local position update time
    float roll;
    float pitch;
    float yaw;
    float bodyXSetCoordinate;  ///< X Setpoint coordinate active on the MAV
    float bodyYSetCoordinate;  ///< Y Setpoint coordinate active on the MAV
    float bodyZSetCoordinate;  ///< Z Setpoint coordinate active on the MAV
    float bodyYawSet;          ///< Yaw setpoint coordinate active on the MAV
    float uiXSetCoordinate;    ///< X Setpoint coordinate wanted by the UI
    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
218
    double metricWidth;        ///< Width the instrument represents in meters (the width of the ground shown by the widget)
219 220

    //
221 222
    float xCenterPos;         ///< X center of instrument in virtual coordinates
    float yCenterPos;         ///< Y center of instrument in virtual coordinates
223

lm's avatar
lm committed
224
    bool positionLock;
225 226 227 228 229 230 231 232 233
    bool attControlEnabled;   ///< Attitude control enabled
    bool xyControlEnabled;    ///< Horizontal control enabled
    bool zControlEnabled;     ///< Vertical control enabled
    bool yawControlEnabled;   ///< Yaw angle position control enabled
    int positionFix;          ///< Total dimensions the MAV is localizaed in
    int gpsFix;               ///< Localization dimensions based on GPS
    int visionFix;            ///< Localizaiton dimensions based on computer vision
    int laserFix;             ///< Localization dimensions based on laser
    int iruFix;               ///< Localization dimensions based on ultrasound
pixhawk's avatar
pixhawk committed
234
    bool mavInitialized;      ///< The MAV is initialized once the setpoint has been received
pixhawk's avatar
pixhawk committed
235 236
    float bottomMargin;       ///< Margin on the bottom of the page, in virtual coordinates
    float topMargin;          ///< Margin on top of the page, in virtual coordinates
lm's avatar
lm committed
237

238 239 240 241 242 243 244 245 246 247 248 249 250
    bool attControlKnown;     ///< Attitude control status known flag
    bool xyControlKnown;      ///< XY control status known flag
    bool zControlKnown;       ///< Z control status known flag
    bool yawControlKnown;     ///< Yaw control status known flag

    // Position lock indicators
    bool positionFixKnown;    ///< Position fix status known flag
    bool visionFixKnown;      ///< Vision fix status known flag
    bool gpsFixKnown;         ///< GPS fix status known flag
    bool iruFixKnown;         ///< Infrared/Ultrasound fix status known flag

    // Data indicators
    bool setPointKnown;       ///< Controller setpoint known status flag
251 252
    bool positionSetPointKnown; ///< Position setpoint known status flag
    bool userSetPointSet;
253

254 255 256 257
private:
};

#endif // HSIDISPLAY_H