QGCVehicleConfig.h 7.24 KB
Newer Older
1 2 3 4
#ifndef QGCVEHICLECONFIG_H
#define QGCVEHICLECONFIG_H

#include <QWidget>
5
#include <QTimer>
6
#include <QList>
7
#include <QGroupBox>
8

9
#include "QGCToolWidget.h"
10 11
#include "UASInterface.h"

12 13 14 15 16 17 18 19 20 21 22
namespace Ui {
class QGCVehicleConfig;
}

class QGCVehicleConfig : public QWidget
{
    Q_OBJECT
    
public:
    explicit QGCVehicleConfig(QWidget *parent = 0);
    ~QGCVehicleConfig();
23

24 25 26 27 28 29 30
    enum RC_MODE {
        RC_MODE_1 = 1,
        RC_MODE_2 = 2,
        RC_MODE_3 = 3,
        RC_MODE_4 = 4
    };

31 32 33
public slots:
    /** Set the MAV currently being calibrated */
    void setActiveUAS(UASInterface* active);
34
    /** Fallback function, automatically called by loadConfig() upon failure to find and xml file*/
35
    void loadQgcConfig(bool primary);
36
    /** Load configuration from xml file */
37
    void loadConfig();
38 39 40 41 42 43
    /** Start the RC calibration routine */
    void startCalibrationRC();
    /** Stop the RC calibration routine */
    void stopCalibrationRC();
    /** Start/stop the RC calibration routine */
    void toggleCalibrationRC(bool enabled);
44 45 46 47
    /** Set trim positions */
    void setTrimPositions();
    /** Detect which channels need to be inverted */
    void detectChannelInversion();
48 49
    /** Change the mode setting of the control inputs */
    void setRCModeIndex(int newRcMode);
50 51 52
    /** Render the data updated */
    void updateView();

53 54 55
    /** Set the RC channel */
    void setRollChan(int channel) {
        rcMapping[0] = channel - 1;
56
        updateInvertedCheckboxes(channel - 1);
57 58 59 60
    }
    /** Set the RC channel */
    void setPitchChan(int channel) {
        rcMapping[1] = channel - 1;
61
        updateInvertedCheckboxes(channel - 1);
62 63 64 65
    }
    /** Set the RC channel */
    void setYawChan(int channel) {
        rcMapping[2] = channel - 1;
66
        updateInvertedCheckboxes(channel - 1);
67 68 69 70
    }
    /** Set the RC channel */
    void setThrottleChan(int channel) {
        rcMapping[3] = channel - 1;
71
        updateInvertedCheckboxes(channel - 1);
72 73 74 75
    }
    /** Set the RC channel */
    void setModeChan(int channel) {
        rcMapping[4] = channel - 1;
76
        updateInvertedCheckboxes(channel - 1);
77 78 79 80
    }
    /** Set the RC channel */
    void setAux1Chan(int channel) {
        rcMapping[5] = channel - 1;
81
        updateInvertedCheckboxes(channel - 1);
82 83 84 85
    }
    /** Set the RC channel */
    void setAux2Chan(int channel) {
        rcMapping[6] = channel - 1;
86
        updateInvertedCheckboxes(channel - 1);
87 88 89 90
    }
    /** Set the RC channel */
    void setAux3Chan(int channel) {
        rcMapping[7] = channel - 1;
91
        updateInvertedCheckboxes(channel - 1);
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    }

    /** Set channel inversion status */
    void setRollInverted(bool inverted) {
        rcRev[rcMapping[0]] = inverted;
    }
    /** Set channel inversion status */
    void setPitchInverted(bool inverted) {
        rcRev[rcMapping[1]] = inverted;
    }
    /** Set channel inversion status */
    void setYawInverted(bool inverted) {
        rcRev[rcMapping[2]] = inverted;
    }
    /** Set channel inversion status */
    void setThrottleInverted(bool inverted) {
        rcRev[rcMapping[3]] = inverted;
    }
    /** Set channel inversion status */
    void setModeInverted(bool inverted) {
        rcRev[rcMapping[4]] = inverted;
    }
    /** Set channel inversion status */
    void setAux1Inverted(bool inverted) {
        rcRev[rcMapping[5]] = inverted;
    }
    /** Set channel inversion status */
    void setAux2Inverted(bool inverted) {
        rcRev[rcMapping[6]] = inverted;
    }
    /** Set channel inversion status */
    void setAux3Inverted(bool inverted) {
        rcRev[rcMapping[7]] = inverted;
    }

127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
protected slots:
    /** 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);
    void setRCType(int type);
    /** Check timeouts */
    void checktimeOuts();
145 146
    /** Update checkbox status */
    void updateInvertedCheckboxes(int index);
147 148

protected:
149
    bool doneLoadingConfig;
150 151
    UASInterface* mav;                  ///< The current MAV
    static const unsigned int chanMax = 8;    ///< Maximum number of channels
152
    unsigned int chanCount;               ///< Actual channels
153 154 155
    int rcType;                         ///< Type of the remote control
    quint64 rcTypeUpdateRequested;      ///< Zero if not requested, non-zero if requested
    static const unsigned int rcTypeTimeout = 5000; ///< 5 seconds timeout, in milliseconds
156 157 158
    float rcMin[chanMax];                 ///< Minimum values
    float rcMax[chanMax];                 ///< Maximum values
    float rcTrim[chanMax];                ///< Zero-position (center for roll/pitch/yaw, 0 throttle for throttle)
159
    int rcMapping[chanMax];             ///< PWM to function mappings
160
    float rcScaling[chanMax];           ///< Scaling of channel input to control commands
161
    bool rcRev[chanMax];                ///< Channel reverse
162
    int rcValue[chanMax];               ///< Last values
163 164 165 166 167 168 169 170 171 172
    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
    float rcAux1;                       ///< PPM input channel used as aux 1 input
    float rcAux2;                       ///< PPM input channel used as aux 1 input
    float rcAux3;                       ///< PPM input channel used as aux 1 input
    bool rcCalChanged;                  ///< Set if the calibration changes (and needs to be written)
    bool changed;                       ///< Set if any of the input data changed
173
    QTimer updateTimer;                 ///< Controls update intervals
174 175
    enum RC_MODE rc_mode;               ///< Mode of the remote control, according to usual convention
    QList<QGCToolWidget*> toolWidgets;  ///< Configurable widgets
176
    bool calibrationEnabled;            ///< calibration mode on / off
177

178 179 180 181 182
    QMap<QString,QGCToolWidget*> *paramToWidgetMap;                     ///< Holds the current active MAV's parameter widgets.
    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.
183 184 185
    
private:
    Ui::QGCVehicleConfig *ui;
186 187 188

signals:
    void visibilityChanged(bool visible);
189 190 191
};

#endif // QGCVEHICLECONFIG_H