Pixhawk3DWidget.h 8.22 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
///*=====================================================================
//
//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/>.
//
//======================================================================*/

/**
 * @file
 *   @brief Definition of the class Pixhawk3DWidget.
 *
28
 *   @author Lionel Heng <hengli@inf.ethz.ch>
29 30 31 32 33 34 35 36
 *
 */

#ifndef PIXHAWK3DWIDGET_H
#define PIXHAWK3DWIDGET_H

#include <osgText/Text>

37
#include "HUDScaleGeode.h"
38
#include "Imagery.h"
39
#include "Q3DWidget.h"
40 41
#include "SystemContainer.h"
#include "ViewParamWidget.h"
42 43 44 45 46 47

class UASInterface;

/**
 * @brief A 3D View widget which displays vehicle-centric information.
 **/
48
class Pixhawk3DWidget : public QWidget
49 50 51 52 53 54 55 56
{
    Q_OBJECT

public:
    explicit Pixhawk3DWidget(QWidget* parent = 0);
    ~Pixhawk3DWidget();

public slots:
57 58 59
    void activeSystemChanged(UASInterface* uas);
    void systemCreated(UASInterface* uas);
    void localPositionChanged(UASInterface* uas, int component, double x, double y, double z, quint64 time);
60
    void localPositionChanged(UASInterface* uas, double x, double y, double z, quint64 time);
61
    void attitudeChanged(UASInterface* uas, int component, double roll, double pitch, double yaw, quint64 time);
62
    void attitudeChanged(UASInterface* uas, double roll, double pitch, double yaw, quint64 time);
63
    void homePositionChanged(int uasId, double lat, double lon, double alt);
64
    void setpointChanged(int uasId, float x, float y, float z, float yaw);
65 66 67

signals:
    void systemCreatedSignal(UASInterface* uas);
68
    void overlayCreatedSignal(int systemId, const QString& name);
69 70

private slots:
71
    void clearData(void);
72
    void showTerrainParamWindow(void);
73 74
    void showViewParamWindow(void);
    void followCameraChanged(int systemId);
75
    void imageryParamsChanged(void);
76 77
    void recenterActiveCamera(void);
    void modelChanged(int systemId, int index);
78
    void setBirdEyeView(void);
79
    void loadTerrainModel(void);
80

81 82 83 84
#if defined(QGC_PROTOBUF_ENABLED) && defined(QGC_USE_PIXHAWK_MESSAGES)
    void addOverlay(UASInterface* uas);
#endif

85
    void selectTargetHeading(void);
86
    void selectTarget(void);
87
    void setTarget(void);
88
    void insertWaypoint(void);
89 90
    void moveWaypointPosition(void);
    void moveWaypointHeading(void);
91 92 93 94
    void deleteWaypoint(void);
    void setWaypointAltitude(void);
    void clearAllWaypoints(void);

95 96 97 98
    void moveImagery(void);
    void moveTerrain(void);
    void rotateTerrain(void);

99 100 101
    void sizeChanged(int width, int height);
    void update(void);

102
protected:
103 104
    void addModels(QVector< osg::ref_ptr<osg::Node> >& models,
                   const QColor& systemColor);
105
    void buildLayout(void);
106

107 108 109 110 111 112 113 114 115
    void keyPressEvent(QKeyEvent* event);
    void keyReleaseEvent(QKeyEvent* event);
    void mousePressEvent(QMouseEvent* event);
    void mouseReleaseEvent(QMouseEvent* event);
    void mouseMoveEvent(QMouseEvent* event);
    void wheelEvent(QWheelEvent* event);

    void showEvent(QShowEvent* event);
    void hideEvent(QHideEvent* event);
116

117 118 119
signals:
    void visibilityChanged(bool visible);

120
private:
121 122 123 124 125
    void initializeSystem(int systemId, const QColor& systemColor);

    void getPose(UASInterface* uas,
                 MAV_FRAME frame,
                 double& x, double& y, double& z,
126
                 double& roll, double& pitch, double& yaw,
127 128 129 130 131 132 133 134 135 136 137 138
                 QString& utmZone) const;
    void getPose(UASInterface* uas,
                 MAV_FRAME frame,
                 double& x, double& y, double& z,
                 double& roll, double& pitch, double& yaw) const;
    void getPosition(UASInterface* uas,
                     MAV_FRAME frame,
                     double& x, double& y, double& z,
                     QString& utmZone) const;
    void getPosition(UASInterface* uas,
                     MAV_FRAME frame,
                     double& x, double& y, double& z) const;
139

140 141
    osg::ref_ptr<osg::Geode> createLocalGrid(void);
    osg::ref_ptr<osg::Geode> createWorldGrid(void);
142
    osg::ref_ptr<osg::Geometry> createTrail(const osg::Vec4& color);
143
    osg::ref_ptr<osg::Geometry> createLink(const QColor& color);
144 145 146
    osg::ref_ptr<Imagery> createImagery(void);
    osg::ref_ptr<osg::Geode> createPointCloud(void);
    osg::ref_ptr<osg::Node> createTarget(const QColor& color);
147

148
    void setupHUD(void);
149
    void resizeHUD(int width, int height);
150

151
    void updateHUD(UASInterface* uas, MAV_FRAME frame);
152 153
    void updateImagery(double originX, double originY,
                       const QString& zone, MAV_FRAME frame);
154 155 156 157 158 159
    void updateTarget(UASInterface* uas, MAV_FRAME frame,
                      double robotX, double robotY, double robotZ,
                      QVector4D& target,
                      osg::ref_ptr<osg::Node>& targetNode);
    void updateTrails(double robotX, double robotY, double robotZ,
                      osg::ref_ptr<osg::Geode>& trailNode,
160
                      osg::ref_ptr<osg::Group>& orientationNode,
161 162 163 164
                      QMap<int, QVector<osg::Vec3d> >& trailMap,
                      QMap<int, int>& trailIndexMap);
    void updateWaypoints(UASInterface* uas, MAV_FRAME frame,
                         osg::ref_ptr<WaypointGroupNode>& waypointGroupNode);
165
#if defined(QGC_PROTOBUF_ENABLED) && defined(QGC_USE_PIXHAWK_MESSAGES)
166 167 168 169 170 171 172 173 174 175 176 177 178
    void updateRGBD(UASInterface* uas, MAV_FRAME frame,
                    osg::ref_ptr<ImageWindowGeode>& rgbImageNode,
                    osg::ref_ptr<ImageWindowGeode>& depthImageNode);
    void updatePointCloud(UASInterface* uas, MAV_FRAME frame,
                          double robotX, double robotY, double robotZ,
                          osg::ref_ptr<osg::Geode>& pointCloudNode,
                          bool colorPointCloudByDistance);
    void updateObstacles(UASInterface* uas, MAV_FRAME frame,
                         double robotX, double robotY, double robotZ,
                         osg::ref_ptr<ObstacleGroupNode>& obstacleGroupNode);
    void updatePlannedPath(UASInterface* uas, MAV_FRAME frame,
                           double robotX, double robotY, double robotZ,
                           osg::ref_ptr<osg::Geode>& plannedPathNode);
179
#endif
180

181
    int findWaypoint(const QPoint& mousePos);
182
    bool findTarget(int mouseX, int mouseY);
183
    bool findTerrain(const QPoint& mousePos);
184 185
    void showInsertWaypointMenu(const QPoint& cursorPos);
    void showEditWaypointMenu(const QPoint& cursorPos);
186
    void showTerrainMenu(const QPoint& cursorPos);
187

188 189
    const qreal kMessageTimeout; // message timeout in seconds

190 191
    enum Mode {
        DEFAULT_MODE,
192 193
        MOVE_WAYPOINT_POSITION_MODE,
        MOVE_WAYPOINT_HEADING_MODE,
194 195 196 197
        SELECT_TARGET_HEADING_MODE,
        MOVE_TERRAIN_MODE,
        ROTATE_TERRAIN_MODE,
        MOVE_IMAGERY_MODE
198
    };
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
    Mode mMode;
    int mSelectedWpIndex;

    int mActiveSystemId;
    UASInterface* mActiveUAS;

    GlobalViewParamsPtr mGlobalViewParams;

    // maps system id to system-specific view parameters
    QMap<int, SystemViewParamsPtr> mSystemViewParamMap;

    // maps system id to system-specific data
    QMap<int, SystemContainer> mSystemContainerMap;

    osg::ref_ptr<osg::Geometry> mHudBackgroundGeometry;
    osg::ref_ptr<Imagery> mImageryNode;
    osg::ref_ptr<HUDScaleGeode> mScaleGeode;
    osg::ref_ptr<osgText::Text> mStatusText;
217
    osg::ref_ptr<osg::Node> mTerrainNode;
218
    osg::ref_ptr<osg::PositionAttitudeTransform> mTerrainPAT;
219
    osg::ref_ptr<osg::Geode> mWorldGridNode;
220

221 222 223 224
    QPoint mCachedMousePos;
    int mFollowCameraId;
    QVector3D mCameraPos;
    bool mInitCameraPos;
225

226 227
    Q3DWidget* m3DWidget;
    ViewParamWidget* mViewParamWidget;
228 229 230
};

#endif // PIXHAWK3DWIDGET_H