PX4RCCalibrationTest.h 4.08 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*=====================================================================
 
 QGroundControl Open Source Ground Control Station
 
 (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 
 This file is part of the QGROUNDCONTROL project
 
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
 
 ======================================================================*/

#ifndef PX4RCCALIBRATIONTEST_H
#define PX4RCCALIBRATIONTEST_H

Don Gagne's avatar
Don Gagne committed
27
#include "UnitTest.h"
28 29
#include "MockUASManager.h"
#include "MockUAS.h"
Don Gagne's avatar
Don Gagne committed
30
#include "MultiSignalSpy.h"
31
#include "px4_configuration/PX4RCCalibration.h"
32
#include "QGCLoggingCategory.h"
33 34

/// @file
Don Gagne's avatar
Don Gagne committed
35
///     @brief PX4RCCalibration Widget unit test
36 37 38
///
///     @author Don Gagne <don@thegagnes.com>

39 40
Q_DECLARE_LOGGING_CATEGORY(PX4RCCalibrationTestLog)

Don Gagne's avatar
Don Gagne committed
41
///     @brief PX4RCCalibration Widget unit test
Don Gagne's avatar
Don Gagne committed
42
class PX4RCCalibrationTest : public UnitTest
43 44 45 46 47 48 49 50 51 52 53 54 55 56
{
    Q_OBJECT
    
public:
    PX4RCCalibrationTest(void);
    
private slots:
    void init(void);
    void cleanup(void);
    
    void _minRCChannels_test(void);
    void _fullCalibration_test(void);
    
private:
Don Gagne's avatar
Don Gagne committed
57 58 59 60 61 62 63
    /// @brief Modes to run worker functions
    enum TestMode {
        testModeStandalone,     ///< Perform standalone test of calibration state
        testModePrerequisite,   ///< Setup prequisites for subsequent calibration state
        testModeFullSequence,   ///< Run as full calibration sequence
    };
    
Don Gagne's avatar
Don Gagne committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77
    enum MoveToDirection {
        moveToMax,
        moveToMin,
        moveToCenter,
    };
    
    void _channelHomePosition(void);
    void _minRCChannels(void);
    void _beginCalibration(void);
    void _stickMoveWaitForSettle(int channel, int value);
    void _stickMoveAutoStep(const char* functionStr, enum PX4RCCalibration::rcCalFunctions function, enum MoveToDirection direction, bool identifyStep);
    void _switchMinMaxStep(void);
    void _flapsDetectStep(void);
    void _switchSelectAutoStep(const char* functionStr, PX4RCCalibration::rcCalFunctions function);
78 79 80 81 82 83 84 85
    
    enum {
        validateMinMaxMask =    1 << 0,
        validateTrimsMask =     1 << 1,
        validateReversedMask =  1 << 2,
        validateMappingMask =   1 << 3,
        validateAllMask = 0xFFFF
    };
Don Gagne's avatar
Don Gagne committed
86 87

    struct ChannelSettings {
88
		int function;
Don Gagne's avatar
Don Gagne committed
89 90 91 92 93 94
        int rcMin;
        int rcMax;
        int rcTrim;
        int reversed;
    };
    
Don Gagne's avatar
Don Gagne committed
95
    void _validateParameters(void);
96 97 98 99 100 101 102 103 104
    
    MockUASManager*     _mockUASManager;
    MockUAS*            _mockUAS;
    
    PX4RCCalibration*   _calWidget;
    
    enum {
        nextButtonMask =        1 << 0,
        cancelButtonMask =      1 << 1,
Don Gagne's avatar
Don Gagne committed
105
        skipButtonMask =        1 << 2
106 107 108 109 110 111 112
    };
    
    QPushButton*    _nextButton;
    QPushButton*    _cancelButton;
    QPushButton*    _skipButton;
    QLabel*         _statusLabel;
    
Don Gagne's avatar
Don Gagne committed
113 114 115 116
    RCValueWidget* _rgValueWidget[PX4RCCalibration::_chanMax];
    
    const char*         _rgSignals[1];
    MultiSignalSpy*     _multiSpyNextButtonMessageBox;
Don Gagne's avatar
Don Gagne committed
117 118 119 120 121
    
    // When settings values into min/max/trim we set them slightly different than the defaults so that
    // we can distinguish between the two values.
    static const int _testMinValue;
    static const int _testMaxValue;
Don Gagne's avatar
Don Gagne committed
122
    static const int _testCenterValue;
Don Gagne's avatar
Don Gagne committed
123
    
124
	static const int _availableChannels = 18;	///< Simulate 18 channel RC Transmitter
Don Gagne's avatar
Don Gagne committed
125
    static const int _stickSettleWait;
126
	
Don Gagne's avatar
Don Gagne committed
127 128
    static const struct ChannelSettings _rgChannelSettings[_availableChannels];
    static const struct ChannelSettings _rgChannelSettingsValidate[PX4RCCalibration::_chanMax];
129
	
130
	int _rgFunctionChannelMap[PX4RCCalibration::rcCalFunctionMax];
131 132 133
};

#endif