FirmwarePlugin.cc 14.1 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"
13
#include "CameraMetaData.h"
Don Gagne's avatar
Don Gagne committed
14 15 16

#include <QDebug>

17 18
static FirmwarePluginFactoryRegister* _instance = NULL;

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

21 22
QVariantList FirmwarePlugin::_cameraList;

23 24 25 26 27 28 29
const char* FirmwarePlugin::px4FollowMeFlightMode = "Follow Me";

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

30 31 32 33 34 35 36
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;
}

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

    return _instance;
}

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

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

58
QList<VehicleComponent*> FirmwarePlugin::componentsForVehicle(AutoPilotPlugin* vehicle)
Don Gagne's avatar
Don Gagne committed
59 60
{
    Q_UNUSED(vehicle);
61

Don Gagne's avatar
Don Gagne committed
62 63 64
    return QList<VehicleComponent*>();
}

Don Gagne's avatar
Don Gagne committed
65
QString FirmwarePlugin::flightMode(uint8_t base_mode, uint32_t custom_mode) const
Don Gagne's avatar
Don Gagne committed
66 67
{
    QString flightMode;
68

Don Gagne's avatar
Don Gagne committed
69 70 71 72 73
    struct Bit2Name {
        uint8_t     baseModeBit;
        const char* name;
    };
    static const struct Bit2Name rgBit2Name[] = {
74 75 76 77 78 79
    { 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" },
};
80

Don Gagne's avatar
Don Gagne committed
81
    Q_UNUSED(custom_mode);
82

Don Gagne's avatar
Don Gagne committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96
    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;
            }
        }
    }
97

Don Gagne's avatar
Don Gagne committed
98 99 100
    return flightMode;
}

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

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

Don Gagne's avatar
Don Gagne committed
109 110
    return false;
}
111

112
int FirmwarePlugin::manualControlReservedButtonCount(void)
113 114 115 116 117
{
    // 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
118

119 120 121 122 123
int FirmwarePlugin::defaultJoystickTXMode(void)
{
    return 2;
}

124 125 126 127 128 129
bool FirmwarePlugin::supportsThrottleModeCenterZero(void)
{
    // By default, this is supported
    return true;
}

130 131 132 133 134
bool FirmwarePlugin::supportsManualControl(void)
{
    return false;
}

135 136 137 138 139
bool FirmwarePlugin::supportsRadio(void)
{
    return true;
}

140 141 142 143 144
bool FirmwarePlugin::supportsCalibratePressure(void)
{
    return false;
}

145 146 147 148 149
bool FirmwarePlugin::supportsMotorInterference(void)
{
    return true;
}

150 151 152 153 154
bool FirmwarePlugin::supportsJSButton(void)
{
    return false;
}

155
bool FirmwarePlugin::adjustIncomingMavlinkMessage(Vehicle* vehicle, mavlink_message_t* message)
Don Gagne's avatar
Don Gagne committed
156 157
{
    Q_UNUSED(vehicle);
158
    Q_UNUSED(message);
Don Gagne's avatar
Don Gagne committed
159
    // Generic plugin does no message adjustment
160
    return true;
Don Gagne's avatar
Don Gagne committed
161 162
}

163
void FirmwarePlugin::adjustOutgoingMavlinkMessage(Vehicle* vehicle, LinkInterface* outgoingLink, mavlink_message_t* message)
Don Gagne's avatar
Don Gagne committed
164
{
165
    Q_UNUSED(vehicle);
166
    Q_UNUSED(outgoingLink);
Don Gagne's avatar
Don Gagne committed
167 168 169
    Q_UNUSED(message);
    // Generic plugin does no message adjustment
}
170

171
void FirmwarePlugin::initializeVehicle(Vehicle* vehicle)
172 173
{
    Q_UNUSED(vehicle);
174

175 176
    // Generic Flight Stack is by definition "generic", so no extra work
}
177

178
bool FirmwarePlugin::sendHomePositionToVehicle(void)
179 180 181 182 183 184
{
    // 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;
}
185

186
QList<MAV_CMD> FirmwarePlugin::supportedMissionCommands(void)
Don Gagne's avatar
Don Gagne committed
187 188 189 190
{
    // Generic supports all commands
    return QList<MAV_CMD>();
}
191

192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
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();
    }
217
}
218 219 220 221 222 223 224

void FirmwarePlugin::getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion)
{
    Q_UNUSED(metaDataFile);
    majorVersion = -1;
    minorVersion = -1;
}
Don Gagne's avatar
Don Gagne committed
225 226 227 228 229 230 231 232 233 234 235 236

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);
237
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
238 239 240 241 242 243
}

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

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

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

261
void FirmwarePlugin::guidedModeTakeoff(Vehicle* vehicle)
Don Gagne's avatar
Don Gagne committed
262 263 264
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
265
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
266 267
}

268 269 270 271 272 273
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
274 275 276 277 278
void FirmwarePlugin::guidedModeGotoLocation(Vehicle* vehicle, const QGeoCoordinate& gotoCoord)
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
    Q_UNUSED(gotoCoord);
279
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
280 281 282 283 284 285 286
}

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

290 291 292 293 294 295 296
void FirmwarePlugin::startMission(Vehicle* vehicle)
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
}

297 298
const FirmwarePlugin::remapParamNameMajorVersionMap_t& FirmwarePlugin::paramNameRemapMajorVersionMap(void) const
{
Don Gagne's avatar
Don Gagne committed
299 300 301
    static const remapParamNameMajorVersionMap_t remap;

    return remap;
302 303 304 305 306 307 308
}

int FirmwarePlugin::remapParamNameHigestMinorVersionNumber(int majorVersionNumber) const
{
    Q_UNUSED(majorVersionNumber);
    return 0;
}
309

310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
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");
}
327

328
const QVariantList &FirmwarePlugin::toolBarIndicators(const Vehicle* vehicle)
329 330 331 332 333 334 335 336 337 338
{
    Q_UNUSED(vehicle);
    //-- Default list of indicators for all vehicles.
    if(_toolBarIndicatorList.size() == 0) {
        _toolBarIndicatorList.append(QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/MessageIndicator.qml")));
        _toolBarIndicatorList.append(QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/GPSIndicator.qml")));
        _toolBarIndicatorList.append(QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/TelemetryRSSIIndicator.qml")));
        _toolBarIndicatorList.append(QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/RCRSSIIndicator.qml")));
        _toolBarIndicatorList.append(QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/BatteryIndicator.qml")));
        _toolBarIndicatorList.append(QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/ModeIndicator.qml")));
339
        _toolBarIndicatorList.append(QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/ArmedIndicator.qml")));
340 341 342
    }
    return _toolBarIndicatorList;
}
343 344 345 346 347 348 349 350

const QVariantList& FirmwarePlugin::cameraList(const Vehicle* vehicle)
{
    Q_UNUSED(vehicle);

    if (_cameraList.size() == 0) {
        CameraMetaData* metaData;

351 352 353 354 355 356 357 358 359
        metaData = new CameraMetaData(tr("Typhoon H CGO3+"),    // Camera name
                                      6.264,                    // sensorWidth
                                      4.698,                    // sensorHeight
                                      4000,                     // imageWidth
                                      3000,                     // imageHeight
                                      14,                       // focalLength
                                      true,                     // landscape orientation
                                      true,                     // camera orientation is fixed
                                      this);                    // parent
360 361
        _cameraList.append(QVariant::fromValue(metaData));

362 363
        metaData = new CameraMetaData(tr("Sony ILCE-QX1"),  //http://www.sony.co.uk/electronics/interchangeable-lens-cameras/ilce-qx1-body-kit/specifications
                                      23.2,                 //http://www.sony.com/electronics/camera-lenses/sel16f28/specifications
364 365 366 367
                                      15.4,
                                      5456,
                                      3632,
                                      16,
368 369
                                      true,
                                      false,
370 371 372 373 374 375 376 377 378
                                      this);
        _cameraList.append(QVariant::fromValue(metaData));

        metaData = new CameraMetaData(tr("Canon S100 PowerShot"),
                                      7.6,
                                      5.7,
                                      4000,
                                      3000,
                                      5.2,
379 380
                                      true,
                                      false,
381 382 383 384 385 386 387 388 389
                                      this);
        _cameraList.append(QVariant::fromValue(metaData));

        metaData = new CameraMetaData(tr("Canon SX260 HS PowerShot"),
                                      6.17,
                                      4.55,
                                      4000,
                                      3000,
                                      4.5,
390 391
                                      true,
                                      false,
392 393 394 395 396 397 398 399
                                      this);

        metaData = new CameraMetaData(tr("Canon EOS-M 22mm"),
                                      22.3,
                                      14.9,
                                      5184,
                                      3456,
                                      22,
400 401
                                      true,
                                      false,
402 403 404 405 406 407 408 409 410
                                      this);
        _cameraList.append(QVariant::fromValue(metaData));

        metaData = new CameraMetaData(tr("Sony a6000 16mm"),    //http://www.sony.co.uk/electronics/interchangeable-lens-cameras/ilce-6000-body-kit#product_details_default
                                      23.5,
                                      15.6,
                                      6000,
                                      4000,
                                      16,
411 412
                                      true,
                                      false,
413 414 415 416 417 418
                                      this);
        _cameraList.append(QVariant::fromValue(metaData));
    }

    return _cameraList;
}
419 420 421 422 423

bool FirmwarePlugin::vehicleYawsToNextWaypointInMission(const Vehicle* vehicle) const
{
    return vehicle->multiRotor() ? false : true;
}
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440

bool FirmwarePlugin::_armVehicle(Vehicle* vehicle)
{
    if (!vehicle->armed()) {
        vehicle->setArmed(true);
    }

    // Wait for vehicle to return armed state for 2 seconds
    for (int i=0; i<20; i++) {
        if (vehicle->armed()) {
            break;
        }
        QGC::SLEEP::msleep(100);
        qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
    }
    return vehicle->armed();
}
441

Don Gagne's avatar
Don Gagne committed
442
void FirmwarePlugin::batteryConsumptionData(Vehicle* vehicle, int& mAhBattery, double& hoverAmps, double& cruiseAmps) const
443 444 445 446 447 448
{
    Q_UNUSED(vehicle);
    mAhBattery = 0;
    hoverAmps = 0;
    cruiseAmps = 0;
}
449 450 451 452 453 454

QString FirmwarePlugin::autoDisarmParameter(Vehicle* vehicle)
{
    Q_UNUSED(vehicle);
    return QString();
}