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

10 11 12 13

#include "MissionControllerTest.h"
#include "LinkManager.h"
#include "MultiVehicleManager.h"
14
#include "SimpleMissionItem.h"
Don Gagne's avatar
Don Gagne committed
15
#include "MissionSettingsItem.h"
16 17 18
#include "QGCApplication.h"
#include "SettingsManager.h"
#include "AppSettings.h"
19 20

MissionControllerTest::MissionControllerTest(void)
21 22 23
    : _multiSpyMissionController(nullptr)
    , _multiSpyMissionItem(nullptr)
    , _missionController(nullptr)
24 25 26 27 28 29
{
    
}

void MissionControllerTest::cleanup(void)
{
30
    delete _masterController;
31
    _masterController = nullptr;
32

Don Gagne's avatar
Don Gagne committed
33
    delete _multiSpyMissionController;
34
    _multiSpyMissionController = nullptr;
Don Gagne's avatar
Don Gagne committed
35 36

    delete _multiSpyMissionItem;
37
    _multiSpyMissionItem = nullptr;
Don Gagne's avatar
Don Gagne committed
38

39 40 41 42 43 44 45
    MissionControllerManagerTest::cleanup();
}

void MissionControllerTest::_initForFirmwareType(MAV_AUTOPILOT firmwareType)
{
    MissionControllerManagerTest::_initForFirmwareType(firmwareType);

Don Gagne's avatar
Don Gagne committed
46 47
    // VisualMissionItem signals
    _rgVisualItemSignals[coordinateChangedSignalIndex] = SIGNAL(coordinateChanged(const QGeoCoordinate&));
Don Gagne's avatar
Don Gagne committed
48 49

    // MissionController signals
50
    _rgMissionControllerSignals[visualItemsChangedSignalIndex] =    SIGNAL(visualItemsChanged());
51

52 53 54 55
    // Master controller pulls offline vehicle info from settings
    qgcApp()->toolbox()->settingsManager()->appSettings()->offlineEditingFirmwareType()->setRawValue(firmwareType);
    _masterController = new PlanMasterController(this);
    _missionController = _masterController->missionController();
56

Don Gagne's avatar
Don Gagne committed
57 58 59
    _multiSpyMissionController = new MultiSignalSpy();
    Q_CHECK_PTR(_multiSpyMissionController);
    QCOMPARE(_multiSpyMissionController->init(_missionController, _rgMissionControllerSignals, _cMissionControllerSignals), true);
60

61
    _masterController->start(false /* flyView */);
62 63

    // All signals should some through on start
Don Gagne's avatar
Don Gagne committed
64
    QCOMPARE(_multiSpyMissionController->checkOnlySignalsByMask(visualItemsChangedSignalMask), true);
Don Gagne's avatar
Don Gagne committed
65
    _multiSpyMissionController->clearAllSignals();
66

67 68
    QmlObjectListModel* visualItems = _missionController->visualItems();
    QVERIFY(visualItems);
69 70

    // Empty vehicle only has home position
71
    QCOMPARE(visualItems->count(), 1);
72

Don Gagne's avatar
Don Gagne committed
73 74 75 76 77 78
    // Mission Settings should be in first slot
    MissionSettingsItem* settingsItem = visualItems->value<MissionSettingsItem*>(0);
    QVERIFY(settingsItem);

    // Offline vehicle, so no home position
    QCOMPARE(settingsItem->coordinate().isValid(), false);
79

Don Gagne's avatar
Don Gagne committed
80 81
    // Empty mission, so no child items possible
    QCOMPARE(settingsItem->childItems()->count(), 0);
82 83 84 85 86 87 88 89 90 91 92 93 94 95

    // No waypoint lines
    QmlObjectListModel* waypointLines = _missionController->waypointLines();
    QVERIFY(waypointLines);
    QCOMPARE(waypointLines->count(), 0);
}

void MissionControllerTest::_testEmptyVehicleWorker(MAV_AUTOPILOT firmwareType)
{
    _initForFirmwareType(firmwareType);

    // FYI: A significant amount of empty vehicle testing is in _initForFirmwareType since that
    // sets up an empty vehicle

96 97
    QmlObjectListModel* visualItems = _missionController->visualItems();
    QVERIFY(visualItems);
Don Gagne's avatar
Don Gagne committed
98 99
    VisualMissionItem* visualItem = visualItems->value<VisualMissionItem*>(0);
    QVERIFY(visualItem);
100

Don Gagne's avatar
Don Gagne committed
101
    _setupVisualItemSignals(visualItem);
102 103 104 105 106 107 108 109 110 111 112 113
}

void MissionControllerTest::_testEmptyVehiclePX4(void)
{
    _testEmptyVehicleWorker(MAV_AUTOPILOT_PX4);
}

void MissionControllerTest::_testEmptyVehicleAPM(void)
{
    _testEmptyVehicleWorker(MAV_AUTOPILOT_ARDUPILOTMEGA);
}

114
#if 0
Don Gagne's avatar
Don Gagne committed
115 116 117 118 119
void MissionControllerTest::_testOfflineToOnlineWorker(MAV_AUTOPILOT firmwareType)
{
    // Start offline and add item
    _missionController = new MissionController();
    Q_CHECK_PTR(_missionController);
120
    _missionController->start(false /* flyView */);
121
    _missionController->insertSimpleMissionItem(QGeoCoordinate(37.803784, -122.462276), _missionController->visualItems()->count());
Don Gagne's avatar
Don Gagne committed
122 123 124 125

    // Go online to empty vehicle
    MissionControllerManagerTest::_initForFirmwareType(firmwareType);

Don Gagne's avatar
Don Gagne committed
126 127 128 129 130
#if 1
    // Due to current limitations, offline items will go away
    QCOMPARE(_missionController->visualItems()->count(), 1);
#else
    //Make sure our offline mission items are still there
131
    QCOMPARE(_missionController->visualItems()->count(), 2);
Don Gagne's avatar
Don Gagne committed
132
#endif
Don Gagne's avatar
Don Gagne committed
133 134 135 136 137 138 139 140 141 142 143
}

void MissionControllerTest::_testOfflineToOnlineAPM(void)
{
    _testOfflineToOnlineWorker(MAV_AUTOPILOT_ARDUPILOTMEGA);
}

void MissionControllerTest::_testOfflineToOnlinePX4(void)
{
    _testOfflineToOnlineWorker(MAV_AUTOPILOT_PX4);
}
144
#endif
Don Gagne's avatar
Don Gagne committed
145

Don Gagne's avatar
Don Gagne committed
146
void MissionControllerTest::_setupVisualItemSignals(VisualMissionItem* visualItem)
Don Gagne's avatar
Don Gagne committed
147 148 149 150 151
{
    delete _multiSpyMissionItem;

    _multiSpyMissionItem = new MultiSignalSpy();
    Q_CHECK_PTR(_multiSpyMissionItem);
Don Gagne's avatar
Don Gagne committed
152
    QCOMPARE(_multiSpyMissionItem->init(visualItem, _rgVisualItemSignals, _cVisualItemSignals), true);
Don Gagne's avatar
Don Gagne committed
153
}
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177

void MissionControllerTest::_testGimbalRecalc(void)
{
    _initForFirmwareType(MAV_AUTOPILOT_PX4);
    _missionController->insertSimpleMissionItem(QGeoCoordinate(0, 0), 1);
    _missionController->insertSimpleMissionItem(QGeoCoordinate(0, 0), 2);
    _missionController->insertSimpleMissionItem(QGeoCoordinate(0, 0), 3);
    _missionController->insertSimpleMissionItem(QGeoCoordinate(0, 0), 4);

    // No specific gimbal yaw set yet
    for (int i=1; i<_missionController->visualItems()->count(); i++) {
        VisualMissionItem* visualItem = _missionController->visualItems()->value<VisualMissionItem*>(i);
        QVERIFY(qIsNaN(visualItem->missionGimbalYaw()));
    }

    // Specify gimbal yaw on settings item should generate yaw on all items
    MissionSettingsItem* settingsItem = _missionController->visualItems()->value<MissionSettingsItem*>(0);
    settingsItem->cameraSection()->setSpecifyGimbal(true);
    settingsItem->cameraSection()->gimbalYaw()->setRawValue(0.0);
    for (int i=1; i<_missionController->visualItems()->count(); i++) {
        VisualMissionItem* visualItem = _missionController->visualItems()->value<VisualMissionItem*>(i);
        QCOMPARE(visualItem->missionGimbalYaw(), 0.0);
    }
}
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201

void MissionControllerTest::_testLoadJsonSectionAvailable(void)
{
    _initForFirmwareType(MAV_AUTOPILOT_PX4);
    _masterController->loadFromFile(":/unittest/SectionTest.plan");

    QmlObjectListModel* visualItems = _missionController->visualItems();
    QVERIFY(visualItems);
    QCOMPARE(visualItems->count(), 5);

    // Check that only waypoint items have camera and speed sections
    for (int i=1; i<visualItems->count(); i++) {
        SimpleMissionItem* item = visualItems->value<SimpleMissionItem*>(i);
        QVERIFY(item);
        if ((int)item->command() == MAV_CMD_NAV_WAYPOINT) {
            QCOMPARE(item->cameraSection()->available(), true);
            QCOMPARE(item->speedSection()->available(), true);
        } else {
            QCOMPARE(item->cameraSection()->available(), false);
            QCOMPARE(item->speedSection()->available(), false);
        }

    }
}