PX4AdvancedFlightModesController.h 10.7 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9
 *
 * 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

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

Don Gagne's avatar
Don Gagne committed
14 15
#ifndef PX4AdvancedFlightModesController_H
#define PX4AdvancedFlightModesController_H
Don Gagne's avatar
Don Gagne committed
16 17 18 19

#include <QObject>
#include <QQuickItem>
#include <QList>
Don Gagne's avatar
Don Gagne committed
20
#include <QStringList>
Don Gagne's avatar
Don Gagne committed
21 22 23

#include "UASInterface.h"
#include "AutoPilotPlugin.h"
Don Gagne's avatar
Don Gagne committed
24
#include "FactPanelController.h"
Don Gagne's avatar
Don Gagne committed
25 26

/// MVC Controller for FlightModesComponent.qml.
Don Gagne's avatar
Don Gagne committed
27
class PX4AdvancedFlightModesController : public FactPanelController
Don Gagne's avatar
Don Gagne committed
28 29 30 31
{
    Q_OBJECT
    
public:
Don Gagne's avatar
Don Gagne committed
32
    PX4AdvancedFlightModesController(void);
Don Gagne's avatar
Don Gagne committed
33 34 35 36 37
    
    Q_PROPERTY(bool validConfiguration MEMBER _validConfiguration CONSTANT)
    Q_PROPERTY(QString configurationErrors MEMBER _configurationErrors CONSTANT)
    
    Q_PROPERTY(int channelCount MEMBER _channelCount CONSTANT)
Don Gagne's avatar
Don Gagne committed
38
    Q_PROPERTY(bool fixedWing MEMBER _fixedWing CONSTANT)
Don Gagne's avatar
Don Gagne committed
39
    
40 41
    Q_PROPERTY(QString reservedChannels MEMBER _reservedChannels CONSTANT)
    
Don Gagne's avatar
Don Gagne committed
42 43 44 45 46 47 48 49 50
    Q_PROPERTY(int assistModeRow    MEMBER _assistModeRow   NOTIFY modeRowsChanged)
    Q_PROPERTY(int autoModeRow      MEMBER _autoModeRow     NOTIFY modeRowsChanged)
    Q_PROPERTY(int acroModeRow      MEMBER _acroModeRow     NOTIFY modeRowsChanged)
    Q_PROPERTY(int altCtlModeRow    MEMBER _altCtlModeRow   NOTIFY modeRowsChanged)
    Q_PROPERTY(int posCtlModeRow    MEMBER _posCtlModeRow   NOTIFY modeRowsChanged)
    Q_PROPERTY(int loiterModeRow    MEMBER _loiterModeRow   NOTIFY modeRowsChanged)
    Q_PROPERTY(int missionModeRow   MEMBER _missionModeRow  NOTIFY modeRowsChanged)
    Q_PROPERTY(int returnModeRow    MEMBER _returnModeRow   NOTIFY modeRowsChanged)
    Q_PROPERTY(int offboardModeRow  MEMBER _offboardModeRow NOTIFY modeRowsChanged)
Don Gagne's avatar
Don Gagne committed
51
    
52 53 54 55 56 57 58 59 60 61
    Q_PROPERTY(int manualModeChannelIndex   READ manualModeChannelIndex     WRITE setManualModeChannelIndex     NOTIFY channelIndicesChanged)
    Q_PROPERTY(int assistModeChannelIndex   READ assistModeChannelIndex                                         NOTIFY channelIndicesChanged)
    Q_PROPERTY(int autoModeChannelIndex     READ autoModeChannelIndex                                           NOTIFY channelIndicesChanged)
    Q_PROPERTY(int acroModeChannelIndex     READ acroModeChannelIndex       WRITE setAcroModeChannelIndex       NOTIFY channelIndicesChanged)
    Q_PROPERTY(int altCtlModeChannelIndex   READ altCtlModeChannelIndex                                         NOTIFY channelIndicesChanged)
    Q_PROPERTY(int posCtlModeChannelIndex   READ posCtlModeChannelIndex     WRITE setPosCtlModeChannelIndex     NOTIFY channelIndicesChanged)
    Q_PROPERTY(int loiterModeChannelIndex   READ loiterModeChannelIndex     WRITE setLoiterModeChannelIndex     NOTIFY channelIndicesChanged)
    Q_PROPERTY(int missionModeChannelIndex  READ missionModeChannelIndex                                        NOTIFY channelIndicesChanged)
    Q_PROPERTY(int returnModeChannelIndex   READ returnModeChannelIndex     WRITE setReturnModeChannelIndex     NOTIFY channelIndicesChanged)
    Q_PROPERTY(int offboardModeChannelIndex READ offboardModeChannelIndex   WRITE setOffboardModeChannelIndex   NOTIFY channelIndicesChanged)
Don Gagne's avatar
Don Gagne committed
62
    
Don Gagne's avatar
Don Gagne committed
63 64 65 66 67 68 69 70 71 72
    Q_PROPERTY(double manualModeRcValue     READ manualModeRcValue      NOTIFY switchLiveRangeChanged)
    Q_PROPERTY(double assistModeRcValue     READ assistModeRcValue      NOTIFY switchLiveRangeChanged)
    Q_PROPERTY(double autoModeRcValue       READ autoModeRcValue        NOTIFY switchLiveRangeChanged)
    Q_PROPERTY(double acroModeRcValue       READ acroModeRcValue        NOTIFY switchLiveRangeChanged)
    Q_PROPERTY(double altCtlModeRcValue     READ altCtlModeRcValue      NOTIFY switchLiveRangeChanged)
    Q_PROPERTY(double posCtlModeRcValue     READ posCtlModeRcValue      NOTIFY switchLiveRangeChanged)
    Q_PROPERTY(double loiterModeRcValue     READ loiterModeRcValue      NOTIFY switchLiveRangeChanged)
    Q_PROPERTY(double missionModeRcValue    READ missionModeRcValue     NOTIFY switchLiveRangeChanged)
    Q_PROPERTY(double returnModeRcValue     READ returnModeRcValue      NOTIFY switchLiveRangeChanged)
    Q_PROPERTY(double offboardModeRcValue   READ offboardModeRcValue    NOTIFY switchLiveRangeChanged)
Don Gagne's avatar
Don Gagne committed
73
    
Don Gagne's avatar
Don Gagne committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
    Q_PROPERTY(double manualModeThreshold   READ manualModeThreshold                                    NOTIFY thresholdsChanged)
    Q_PROPERTY(double assistModeThreshold   READ assistModeThreshold    WRITE setAssistModeThreshold    NOTIFY thresholdsChanged)
    Q_PROPERTY(double autoModeThreshold     READ autoModeThreshold      WRITE setAutoModeThreshold      NOTIFY thresholdsChanged)
    Q_PROPERTY(double acroModeThreshold     READ acroModeThreshold      WRITE setAcroModeThreshold      NOTIFY thresholdsChanged)
    Q_PROPERTY(double altCtlModeThreshold   READ altCtlModeThreshold    WRITE setAltCtlModeThreshold    NOTIFY thresholdsChanged)
    Q_PROPERTY(double posCtlModeThreshold   READ posCtlModeThreshold    WRITE setPosCtlModeThreshold    NOTIFY thresholdsChanged)
    Q_PROPERTY(double loiterModeThreshold   READ loiterModeThreshold    WRITE setLoiterModeThreshold    NOTIFY thresholdsChanged)
    Q_PROPERTY(double missionModeThreshold  READ missionModeThreshold   WRITE setMissionModeThreshold   NOTIFY thresholdsChanged)
    Q_PROPERTY(double returnModeThreshold   READ returnModeThreshold    WRITE setReturnModeThreshold    NOTIFY thresholdsChanged)
    Q_PROPERTY(double offboardModeThreshold READ offboardModeThreshold  WRITE setOffboardModeThreshold  NOTIFY thresholdsChanged)
    
    Q_PROPERTY(bool assistModeVisible   MEMBER _assistModeVisible   NOTIFY modesVisibleChanged)
    Q_PROPERTY(bool autoModeVisible     MEMBER _autoModeVisible     NOTIFY modesVisibleChanged)
    
    Q_PROPERTY(bool manualModeSelected      MEMBER _manualModeSelected      NOTIFY modesSelectedChanged)
    Q_PROPERTY(bool assistModeSelected      MEMBER _assistModeSelected      NOTIFY modesSelectedChanged)
    Q_PROPERTY(bool autoModeSelected        MEMBER _autoModeSelected        NOTIFY modesSelectedChanged)
    Q_PROPERTY(bool acroModeSelected        MEMBER _acroModeSelected        NOTIFY modesSelectedChanged)
    Q_PROPERTY(bool altCtlModeSelected      MEMBER _altCtlModeSelected      NOTIFY modesSelectedChanged)
    Q_PROPERTY(bool posCtlModeSelected      MEMBER _posCtlModeSelected      NOTIFY modesSelectedChanged)
    Q_PROPERTY(bool missionModeSelected     MEMBER _missionModeSelected     NOTIFY modesSelectedChanged)
    Q_PROPERTY(bool loiterModeSelected      MEMBER _loiterModeSelected      NOTIFY modesSelectedChanged)
    Q_PROPERTY(bool returnModeSelected      MEMBER _returnModeSelected      NOTIFY modesSelectedChanged)
    Q_PROPERTY(bool offboardModeSelected    MEMBER _offboardModeSelected    NOTIFY modesSelectedChanged)
    
    Q_PROPERTY(QStringList channelListModel MEMBER _channelListModel CONSTANT)
    
    Q_INVOKABLE void generateThresholds(void);
    
    int assistModeRow(void);
    int autoModeRow(void);
    int acroModeRow(void);
    int altCtlModeRow(void);
    int posCtlModeRow(void);
    int loiterModeRow(void);
    int missionModeRow(void);
    int returnModeRow(void);
    int offboardModeRow(void);
    
    int manualModeChannelIndex(void);
    int assistModeChannelIndex(void);
    int autoModeChannelIndex(void);
    int acroModeChannelIndex(void);
    int altCtlModeChannelIndex(void);
    int posCtlModeChannelIndex(void);
    int loiterModeChannelIndex(void);
    int missionModeChannelIndex(void);
    int returnModeChannelIndex(void);
    int offboardModeChannelIndex(void);
    
    void setManualModeChannelIndex(int index);
    void setAcroModeChannelIndex(int index);
    void setPosCtlModeChannelIndex(int index);
    void setLoiterModeChannelIndex(int index);
    void setReturnModeChannelIndex(int index);
    void setOffboardModeChannelIndex(int index);
    
    double manualModeRcValue(void);
    double assistModeRcValue(void);
    double autoModeRcValue(void);
    double acroModeRcValue(void);
    double altCtlModeRcValue(void);
    double posCtlModeRcValue(void);
    double missionModeRcValue(void);
    double loiterModeRcValue(void);
    double returnModeRcValue(void);
    double offboardModeRcValue(void);
    
    double manualModeThreshold(void);
    double assistModeThreshold(void);
    double autoModeThreshold(void);
    double acroModeThreshold(void);
    double altCtlModeThreshold(void);
    double posCtlModeThreshold(void);
    double missionModeThreshold(void);
    double loiterModeThreshold(void);
    double returnModeThreshold(void);
    double offboardModeThreshold(void);
    
    void setAssistModeThreshold(double threshold);
    void setAutoModeThreshold(double threshold);
    void setAcroModeThreshold(double threshold);
    void setAltCtlModeThreshold(double threshold);
    void setPosCtlModeThreshold(double threshold);
    void setMissionModeThreshold(double threshold);
    void setLoiterModeThreshold(double threshold);
    void setReturnModeThreshold(double threshold);
    void setOffboardModeThreshold(double threshold);
Don Gagne's avatar
Don Gagne committed
162 163 164
    
signals:
    void switchLiveRangeChanged(void);
Don Gagne's avatar
Don Gagne committed
165 166 167
    void thresholdsChanged(void);
    void modesSelectedChanged(void);
    void modesVisibleChanged(void);
168
    void channelIndicesChanged(void);
Don Gagne's avatar
Don Gagne committed
169
    void modeRowsChanged(void);
Don Gagne's avatar
Don Gagne committed
170 171
    
private slots:
Don Gagne's avatar
Don Gagne committed
172
    void _rcChannelsChanged(int channelCount, int pwmValues[Vehicle::cMaxRcChannels]);
Don Gagne's avatar
Don Gagne committed
173 174 175
    
private:
    double _switchLiveRange(const QString& param);
Don Gagne's avatar
Don Gagne committed
176
    void _init(void);
Don Gagne's avatar
Don Gagne committed
177
    void _validateConfiguration(void);
Don Gagne's avatar
Don Gagne committed
178 179 180 181 182
    void _recalcModeSelections(void);
    void _recalcModeRows(void);
    int _channelToChannelIndex(int channel);
    int _channelToChannelIndex(const QString& channelParam);
    int _channelIndexToChannel(int index);
Don Gagne's avatar
Don Gagne committed
183 184 185
    
    static const int _chanMax = 18;
    
Don Gagne's avatar
Don Gagne committed
186 187 188 189 190 191
    bool _fixedWing;
    
    double  _rcValues[_chanMax];
    int     _rgRCMin[_chanMax];
    int     _rgRCMax[_chanMax];
    bool    _rgRCReversed[_chanMax];
Don Gagne's avatar
Don Gagne committed
192 193 194 195
    
    bool    _validConfiguration;
    QString _configurationErrors;
    int     _channelCount;
196
    QString _reservedChannels;
Don Gagne's avatar
Don Gagne committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223

    int _assistModeRow;
    int _autoModeRow;
    int _acroModeRow;
    int _altCtlModeRow;
    int _posCtlModeRow;
    int _loiterModeRow;
    int _missionModeRow;
    int _returnModeRow;
    int _offboardModeRow;
    
    bool _manualModeSelected;
    bool _assistModeSelected;
    bool _autoModeSelected;
    bool _acroModeSelected;
    bool _altCtlModeSelected;
    bool _posCtlModeSelected;
    bool _missionModeSelected;
    bool _loiterModeSelected;
    bool _returnModeSelected;
    bool _offboardModeSelected;
    
    bool _assistModeVisible;
    bool _autoModeVisible;
    
    QStringList _channelListModel;
    QList<int>  _channelListModelChannel;
Don Gagne's avatar
Don Gagne committed
224 225 226
};

#endif