添加航点的线程
This commit is contained in:
@@ -58,11 +58,14 @@ INCLUDEPATH += $$PWD/../mavlink \
|
||||
|
||||
|
||||
HEADERS += \
|
||||
mavlinknode.h \ \
|
||||
mavlinknodeglobal.h
|
||||
mavlinknode.h \
|
||||
mavlinknodeglobal.h \
|
||||
missionprocess.h
|
||||
|
||||
SOURCES += \
|
||||
mavlinknode.cpp
|
||||
mavlinknode.cpp \
|
||||
missionprocess.cpp
|
||||
|
||||
|
||||
|
||||
win32|win64 {
|
||||
|
||||
@@ -2,16 +2,24 @@
|
||||
|
||||
MavLinkNode::MavLinkNode(QObject *parent) : QObject(parent)
|
||||
{
|
||||
//main thread
|
||||
running_flag = false;
|
||||
Nodethread = new QThread();
|
||||
|
||||
this->moveToThread(Nodethread);
|
||||
connect(Nodethread, &QThread::started, this, &MavLinkNode::process);
|
||||
|
||||
setRunFrq(50);//50
|
||||
|
||||
//初始化buff
|
||||
initbuff();
|
||||
|
||||
Mission = new MissionProcess();
|
||||
Mission->setRunFrq(200);
|
||||
Mission->start();
|
||||
|
||||
|
||||
|
||||
Parameterthread = new QThread();
|
||||
|
||||
|
||||
}
|
||||
|
||||
MavLinkNode::~MavLinkNode()
|
||||
@@ -432,3 +440,9 @@ void MavLinkNode::MissionParse(mavlink_message_t msg)
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "QDebug"
|
||||
|
||||
#include "mavlink.h"
|
||||
#include "missionprocess.h"
|
||||
|
||||
|
||||
#ifdef QtMavlinkNode
|
||||
#include <mavlinknodeglobal.h>
|
||||
@@ -126,6 +128,10 @@ protected:
|
||||
quint32 running_frq = 200;//200Hz
|
||||
|
||||
QThread *Nodethread;
|
||||
MissionProcess *Mission = nullptr;
|
||||
|
||||
QThread *Parameterthread;
|
||||
|
||||
|
||||
_buffdef serial_buff;
|
||||
_buffdef client_buff;
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
#include "missionprocess.h"
|
||||
|
||||
MissionProcess::MissionProcess(QObject *parent) : QObject(parent)
|
||||
{
|
||||
//mission thread
|
||||
/*
|
||||
Missionthread = new QThread();
|
||||
this->moveToThread(Missionthread);
|
||||
connect(Missionthread, &QThread::started, this, &MavLinkNode::process);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void MissionProcess::setRunFrq(uint32_t frq)
|
||||
{
|
||||
if((frq != 0)||(frq <= 1000))
|
||||
{
|
||||
running_frq = frq;
|
||||
qDebug() << "set mission thread running frquency:" <<frq <<"Hz";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MissionProcess::start()
|
||||
{
|
||||
if(Missionthread == nullptr)
|
||||
{
|
||||
Missionthread = new QThread();
|
||||
this->moveToThread(Missionthread);
|
||||
connect(Missionthread, &QThread::started, this, &MissionProcess::process);
|
||||
}
|
||||
|
||||
if(!Missionthread->isRunning())
|
||||
{
|
||||
running_flag = true;
|
||||
Missionthread->start();
|
||||
qDebug() << "thread start" << running_flag;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "thread has started";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MissionProcess::stop()
|
||||
{
|
||||
if(Missionthread->isRunning())
|
||||
{
|
||||
running_flag = false;
|
||||
qDebug() << "thread stop" << running_flag;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "thread is not running";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//这里一直传输和接收航线信息
|
||||
void MissionProcess::process()//线程函数
|
||||
{
|
||||
uint8_t count = 0;
|
||||
while (running_flag)
|
||||
{
|
||||
count ++;
|
||||
QThread::msleep(1000/running_frq);
|
||||
|
||||
|
||||
}
|
||||
//退出线程
|
||||
Missionthread->quit();
|
||||
Missionthread->deleteLater();
|
||||
Missionthread = nullptr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef MISSIONPROCESS_H
|
||||
#define MISSIONPROCESS_H
|
||||
|
||||
#include <QObject>
|
||||
//#include "mavlinknode.h"
|
||||
|
||||
#include "QDebug"
|
||||
#include "QThread"
|
||||
|
||||
|
||||
#ifdef QtMavlinkNode
|
||||
#include <mavlinknodeglobal.h>
|
||||
class MAVLINKNODESHARED_EXPORT MissionProcess : public QObject {
|
||||
#else
|
||||
class MissionProcess : public QObject
|
||||
{
|
||||
#endif
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MissionProcess(QObject *parent = nullptr);
|
||||
|
||||
|
||||
public slots:
|
||||
//线程对外接口
|
||||
void setRunFrq(uint32_t frq);
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
private slots:
|
||||
//线程私有接口
|
||||
void process();
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
private:
|
||||
|
||||
bool running_flag = false;
|
||||
quint32 running_frq = 200;//200Hz
|
||||
QThread *Missionthread = nullptr;
|
||||
|
||||
};
|
||||
|
||||
#endif // MISSIONPROCESS_H
|
||||
Reference in New Issue
Block a user