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 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
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();
43
    void tuningMenuButtonClicked();
Lorenz Meier's avatar
Lorenz Meier committed
44 45
    void flightModeMenuButtonClicked();
    void safetyConfigMenuButtonClicked();
46
    void advancedMenuButtonClicked();
47
    void airframeMenuButtonClicked();
48 49
    void firmwareMenuButtonClicked();

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

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

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


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

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

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

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

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

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

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

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

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

protected:
277 278 279

    void setChannelToFunctionMapping(int function, int channel);

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

    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.

331
    QGCPX4AirframeConfig* px4AirframeConfig;
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