FirmwarePlugin.cc 8.71 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9

10
#include "FirmwarePlugin.h"
Don Gagne's avatar
Don Gagne committed
11
#include "QGCApplication.h"
12
#include "Generic/GenericAutoPilotPlugin.h"
Don Gagne's avatar
Don Gagne committed
13 14 15

#include <QDebug>

16 17
static FirmwarePluginFactoryRegister* _instance = NULL;

18 19
const char* guided_mode_not_supported_by_vehicle = "Guided mode not supported by Vehicle.";

20 21 22 23 24 25 26
const char* FirmwarePlugin::px4FollowMeFlightMode = "Follow Me";

FirmwarePluginFactory::FirmwarePluginFactory(void)
{
    FirmwarePluginFactoryRegister::instance()->registerPluginFactory(this);
}

27 28 29 30 31 32 33
QList<MAV_TYPE> FirmwarePluginFactory::supportedVehicleTypes(void) const
{
    QList<MAV_TYPE> vehicleTypes;
    vehicleTypes << MAV_TYPE_FIXED_WING << MAV_TYPE_QUADROTOR << MAV_TYPE_VTOL_QUADROTOR << MAV_TYPE_GROUND_ROVER << MAV_TYPE_SUBMARINE;
    return vehicleTypes;
}

34 35 36 37 38 39 40 41 42 43 44 45 46 47
FirmwarePluginFactoryRegister* FirmwarePluginFactoryRegister::instance(void)
{
    if (!_instance) {
        _instance = new FirmwarePluginFactoryRegister;
    }

    return _instance;
}

AutoPilotPlugin* FirmwarePlugin::autopilotPlugin(Vehicle* vehicle)
{
    return new GenericAutoPilotPlugin(vehicle, vehicle);
}

48
bool FirmwarePlugin::isCapable(const Vehicle *vehicle, FirmwareCapabilities capabilities)
Don Gagne's avatar
Don Gagne committed
49
{
50
    Q_UNUSED(vehicle);
Don Gagne's avatar
Don Gagne committed
51 52 53 54
    Q_UNUSED(capabilities);
    return false;
}

55
QList<VehicleComponent*> FirmwarePlugin::componentsForVehicle(AutoPilotPlugin* vehicle)
Don Gagne's avatar
Don Gagne committed
56 57
{
    Q_UNUSED(vehicle);
58

Don Gagne's avatar
Don Gagne committed
59 60 61
    return QList<VehicleComponent*>();
}

Don Gagne's avatar
Don Gagne committed
62
QString FirmwarePlugin::flightMode(uint8_t base_mode, uint32_t custom_mode) const
Don Gagne's avatar
Don Gagne committed
63 64
{
    QString flightMode;
65

Don Gagne's avatar
Don Gagne committed
66 67 68 69 70
    struct Bit2Name {
        uint8_t     baseModeBit;
        const char* name;
    };
    static const struct Bit2Name rgBit2Name[] = {
71 72 73 74 75 76
    { MAV_MODE_FLAG_MANUAL_INPUT_ENABLED,   "Manual" },
    { MAV_MODE_FLAG_STABILIZE_ENABLED,      "Stabilize" },
    { MAV_MODE_FLAG_GUIDED_ENABLED,         "Guided" },
    { MAV_MODE_FLAG_AUTO_ENABLED,           "Auto" },
    { MAV_MODE_FLAG_TEST_ENABLED,           "Test" },
};
77

Don Gagne's avatar
Don Gagne committed
78
    Q_UNUSED(custom_mode);
79

Don Gagne's avatar
Don Gagne committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93
    if (base_mode == 0) {
        flightMode = "PreFlight";
    } else if (base_mode & MAV_MODE_FLAG_CUSTOM_MODE_ENABLED) {
        flightMode = QString("Custom:0x%1").arg(custom_mode, 0, 16);
    } else {
        for (size_t i=0; i<sizeof(rgBit2Name)/sizeof(rgBit2Name[0]); i++) {
            if (base_mode & rgBit2Name[i].baseModeBit) {
                if (i != 0) {
                    flightMode += " ";
                }
                flightMode += rgBit2Name[i].name;
            }
        }
    }
94

Don Gagne's avatar
Don Gagne committed
95 96 97
    return flightMode;
}

98
bool FirmwarePlugin::setFlightMode(const QString& flightMode, uint8_t* base_mode, uint32_t* custom_mode)
Don Gagne's avatar
Don Gagne committed
99 100 101 102
{
    Q_UNUSED(flightMode);
    Q_UNUSED(base_mode);
    Q_UNUSED(custom_mode);
103

104
    qWarning() << "FirmwarePlugin::setFlightMode called on base class, not supported";
105

Don Gagne's avatar
Don Gagne committed
106 107
    return false;
}
108

109
int FirmwarePlugin::manualControlReservedButtonCount(void)
110 111 112 113 114
{
    // We don't know whether the firmware is going to used any of these buttons.
    // So reserve them all.
    return -1;
}
Don Gagne's avatar
Don Gagne committed
115

116 117 118 119 120
int FirmwarePlugin::defaultJoystickTXMode(void)
{
    return 2;
}

121 122 123 124 125 126
bool FirmwarePlugin::supportsThrottleModeCenterZero(void)
{
    // By default, this is supported
    return true;
}

127 128 129 130 131
bool FirmwarePlugin::supportsManualControl(void)
{
    return false;
}

132 133 134 135 136
bool FirmwarePlugin::supportsRadio(void)
{
    return true;
}

137 138 139 140 141
bool FirmwarePlugin::supportsJSButton(void)
{
    return false;
}

142
bool FirmwarePlugin::adjustIncomingMavlinkMessage(Vehicle* vehicle, mavlink_message_t* message)
Don Gagne's avatar
Don Gagne committed
143 144
{
    Q_UNUSED(vehicle);
145
    Q_UNUSED(message);
Don Gagne's avatar
Don Gagne committed
146
    // Generic plugin does no message adjustment
147
    return true;
Don Gagne's avatar
Don Gagne committed
148 149
}

150
void FirmwarePlugin::adjustOutgoingMavlinkMessage(Vehicle* vehicle, LinkInterface* outgoingLink, mavlink_message_t* message)
Don Gagne's avatar
Don Gagne committed
151
{
152
    Q_UNUSED(vehicle);
153
    Q_UNUSED(outgoingLink);
Don Gagne's avatar
Don Gagne committed
154 155 156
    Q_UNUSED(message);
    // Generic plugin does no message adjustment
}
157

158
void FirmwarePlugin::initializeVehicle(Vehicle* vehicle)
159 160
{
    Q_UNUSED(vehicle);
161

162 163
    // Generic Flight Stack is by definition "generic", so no extra work
}
164

165
bool FirmwarePlugin::sendHomePositionToVehicle(void)
166 167 168 169 170 171
{
    // Generic stack does not want home position sent in the first position.
    // Subsequent sequence numbers must be adjusted.
    // This is the mavlink spec default.
    return false;
}
172

173
QList<MAV_CMD> FirmwarePlugin::supportedMissionCommands(void)
Don Gagne's avatar
Don Gagne committed
174 175 176 177
{
    // Generic supports all commands
    return QList<MAV_CMD>();
}
178

179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
QString FirmwarePlugin::missionCommandOverrides(MAV_TYPE vehicleType) const
{
    switch (vehicleType) {
    case MAV_TYPE_GENERIC:
        return QStringLiteral(":/json/MavCmdInfoCommon.json");
        break;
    case MAV_TYPE_FIXED_WING:
        return QStringLiteral(":/json/MavCmdInfoFixedWing.json");
        break;
    case MAV_TYPE_QUADROTOR:
        return QStringLiteral(":/json/MavCmdInfoMultiRotor.json");
        break;
    case MAV_TYPE_VTOL_QUADROTOR:
        return QStringLiteral(":/json/MavCmdInfoVTOL.json");
        break;
    case MAV_TYPE_SUBMARINE:
        return QStringLiteral(":/json/MavCmdInfoSub.json");
        break;
    case MAV_TYPE_GROUND_ROVER:
        return QStringLiteral(":/json/MavCmdInfoRover.json");
        break;
    default:
        qWarning() << "FirmwarePlugin::missionCommandOverrides called with bad MAV_TYPE:" << vehicleType;
        return QString();
    }
204
}
205 206 207 208 209 210 211

void FirmwarePlugin::getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion)
{
    Q_UNUSED(metaDataFile);
    majorVersion = -1;
    minorVersion = -1;
}
Don Gagne's avatar
Don Gagne committed
212 213 214 215 216 217 218 219 220 221 222 223

bool FirmwarePlugin::isGuidedMode(const Vehicle* vehicle) const
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
    return false;
}

void FirmwarePlugin::setGuidedMode(Vehicle* vehicle, bool guidedMode)
{
    Q_UNUSED(vehicle);
    Q_UNUSED(guidedMode);
224
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
225 226 227 228 229 230 231 232 233 234 235 236 237
}

bool FirmwarePlugin::isPaused(const Vehicle* vehicle) const
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
    return false;
}

void FirmwarePlugin::pauseVehicle(Vehicle* vehicle)
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
238
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
239 240 241 242 243 244
}

void FirmwarePlugin::guidedModeRTL(Vehicle* vehicle)
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
245
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
246 247 248 249 250 251
}

void FirmwarePlugin::guidedModeLand(Vehicle* vehicle)
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
252
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
253 254 255 256 257 258 259
}

void FirmwarePlugin::guidedModeTakeoff(Vehicle* vehicle, double altitudeRel)
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
    Q_UNUSED(altitudeRel);
260
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
261 262
}

263 264 265 266 267 268
void FirmwarePlugin::guidedModeOrbit(Vehicle* /*vehicle*/, const QGeoCoordinate& /*centerCoord*/, double /*radius*/, double /*velocity*/, double /*altitude*/)
{
    // Not supported by generic vehicle
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
}

Don Gagne's avatar
Don Gagne committed
269 270 271 272 273
void FirmwarePlugin::guidedModeGotoLocation(Vehicle* vehicle, const QGeoCoordinate& gotoCoord)
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
    Q_UNUSED(gotoCoord);
274
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
275 276 277 278 279 280 281
}

void FirmwarePlugin::guidedModeChangeAltitude(Vehicle* vehicle, double altitudeRel)
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
    Q_UNUSED(altitudeRel);
282
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
283
}
284 285 286

const FirmwarePlugin::remapParamNameMajorVersionMap_t& FirmwarePlugin::paramNameRemapMajorVersionMap(void) const
{
Don Gagne's avatar
Don Gagne committed
287 288 289
    static const remapParamNameMajorVersionMap_t remap;

    return remap;
290 291 292 293 294 295 296
}

int FirmwarePlugin::remapParamNameHigestMinorVersionNumber(int majorVersionNumber) const
{
    Q_UNUSED(majorVersionNumber);
    return 0;
}
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311

QString FirmwarePlugin::missionFlightMode(void)
{
    return QString();
}

QString FirmwarePlugin::rtlFlightMode(void)
{
    return QString();
}

QString FirmwarePlugin::takeControlFlightMode(void)
{
    return QString();
}
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329

QString FirmwarePlugin::vehicleImageOpaque(const Vehicle* vehicle) const
{
    Q_UNUSED(vehicle);
    return QStringLiteral("/qmlimages/vehicleArrowOpaque.svg");
}

QString FirmwarePlugin::vehicleImageOutline(const Vehicle* vehicle) const
{
    Q_UNUSED(vehicle);
    return QStringLiteral("/qmlimages/vehicleArrowOutline.svg");
}

QString FirmwarePlugin::vehicleImageCompass(const Vehicle* vehicle) const
{
    Q_UNUSED(vehicle);
    return QStringLiteral("/qmlimages/compassInstrumentArrow.svg");
}