QGCPX4VehicleConfig.h 11.9 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 63 64 65

    /** 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 */
66
    void detectChannelInversion(int aert_index);
67 68
    /** Render the data updated */
    void updateView();
69

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


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

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

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

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

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

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

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

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

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

protected:
272 273 274

    void setChannelToFunctionMapping(int function, int channel);

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

    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.

326
    QGCPX4AirframeConfig* px4AirframeConfig;
327
    DialogBare* firmwareDialog;
Lorenz Meier's avatar
Lorenz Meier committed
328 329
    QPixmap planeBack;
    QPixmap planeSide;
330
    QGCPX4SensorCalibration* px4SensorCalibration;
331
    QMessageBox msgBox;
Lorenz Meier's avatar
Lorenz Meier committed
332
    QGraphicsScene scene;
333
    QPushButton* skipActionButton;
334

335 336 337 338 339 340 341 342
private:
    Ui::QGCPX4VehicleConfig *ui;
    QMap<QPushButton*,QWidget*> buttonToWidgetMap;
signals:
    void visibilityChanged(bool visible);
};

#endif // QGCPX4VehicleConfig_H