UASView.h 5.31 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2
/*=====================================================================

3
QGroundControl Open Source Ground Control Station
pixhawk's avatar
pixhawk committed
4

5
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
pixhawk's avatar
pixhawk committed
6

7
This file is part of the QGROUNDCONTROL project
pixhawk's avatar
pixhawk committed
8

9
    QGROUNDCONTROL is free software: you can redistribute it and/or modify
pixhawk's avatar
pixhawk committed
10 11 12 13
    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.

14
    QGROUNDCONTROL is distributed in the hope that it will be useful,
pixhawk's avatar
pixhawk committed
15 16 17 18 19
    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
20
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
pixhawk's avatar
pixhawk committed
21 22 23 24 25

======================================================================*/

/**
 * @file
26
 *   @brief Definition of class UASView
pixhawk's avatar
pixhawk committed
27 28 29 30 31 32 33 34
 *
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
 *
 */

#ifndef UASVIEW_H
#define UASVIEW_H

35
#include <QWidget>
pixhawk's avatar
pixhawk committed
36 37 38 39 40
#include <QString>
#include <QTimer>
#include <QMouseEvent>
#include <UASInterface.h>

41 42 43
namespace Ui
{
class UASView;
pixhawk's avatar
pixhawk committed
44 45
}

46 47
class UASView : public QWidget
{
pixhawk's avatar
pixhawk committed
48 49 50 51
    Q_OBJECT
public:
    UASView(UASInterface* uas, QWidget *parent = 0);
    ~UASView();
52
    UASInterface* uas;
pixhawk's avatar
pixhawk committed
53 54

public slots:
55 56
    /** @brief Update the name of the system */
    void updateName(const QString& name);
pixhawk's avatar
pixhawk committed
57 58
    void receiveHeartbeat(UASInterface* uas);
    void updateThrust(UASInterface* uas, double thrust);
dongfang's avatar
dongfang committed
59
    void updateBattery(UASInterface* uas, double voltage, double current, double percent, int seconds);
pixhawk's avatar
pixhawk committed
60
    void updateLocalPosition(UASInterface*, double x, double y, double z, quint64 usec);
61
    void updateGlobalPosition(UASInterface*, double lon, double lat, double altAMSL, double altWGS84, quint64 usec);
pixhawk's avatar
pixhawk committed
62 63
    void updateSpeed(UASInterface*, double x, double y, double z, quint64 usec);
    void updateState(UASInterface*, QString uasState, QString stateDescription);
pixhawk's avatar
pixhawk committed
64 65
    /** @brief Update the MAV mode */
    void updateMode(int sysId, QString status, QString description);
pixhawk's avatar
pixhawk committed
66
    void updateLoad(UASInterface* uas, double load);
67
    //void receiveValue(int uasid, QString id, double value, quint64 time);
68 69 70 71 72
    /**
     * Request that the UASManager deletes this UAS. This doesn't delete this widget
     * yet, it waits for the approprait uasDeleted signal.
     */
    void triggerUASDeletion();
pixhawk's avatar
pixhawk committed
73 74 75
    void refresh();
    /** @brief Receive new waypoint information */
    void setWaypoint(int uasId, int id, double x, double y, double z, double yaw, bool autocontinue, bool current);
76 77
    /** @brief Update the current active waypoint */
    void currentWaypointUpdated(quint16 waypoint);
pixhawk's avatar
pixhawk committed
78 79 80 81
    /** @brief Set waypoint as current target */
    void selectWaypoint(int uasId, int id);
    /** @brief Set the current system type */
    void setSystemType(UASInterface* uas, unsigned int systemType);
pixhawk's avatar
pixhawk committed
82 83
    /** @brief Set the current UAS as the globally active system */
    void setUASasActive(bool);
84 85
    /** @brief Update the view if an UAS has been set to active */
    void updateActiveUAS(UASInterface* uas, bool active);
86
    /** @brief Set the widget into critical mode */
87
    void heartbeatTimeout(bool timeout, unsigned int ms);
88 89
    /** @brief Bring up the dialog to rename the system */
    void rename();
90 91
    /** @brief Select airframe for this vehicle */
    void selectAirframe();
92 93
    /** @brief Select the battery type */
    void setBatterySpecs();
94 95 96 97
    /** @brief Show a status text message */
    void showStatusText(int uasid, int componentid, int severity, QString text);
    /** @brief Update the navigation mode state */
    void updateNavMode(int uasid, int mode, const QString& text);
pixhawk's avatar
pixhawk committed
98 99 100 101 102 103

protected:
    void changeEvent(QEvent *e);
    QTimer* refreshTimer;
    QColor heartbeatColor;
    quint64 startTime;
104
    bool timeout;
105
    bool iconIsRed;
106
    bool disconnected;
pixhawk's avatar
pixhawk committed
107
    int timeRemaining;
108 109
    float chargeLevel;
    float load;
pixhawk's avatar
pixhawk committed
110 111
    QString state;
    QString stateDesc;
pixhawk's avatar
pixhawk committed
112
    QString mode;
113 114
    double thrust; ///< Current vehicle thrust: 0 - 1.0 for 100% thrust
    bool isActive; ///< Is this MAV selected by the user?
115 116 117 118 119 120 121
    float x;
    float y;
    float z;
    float totalSpeed;
    float lat;
    float lon;
    float alt;
122
    float groundDistance;
123
    bool localFrame;
124
    bool globalFrameKnown;
125
    QAction* removeAction;
126
    QAction* renameAction;
127
    QAction* selectAction;
lm's avatar
lm committed
128
    QAction* hilAction;
129
    QAction* hilXAction;
130
    QAction* selectAirframeAction;
131
    QAction* setBatterySpecsAction;
LM's avatar
LM committed
132 133
    static const int updateInterval = 800;
    static const int errorUpdateInterval = 200;
134
    bool lowPowerModeEnabled; ///< Low power mode reduces update rates
135 136
    unsigned int generalUpdateCount; ///< Skip counter for updates
    double filterTime; ///< Filter time estimate of battery
137 138 139 140 141 142 143 144 145
    /**
     * If a user double-clicks on this view, set the active UAS to this one.
     */
    void mouseDoubleClickEvent(QMouseEvent *event);
    /**
     * Right-clicking on the view provides a custom menu for interacting
     * with the UAS.
     */
    void contextMenuEvent(QContextMenuEvent *event);
pixhawk's avatar
pixhawk committed
146 147 148 149

private:
    Ui::UASView *m_ui;

150 151 152 153
    /**
     * Implement paintEvent() so that stylesheets work for our custom widget.
     */
    virtual void paintEvent(QPaintEvent *event);
pixhawk's avatar
pixhawk committed
154 155 156
};

#endif // UASVIEW_H