HSIDisplay.h 7.05 KB
Newer Older
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 39
/*=====================================================================

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 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);
lm's avatar
lm committed
54
    void updateSatellite(int uasid, int satid, float azimuth, float direction, float snr, bool used);
55
    void updateAttitudeSetpoints(UASInterface*, double rollDesired, double pitchDesired, double yawDesired, double thrustDesired, quint64 usec);
lm's avatar
lm committed
56
    void updateAttitude(UASInterface* uas, double roll, double pitch, double yaw, quint64 time);
lm's avatar
lm committed
57
    void updatePositionSetpoints(int uasid, float xDesired, float yDesired, float zDesired, float yawDesired, quint64 usec);
58 59
    void updateLocalPosition(UASInterface*, double x, double y, double z, quint64 usec);
    void updateGlobalPosition(UASInterface*, double lat, double lon, double alt, quint64 usec);
60
    void updateSpeed(UASInterface* uas, double vx, double vy, double vz, quint64 time);
lm's avatar
lm committed
61 62 63 64 65
    void updatePositionLock(UASInterface* uas, bool lock);
    void updateAttitudeControllerEnabled(UASInterface* uas, bool enabled);
    void updatePositionXYControllerEnabled(UASInterface* uas, bool enabled);
    void updatePositionZControllerEnabled(UASInterface* uas, bool enabled);

lm's avatar
lm committed
66
    void paintEvent(QPaintEvent * event);
67 68 69
    /** @brief Update state from joystick */
    void updateJoystick(double roll, double pitch, double yaw, double thrust, int xHat, int yHat);
    void pressKey(int key);
70 71 72

protected slots:
    void paintDisplay();
73 74 75 76
    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);
77
    void drawAltitudeSetpoint(float xRef, float yRef, float radius, const QColor& color, QPainter* painter);
78 79 80 81 82 83 84 85
    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);
    /** @brief Draw the limiting safety area */
    void drawSafetyArea(const QPointF &topLeft, const QPointF &bottomRight,  const QColor &color, QPainter &painter);
lm's avatar
lm committed
86

87
    void mouseDoubleClickEvent(QMouseEvent* event);
88 89

protected:
pixhawk's avatar
pixhawk committed
90
    /** @brief Get color from GPS signal-to-noise colormap */
lm's avatar
lm committed
91
    static QColor getColorForSNR(float snr);
pixhawk's avatar
pixhawk committed
92 93 94 95
    /** @brief Metric world coordinates to metric body coordinates */
    QPointF metricWorldToBody(QPointF world);
    /** @brief Metric body coordinates to metric world coordinates */
    QPointF metricBodyToWorld(QPointF body);
96 97 98 99 100
    /** @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 */
101 102 103
    QPointF metricBodyToRef(QPointF &metric);
    /** @brief Metric body coordinates to screen coordinates */
    QPointF metricBodyToScreen(QPointF metric);
lm's avatar
lm committed
104 105 106 107 108 109 110

    /**
     * @brief Private data container class to be used within the HSI widget
     */
    class GPSSatellite
    {
    public:
lm's avatar
lm committed
111
        GPSSatellite(int id, float elevation, float azimuth, float snr, bool used) :
lm's avatar
lm committed
112
                id(id),
lm's avatar
lm committed
113
                elevation(elevation),
lm's avatar
lm committed
114 115
                azimuth(azimuth),
                snr(snr),
lm's avatar
lm committed
116 117
                used(used),
                lastUpdate(MG::TIME::getGroundTimeNowUsecs())
lm's avatar
lm committed
118 119 120 121
        {

        }

lm's avatar
lm committed
122
        void update(int id, float elevation, float azimuth, float snr, bool used)
lm's avatar
lm committed
123 124
        {
            this->id = id;
lm's avatar
lm committed
125
            this->elevation = elevation;
lm's avatar
lm committed
126 127 128
            this->azimuth = azimuth;
            this->snr = snr;
            this->used = used;
lm's avatar
lm committed
129
            this->lastUpdate = MG::TIME::getGroundTimeNowUsecs();
lm's avatar
lm committed
130 131 132
        }

        int id;
lm's avatar
lm committed
133
        float elevation;
lm's avatar
lm committed
134 135 136
        float azimuth;
        float snr;
        bool used;
lm's avatar
lm committed
137
        quint64 lastUpdate;
lm's avatar
lm committed
138 139 140 141

        friend class HSIDisplay;
    };

lm's avatar
lm committed
142
    QMap<int, GPSSatellite*> gpsSatellites;
pixhawk's avatar
pixhawk committed
143
    unsigned int satellitesUsed;
144

145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    // 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;
168
    quint64 globalAvailable;   ///< Last global position update time
169 170 171
    float x;
    float y;
    float z;
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
    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
    float metricWidth;         ///< Width the instrument represents in meters (the width of the ground shown by the widget)

    //
    float xCenterPos;
    float yCenterPos;
193

lm's avatar
lm committed
194 195 196 197 198
    bool positionLock;
    bool attControlEnabled;
    bool xyControlEnabled;
    bool zControlEnabled;

199 200 201 202
private:
};

#endif // HSIDISPLAY_H