PX4AutoPilotPlugin.cc 5 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 11

#include "PX4AutoPilotPlugin.h"
Don Gagne's avatar
Don Gagne committed
12
#include "AutoPilotPluginManager.h"
13
#include "PX4AirframeLoader.h"
Don Gagne's avatar
Don Gagne committed
14
#include "PX4AdvancedFlightModesController.h"
15
#include "AirframeComponentController.h"
16
#include "UAS.h"
17
#include "FirmwarePlugin/PX4/PX4ParameterMetaData.h"  // FIXME: Hack
18
#include "FirmwarePlugin/PX4/PX4FirmwarePlugin.h"  // FIXME: Hack
19
#include "QGCApplication.h"
20 21 22 23 24

/// @file
///     @brief This is the AutoPilotPlugin implementatin for the MAV_AUTOPILOT_PX4 type.
///     @author Don Gagne <don@thegagnes.com>

25 26
PX4AutoPilotPlugin::PX4AutoPilotPlugin(Vehicle* vehicle, QObject* parent) :
    AutoPilotPlugin(vehicle, parent),
Don Gagne's avatar
Don Gagne committed
27 28
    _airframeComponent(NULL),
    _radioComponent(NULL),
dogmaphobic's avatar
dogmaphobic committed
29
    _esp8266Component(NULL),
Don Gagne's avatar
Don Gagne committed
30 31
    _flightModesComponent(NULL),
    _sensorsComponent(NULL),
32
    _safetyComponent(NULL),
dogmaphobic's avatar
dogmaphobic committed
33
    _powerComponent(NULL),
34
    _incorrectParameterVersion(false)
35
{
36
    Q_ASSERT(vehicle);
37

38
    _airframeFacts = new PX4AirframeLoader(this, _vehicle->uas(), this);
39
    Q_CHECK_PTR(_airframeFacts);
40

41
    PX4AirframeLoader::loadAirframeMetaData();
Don Gagne's avatar
Don Gagne committed
42 43 44 45
}

PX4AutoPilotPlugin::~PX4AutoPilotPlugin()
{
46
    delete _airframeFacts;
47 48
}

49
const QVariantList& PX4AutoPilotPlugin::vehicleComponents(void)
50
{
51
    if (_components.count() == 0 && !_incorrectParameterVersion) {
52
        Q_ASSERT(_vehicle);
53

54
        if (parametersReady()) {
55
            _airframeComponent = new AirframeComponent(_vehicle, this);
56 57
            _airframeComponent->setupTriggerSignals();
            _components.append(QVariant::fromValue((VehicleComponent*)_airframeComponent));
58

Don Gagne's avatar
Don Gagne committed
59
            _radioComponent = new PX4RadioComponent(_vehicle, this);
60 61
            _radioComponent->setupTriggerSignals();
            _components.append(QVariant::fromValue((VehicleComponent*)_radioComponent));
dogmaphobic's avatar
dogmaphobic committed
62

63 64 65 66 67
            if (!_vehicle->hilMode()) {
                _sensorsComponent = new SensorsComponent(_vehicle, this);
                _sensorsComponent->setupTriggerSignals();
                _components.append(QVariant::fromValue((VehicleComponent*)_sensorsComponent));
            }
68 69 70 71 72

            _flightModesComponent = new FlightModesComponent(_vehicle, this);
            _flightModesComponent->setupTriggerSignals();
            _components.append(QVariant::fromValue((VehicleComponent*)_flightModesComponent));

73
            _powerComponent = new PowerComponent(_vehicle, this);
74 75
            _powerComponent->setupTriggerSignals();
            _components.append(QVariant::fromValue((VehicleComponent*)_powerComponent));
76

77
            _safetyComponent = new SafetyComponent(_vehicle, this);
78 79
            _safetyComponent->setupTriggerSignals();
            _components.append(QVariant::fromValue((VehicleComponent*)_safetyComponent));
Don Gagne's avatar
Don Gagne committed
80 81 82 83

            _tuningComponent = new PX4TuningComponent(_vehicle, this);
            _tuningComponent->setupTriggerSignals();
            _components.append(QVariant::fromValue((VehicleComponent*)_tuningComponent));
Don Gagne's avatar
Don Gagne committed
84

dogmaphobic's avatar
dogmaphobic committed
85 86 87 88 89 90
            //-- Is there support for cameras?
            if(factExists(FactSystem::ParameterProvider, _vehicle->id(), "TRIG_MODE")) {
                _cameraComponent = new CameraComponent(_vehicle, this);
                _cameraComponent->setupTriggerSignals();
                _components.append(QVariant::fromValue((VehicleComponent*)_cameraComponent));
            }
91

Don Gagne's avatar
Don Gagne committed
92 93 94 95 96 97
            //-- Is there an ESP8266 Connected?
            if(factExists(FactSystem::ParameterProvider, MAV_COMP_ID_UDP_BRIDGE, "SW_VER")) {
                _esp8266Component = new ESP8266Component(_vehicle, this);
                _esp8266Component->setupTriggerSignals();
                _components.append(QVariant::fromValue((VehicleComponent*)_esp8266Component));
            }
98
        } else {
99
            qWarning() << "Call to vehicleCompenents prior to parametersReady";
100
        }
101
    }
102

103 104 105
    return _components;
}

Don Gagne's avatar
Don Gagne committed
106
/// This will perform various checks prior to signalling that the plug in ready
107
void PX4AutoPilotPlugin::_parametersReadyPreChecks(bool missingParameters)
108
{
Don Gagne's avatar
Don Gagne committed
109 110 111
    // Check for older parameter version set
    // FIXME: Firmware is moving to version stamp parameter set. Once that is complete the version stamp
    // should be used instead.
112 113
    if (parameterExists(FactSystem::defaultComponentId, "SENS_GYRO_XOFF") ||
            parameterExists(FactSystem::defaultComponentId, "COM_DL_LOSS_EN")) {
114
        _incorrectParameterVersion = true;
115 116
        qgcApp()->showMessage("This version of GroundControl can only perform vehicle setup on a newer version of firmware. "
                              "Please perform a Firmware Upgrade if you wish to use Vehicle Setup.");
117 118
    }

119 120 121 122
    _parametersReady = true;
    _missingParameters = missingParameters;
    emit missingParametersChanged(_missingParameters);
    emit parametersReadyChanged(_parametersReady);
123
}