QGCPX4VehicleConfig.h 11.7 KB
Newer Older
1 2 3 4 5 6 7 8
#ifndef QGCPX4VehicleConfig_H
#define QGCPX4VehicleConfig_H

#include <QWidget>
#include <QTimer>
#include <QList>
#include <QGroupBox>
#include <QPushButton>
9
#include <QStringList>
10
#include <QMessageBox>
11 12 13

#include "QGCToolWidget.h"
#include "UASInterface.h"
14
#include "px4_configuration/QGCPX4AirframeConfig.h"
15

16
class UASParameterCommsMgr;
17
class DialogBare;
18
class QGCPX4SensorCalibration;
19

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
namespace Ui {
class QGCPX4VehicleConfig;
}

class QGCPX4VehicleConfig : public QWidget
{
    Q_OBJECT

public:
    explicit QGCPX4VehicleConfig(QWidget *parent = 0);
    ~QGCPX4VehicleConfig();

    enum RC_MODE {
        RC_MODE_1 = 1,
        RC_MODE_2 = 2,
        RC_MODE_3 = 3,
        RC_MODE_4 = 4,
        RC_MODE_NONE = 5
    };

public slots:
    void rcMenuButtonClicked();
    void sensorMenuButtonClicked();
    void generalMenuButtonClicked();
    void advancedMenuButtonClicked();
45
    void airframeMenuButtonClicked();
46 47
    void firmwareMenuButtonClicked();

48
    void identifyChannelMapping(int aert_index);
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

    /** Set the MAV currently being calibrated */
    void setActiveUAS(UASInterface* active);
    /** Fallback function, automatically called by loadConfig() upon failure to find and xml file*/
    void loadQgcConfig(bool primary);
    /** Load configuration from xml file */
    void loadConfig();
    /** Start the RC calibration routine */
    void startCalibrationRC();
    /** Stop the RC calibration routine */
    void stopCalibrationRC();
    /** Start/stop the RC calibration routine */
    void toggleCalibrationRC(bool enabled);
    /** Set trim positions */
    void setTrimPositions();
    /** Detect which channels need to be inverted */
65
    void detectChannelInversion(int aert_index);
66 67
    /** Render the data updated */
    void updateView();
68

69
    void handleRcParameterChange(QString parameterName, QVariant value);
70 71 72 73 74


    /** Set the RC channel */
    void setRollChan(int channel) {
        rcMapping[0] = channel - 1;
75
        updateMappingView(0);
76 77 78 79
    }
    /** Set the RC channel */
    void setPitchChan(int channel) {
        rcMapping[1] = channel - 1;
80
        updateMappingView(1);
81 82 83 84
    }
    /** Set the RC channel */
    void setYawChan(int channel) {
        rcMapping[2] = channel - 1;
85
        updateMappingView(2);
86 87 88 89
    }
    /** Set the RC channel */
    void setThrottleChan(int channel) {
        rcMapping[3] = channel - 1;
90
        updateMappingView(3);
91 92 93 94
    }
    /** Set the RC channel */
    void setModeChan(int channel) {
        rcMapping[4] = channel - 1;
95
        updateMappingView(4);
96 97
    }
    /** Set the RC channel */
98
    void setAssistChan(int channel) {
99
        rcMapping[5] = channel - 1;
100
        updateMappingView(5);
101 102
    }
    /** Set the RC channel */
103
    void setMissionChan(int channel) {
104
        rcMapping[6] = channel - 1;
105
        updateMappingView(6);
106 107
    }
    /** Set the RC channel */
108
    void setReturnChan(int channel) {
109
        rcMapping[7] = channel - 1;
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
        updateMappingView(7);
    }
    /** Set the RC channel */
    void setFlapsChan(int channel) {
        rcMapping[8] = channel - 1;
        updateMappingView(8);
    }
    /** Set the RC channel */
    void setAux1Chan(int channel) {
        rcMapping[9] = channel - 1;
        updateMappingView(9);
    }
    /** Set the RC channel */
    void setAux2Chan(int channel) {
        rcMapping[10] = channel - 1;
        updateMappingView(10);
126 127 128 129 130
    }

    /** Set channel inversion status */
    void setRollInverted(bool inverted) {
        rcRev[rcMapping[0]] = inverted;
131
        updateMappingView(0);
132 133 134 135
    }
    /** Set channel inversion status */
    void setPitchInverted(bool inverted) {
        rcRev[rcMapping[1]] = inverted;
136
        updateMappingView(1);
137 138 139 140
    }
    /** Set channel inversion status */
    void setYawInverted(bool inverted) {
        rcRev[rcMapping[2]] = inverted;
141
        updateMappingView(2);
142 143 144 145
    }
    /** Set channel inversion status */
    void setThrottleInverted(bool inverted) {
        rcRev[rcMapping[3]] = inverted;
146
        updateMappingView(3);
147 148 149 150
    }
    /** Set channel inversion status */
    void setModeInverted(bool inverted) {
        rcRev[rcMapping[4]] = inverted;
151
        updateMappingView(4);
152 153
    }
    /** Set channel inversion status */
154
    void setAssistInverted(bool inverted) {
155
        rcRev[rcMapping[5]] = inverted;
156
        updateMappingView(5);
157 158
    }
    /** Set channel inversion status */
159
    void setMissionInverted(bool inverted) {
160
        rcRev[rcMapping[6]] = inverted;
161
        updateMappingView(6);
162 163
    }
    /** Set channel inversion status */
164
    void setReturnInverted(bool inverted) {
165
        rcRev[rcMapping[7]] = inverted;
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
        updateMappingView(7);
    }
    /** Set channel inversion status */
    void setFlapsInverted(bool inverted) {
        rcRev[rcMapping[8]] = inverted;
        updateMappingView(8);
    }
    /** Set channel inversion status */
    void setAux1Inverted(bool inverted) {
        rcRev[rcMapping[9]] = inverted;
        updateMappingView(9);
    }
    /** Set channel inversion status */
    void setAux2Inverted(bool inverted) {
        rcRev[rcMapping[10]] = inverted;
        updateMappingView(10);
182 183
    }

184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
    /** Identify roll */
    void identifyRollChannel() {
        identifyChannelMapping(0);
    }

    /** Identify pitch */
    void identifyPitchChannel() {
        identifyChannelMapping(1);
    }

    /** Identify yaw */
    void identifyYawChannel() {
        identifyChannelMapping(2);
    }

    /** Identify throttle */
    void identifyThrottleChannel() {
        identifyChannelMapping(3);
    }

    /** Identify mode */
    void identifyModeChannel() {
        identifyChannelMapping(4);
    }

209 210
    /** Identify assist channel */
    void identifyAssistChannel() {
211 212 213
        identifyChannelMapping(5);
    }

214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
    /** Identify mission channel */
    void identifyMissionChannel() {
        identifyChannelMapping(6);
    }

    /** Identify return channel */
    void identifyReturnChannel() {
        identifyChannelMapping(7);
    }

    /** Identify flaps channel */
    void identifyFlapsChannel() {
        identifyChannelMapping(8);
    }

229 230
    /** Identify aux 1 */
    void identifyAux1Channel() {
231
        identifyChannelMapping(9);
232 233 234 235
    }

    /** Identify aux 2 */
    void identifyAux2Channel() {
236
        identifyChannelMapping(10);
237 238
    }

239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
protected slots:
    void menuButtonClicked();
    /** Reset the RC calibration */
    void resetCalibrationRC();
    /** Write the RC calibration */
    void writeCalibrationRC();
    /** Request the RC calibration */
    void requestCalibrationRC();
    /** Store all parameters in onboard EEPROM */
    void writeParameters();
    /** Receive remote control updates from MAV */
    void remoteControlChannelRawChanged(int chan, float val);
    /** Parameter changed onboard */
    void parameterChanged(int uas, int component, QString parameterName, QVariant value);
    void updateStatus(const QString& str);
    void updateError(const QString& str);
    /** Check timeouts */
    void checktimeOuts();
    /** Update checkbox status */
258 259 260
    void updateAllInvertedCheckboxes();
    /** Update mapping view state */
    void updateMappingView(int index);
261 262 263 264 265 266 267 268
    /** Update the displayed values */
    void updateRcWidgetValues();
    /** update the channel labels */
    void updateRcChanLabels();

    QString labelForRcValue(float val) {
        return  QString("%1").arg(val, 5, 'f', 2, QChar(' '));
    }
269 270

protected:
271 272 273

    void setChannelToFunctionMapping(int function, int channel);

274 275
    bool doneLoadingConfig;
    UASInterface* mav;                  ///< The current MAV
276
    QGCUASParamManager* paramMgr;       ///< params mgr for the mav
277 278
    static const unsigned int chanMax = 14;    ///< Maximum number of channels
    static const unsigned int chanMappedMax = 16; ///< Maximum number of mapped channels (can be higher than input channel count)
279 280 281 282
    unsigned int chanCount;               ///< Actual channels
    float rcMin[chanMax];                 ///< Minimum values
    float rcMax[chanMax];                 ///< Maximum values
    float rcTrim[chanMax];                ///< Zero-position (center for roll/pitch/yaw, 0 throttle for throttle)
283 284
    int rcMapping[chanMappedMax];             ///< PWM to function mappings
    int rcToFunctionMapping[chanMax];
285 286
    float rcScaling[chanMax];           ///< Scaling of channel input to control commands
    bool rcRev[chanMax];                ///< Channel reverse
287 288 289 290 291 292
    int rcValue[chanMax];               ///< Last values, RAW
    float rcValueReversed[chanMax];            ///< Last values, accounted for reverse
    float rcMappedMin[chanMappedMax];            ///< Mapped channels in default order
    float rcMappedMax[chanMappedMax];            ///< Mapped channels in default order
    float rcMappedValue[chanMappedMax];            ///< Mapped channels in default order
    float rcMappedNormalizedValue[chanMappedMax];            ///< Mapped channels in default order
293
    int channelWanted;                  ///< During channel assignment search the requested default index
294
    int channelReverseStateWanted;
295
    float channelWantedList[chanMax];   ///< During channel assignment search the start values
296
    float channelReverseStateWantedList[chanMax];
297
    QStringList channelNames;           ///< List of channel names in standard order
298 299 300 301 302
    float rcRoll;                       ///< PPM input channel used as roll control input
    float rcPitch;                      ///< PPM input channel used as pitch control input
    float rcYaw;                        ///< PPM input channel used as yaw control input
    float rcThrottle;                   ///< PPM input channel used as throttle control input
    float rcMode;                       ///< PPM input channel used as mode switch control input
303 304 305 306
    float rcAssist;                     ///< PPM input channel used as assist switch control input
    float rcMission;                    ///< PPM input channel used as mission switch control input
    float rcReturn;                     ///< PPM input channel used as return switch control input
    float rcFlaps;                      ///< PPM input channel used as flaps control input
307
    float rcAux1;                       ///< PPM input channel used as aux 1 input
308
    float rcAux2;                       ///< PPM input channel used as aux 2 input
309
    bool rcCalChanged;                  ///< Set if the calibration changes (and needs to be written)
310
    bool dataModelChanged;              ///< Set if any of the input data changed
311 312
    QTimer updateTimer;                 ///< Controls update intervals
    QList<QGCToolWidget*> toolWidgets;  ///< Configurable widgets
313
    QMap<QString,QGCToolWidget*> toolWidgetsByName; ///<
314
    bool calibrationEnabled;            ///< calibration mode on / off
315
    bool configEnabled;                 ///< config mode on / off
316 317 318 319 320 321 322 323

    QMap<QString,QGCToolWidget*> paramToWidgetMap;                     ///< Holds the current active MAV's parameter widgets.
    QList<QWidget*> additionalTabs;                                   ///< Stores additional tabs loaded for this vehicle/autopilot configuration. Used for cleaning up.
    QMap<QString,QGCToolWidget*> libParamToWidgetMap;                  ///< Holds the library parameter widgets
    QMap<QString,QMap<QString,QGCToolWidget*> > systemTypeToParamMap;   ///< Holds all loaded MAV specific parameter widgets, for every MAV.
    QMap<QGCToolWidget*,QGroupBox*> toolToBoxMap;                       ///< Easy method of figuring out which QGroupBox is tied to which ToolWidget.
    QMap<QString,QString> paramTooltips;                                ///< Tooltips for the ? button next to a parameter.

324
    QGCPX4AirframeConfig* px4AirframeConfig;
325
    DialogBare* firmwareDialog;
326
    QGCPX4SensorCalibration* px4SensorCalibration;
327
    QMessageBox msgBox;
328
    QPushButton* skipActionButton;
329

330 331 332 333 334 335 336 337
private:
    Ui::QGCPX4VehicleConfig *ui;
    QMap<QPushButton*,QWidget*> buttonToWidgetMap;
signals:
    void visibilityChanged(bool visible);
};

#endif // QGCPX4VehicleConfig_H