Pixhawk3DWidget.h 6.16 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 64

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

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

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

96 97
    UASInterface* uas;

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

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

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

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

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

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

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

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

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

163
    bool followCamera;
164

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

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

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

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

#endif // PIXHAWK3DWIDGET_H