PX4AutoPilotPlugin.cc 5.29 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>

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

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

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

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

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

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

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

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

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

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

Don Gagne's avatar
Don Gagne committed
78 79 80 81 82 83 84
#if 0
            // Coming soon
            _motorComponent = new MotorComponent(_vehicle, this);
            _motorComponent->setupTriggerSignals();
            _components.append(QVariant::fromValue((VehicleComponent*)_motorComponent));
#endif

85
            _safetyComponent = new SafetyComponent(_vehicle, this);
86 87
            _safetyComponent->setupTriggerSignals();
            _components.append(QVariant::fromValue((VehicleComponent*)_safetyComponent));
Don Gagne's avatar
Don Gagne committed
88 89 90 91

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

dogmaphobic's avatar
dogmaphobic committed
93 94 95 96 97 98
            //-- 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));
            }
99

Don Gagne's avatar
Don Gagne committed
100 101 102 103 104 105
            //-- 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));
            }
106
        } else {
107
            qWarning() << "Call to vehicleCompenents prior to parametersReady";
108
        }
109
    }
110

111 112 113
    return _components;
}

Don Gagne's avatar
Don Gagne committed
114
/// This will perform various checks prior to signalling that the plug in ready
115
void PX4AutoPilotPlugin::_parametersReadyPreChecks(bool missingParameters)
116
{
Don Gagne's avatar
Don Gagne committed
117 118 119
    // 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.
120 121
    if (_vehicle->parameterExists(FactSystem::defaultComponentId, "SENS_GYRO_XOFF") ||
            _vehicle->parameterExists(FactSystem::defaultComponentId, "COM_DL_LOSS_EN")) {
122
        _incorrectParameterVersion = true;
123 124
        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.");
125 126
    }

127 128 129 130
    _parametersReady = true;
    _missingParameters = missingParameters;
    emit missingParametersChanged(_missingParameters);
    emit parametersReadyChanged(_parametersReady);
131
}