PX4AutoPilotPlugin.cc 5.92 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
/*=====================================================================
 
 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/>.
 
 ======================================================================*/

#include "PX4AutoPilotPlugin.h"
Don Gagne's avatar
Don Gagne committed
25
#include "AutoPilotPluginManager.h"
26
#include "PX4AirframeLoader.h"
Don Gagne's avatar
Don Gagne committed
27
#include "PX4AdvancedFlightModesController.h"
28
#include "AirframeComponentController.h"
29
#include "UAS.h"
30
#include "FirmwarePlugin/PX4/PX4ParameterMetaData.h"  // FIXME: Hack
31
#include "FirmwarePlugin/PX4/PX4FirmwarePlugin.h"  // FIXME: Hack
32
#include "QGCApplication.h"
33 34 35 36 37 38 39 40 41 42 43 44

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

enum PX4_CUSTOM_MAIN_MODE {
    PX4_CUSTOM_MAIN_MODE_MANUAL = 1,
    PX4_CUSTOM_MAIN_MODE_ALTCTL,
    PX4_CUSTOM_MAIN_MODE_POSCTL,
    PX4_CUSTOM_MAIN_MODE_AUTO,
    PX4_CUSTOM_MAIN_MODE_ACRO,
    PX4_CUSTOM_MAIN_MODE_OFFBOARD,
45
    PX4_CUSTOM_MAIN_MODE_STABILIZED,
46 47
    PX4_CUSTOM_MAIN_MODE_RATTITUDE
    
48 49 50 51 52 53 54 55 56
};

enum PX4_CUSTOM_SUB_MODE_AUTO {
    PX4_CUSTOM_SUB_MODE_AUTO_READY = 1,
    PX4_CUSTOM_SUB_MODE_AUTO_TAKEOFF,
    PX4_CUSTOM_SUB_MODE_AUTO_LOITER,
    PX4_CUSTOM_SUB_MODE_AUTO_MISSION,
    PX4_CUSTOM_SUB_MODE_AUTO_RTL,
    PX4_CUSTOM_SUB_MODE_AUTO_LAND,
Jimmy Johnson's avatar
Jimmy Johnson committed
57 58
    PX4_CUSTOM_SUB_MODE_AUTO_RTGS,
    PX4_CUSTOM_SUB_MODE_AUTO_FOLLOW_ME
59 60 61 62 63 64 65 66 67 68 69 70
};

union px4_custom_mode {
    struct {
        uint16_t reserved;
        uint8_t main_mode;
        uint8_t sub_mode;
    };
    uint32_t data;
    float data_float;
};

71 72
PX4AutoPilotPlugin::PX4AutoPilotPlugin(Vehicle* vehicle, QObject* parent) :
    AutoPilotPlugin(vehicle, parent),
Don Gagne's avatar
Don Gagne committed
73 74
    _airframeComponent(NULL),
    _radioComponent(NULL),
dogmaphobic's avatar
dogmaphobic committed
75
    _esp8266Component(NULL),
Don Gagne's avatar
Don Gagne committed
76 77
    _flightModesComponent(NULL),
    _sensorsComponent(NULL),
78
    _safetyComponent(NULL),
dogmaphobic's avatar
dogmaphobic committed
79
    _powerComponent(NULL),
80
    _incorrectParameterVersion(false)
81
{
82
    Q_ASSERT(vehicle);
83
    
84
    _airframeFacts = new PX4AirframeLoader(this, _vehicle->uas(), this);
85
    Q_CHECK_PTR(_airframeFacts);
Don Gagne's avatar
Don Gagne committed
86
    
87
    PX4AirframeLoader::loadAirframeMetaData();
Don Gagne's avatar
Don Gagne committed
88 89 90 91
}

PX4AutoPilotPlugin::~PX4AutoPilotPlugin()
{
92
    delete _airframeFacts;
93 94
}

95
const QVariantList& PX4AutoPilotPlugin::vehicleComponents(void)
96
{
97
    if (_components.count() == 0 && !_incorrectParameterVersion) {
98
        Q_ASSERT(_vehicle);
99
        
100
        if (parametersReady()) {
101
            _airframeComponent = new AirframeComponent(_vehicle, this);
102 103 104
            _airframeComponent->setupTriggerSignals();
            _components.append(QVariant::fromValue((VehicleComponent*)_airframeComponent));
            
Don Gagne's avatar
Don Gagne committed
105
            _radioComponent = new PX4RadioComponent(_vehicle, this);
106 107
            _radioComponent->setupTriggerSignals();
            _components.append(QVariant::fromValue((VehicleComponent*)_radioComponent));
dogmaphobic's avatar
dogmaphobic committed
108

109
            _flightModesComponent = new FlightModesComponent(_vehicle, this);
110 111
            _flightModesComponent->setupTriggerSignals();
            _components.append(QVariant::fromValue((VehicleComponent*)_flightModesComponent));
112
            
113
            _sensorsComponent = new SensorsComponent(_vehicle, this);
114 115 116
            _sensorsComponent->setupTriggerSignals();
            _components.append(QVariant::fromValue((VehicleComponent*)_sensorsComponent));
            
117
            _powerComponent = new PowerComponent(_vehicle, this);
118 119 120
            _powerComponent->setupTriggerSignals();
            _components.append(QVariant::fromValue((VehicleComponent*)_powerComponent));
            
121
            _safetyComponent = new SafetyComponent(_vehicle, this);
122 123
            _safetyComponent->setupTriggerSignals();
            _components.append(QVariant::fromValue((VehicleComponent*)_safetyComponent));
Don Gagne's avatar
Don Gagne committed
124 125 126 127

            _tuningComponent = new PX4TuningComponent(_vehicle, this);
            _tuningComponent->setupTriggerSignals();
            _components.append(QVariant::fromValue((VehicleComponent*)_tuningComponent));
Don Gagne's avatar
Don Gagne committed
128 129 130 131 132 133 134

            //-- 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));
            }
135
        } else {
136
            qWarning() << "Call to vehicleCompenents prior to parametersReady";
137
        }
138 139 140 141 142
    }
    
    return _components;
}

Don Gagne's avatar
Don Gagne committed
143
/// This will perform various checks prior to signalling that the plug in ready
144
void PX4AutoPilotPlugin::_parametersReadyPreChecks(bool missingParameters)
145
{
Don Gagne's avatar
Don Gagne committed
146 147 148
    // 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.
Don Gagne's avatar
Don Gagne committed
149
    if (parameterExists(FactSystem::defaultComponentId, "SENS_GYRO_XOFF")) {
150
        _incorrectParameterVersion = true;
151 152
        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.");
153 154
	}
	
155 156 157 158
    _parametersReady = true;
    _missingParameters = missingParameters;
    emit missingParametersChanged(_missingParameters);
    emit parametersReadyChanged(_parametersReady);
159
}