QGCPX4VehicleConfig.h 12 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 67
    /** Set trim positions */
    void setTrimPositions();
    /** Detect which channels need to be inverted */
68
    void detectChannelInversion(int aert_index);
69 70
    /** Render the data updated */
    void updateView();
71

72
    void handleRcParameterChange(QString parameterName, QVariant value);
73 74 75 76 77


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

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

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

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

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

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

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

    /** Identify aux 2 */
    void identifyAux2Channel() {
239
        identifyChannelMapping(10);
240 241
    }

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

protected:
274 275 276

    void setChannelToFunctionMapping(int function, int channel);

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

    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.

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

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

#endif // QGCPX4VehicleConfig_H