QGCPX4VehicleConfig.h 12.1 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>
Lorenz Meier's avatar
Lorenz Meier committed
11
#include <QGraphicsScene>
12 13 14

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

17
class UASParameterCommsMgr;
18
class DialogBare;
19
class QGCPX4SensorCalibration;
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 45
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();
46
    void airframeMenuButtonClicked();
47 48
    void firmwareMenuButtonClicked();

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

    /** 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);
63 64
    /** Start/stop the Spektrum pair routine */
    void toggleSpektrumPairing(bool enabled);
65 66
    /** Set the current trim values as attitude trim values */
    void copyAttitudeTrim();
67 68 69
    /** Set trim positions */
    void setTrimPositions();
    /** Detect which channels need to be inverted */
70
    void detectChannelInversion(int aert_index);
71 72
    /** Render the data updated */
    void updateView();
73

74
    void handleRcParameterChange(QString parameterName, QVariant value);
75 76 77 78 79


    /** Set the RC channel */
    void setRollChan(int channel) {
        rcMapping[0] = channel - 1;
80
        updateMappingView(0);
81 82 83 84
    }
    /** Set the RC channel */
    void setPitchChan(int channel) {
        rcMapping[1] = channel - 1;
85
        updateMappingView(1);
86 87 88 89
    }
    /** Set the RC channel */
    void setYawChan(int channel) {
        rcMapping[2] = channel - 1;
90
        updateMappingView(2);
91 92 93 94
    }
    /** Set the RC channel */
    void setThrottleChan(int channel) {
        rcMapping[3] = channel - 1;
95
        updateMappingView(3);
96 97 98 99
    }
    /** Set the RC channel */
    void setModeChan(int channel) {
        rcMapping[4] = channel - 1;
100
        updateMappingView(4);
101 102
    }
    /** Set the RC channel */
103
    void setAssistChan(int channel) {
104
        rcMapping[5] = channel - 1;
105
        updateMappingView(5);
106 107
    }
    /** Set the RC channel */
108
    void setMissionChan(int channel) {
109
        rcMapping[6] = channel - 1;
110
        updateMappingView(6);
111 112
    }
    /** Set the RC channel */
113
    void setReturnChan(int channel) {
114
        rcMapping[7] = channel - 1;
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
        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);
131 132 133 134 135
    }

    /** Set channel inversion status */
    void setRollInverted(bool inverted) {
        rcRev[rcMapping[0]] = inverted;
136
        updateMappingView(0);
137 138 139 140
    }
    /** Set channel inversion status */
    void setPitchInverted(bool inverted) {
        rcRev[rcMapping[1]] = inverted;
141
        updateMappingView(1);
142 143 144 145
    }
    /** Set channel inversion status */
    void setYawInverted(bool inverted) {
        rcRev[rcMapping[2]] = inverted;
146
        updateMappingView(2);
147 148 149 150
    }
    /** Set channel inversion status */
    void setThrottleInverted(bool inverted) {
        rcRev[rcMapping[3]] = inverted;
151
        updateMappingView(3);
152 153 154 155
    }
    /** Set channel inversion status */
    void setModeInverted(bool inverted) {
        rcRev[rcMapping[4]] = inverted;
156
        updateMappingView(4);
157 158
    }
    /** Set channel inversion status */
159
    void setAssistInverted(bool inverted) {
160
        rcRev[rcMapping[5]] = inverted;
161
        updateMappingView(5);
162 163
    }
    /** Set channel inversion status */
164
    void setMissionInverted(bool inverted) {
165
        rcRev[rcMapping[6]] = inverted;
166
        updateMappingView(6);
167 168
    }
    /** Set channel inversion status */
169
    void setReturnInverted(bool inverted) {
170
        rcRev[rcMapping[7]] = inverted;
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
        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);
187 188
    }

189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
    /** 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);
    }

214 215
    /** Identify assist channel */
    void identifyAssistChannel() {
216 217 218
        identifyChannelMapping(5);
    }

219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
    /** Identify mission channel */
    void identifyMissionChannel() {
        identifyChannelMapping(6);
    }

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

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

234 235
    /** Identify aux 1 */
    void identifyAux1Channel() {
236
        identifyChannelMapping(9);
237 238 239 240
    }

    /** Identify aux 2 */
    void identifyAux2Channel() {
241
        identifyChannelMapping(10);
242 243
    }

244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
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 */
263 264 265
    void updateAllInvertedCheckboxes();
    /** Update mapping view state */
    void updateMappingView(int index);
266 267 268 269 270 271 272 273
    /** 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(' '));
    }
274 275

protected:
276 277 278

    void setChannelToFunctionMapping(int function, int channel);

279 280
    bool doneLoadingConfig;
    UASInterface* mav;                  ///< The current MAV
281
    QGCUASParamManagerInterface* paramMgr;       ///< params mgr for the mav
282
    static const unsigned int chanMax = 18;    ///< Maximum number of channels
283
    static const unsigned int chanMappedMax = 18; ///< Maximum number of mapped channels (can be higher than input channel count)
284 285 286 287
    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)
288 289
    int rcMapping[chanMappedMax];             ///< PWM to function mappings
    int rcToFunctionMapping[chanMax];
290 291
    float rcScaling[chanMax];           ///< Scaling of channel input to control commands
    bool rcRev[chanMax];                ///< Channel reverse
292
    int rcValue[chanMax];               ///< Last values, RAW
Lorenz Meier's avatar
Lorenz Meier committed
293 294 295 296 297
    int rcValueReversed[chanMax];            ///< Last values, accounted for reverse
    int rcMappedMin[chanMappedMax];            ///< Mapped channels in default order
    int rcMappedMax[chanMappedMax];            ///< Mapped channels in default order
    int rcMappedValue[chanMappedMax];            ///< Mapped channels in default order
    int rcMappedValueRev[chanMappedMax];
298
    float rcMappedNormalizedValue[chanMappedMax];            ///< Mapped channels in default order
299
    int channelWanted;                  ///< During channel assignment search the requested default index
300
    int channelReverseStateWanted;
301
    float channelWantedList[chanMax];   ///< During channel assignment search the start values
302
    float channelReverseStateWantedList[chanMax];
303
    QStringList channelNames;           ///< List of channel names in standard order
304 305 306 307 308
    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
309 310 311 312
    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
313
    float rcAux1;                       ///< PPM input channel used as aux 1 input
314
    float rcAux2;                       ///< PPM input channel used as aux 2 input
315
    bool rcCalChanged;                  ///< Set if the calibration changes (and needs to be written)
316
    bool dataModelChanged;              ///< Set if any of the input data changed
317 318
    QTimer updateTimer;                 ///< Controls update intervals
    QList<QGCToolWidget*> toolWidgets;  ///< Configurable widgets
319
    QMap<QString,QGCToolWidget*> toolWidgetsByName; ///<
320
    bool calibrationEnabled;            ///< calibration mode on / off
321
    bool configEnabled;                 ///< config mode on / off
322 323 324 325 326 327 328 329

    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.

330
    QGCPX4AirframeConfig* px4AirframeConfig;
331
    DialogBare* firmwareDialog;
Lorenz Meier's avatar
Lorenz Meier committed
332 333
    QPixmap planeBack;
    QPixmap planeSide;
334
    QGCPX4SensorCalibration* px4SensorCalibration;
335
    QMessageBox msgBox;
Lorenz Meier's avatar
Lorenz Meier committed
336
    QGraphicsScene scene;
337
    QPushButton* skipActionButton;
338

339 340 341 342 343 344 345 346
private:
    Ui::QGCPX4VehicleConfig *ui;
    QMap<QPushButton*,QWidget*> buttonToWidgetMap;
signals:
    void visibilityChanged(bool visible);
};

#endif // QGCPX4VehicleConfig_H