PX4AdvancedFlightModesController.h 11.3 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*=====================================================================
 
 QGroundControl Open Source Ground Control Station
 
 (c) 2009, 2015 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/>.
 
 ======================================================================*/

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

Don Gagne's avatar
Don Gagne committed
27 28
#ifndef PX4AdvancedFlightModesController_H
#define PX4AdvancedFlightModesController_H
Don Gagne's avatar
Don Gagne committed
29 30 31 32

#include <QObject>
#include <QQuickItem>
#include <QList>
Don Gagne's avatar
Don Gagne committed
33
#include <QStringList>
Don Gagne's avatar
Don Gagne committed
34 35 36

#include "UASInterface.h"
#include "AutoPilotPlugin.h"
Don Gagne's avatar
Don Gagne committed
37
#include "FactPanelController.h"
Don Gagne's avatar
Don Gagne committed
38 39

/// MVC Controller for FlightModesComponent.qml.
Don Gagne's avatar
Don Gagne committed
40
class PX4AdvancedFlightModesController : public FactPanelController
Don Gagne's avatar
Don Gagne committed
41 42 43 44
{
    Q_OBJECT
    
public:
Don Gagne's avatar
Don Gagne committed
45
    PX4AdvancedFlightModesController(void);
Don Gagne's avatar
Don Gagne committed
46 47 48 49 50
    
    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
51
    Q_PROPERTY(bool fixedWing MEMBER _fixedWing CONSTANT)
Don Gagne's avatar
Don Gagne committed
52
    
53 54
    Q_PROPERTY(QString reservedChannels MEMBER _reservedChannels CONSTANT)
    
Don Gagne's avatar
Don Gagne committed
55 56 57 58 59 60 61 62 63
    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
64
    
65 66 67 68 69 70 71 72 73 74
    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
75
    
Don Gagne's avatar
Don Gagne committed
76 77 78 79 80 81 82 83 84 85
    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
86
    
Don Gagne's avatar
Don Gagne committed
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 162 163 164 165 166 167 168 169 170 171 172 173 174
    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
175 176 177
    
signals:
    void switchLiveRangeChanged(void);
Don Gagne's avatar
Don Gagne committed
178 179 180
    void thresholdsChanged(void);
    void modesSelectedChanged(void);
    void modesVisibleChanged(void);
181
    void channelIndicesChanged(void);
Don Gagne's avatar
Don Gagne committed
182
    void modeRowsChanged(void);
Don Gagne's avatar
Don Gagne committed
183 184
    
private slots:
Don Gagne's avatar
Don Gagne committed
185
    void _rcChannelsChanged(int channelCount, int pwmValues[Vehicle::cMaxRcChannels]);
Don Gagne's avatar
Don Gagne committed
186 187 188
    
private:
    double _switchLiveRange(const QString& param);
Don Gagne's avatar
Don Gagne committed
189
    void _init(void);
Don Gagne's avatar
Don Gagne committed
190
    void _validateConfiguration(void);
Don Gagne's avatar
Don Gagne committed
191 192 193 194 195
    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
196 197 198
    
    static const int _chanMax = 18;
    
Don Gagne's avatar
Don Gagne committed
199 200 201 202 203 204
    bool _fixedWing;
    
    double  _rcValues[_chanMax];
    int     _rgRCMin[_chanMax];
    int     _rgRCMax[_chanMax];
    bool    _rgRCReversed[_chanMax];
Don Gagne's avatar
Don Gagne committed
205 206 207 208
    
    bool    _validConfiguration;
    QString _configurationErrors;
    int     _channelCount;
209
    QString _reservedChannels;
Don Gagne's avatar
Don Gagne committed
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236

    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
237 238 239
};

#endif