APMSensorsComponentController.h 11.5 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

10
#pragma once
Don Gagne's avatar
Don Gagne committed
11 12 13 14 15 16

#include <QObject>

#include "UASInterface.h"
#include "FactPanelController.h"
#include "QGCLoggingCategory.h"
17
#include "APMSensorsComponent.h"
18
#include "APMCompassCal.h"
Don Gagne's avatar
Don Gagne committed
19 20

Q_DECLARE_LOGGING_CATEGORY(APMSensorsComponentControllerLog)
21
Q_DECLARE_LOGGING_CATEGORY(APMSensorsComponentControllerVerboseLog)
Don Gagne's avatar
Don Gagne committed
22 23 24 25 26 27 28 29

/// Sensors Component MVC Controller for SensorsComponent.qml.
class APMSensorsComponentController : public FactPanelController
{
    Q_OBJECT
    
public:
    APMSensorsComponentController(void);
30
    ~APMSensorsComponentController();
31

32 33
    Q_PROPERTY(QQuickItem* statusLog                        MEMBER _statusLog)
    Q_PROPERTY(QQuickItem* progressBar                      MEMBER _progressBar)
Don Gagne's avatar
Don Gagne committed
34
    
35 36 37
    Q_PROPERTY(QQuickItem* nextButton                       MEMBER _nextButton)
    Q_PROPERTY(QQuickItem* cancelButton                     MEMBER _cancelButton)
    Q_PROPERTY(QQuickItem* orientationCalAreaHelpText       MEMBER _orientationCalAreaHelpText)
38

39 40
    Q_PROPERTY(bool compassSetupNeeded                      READ compassSetupNeeded                         NOTIFY setupNeededChanged)
    Q_PROPERTY(bool accelSetupNeeded                        READ accelSetupNeeded                           NOTIFY setupNeededChanged)
41

42
    Q_PROPERTY(bool showOrientationCalArea                  MEMBER _showOrientationCalArea                  NOTIFY showOrientationCalAreaChanged)
Don Gagne's avatar
Don Gagne committed
43
    
44 45 46 47 48 49
    Q_PROPERTY(bool orientationCalDownSideDone              MEMBER _orientationCalDownSideDone              NOTIFY orientationCalSidesDoneChanged)
    Q_PROPERTY(bool orientationCalUpsideDownSideDone        MEMBER _orientationCalUpsideDownSideDone        NOTIFY orientationCalSidesDoneChanged)
    Q_PROPERTY(bool orientationCalLeftSideDone              MEMBER _orientationCalLeftSideDone              NOTIFY orientationCalSidesDoneChanged)
    Q_PROPERTY(bool orientationCalRightSideDone             MEMBER _orientationCalRightSideDone             NOTIFY orientationCalSidesDoneChanged)
    Q_PROPERTY(bool orientationCalNoseDownSideDone          MEMBER _orientationCalNoseDownSideDone          NOTIFY orientationCalSidesDoneChanged)
    Q_PROPERTY(bool orientationCalTailDownSideDone          MEMBER _orientationCalTailDownSideDone          NOTIFY orientationCalSidesDoneChanged)
Don Gagne's avatar
Don Gagne committed
50
    
51 52 53 54 55 56
    Q_PROPERTY(bool orientationCalDownSideVisible           MEMBER _orientationCalDownSideVisible           NOTIFY orientationCalSidesVisibleChanged)
    Q_PROPERTY(bool orientationCalUpsideDownSideVisible     MEMBER _orientationCalUpsideDownSideVisible     NOTIFY orientationCalSidesVisibleChanged)
    Q_PROPERTY(bool orientationCalLeftSideVisible           MEMBER _orientationCalLeftSideVisible           NOTIFY orientationCalSidesVisibleChanged)
    Q_PROPERTY(bool orientationCalRightSideVisible          MEMBER _orientationCalRightSideVisible          NOTIFY orientationCalSidesVisibleChanged)
    Q_PROPERTY(bool orientationCalNoseDownSideVisible       MEMBER _orientationCalNoseDownSideVisible       NOTIFY orientationCalSidesVisibleChanged)
    Q_PROPERTY(bool orientationCalTailDownSideVisible       MEMBER _orientationCalTailDownSideVisible       NOTIFY orientationCalSidesVisibleChanged)
Don Gagne's avatar
Don Gagne committed
57
    
58 59 60 61 62 63
    Q_PROPERTY(bool orientationCalDownSideInProgress        MEMBER _orientationCalDownSideInProgress        NOTIFY orientationCalSidesInProgressChanged)
    Q_PROPERTY(bool orientationCalUpsideDownSideInProgress  MEMBER _orientationCalUpsideDownSideInProgress  NOTIFY orientationCalSidesInProgressChanged)
    Q_PROPERTY(bool orientationCalLeftSideInProgress        MEMBER _orientationCalLeftSideInProgress        NOTIFY orientationCalSidesInProgressChanged)
    Q_PROPERTY(bool orientationCalRightSideInProgress       MEMBER _orientationCalRightSideInProgress       NOTIFY orientationCalSidesInProgressChanged)
    Q_PROPERTY(bool orientationCalNoseDownSideInProgress    MEMBER _orientationCalNoseDownSideInProgress    NOTIFY orientationCalSidesInProgressChanged)
    Q_PROPERTY(bool orientationCalTailDownSideInProgress    MEMBER _orientationCalTailDownSideInProgress    NOTIFY orientationCalSidesInProgressChanged)
Don Gagne's avatar
Don Gagne committed
64
    
65 66 67 68 69 70
    Q_PROPERTY(bool orientationCalDownSideRotate            MEMBER _orientationCalDownSideRotate            NOTIFY orientationCalSidesRotateChanged)
    Q_PROPERTY(bool orientationCalUpsideDownSideRotate      MEMBER _orientationCalUpsideDownSideRotate      NOTIFY orientationCalSidesRotateChanged)
    Q_PROPERTY(bool orientationCalLeftSideRotate            MEMBER _orientationCalLeftSideRotate            NOTIFY orientationCalSidesRotateChanged)
    Q_PROPERTY(bool orientationCalRightSideRotate           MEMBER _orientationCalRightSideRotate           NOTIFY orientationCalSidesRotateChanged)
    Q_PROPERTY(bool orientationCalNoseDownSideRotate        MEMBER _orientationCalNoseDownSideRotate        NOTIFY orientationCalSidesRotateChanged)
    Q_PROPERTY(bool orientationCalTailDownSideRotate        MEMBER _orientationCalTailDownSideRotate        NOTIFY orientationCalSidesRotateChanged)
Don Gagne's avatar
Don Gagne committed
71
    
72
    Q_PROPERTY(bool waitingForCancel                        MEMBER _waitingForCancel                        NOTIFY waitingForCancelChanged)
73

74 75 76
    Q_PROPERTY(bool compass1CalSucceeded                    READ compass1CalSucceeded                       NOTIFY compass1CalSucceededChanged)
    Q_PROPERTY(bool compass2CalSucceeded                    READ compass2CalSucceeded                       NOTIFY compass2CalSucceededChanged)
    Q_PROPERTY(bool compass3CalSucceeded                    READ compass3CalSucceeded                       NOTIFY compass3CalSucceededChanged)
77

78 79 80
    Q_PROPERTY(double compass1CalFitness                    READ compass1CalFitness                         NOTIFY compass1CalFitnessChanged)
    Q_PROPERTY(double compass2CalFitness                    READ compass2CalFitness                         NOTIFY compass2CalFitnessChanged)
    Q_PROPERTY(double compass3CalFitness                    READ compass3CalFitness                         NOTIFY compass3CalFitnessChanged)
81

82 83 84 85 86 87 88 89 90
    Q_INVOKABLE void calibrateCompass           (void);
    Q_INVOKABLE void calibrateAccel             (void);
    Q_INVOKABLE void calibrateGyro              (void);
    Q_INVOKABLE void calibrateMotorInterference (void);
    Q_INVOKABLE void levelHorizon               (void);
    Q_INVOKABLE void calibratePressure          (void);
    Q_INVOKABLE void cancelCalibration          (void);
    Q_INVOKABLE void nextClicked                (void);
    Q_INVOKABLE bool usingUDPLink               (void);
Don Gagne's avatar
Don Gagne committed
91

92 93
    bool compassSetupNeeded (void) const;
    bool accelSetupNeeded   (void) const;
94 95 96

    typedef enum {
        CalTypeAccel,
97
        CalTypeGyro,
98 99 100 101
        CalTypeOnboardCompass,
        CalTypeOffboardCompass,
        CalTypeLevelHorizon,
        CalTypeCompassMot,
102
        CalTypePressure,
103 104 105 106 107 108 109 110 111 112 113 114
        CalTypeNone
    } CalType_t;
    Q_ENUM(CalType_t)

    bool compass1CalSucceeded(void) const { return _rgCompassCalSucceeded[0]; }
    bool compass2CalSucceeded(void) const { return _rgCompassCalSucceeded[1]; }
    bool compass3CalSucceeded(void) const { return _rgCompassCalSucceeded[2]; }

    double compass1CalFitness(void) const { return _rgCompassCalFitness[0]; }
    double compass2CalFitness(void) const { return _rgCompassCalFitness[1]; }
    double compass3CalFitness(void) const { return _rgCompassCalFitness[2]; }

Don Gagne's avatar
Don Gagne committed
115
signals:
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    void showGyroCalAreaChanged                 (void);
    void showOrientationCalAreaChanged          (void);
    void orientationCalSidesDoneChanged         (void);
    void orientationCalSidesVisibleChanged      (void);
    void orientationCalSidesInProgressChanged   (void);
    void orientationCalSidesRotateChanged       (void);
    void resetStatusTextArea                    (void);
    void waitingForCancelChanged                (void);
    void setupNeededChanged                     (void);
    void calibrationComplete                    (CalType_t calType);
    void compass1CalSucceededChanged            (bool compass1CalSucceeded);
    void compass2CalSucceededChanged            (bool compass2CalSucceeded);
    void compass3CalSucceededChanged            (bool compass3CalSucceeded);
    void compass1CalFitnessChanged              (double compass1CalFitness);
    void compass2CalFitnessChanged              (double compass2CalFitness);
    void compass3CalFitnessChanged              (double compass3CalFitness);
    void setAllCalButtonsEnabled                (bool enabled);
133

Don Gagne's avatar
Don Gagne committed
134
private slots:
135
    void _handleUASTextMessage  (int uasId, int compId, int severity, QString text);
Don Gagne's avatar
Don Gagne committed
136
    void _mavlinkMessageReceived(LinkInterface* link, mavlink_message_t message);
137
    void _mavCommandResult      (int vehicleId, int component, int command, int result, bool noReponseFromVehicle);
Don Gagne's avatar
Don Gagne committed
138

Don Gagne's avatar
Don Gagne committed
139
private:
140 141 142 143 144 145 146 147 148 149
    void _startLogCalibration               (void);
    void _startVisualCalibration            (void);
    void _appendStatusLog                   (const QString& text);
    void _refreshParams                     (void);
    void _hideAllCalAreas                   (void);
    void _resetInternalState                (void);
    void _handleCommandAck                  (mavlink_message_t& message);
    void _handleMagCalProgress              (mavlink_message_t& message);
    void _handleMagCalReport                (mavlink_message_t& message);
    void _restorePreviousCompassCalFitness  (void);
150

Don Gagne's avatar
Don Gagne committed
151 152
    enum StopCalibrationCode {
        StopCalibrationSuccess,
Don Gagne's avatar
Don Gagne committed
153
        StopCalibrationSuccessShowLog,
Don Gagne's avatar
Don Gagne committed
154 155 156 157 158 159 160
        StopCalibrationFailed,
        StopCalibrationCancelled
    };
    void _stopCalibration(StopCalibrationCode code);
    
    void _updateAndEmitShowOrientationCalArea(bool show);

161
    APMCompassCal           _compassCal;
162 163
    APMSensorsComponent*    _sensorsComponent;

Don Gagne's avatar
Don Gagne committed
164 165 166 167 168 169 170 171
    QQuickItem* _statusLog;
    QQuickItem* _progressBar;
    QQuickItem* _nextButton;
    QQuickItem* _cancelButton;
    QQuickItem* _orientationCalAreaHelpText;
    
    bool _showOrientationCalArea;
    
172 173 174 175 176 177 178
    CalType_t _calTypeInProgress;

    uint8_t _rgCompassCalProgress[3];
    bool    _rgCompassCalComplete[3];
    bool    _rgCompassCalSucceeded[3];
    float   _rgCompassCalFitness[3];

Don Gagne's avatar
Don Gagne committed
179 180 181 182 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
    bool _orientationCalDownSideDone;
    bool _orientationCalUpsideDownSideDone;
    bool _orientationCalLeftSideDone;
    bool _orientationCalRightSideDone;
    bool _orientationCalNoseDownSideDone;
    bool _orientationCalTailDownSideDone;
    
    bool _orientationCalDownSideVisible;
    bool _orientationCalUpsideDownSideVisible;
    bool _orientationCalLeftSideVisible;
    bool _orientationCalRightSideVisible;
    bool _orientationCalNoseDownSideVisible;
    bool _orientationCalTailDownSideVisible;
    
    bool _orientationCalDownSideInProgress;
    bool _orientationCalUpsideDownSideInProgress;
    bool _orientationCalLeftSideInProgress;
    bool _orientationCalRightSideInProgress;
    bool _orientationCalNoseDownSideInProgress;
    bool _orientationCalTailDownSideInProgress;
    
    bool _orientationCalDownSideRotate;
    bool _orientationCalUpsideDownSideRotate;
    bool _orientationCalLeftSideRotate;
    bool _orientationCalRightSideRotate;
    bool _orientationCalNoseDownSideRotate;
    bool _orientationCalTailDownSideRotate;
    
    bool _waitingForCancel;
208 209 210 211

    bool _restoreCompassCalFitness;
    float _previousCompassCalFitness;
    static const char* _compassCalFitnessParam;
Don Gagne's avatar
Don Gagne committed
212 213 214
    
    static const int _supportedFirmwareCalVersion = 2;
};