Pixhawk3DWidget.h 6.32 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
#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);
62
    void addToTrails(UASInterface* uas, int component, double x, double y, double z, quint64 time);
63
    void updateAttitude(UASInterface* uas, int component, double roll, double pitch, double yaw, quint64 time);
64 65

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

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

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

97 98
    UASInterface* uas;

99 100 101
signals:
    void visibilityChanged(bool visible);

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

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

119
    void setupHUD(void);
120
    void resizeHUD(void);
121

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

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

141 142
    const qreal kMessageTimeout; // message timeout in seconds

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

152 153
    bool displayLocalGrid;
    bool displayWorldGrid;
154
    bool displayTrails;
155
    bool displayImagery;
156
    bool displayWaypoints;
157 158
    bool displayRGBD2D;
    bool displayRGBD3D;
159
    bool displayObstacleList;
160
    bool displayPath;
161
    bool enableRGBDColor;
162
    bool enableTarget;
163

164
    bool followCamera;
165

166 167
    QMap<int, QVarLengthArray<osg::Vec3d, 10000> > trails;
    QMap<int, int> trailDrawableIdxs;
168

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

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

192
    MAV_FRAME frame;
193
    QVector4D target;
194
    QPoint cachedMousePos;
195
    double lastRobotX, lastRobotY, lastRobotZ;
196 197 198
};

#endif // PIXHAWK3DWIDGET_H