Pixhawk3DWidget.h 7.94 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 63
    void attitudeChanged(UASInterface* uas, double roll, double pitch, double yaw, quint64 time);
    void setpointChanged(int uasId, float x, float y, float z, float yaw);
64 65 66

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

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

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

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

93 94 95
    void sizeChanged(int width, int height);
    void update(void);

96
protected:
97 98
    void addModels(QVector< osg::ref_ptr<osg::Node> >& models,
                   const QColor& systemColor);
99
    void buildLayout(void);
100

101 102 103 104 105 106 107 108 109
    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);
110

111 112 113
signals:
    void visibilityChanged(bool visible);

114
private:
115 116 117 118 119
    void initializeSystem(int systemId, const QColor& systemColor);

    void getPose(UASInterface* uas,
                 MAV_FRAME frame,
                 double& x, double& y, double& z,
120
                 double& roll, double& pitch, double& yaw,
121 122 123 124 125 126 127 128 129 130 131 132
                 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;
133

134 135
    osg::ref_ptr<osg::Geode> createLocalGrid(void);
    osg::ref_ptr<osg::Geode> createWorldGrid(void);
136
    osg::ref_ptr<osg::Geometry> createTrail(const osg::Vec4& color);
137
    osg::ref_ptr<osg::Geometry> createLink(const QColor& color);
138 139 140
    osg::ref_ptr<Imagery> createImagery(void);
    osg::ref_ptr<osg::Geode> createPointCloud(void);
    osg::ref_ptr<osg::Node> createTarget(const QColor& color);
141

142
    void setupHUD(void);
143
    void resizeHUD(int width, int height);
144

145
    void updateHUD(UASInterface* uas, MAV_FRAME frame);
146 147
    void updateImagery(double originX, double originY, double originZ,
                       const QString& zone);
148 149 150 151 152 153
    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,
154
                      osg::ref_ptr<osg::Group>& orientationNode,
155 156 157 158
                      QMap<int, QVector<osg::Vec3d> >& trailMap,
                      QMap<int, int>& trailIndexMap);
    void updateWaypoints(UASInterface* uas, MAV_FRAME frame,
                         osg::ref_ptr<WaypointGroupNode>& waypointGroupNode);
159
#if defined(QGC_PROTOBUF_ENABLED) && defined(QGC_USE_PIXHAWK_MESSAGES)
160 161 162 163 164 165 166 167 168 169 170 171 172
    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);
173
#endif
174

175
    int findWaypoint(const QPoint& mousePos);
176
    bool findTarget(int mouseX, int mouseY);
177
    bool findTerrain(const QPoint& mousePos);
178 179
    void showInsertWaypointMenu(const QPoint& cursorPos);
    void showEditWaypointMenu(const QPoint& cursorPos);
180
    void showTerrainMenu(const QPoint& cursorPos);
181

182 183
    const qreal kMessageTimeout; // message timeout in seconds

184 185
    enum Mode {
        DEFAULT_MODE,
186 187 188
        MOVE_WAYPOINT_POSITION_MODE,
        MOVE_WAYPOINT_HEADING_MODE,
        SELECT_TARGET_HEADING_MODE
189
    };
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
    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;
208
    osg::ref_ptr<osg::Node> mTerrainNode;
209
    osg::ref_ptr<osg::PositionAttitudeTransform> mTerrainPAT;
210
    osg::ref_ptr<osg::Geode> mWorldGridNode;
211

212 213 214 215
    QPoint mCachedMousePos;
    int mFollowCameraId;
    QVector3D mCameraPos;
    bool mInitCameraPos;
216

217 218
    Q3DWidget* m3DWidget;
    ViewParamWidget* mViewParamWidget;
219 220 221
};

#endif // PIXHAWK3DWIDGET_H