Pixhawk3DWidget.h 6.01 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 "ImageWindowGeode.h"
40
#include "WaypointGroupNode.h"
41 42 43
#ifdef QGC_PROTOBUF_ENABLED
    #include "ObstacleGroupNode.h"
#endif
44

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#include "Q3DWidget.h"

class UASInterface;

/**
 * @brief A 3D View widget which displays vehicle-centric information.
 **/
class Pixhawk3DWidget : public Q3DWidget
{
    Q_OBJECT

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

public slots:
    void setActiveUAS(UASInterface* uas);

private slots:
64
    void selectFrame(QString text);
65 66
    void showLocalGrid(int state);
    void showWorldGrid(int state);
67
    void showTrail(int state);
68
    void showWaypoints(int state);
69
    void selectMapSource(int index);
70
    void selectVehicleModel(int index);
71
    void recenter(void);
72
    void toggleFollowCamera(int state);
73

74
    void selectTargetHeading(void);
75
    void selectTarget(void);
76
    void setTarget(void);
77
    void insertWaypoint(void);
78 79
    void moveWaypointPosition(void);
    void moveWaypointHeading(void);
80 81 82 83
    void deleteWaypoint(void);
    void setWaypointAltitude(void);
    void clearAllWaypoints(void);

84
protected:
85 86
    QVector< osg::ref_ptr<osg::Node> > findVehicleModels(void);
    void buildLayout(void);
87
    virtual void resizeGL(int width, int height);
88
    virtual void display(void);
89
    virtual void keyPressEvent(QKeyEvent* event);
90
    virtual void mousePressEvent(QMouseEvent* event);
91 92
    virtual void showEvent(QShowEvent* event);
    virtual void hideEvent(QHideEvent* event);
93
    virtual void mouseMoveEvent(QMouseEvent* event);
94

95 96
    UASInterface* uas;

97 98 99
signals:
    void visibilityChanged(bool visible);

100
private:
101 102 103 104 105 106 107 108 109
    void getPose(double& x, double& y, double& z,
                 double& roll, double& pitch, double& yaw,
                 QString& utmZone);
    void getPose(double& x, double& y, double& z,
                 double& roll, double& pitch, double& yaw);
    void getPosition(double& x, double& y, double& z,
                     QString& utmZone);
    void getPosition(double& x, double& y, double& z);

110 111
    osg::ref_ptr<osg::Geode> createLocalGrid(void);
    osg::ref_ptr<osg::Geode> createWorldGrid(void);
112
    osg::ref_ptr<osg::Geode> createTrail(const osg::Vec4& color);
113
    osg::ref_ptr<Imagery> createMap(void);
114
    osg::ref_ptr<osg::Geode> createRGBD3D(void);
115
    osg::ref_ptr<osg::Node> createTarget(void);
116

117
    void setupHUD(void);
118
    void resizeHUD(void);
119

120
    void updateHUD(double robotX, double robotY, double robotZ,
121 122
                   double robotRoll, double robotPitch, double robotYaw,
                   const QString& utmZone);
123
    void updateTrail(double robotX, double robotY, double robotZ);
124 125
    void updateImagery(double originX, double originY, double originZ,
                       const QString& zone);
126
    void updateWaypoints(void);
127
    void updateTarget(double robotX, double robotY, double robotZ);
128 129
#ifdef QGC_PROTOBUF_ENABLED
    void updateRGBD(double robotX, double robotY, double robotZ);
130
    void updateObstacles(double robotX, double robotY, double robotZ);
131
    void updatePath(double robotX, double robotY, double robotZ);
132
#endif
133

134
    int findWaypoint(const QPoint& mousePos);
135
    bool findTarget(int mouseX, int mouseY);
136 137 138
    void showInsertWaypointMenu(const QPoint& cursorPos);
    void showEditWaypointMenu(const QPoint& cursorPos);

139 140
    const qreal kMessageTimeout; // message timeout in seconds

141 142
    enum Mode {
        DEFAULT_MODE,
143 144 145
        MOVE_WAYPOINT_POSITION_MODE,
        MOVE_WAYPOINT_HEADING_MODE,
        SELECT_TARGET_HEADING_MODE
146 147 148 149
    };
    Mode mode;
    int selectedWpIndex;

150 151
    bool displayLocalGrid;
    bool displayWorldGrid;
152
    bool displayTrail;
153
    bool displayImagery;
154
    bool displayWaypoints;
155 156
    bool displayRGBD2D;
    bool displayRGBD3D;
157
    bool displayObstacleList;
158
    bool displayPath;
159
    bool enableRGBDColor;
160
    bool enableTarget;
161

162
    bool followCamera;
163

164
    QVarLengthArray<osg::Vec3d, 10000> trail;
165

166
    osg::ref_ptr<osg::Node> vehicleModel;
167 168
    osg::ref_ptr<osg::Geometry> hudBackgroundGeometry;
    osg::ref_ptr<osgText::Text> statusText;
169
    osg::ref_ptr<HUDScaleGeode> scaleGeode;
170 171 172 173
    osg::ref_ptr<ImageWindowGeode> rgb2DGeode;
    osg::ref_ptr<ImageWindowGeode> depth2DGeode;
    osg::ref_ptr<osg::Image> rgbImage;
    osg::ref_ptr<osg::Image> depthImage;
174 175
    osg::ref_ptr<osg::Geode> localGridNode;
    osg::ref_ptr<osg::Geode> worldGridNode;
176
    osg::ref_ptr<osg::Geode> trailNode;
177
    osg::ref_ptr<Imagery> mapNode;
178
    osg::ref_ptr<WaypointGroupNode> waypointGroupNode;
179
    osg::ref_ptr<osg::Node> targetNode;
180
    osg::ref_ptr<osg::Geode> rgbd3DNode;
181 182
#ifdef QGC_PROTOBUF_ENABLED
    osg::ref_ptr<ObstacleGroupNode> obstacleGroupNode;
183
    osg::ref_ptr<osg::Geode> pathNode;
184
#endif
185 186

    QVector< osg::ref_ptr<osg::Node> > vehicleModels;
187

188
    MAV_FRAME frame;
189
    QVector4D target;
190
    QPoint cachedMousePos;
191
    double lastRobotX, lastRobotY, lastRobotZ;
192 193 194
};

#endif // PIXHAWK3DWIDGET_H