From 15812f3a3f6932ae18f4f03f1496ad8e64627ca4 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Wed, 7 May 2014 08:50:09 +0200 Subject: [PATCH] Move UAS objects to their own worker threads --- src/uas/QGCMAVLinkUASFactory.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/uas/QGCMAVLinkUASFactory.cc b/src/uas/QGCMAVLinkUASFactory.cc index 6b1b9967e..b6fac1408 100644 --- a/src/uas/QGCMAVLinkUASFactory.cc +++ b/src/uas/QGCMAVLinkUASFactory.cc @@ -21,6 +21,8 @@ UASInterface* QGCMAVLinkUASFactory::createUAS(MAVLinkProtocol* mavlink, LinkInte UASInterface* uas; + QThread* worker = new QThread(); + switch (heartbeat->autopilot) { case MAV_AUTOPILOT_GENERIC: @@ -28,6 +30,9 @@ UASInterface* QGCMAVLinkUASFactory::createUAS(MAVLinkProtocol* mavlink, LinkInte UAS* mav = new UAS(mavlink, sysid); // Set the system type mav->setSystemType((int)heartbeat->type); + + mav->moveToThread(worker); + // Connect this robot to the UAS object connect(mavlink, SIGNAL(messageReceived(LinkInterface*, mavlink_message_t)), mav, SLOT(receiveMessage(LinkInterface*, mavlink_message_t))); #ifdef QGC_PROTOBUF_ENABLED @@ -41,6 +46,9 @@ UASInterface* QGCMAVLinkUASFactory::createUAS(MAVLinkProtocol* mavlink, LinkInte PxQuadMAV* mav = new PxQuadMAV(mavlink, sysid); // Set the system type mav->setSystemType((int)heartbeat->type); + + mav->moveToThread(worker); + // 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 @@ -57,6 +65,9 @@ UASInterface* QGCMAVLinkUASFactory::createUAS(MAVLinkProtocol* mavlink, LinkInte SlugsMAV* mav = new SlugsMAV(mavlink, sysid); // Set the system type mav->setSystemType((int)heartbeat->type); + + mav->moveToThread(worker); + // 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 @@ -70,6 +81,9 @@ UASInterface* QGCMAVLinkUASFactory::createUAS(MAVLinkProtocol* mavlink, LinkInte ArduPilotMegaMAV* mav = new ArduPilotMegaMAV(mavlink, sysid); // Set the system type mav->setSystemType((int)heartbeat->type); + + mav->moveToThread(worker); + // 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 @@ -83,6 +97,9 @@ UASInterface* QGCMAVLinkUASFactory::createUAS(MAVLinkProtocol* mavlink, LinkInte { senseSoarMAV* mav = new senseSoarMAV(mavlink,sysid); mav->setSystemType((int)heartbeat->type); + + mav->moveToThread(worker); + connect(mavlink, SIGNAL(messageReceived(LinkInterface*, mavlink_message_t)), mav, SLOT(receiveMessage(LinkInterface*, mavlink_message_t))); uas = mav; break; @@ -92,6 +109,9 @@ UASInterface* QGCMAVLinkUASFactory::createUAS(MAVLinkProtocol* mavlink, LinkInte { UAS* mav = new UAS(mavlink, sysid); mav->setSystemType((int)heartbeat->type); + + mav->moveToThread(worker); + // 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 @@ -111,5 +131,7 @@ UASInterface* QGCMAVLinkUASFactory::createUAS(MAVLinkProtocol* mavlink, LinkInte // Now add UAS to "official" list, which makes the whole application aware of it UASManager::instance()->addUAS(uas); + worker->start(QThread::HighPriority); + return uas; } -- 2.22.0