AirframeComponent.cc 6.08 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 - 2014 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
///     @author Don Gagne <don@thegagnes.com>

#include "AirframeComponent.h"
28
#include "QGCQmlWidgetHolder.h"
29

30 31 32
#if 0
// Broken by latest mavlink module changes. Not used yet. Comment out for now.
// Discussing mavlink fix.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
struct mavType {
    int         type;
    const char* description;
};

/// @brief Used to translate from MAV_TYPE_* id to user string
static const struct mavType mavTypeInfo[] = {
    { MAV_TYPE_GENERIC,             "Generic" },
    { MAV_TYPE_FIXED_WING,          "Fixed Wing" },
    { MAV_TYPE_QUADROTOR,           "Quadrotor" },
    { MAV_TYPE_COAXIAL,             "Coaxial" },
    { MAV_TYPE_HELICOPTER,          "Helicopter"},
    { MAV_TYPE_ANTENNA_TRACKER,     "Antenna Tracker" },
    { MAV_TYPE_GCS,                 "Ground Control Station" },
    { MAV_TYPE_AIRSHIP,             "Airship" },
    { MAV_TYPE_FREE_BALLOON,        "Free Balloon" },
    { MAV_TYPE_ROCKET,              "Rocket" },
    { MAV_TYPE_GROUND_ROVER,        "Ground Rover" },
    { MAV_TYPE_SURFACE_BOAT,        "Boat" },
    { MAV_TYPE_SUBMARINE,           "Submarine" },
    { MAV_TYPE_HEXAROTOR,           "Hexarotor" },
    { MAV_TYPE_OCTOROTOR,           "Octorotor" },
    { MAV_TYPE_TRICOPTER,           "Tricopter" },
    { MAV_TYPE_FLAPPING_WING,       "Flapping Wing" },
    { MAV_TYPE_KITE,                "Kite" },
    { MAV_TYPE_ONBOARD_CONTROLLER,  "Onbard companion controller" },
    { MAV_TYPE_VTOL_DUOROTOR,       "Two-rotor VTOL" },
    { MAV_TYPE_VTOL_QUADROTOR,      "Quad-rotor VTOL" },
61 62 63 64 65
    { MAV_TYPE_VTOL_RESERVED1,      "Reserved" },
    { MAV_TYPE_VTOL_RESERVED2,      "Reserved" },
    { MAV_TYPE_VTOL_RESERVED3,      "Reserved" },
    { MAV_TYPE_VTOL_RESERVED4,      "Reserved" },
    { MAV_TYPE_VTOL_RESERVED5,      "Reserved" },
66
    { MAV_TYPE_GIMBAL,              "Gimbal" },
67 68
};
static size_t cMavTypes = sizeof(mavTypeInfo) / sizeof(mavTypeInfo[0]);
69
#endif
70

Don Gagne's avatar
Don Gagne committed
71 72
AirframeComponent::AirframeComponent(UASInterface* uas, AutoPilotPlugin* autopilot, QObject* parent) :
    PX4Component(uas, autopilot, parent),
73 74
    _name(tr("Airframe"))
{
75 76 77
#if 0
    // Broken by latest mavlink module changes. Not used yet. Comment out for now.
    // Discussing mavlink fix.
Don Gagne's avatar
Don Gagne committed
78 79
    Q_UNUSED(mavTypeInfo);  // Keeping this around for later use
    
80 81
    // Validate that our mavTypeInfo array hasn't gotten out of sync
    
82
    qDebug() << cMavTypes << MAV_TYPE_ENUM_END;
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    Q_ASSERT(cMavTypes == MAV_TYPE_ENUM_END);
    
    static const int mavTypes[] = {
        MAV_TYPE_GENERIC,
        MAV_TYPE_FIXED_WING,
        MAV_TYPE_QUADROTOR,
        MAV_TYPE_COAXIAL,
        MAV_TYPE_HELICOPTER,
        MAV_TYPE_ANTENNA_TRACKER,
        MAV_TYPE_GCS,
        MAV_TYPE_AIRSHIP,
        MAV_TYPE_FREE_BALLOON,
        MAV_TYPE_ROCKET,
        MAV_TYPE_GROUND_ROVER,
        MAV_TYPE_SURFACE_BOAT,
        MAV_TYPE_SUBMARINE,
        MAV_TYPE_HEXAROTOR,
        MAV_TYPE_OCTOROTOR,
        MAV_TYPE_TRICOPTER,
        MAV_TYPE_FLAPPING_WING,
        MAV_TYPE_KITE,
        MAV_TYPE_ONBOARD_CONTROLLER,
        MAV_TYPE_VTOL_DUOROTOR,
106
        MAV_TYPE_VTOL_QUADROTOR,
107 108 109 110 111
        MAV_TYPE_VTOL_RESERVED1,
        MAV_TYPE_VTOL_RESERVED2,
        MAV_TYPE_VTOL_RESERVED3,
        MAV_TYPE_VTOL_RESERVED4,
        MAV_TYPE_VTOL_RESERVED5,
112
        MAV_TYPE_GIMBAL,
113
    };
Don Gagne's avatar
Don Gagne committed
114
    Q_UNUSED(mavTypes); // Keeping this around for later use
115
    
Don Gagne's avatar
Don Gagne committed
116
    for (size_t i=0; i<cMavTypes; i++) {
117 118
        Q_ASSERT(mavTypeInfo[i].type == mavTypes[i]);
    }
119
#endif
120 121 122 123 124 125 126 127 128 129 130 131 132
}

QString AirframeComponent::name(void) const
{
    return _name;
}

QString AirframeComponent::description(void) const
{
    return tr("The Airframe Component is used to select the airframe which matches your vehicle. "
              "This will in turn set up the various tuning values for flight paramters.");
}

133
QString AirframeComponent::iconResource(void) const
134
{
135
    return "AirframeComponentIcon.png";
136 137 138 139 140 141 142 143 144 145
}

bool AirframeComponent::requiresSetup(void) const
{
    return true;
}

bool AirframeComponent::setupComplete(void) const
{
    QVariant value;
Don Gagne's avatar
Don Gagne committed
146
    if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), "SYS_AUTOSTART", value)) {
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
        return value.toInt() != 0;
    } else {
        Q_ASSERT(false);
        return false;
    }
}

QString AirframeComponent::setupStateDescription(void) const
{
    const char* stateDescription;
    
    if (requiresSetup()) {
        stateDescription = "Requires calibration";
    } else {
        stateDescription = "Calibrated";
    }
    return QString(stateDescription);
}

Don Gagne's avatar
Don Gagne committed
166
QStringList AirframeComponent::setupCompleteChangedTriggerList(void) const
167
{
Don Gagne's avatar
Don Gagne committed
168
    return QStringList("SYS_AUTOSTART");
169 170 171 172 173 174 175 176 177 178 179 180 181
}

QStringList AirframeComponent::paramFilterList(void) const
{
    QStringList list;
    
    list << "SYS_AUTOSTART";
    
    return list;
}

QWidget* AirframeComponent::setupWidget(void) const
{
182 183 184 185 186 187 188 189
    QGCQmlWidgetHolder* holder = new QGCQmlWidgetHolder();
    Q_CHECK_PTR(holder);
    
    holder->setAutoPilot(_autopilot);
    
    holder->setSource(QUrl::fromUserInput("qrc:/qml/AirframeComponent.qml"));
    
    return holder;
190 191
}

192
QUrl AirframeComponent::summaryQmlSource(void) const
193
{
194
    return QUrl::fromUserInput("qrc:/qml/AirframeComponentSummary.qml");
195
}
Don Gagne's avatar
Don Gagne committed
196 197 198 199 200

QString AirframeComponent::prerequisiteSetup(void) const
{
    return QString();
}