QGCMAVLinkUASFactory.cc 5.37 KB
Newer Older
1 2
#include "QGCMAVLinkUASFactory.h"
#include "UASManager.h"
3
#include "QGCUASWorker.h"
4
#include "QGXPX4UAS.h"
5 6 7 8 9 10 11 12 13 14

QGCMAVLinkUASFactory::QGCMAVLinkUASFactory(QObject *parent) :
    QObject(parent)
{
}

UASInterface* QGCMAVLinkUASFactory::createUAS(MAVLinkProtocol* mavlink, LinkInterface* link, int sysid, mavlink_heartbeat_t* heartbeat, QObject* parent)
{
    QPointer<QObject> p;

lm's avatar
lm committed
15 16
    if (parent != NULL)
    {
17
        p = parent;
lm's avatar
lm committed
18 19 20
    }
    else
    {
21 22 23 24 25
        p = mavlink;
    }

    UASInterface* uas;

26
    QGCUASWorker* worker = new QGCUASWorker();
27

lm's avatar
lm committed
28 29
    switch (heartbeat->autopilot)
    {
30
    case MAV_AUTOPILOT_GENERIC:
lm's avatar
lm committed
31
    {
32
        UAS* mav = new UAS(mavlink, worker, sysid);
33 34
        // Set the system type
        mav->setSystemType((int)heartbeat->type);
35

36 37
        // Connect this robot to the UAS object
        connect(mavlink, SIGNAL(messageReceived(LinkInterface*, mavlink_message_t)), mav, SLOT(receiveMessage(LinkInterface*, mavlink_message_t)));
Lorenz Meier's avatar
Lorenz Meier committed
38
        connect(mavlink, SIGNAL(messageReceived(LinkInterface*,mavlink_message_t)), mav->getFileManager(), SLOT(receiveMessage(LinkInterface*, mavlink_message_t)));
39 40 41
#ifdef QGC_PROTOBUF_ENABLED
        connect(mavlink, SIGNAL(extendedMessageReceived(LinkInterface*, std::tr1::shared_ptr<google::protobuf::Message>)), mav, SLOT(receiveExtendedMessage(LinkInterface*, std::tr1::shared_ptr<google::protobuf::Message>)));
#endif
42
        uas = mav;
43 44
    }
    break;
45
    case MAV_AUTOPILOT_PIXHAWK:
lm's avatar
lm committed
46
    {
47
        PxQuadMAV* mav = new PxQuadMAV(mavlink, worker, sysid);
48 49
        // Set the system type
        mav->setSystemType((int)heartbeat->type);
50

51 52 53 54 55
        // Connect this robot to the UAS object
        // it is IMPORTANT here to use the right object type,
        // else the slot of the parent object is called (and thus the special
        // packets never reach their goal)
        connect(mavlink, SIGNAL(messageReceived(LinkInterface*, mavlink_message_t)), mav, SLOT(receiveMessage(LinkInterface*, mavlink_message_t)));
56 57 58
#ifdef QGC_PROTOBUF_ENABLED
        connect(mavlink, SIGNAL(extendedMessageReceived(LinkInterface*, std::tr1::shared_ptr<google::protobuf::Message>)), mav, SLOT(receiveExtendedMessage(LinkInterface*, std::tr1::shared_ptr<google::protobuf::Message>)));
#endif
59 60 61
        uas = mav;
    }
    break;
62 63 64 65 66 67 68 69 70 71 72 73 74 75
    case MAV_AUTOPILOT_PX4:
    {
        QGXPX4UAS* px4 = new QGXPX4UAS(mavlink, worker, sysid);
        // Set the system type
        px4->setSystemType((int)heartbeat->type);

        // Connect this robot to the UAS object
        // it is IMPORTANT here to use the right object type,
        // else the slot of the parent object is called (and thus the special
        // packets never reach their goal)
        connect(mavlink, SIGNAL(messageReceived(LinkInterface*, mavlink_message_t)), px4, SLOT(receiveMessage(LinkInterface*, mavlink_message_t)));
        uas = px4;
    }
    break;
76
    case MAV_AUTOPILOT_SLUGS:
lm's avatar
lm committed
77
    {
78
        SlugsMAV* mav = new SlugsMAV(mavlink, worker, sysid);
79 80
        // Set the system type
        mav->setSystemType((int)heartbeat->type);
81

82 83 84 85 86 87 88 89
        // Connect this robot to the UAS object
        // it is IMPORTANT here to use the right object type,
        // else the slot of the parent object is called (and thus the special
        // packets never reach their goal)
        connect(mavlink, SIGNAL(messageReceived(LinkInterface*, mavlink_message_t)), mav, SLOT(receiveMessage(LinkInterface*, mavlink_message_t)));
        uas = mav;
    }
    break;
90
    case MAV_AUTOPILOT_ARDUPILOTMEGA:
lm's avatar
lm committed
91
    {
92
        ArduPilotMegaMAV* mav = new ArduPilotMegaMAV(mavlink, worker, sysid);
93 94
        // Set the system type
        mav->setSystemType((int)heartbeat->type);
95

96 97 98 99 100 101 102 103
        // Connect this robot to the UAS object
        // it is IMPORTANT here to use the right object type,
        // else the slot of the parent object is called (and thus the special
        // packets never reach their goal)
        connect(mavlink, SIGNAL(messageReceived(LinkInterface*, mavlink_message_t)), mav, SLOT(receiveMessage(LinkInterface*, mavlink_message_t)));
        uas = mav;
    }
    break;
oberion's avatar
oberion committed
104
#ifdef QGC_USE_SENSESOAR_MESSAGES
oberion's avatar
oberion committed
105 106
	case MAV_AUTOPILOT_SENSESOAR:
		{
107
            senseSoarMAV* mav = new senseSoarMAV(mavlink,worker, sysid);
oberion's avatar
oberion committed
108
			mav->setSystemType((int)heartbeat->type);
109 110 111

            mav->moveToThread(worker);

oberion's avatar
oberion committed
112 113 114 115
			connect(mavlink, SIGNAL(messageReceived(LinkInterface*, mavlink_message_t)), mav, SLOT(receiveMessage(LinkInterface*, mavlink_message_t)));
			uas = mav;
			break;
		}
oberion's avatar
oberion committed
116
#endif
lm's avatar
lm committed
117 118
    default:
    {
119
        UAS* mav = new UAS(mavlink, worker, sysid);
120
        mav->setSystemType((int)heartbeat->type);
121

122 123 124 125 126 127 128 129
        // Connect this robot to the UAS object
        // it is IMPORTANT here to use the right object type,
        // else the slot of the parent object is called (and thus the special
        // packets never reach their goal)
        connect(mavlink, SIGNAL(messageReceived(LinkInterface*, mavlink_message_t)), mav, SLOT(receiveMessage(LinkInterface*, mavlink_message_t)));
        uas = mav;
    }
    break;
130 131
    }

132 133 134 135
    // Get the UAS ready
    worker->start(QThread::HighPriority);
    connect(uas, SIGNAL(destroyed()), worker, SLOT(quit()));

136 137 138 139 140 141 142 143 144 145 146
    // Set the autopilot type
    uas->setAutopilotType((int)heartbeat->autopilot);

    // Make UAS aware that this link can be used to communicate with the actual robot
    uas->addLink(link);

    // Now add UAS to "official" list, which makes the whole application aware of it
    UASManager::instance()->addUAS(uas);

    return uas;
}