PX4FirmwarePlugin.h 7.04 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

Don Gagne's avatar
Don Gagne committed
10 11 12 13 14 15 16 17

/// @file
///     @author Don Gagne <don@thegagnes.com>

#ifndef PX4FirmwarePlugin_H
#define PX4FirmwarePlugin_H

#include "FirmwarePlugin.h"
18
#include "ParameterManager.h"
19
#include "PX4ParameterMetaData.h"
Don Gagne's avatar
Don Gagne committed
20 21 22 23 24 25

class PX4FirmwarePlugin : public FirmwarePlugin
{
    Q_OBJECT

public:
26
    PX4FirmwarePlugin   ();
27
    ~PX4FirmwarePlugin  () override;
28

Don Gagne's avatar
Don Gagne committed
29
    // Overrides from FirmwarePlugin
30

31 32
    QList<VehicleComponent*> componentsForVehicle(AutoPilotPlugin* vehicle) override;
    QList<MAV_CMD> supportedMissionCommands(void) override;
Don Gagne's avatar
Don Gagne committed
33

34 35 36 37 38 39
    AutoPilotPlugin*    autopilotPlugin                 (Vehicle* vehicle) override;
    bool                isCapable                       (const Vehicle *vehicle, FirmwareCapabilities capabilities) override;
    QStringList         flightModes                     (Vehicle* vehicle) override;
    QString             flightMode                      (uint8_t base_mode, uint32_t custom_mode) const override;
    bool                setFlightMode                   (const QString& flightMode, uint8_t* base_mode, uint32_t* custom_mode) override;
    void                setGuidedMode                   (Vehicle* vehicle, bool guidedMode) override;
40 41 42 43 44
    QString             pauseFlightMode                 (void) const override { return _holdFlightMode; }
    QString             missionFlightMode               (void) const override { return _missionFlightMode; }
    QString             rtlFlightMode                   (void) const override { return _rtlFlightMode; }
    QString             landFlightMode                  (void) const override { return _landingFlightMode; }
    QString             takeControlFlightMode           (void) const override { return _manualFlightMode; }
Don Gagne's avatar
Don Gagne committed
45
    QString             gotoFlightMode                  (void) const override { return _holdFlightMode; }
46
    QString             followFlightMode                (void) const override { return _followMeFlightMode; };
47
    void                pauseVehicle                    (Vehicle* vehicle) override;
DonLakeFlyer's avatar
DonLakeFlyer committed
48
    void                guidedModeRTL                   (Vehicle* vehicle, bool smartRTL) override;
49
    void                guidedModeLand                  (Vehicle* vehicle) override;
50
    void                guidedModeTakeoff               (Vehicle* vehicle, double takeoffAltRel) override;
51 52
    void                guidedModeGotoLocation          (Vehicle* vehicle, const QGeoCoordinate& gotoCoord) override;
    void                guidedModeChangeAltitude        (Vehicle* vehicle, double altitudeRel) override;
53
    double              minimumTakeoffAltitude          (Vehicle* vehicle) override;
54
    void                startMission                    (Vehicle* vehicle) override;
55 56 57 58
    bool                isGuidedMode                    (const Vehicle* vehicle) const override;
    void                initializeVehicle               (Vehicle* vehicle) override;
    bool                sendHomePositionToVehicle       (void) override;
    void                addMetaDataToFact               (QObject* parameterMetaData, Fact* fact, MAV_TYPE vehicleType) override;
59
    FactMetaData*       getMetaDataForFact              (QObject* parameterMetaData, const QString& name, MAV_TYPE vehicleType) override;
60 61 62
    QString             missionCommandOverrides         (MAV_TYPE vehicleType) const override;
    QString             getVersionParam                 (void) override { return QString("SYS_PARAM_VER"); }
    QString             internalParameterMetaDataFile   (Vehicle* vehicle) override { Q_UNUSED(vehicle); return QString(":/FirmwarePlugin/PX4/PX4ParameterFactMetaData.xml"); }
63
    void                getParameterMetaDataVersionInfo (const QString& metaDataFile, int& majorVersion, int& minorVersion) override;
64 65 66
    QObject*            loadParameterMetaData           (const QString& metaDataFile) final;
    bool                adjustIncomingMavlinkMessage    (Vehicle* vehicle, mavlink_message_t* message) override;
    QString             offlineEditingParamFile(Vehicle* vehicle) override { Q_UNUSED(vehicle); return QStringLiteral(":/FirmwarePlugin/PX4/PX4.OfflineEditing.params"); }
67 68
    QString             brandImageIndoor                (const Vehicle* vehicle) const override { Q_UNUSED(vehicle); return QStringLiteral("/qmlimages/PX4/BrandImage"); }
    QString             brandImageOutdoor               (const Vehicle* vehicle) const override { Q_UNUSED(vehicle); return QStringLiteral("/qmlimages/PX4/BrandImage"); }
69
    QString             autoDisarmParameter             (Vehicle* vehicle) override { Q_UNUSED(vehicle); return QStringLiteral("COM_DISARM_LAND"); }
70
    uint32_t            highLatencyCustomModeTo32Bits   (uint16_t hlCustomMode) override;
71
    bool                supportsTerrainFrame            (void) const override { return false; }
72
    bool                supportsNegativeThrust          (Vehicle *vehicle) override;
Don Gagne's avatar
Don Gagne committed
73

74 75
protected:
    typedef struct {
76 77 78 79 80 81
        uint8_t         main_mode;
        uint8_t         sub_mode;
        const QString*  name;       ///< Name for flight mode
        bool            canBeSet;   ///< true: Vehicle can be set to this flight mode
        bool            fixedWing;  /// fixed wing compatible
        bool            multiRotor; /// multi rotor compatible
82 83 84 85
    } FlightModeInfo_t;

    QList<FlightModeInfo_t> _flightModeInfoList;

86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
    // Use these constants to set flight modes using setFlightMode method. Don't use hardcoded string names since the
    // names may change.

    // If plugin superclass wants to change a mode name, then set a new name for the flight mode in the superclass constructor
    QString _manualFlightMode;
    QString _acroFlightMode;
    QString _stabilizedFlightMode;
    QString _rattitudeFlightMode;
    QString _altCtlFlightMode;
    QString _posCtlFlightMode;
    QString _offboardFlightMode;
    QString _readyFlightMode;
    QString _takeoffFlightMode;
    QString _holdFlightMode;
    QString _missionFlightMode;
    QString _rtlFlightMode;
    QString _landingFlightMode;
103
    QString _preclandFlightMode;
104 105 106
    QString _rtgsFlightMode;
    QString _followMeFlightMode;
    QString _simpleFlightMode;
107
    QString _orbitFlightMode;
108

109 110 111
private slots:
    void _mavCommandResult(int vehicleId, int component, int command, int result, bool noReponseFromVehicle);

112 113
private:
    void _handleAutopilotVersion(Vehicle* vehicle, mavlink_message_t* message);
114 115
    QString _getLatestVersionFileUrl(Vehicle* vehicle) override;
    QString _versionRegex() override;
116

117 118 119 120 121 122 123 124 125
    // Any instance data here must be global to all vehicles
    // Vehicle specific data should go into PX4FirmwarePluginInstanceData
};

class PX4FirmwarePluginInstanceData : public QObject
{
    Q_OBJECT

public:
126
    PX4FirmwarePluginInstanceData(QObject* parent = nullptr);
127 128

    bool versionNotified;  ///< true: user notified over version issue
Don Gagne's avatar
Don Gagne committed
129 130 131
};

#endif