UASManager.h 6.26 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 UASManager
pixhawk's avatar
pixhawk committed
27 28 29 30 31 32 33 34 35 36 37 38 39
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
 *
 */

#ifndef _UASMANAGER_H_
#define _UASMANAGER_H_

#include <QThread>
#include <QList>
#include <QMutex>
#include <UASInterface.h>

/**
40
 * @brief Central manager for all connected aerial vehicles
pixhawk's avatar
pixhawk committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
 *
 * This class keeps a list of all connected / configured UASs. It also stores which
 * UAS is currently select with respect to user input or manual controls.
 **/
class UASManager : public QThread
{
    Q_OBJECT

public:
    static UASManager* instance();
    ~UASManager();

    void run();
    /**
     * @brief Get the currently selected UAS
     *
     * @return NULL pointer if no UAS exists, active UAS else
     **/
    UASInterface* getActiveUAS();
60
    UASInterface* silentGetActiveUAS();
pixhawk's avatar
pixhawk committed
61 62 63 64 65 66 67 68 69 70 71
    /**
     * @brief Get the UAS with this id
     *
     * Although not enforced by this implementation, the IDs are constrained to be
     * in the range of 1 - 127 by the MAVLINK protocol.
     *
     * @param id unique system / aircraft id
     * @return UAS with the given ID, NULL pointer else
     **/
    UASInterface* getUASForId(int id);

lm's avatar
lm committed
72
    QList<UASInterface*> getUASList();
73
    /** @brief Get home position latitude */
74 75 76
    double getHomeLatitude() const {
        return homeLat;
    }
77
    /** @brief Get home position longitude */
78 79 80
    double getHomeLongitude() const {
        return homeLon;
    }
81
    /** @brief Get home position altitude */
82 83 84
    double getHomeAltitude() const {
        return homeAlt;
    }
lm's avatar
lm committed
85

pixhawk's avatar
pixhawk committed
86 87 88 89 90 91 92 93 94 95 96

public slots:

    /**
     * @brief Add a new UAS to the list
     *
     * This command will only be executed if this UAS does not yet exist.
     * @param UAS unmanned air system to add
     **/
    void addUAS(UASInterface* UAS);

97 98 99
    /** @brief Remove a system from the list */
    void removeUAS(QObject* uas);

pixhawk's avatar
pixhawk committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173

    /**
      * @brief Set a UAS as currently selected
      *
      * @param UAS Unmanned Air System to set
      **/
    void setActiveUAS(UASInterface* UAS);


    /**
     * @brief Launch the active UAS
     *
     * The groundstation has always one Unmanned Air System selected.
     * All commands are executed on the UAS in focus. This command starts
     * the launch sequence.
     *
     * @return True if the UAS could be launched, false else
     */
    bool launchActiveUAS();

    bool haltActiveUAS();

    bool continueActiveUAS();

    /**
     * @brief Land the active UAS
     *
     * The groundstation has always one Unmanned Air System selected.
     * All commands are executed on the UAS in focus. This command starts
     * the land sequence. Depending on the onboard control, this could mean
     * returning to the landing spot as well as descending on the current
     * position.
     *
     * @return True if the UAS could be landed, false else
     */
    bool returnActiveUAS();


    /**
     * @brief EMERGENCY: Stop active UAS
     *
     * The groundstation has always one Unmanned Air System selected.
     * All commands are executed on the UAS in focus. This command
     * starts an emergency landing. Depending on the onboard control,
     * this usually means descending rapidly on the current position.
     *
     * @warning This command can severely damage the UAS!
     *
     * @return True if the UAS could be landed, false else
     */
    bool stopActiveUAS();

    /**
     * @brief EMERGENCY: Kill active UAS
     *
     * The groundstation has always one Unmanned Air System selected.
     * All commands are executed on the UAS in focus. This command
     * shuts off all onboard motors immediately. This leads to a
     * system crash, but might prevent external damage, e.g. to people.
     * This command is secured by an additional popup message window.
     *
     * @warning THIS COMMAND RESULTS IN THE LOSS OF THE SYSTEM!
     *
     * @return True if the UAS could be landed, false else
     */
    bool killActiveUAS();

    /**
     * @brief Configure the currently active UAS
     *
     * This command will bring up the configuration dialog for the particular UAS.
     */
    void configureActiveUAS();

pixhawk's avatar
pixhawk committed
174
    /** @brief Shut down the onboard operating system down */
pixhawk's avatar
pixhawk committed
175 176
    bool shutdownActiveUAS();

177 178 179 180 181 182 183 184
    /** @brief Set the current home position */
    void setHomePosition(double lat, double lon, double alt);

    /** @brief Load settings */
    void loadSettings();
    /** @brief Store settings */
    void storeSettings();

pixhawk's avatar
pixhawk committed
185 186 187

protected:
    UASManager();
188
    QList<UASInterface*> systems;
pixhawk's avatar
pixhawk committed
189 190
    UASInterface* activeUAS;
    QMutex activeUASMutex;
191 192 193
    double homeLat;
    double homeLon;
    double homeAlt;
pixhawk's avatar
pixhawk committed
194 195 196

signals:
    void UASCreated(UASInterface* UAS);
197
    /** @brief The UAS currently under main operator control changed */
pixhawk's avatar
pixhawk committed
198
    void activeUASSet(UASInterface* UAS);
199
    /** @brief The UAS currently under main operator control changed */
200
    void activeUASSet(int systemId);
201
    /** @brief The UAS currently under main operator control changed */
202 203
    void activeUASSetListIndex(int listIndex);
    /** @brief The UAS currently under main operator control changed */
204 205 206
    void activeUASStatusChanged(UASInterface* UAS, bool active);
    /** @brief The UAS currently under main operator control changed */
    void activeUASStatusChanged(int systemId, bool active);
207 208
    /** @brief Current home position changed */
    void homePositionChanged(double lat, double lon, double alt);
pixhawk's avatar
pixhawk committed
209 210 211 212

};

#endif // _UASMANAGER_H_