多机管理完成

This commit is contained in:
2020-06-02 18:39:43 +08:00
parent 9c69cd6522
commit eb7e7913e1
14 changed files with 215 additions and 158 deletions
+6 -5
View File
@@ -70,12 +70,12 @@ MainWindow::MainWindow(QWidget *parent)
map->setMouseTracking(true);
//=========初始化UAV=========
map->SetShowUAV(true);//先show才能设置
map->SetUavPic("Fixwing.png");
//map->SetShowUAV(true);//先show才能设置
//map->SetUavPic("Fixwing.png");
internals::PointLatLng position;
position.SetLat(0);
position.SetLng(0);
position.SetLat(10);
position.SetLng(10);
//map->UAV->SetUAVPos(position,10);
//map->UAV->SetShowTrail(false);
@@ -186,7 +186,8 @@ MainWindow::MainWindow(QWidget *parent)
map,SLOT(addUAV(int,int)));
connect(map,SIGNAL(uav_selected(int,int)),
dlink->mavlinknode,SLOT(setCurrentSelected(int,int)),Qt::DirectConnection);
+9 -2
View File
@@ -78,6 +78,13 @@ void commandprocess::process()//线程函数
thread = nullptr;
}
void commandprocess::setID(int m_sysid,int m_compid)
{
//qDebug() << "command set id";
sysid = (uint8_t)m_sysid;
compid = (uint8_t)m_compid;
}
void commandprocess::SendMessage(mavlink_message_t msg)
{
uint8_t buff[256+20];
@@ -95,8 +102,8 @@ void commandprocess::WriteCmd(uint8_t m_sysid, uint8_t m_compid ,
int32_t y,
float z, uint16_t command, uint8_t frame, uint8_t current, uint8_t autocontinue)
{
sysid = m_sysid;
compid = m_compid;
//sysid = m_sysid;
//compid = m_compid;
//给指令赋值
cmd_int.param1 = param1;
+2
View File
@@ -57,6 +57,8 @@ public:
public slots:
void setID(int m_sysid, int m_compid);
void WriteCmd_long(float param1, float param2, float param3, float param4, float param5, float param6, float param7);
//读取和写入指令
+18 -5
View File
@@ -9,10 +9,6 @@
MavLinkNode::MavLinkNode(QObject *parent) : QObject(parent)
{
// qmlRegisterType<commandprocess>(static_cast<void>("Protocol.Command"), static_cast<void>(1), static_cast<void>(0), "Command");
//main thread
running_flag = false;
Nodethread = new QThread();
@@ -26,17 +22,25 @@ MavLinkNode::MavLinkNode(QObject *parent) : QObject(parent)
connect(Mission,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),Qt::DirectConnection);
connect(this,SIGNAL(setCurrentID(int,int)),
Mission,SLOT(setID(int,int)),Qt::DirectConnection);
Parameter = new ParameterProcess();
connect(Parameter,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),Qt::DirectConnection);
connect(this,SIGNAL(setCurrentID(int,int)),
Parameter,SLOT(setID(int,int)),Qt::DirectConnection);
Commander = new commandprocess();
connect(Commander,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),Qt::DirectConnection);
connect(this,SIGNAL(setCurrentID(int,int)),
Commander,SLOT(setID(int,int)),Qt::DirectConnection);
mavlinkinspector = new MAVLinkInspector("mavlink inspector",nullptr,nullptr);
@@ -464,5 +468,14 @@ void MavLinkNode::CheckVehicle(int sysid,int compid)
}
}
void MavLinkNode::setCurrentSelected(int sysid,int compid)
{
//qDebug() << "CurrentSelected" << sysid << compid;
Current_sysID = sysid;
Current_CompID = compid;
emit setCurrentID(sysid,compid);
}
+9
View File
@@ -86,6 +86,9 @@ signals:
void state_updated();
void parameter_updated();
//void mission_updated();
void setCurrentID(int sysid,int compid);
public slots:
//线程对外接口
void setRunFrq(uint32_t frq);
@@ -95,6 +98,9 @@ public slots:
//缓存对外接口
void setbuff(quint32 src, QByteArray data);
void setCurrentSelected(int sysid,int compid);
private slots:
//线程私有接口
@@ -119,6 +125,9 @@ private slots:
protected:
int Current_sysID;
int Current_CompID;
enum SourceType{
c_sock = 0,
s_port = 1
+15 -6
View File
@@ -74,6 +74,15 @@ void MissionProcess::process()//线程函数
Missionthread = nullptr;
}
void MissionProcess::setID(int m_sysid,int m_compid)
{
//qDebug() << "Mission set id";
sysid = (uint8_t)m_sysid;
compid = (uint8_t)m_compid;
}
void MissionProcess::SendMessage(mavlink_message_t msg)
{
uint8_t buff[256+20];
@@ -84,22 +93,22 @@ void MissionProcess::SendMessage(mavlink_message_t msg)
void MissionProcess::ReadCmd(uint8_t m_sysid, uint8_t m_compid)
{
sysid = m_sysid;
compid = m_compid;
//sysid = m_sysid;
//compid = m_compid;
mission_status.m_Mode = RecieveMode;//接收模式
qDebug() << "recieve read cmd";
qDebug() << "read mission" << sysid << compid;
start();//开启线程
}
void MissionProcess::WriteCmd(uint8_t m_sysid, uint8_t m_compid ,uint32_t count )
{
sysid = m_sysid;
compid = m_compid;
//sysid = m_sysid;
//compid = m_compid;
mission_status.transmit.count = count;
mission_status.m_Mode = TransmitMode;//发送模式
qDebug() << "write mission" << sysid << compid;
start();//开启线程
}
+3
View File
@@ -57,6 +57,9 @@ public:
public slots:
void setID(int m_sysid, int m_compid);
//线程对外接口
void setRunFrq(uint32_t frq);
void start();
+6
View File
@@ -99,6 +99,12 @@ void ParameterProcess::process()//线程函数
thread = nullptr;
}
void ParameterProcess::setID(int m_sysid,int m_compid)
{
//qDebug() << "Parameter set id";
sysid = (uint8_t)m_sysid;
compid = (uint8_t)m_compid;
}
void ParameterProcess::SendMessage(mavlink_message_t msg)
{
+3
View File
@@ -69,6 +69,9 @@ public:
public slots:
void setID(int m_sysid, int m_compid);
//读取和写入指令
void ReadCmd(uint8_t m_sysid, uint8_t m_compid, uint8_t type);
void WriteCmd(uint8_t m_sysid, uint8_t m_compid ,uint32_t count);
+25 -3
View File
@@ -135,6 +135,10 @@ void OPMapWidget::SetShowUAV(const bool &value)
UAV->setParentItem(map);
connect(this, SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)), UAV, SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)));
connect(this, SIGNAL(UAVReachedWayPoint(int, WayPointItem *)), UAV, SIGNAL(UAVReachedWayPoint(int, WayPointItem *)));
connect(UAV,SIGNAL(selected(int,int)),
this,SIGNAL(uav_selected(int,int)));
UAV->setOpacity(overlayOpacity);
} else if (!value) {
if (UAV != 0) {
@@ -149,11 +153,21 @@ void OPMapWidget::addUAV(int sysid,int compid)
{
UAVItem *uavItem = new UAVItem(map, this);
uavItem->setParentItem(map);
connect(this, SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)), uavItem, SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)));
connect(this, SIGNAL(UAVReachedWayPoint(int, WayPointItem *)), uavItem, SIGNAL(UAVReachedWayPoint(int, WayPointItem *)));
uavItem->SetUavPic("Fixwing.png");
uavItem->setID(sysid,compid);
connect(this, SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)),
uavItem, SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)));
connect(this, SIGNAL(UAVReachedWayPoint(int, WayPointItem *)),
uavItem, SIGNAL(UAVReachedWayPoint(int, WayPointItem *)));
connect(uavItem,SIGNAL(selected(int,int)),
this,SIGNAL(uav_selected(int,int)));
uavItem->setOpacity(overlayOpacity);
uavItem->setID(sysid,compid);
uavItem->setSelect(true);
}
@@ -888,6 +902,14 @@ void OPMapWidget::setWPLock(bool const & lock)
w->WPSetEdit(isEdit);
}
}
foreach(QGraphicsItem * i, map->childItems()) {
UAVItem *uav = qgraphicsitem_cast<UAVItem *>(i);
if (uav) {
uav->setEdit(isEdit);
}
}
}
void OPMapWidget::WPsearchall(void)
+3
View File
@@ -552,6 +552,9 @@ signals:
uint8_t mission_type);
void uav_selected(int sys,int comp);
public slots:
void addUAV(int sysid, int compid);
+54 -8
View File
@@ -79,11 +79,25 @@ void UAVItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q
Q_UNUSED(option);
Q_UNUSED(widget);
qDebug() << "selected" << sysid << compid << this->isSelected();
if(isEdit)
{
this->setZValue(1);
}
else
{
if (isSelected)
{
this->setZValue(5);
}
else
{
this->setZValue(4);
}
}
if (this->isSelected()) {
qDebug() << "selected" << sysid << compid;
painter->setPen(Qt::red);
if (isSelected) {
//qDebug() << "selected" << sysid << compid;
painter->setPen(QColor(255*(1-sysid/255.0f),255*(1-sysid/255.0f),255*(1-sysid/255.0f)));
painter->drawRect(QRectF(boundingRect()));
}
@@ -170,12 +184,20 @@ void UAVItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
void UAVItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
qDebug() << "UAV mouseReleaseEvent";
//this->setSelected(true);
isSelected = true;
//查找所有
foreach(QGraphicsItem * i, map->childItems()) {
UAVItem *uav = qgraphicsitem_cast<UAVItem *>(i);
if (uav) {
if(uav != this)
{
uav->setSelect(false);
}
}
}
qDebug() << "emit select" << sysid << compid;
emit selected(sysid,compid);
update();
}
@@ -196,6 +218,28 @@ void UAVItem::setID(int sys,int comp)
compid = comp;
}
void UAVItem::setSelect(bool select)
{
isSelected = select;
qDebug() << "emit select" << sysid << compid;
emit selected(sysid,compid);
update();
}
void UAVItem::setEdit(bool value)
{
isEdit = value;
if(isEdit)
{
this->setZValue(1);
}
else
{
this->setZValue(4);
}
}
void UAVItem::updateTextOverlay()
{
@@ -351,6 +395,7 @@ void UAVItem::SetUAVPos(const internals::PointLatLng &position, const int &altit
if (mapfollowtype == UAVMapFollowType::CenterAndRotateMap || mapfollowtype == UAVMapFollowType::CenterMap) {
mapwidget->SetCurrentPosition(coord);
}
if (autosetreached) {
foreach(QGraphicsItem * i, map->childItems()) {
WayPointItem *wp = qgraphicsitem_cast<WayPointItem *>(i);
@@ -363,6 +408,7 @@ void UAVItem::SetUAVPos(const internals::PointLatLng &position, const int &altit
}
}
}
if (mapwidget->Home != 0) {
// verify if the UAV is inside the safety bouble
if (Distance3D(mapwidget->Home->Coord(), mapwidget->Home->Altitude()) > mapwidget->Home->SafeArea()) {
+53 -129
View File
@@ -64,81 +64,28 @@ public:
UAVItem(MapGraphicItem *map, OPMapWidget *parent, QString uavPic = QString::fromUtf8(":/uavs/images/mapquad.png"), uint8_t sysid = 0, uint8_t compid = 0);
~UAVItem();
/**
* @brief Sets the UAV NED position
*
* @param NED
*/
void SetNED(double NED[3]);
/**
* @brief Sets the UAV groundspeed
*
* @param NED
*/
void SetGroundspeed(double vNED[3], int m_maxUpdateRate);
/**
* @brief Sets the UAV Calibrated Airspeed
*
* @param NED
*/
void SetCAS(double CAS);
/**
* @brief Sets the UAV yaw rate
*
* @param NED
*/
void SetYawRate(double yawRate_dps);
/**
* @brief Sets the UAV position
*
* @param position LatLng point
* @param altitude altitude in meters
*/
void SetUAVPos(internals::PointLatLng const & position, int const & altitude);
/**
* @brief Sets the UAV heading
*
* @param value heading angle (north=0deg)
*/
void SetUAVHeading(qreal const & value);
/**
* @brief Returns the UAV position
*
* @return internals::PointLatLng
*/
internals::PointLatLng UAVPos() const
{
return coord;
}
/**
* @brief Sets the Map follow type
*
* @param value can be "none"(map doesnt follow UAV), "CenterMap"(map moves to keep UAV centered) or "CenterAndRotateMap"(map moves and rotates to keep UAV centered and straight)
*/
void SetMapFollowType(UAVMapFollowType::Types const & value)
{
mapfollowtype = value;
}
/**
* @brief Sets the trail type
*
* @param value can be "NoTrail"(no trail is plotted), "ByTimeElapsed"(a trail point is plotted each TrailTime()) or ByDistance(a trail point is plotted if the distance between the UAV and the last trail point is bigger than TrailDistance())
*/
void SetTrailType(UAVTrailType::Types const & value);
/**
* @brief Returns the map follow method used
*
* @return UAVMapFollowType::Types
*/
UAVMapFollowType::Types GetMapFollowType() const
{
return mapfollowtype;
}
/**
* @brief Returns the UAV trail type. It can be plotted by time elapsed or distance
*
* @return UAVTrailType::Types
*/
UAVTrailType::Types GetTrailType() const
{
return trailtype;
@@ -147,116 +94,58 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
QRectF boundingRect() const;
/**
* @brief Sets the trail time to be used if TrailType is ByTimeElapsed
*
* @param seconds the UAV trail time elapsed value. If the trail type is time elapsed
* a trail point will be plotted each "value returned" seconds.
*/
void SetTrailTime(int const & seconds)
{
trailtime = seconds;
}
/**
* @brief Returns the UAV trail time elapsed value. If the trail type is time elapsed
* a trail point will be plotted each "value returned" seconds.
*
* @return int
*/
int TrailTime() const
{
return trailtime;
}
/**
* @brief Sets the trail distance to be used if TrailType is ByDistance
*
* @param distance the UAV trail plot distance.
* If the trail type is ByDistance a trail dot is plotted if
* the distance between the current UAV position and the last trail point
* is bigger than the returned value
*/
void SetTrailDistance(int const & distance)
{
traildistance = distance;
}
/**
* @brief Returns the UAV trail plot distance.
* If the trail type is distance diference a trail dot is plotted if
* the distance between the current UAV position and the last trail point
* is bigger than the returned value
*
* @return int
*/
int TrailDistance() const
{
return traildistance;
}
/**
* @brief Returns true if UAV trail is shown
*
* @return bool
*/
bool ShowTrail() const
{
return showtrail;
}
/**
* @brief Returns true if UAV trail line is shown
*
* @return bool
*/
bool ShowTrailLine() const
{
return showtrailline;
}
/**
* @brief Used to define if the UAV displays a trail
*
* @param value
*/
void SetShowTrail(bool const & value);
/**
* @brief Used to define if the UAV displays a trail line
*
* @param value
*/
void SetShowTrailLine(bool const & value);
/**
* @brief Deletes all the trail points
*/
void DeleteTrail() const;
/**
* @brief Returns true if the UAV automaticaly sets WP reached value (changing its color)
*
* @return bool
*/
bool AutoSetReached() const
{
return autosetreached;
}
/**
* @brief Defines if the UAV can set the WP's "reached" value automaticaly.
*
* @param value
*/
void SetAutoSetReached(bool const & value)
{
autosetreached = value;
}
/**
* @brief Returns the 3D distance in meters necessary for the UAV to set WP's to "reached"
*
* @return double
*/
double AutoSetDistance() const
{
return autosetdistance;
}
/**
* @brief Sets the the 3D distance in meters necessary for the UAV to set WP's to "reached"
*
* @param value
*/
void SetAutoSetDistance(double const & value)
{
autosetdistance = value;
@@ -267,6 +156,37 @@ public:
void SetUavPic(QString UAVPic);
void SetShowUAVInfo(bool const & value);
void updateTextOverlay();
int SysID()
{
return sysid;
}
void setSysID(int id)
{
sysid = id;
}
int CompID()
{
return compid;
}
void setCompID(int id)
{
compid = id;
}
bool Select(void)
{
return isSelected;
}
void setSelect(bool select);
private:
void generateArrowhead();
MapGraphicItem *map;
@@ -311,10 +231,13 @@ private:
QPainterPath textPath;
//bool isSelected = false;
bool isSelected = false;
uint8_t sysid;
uint8_t compid;
bool isEdit = false;
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
@@ -323,6 +246,7 @@ protected:
public slots:
void setEdit(bool value);
void setID(int sys,int comp);
@@ -331,7 +255,7 @@ public slots:
void zoomChangedSlot();
signals:
void selected(uint8_t sys,uint8_t comp);
void selected(int sys,int comp);
void UAVReachedWayPoint(int const & waypointnumber, WayPointItem *waypoint);
void UAVLeftSafetyBouble(internals::PointLatLng const & position);
+9
View File
@@ -211,6 +211,15 @@ void WayPointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
Q_UNUSED(option);
Q_UNUSED(widget);
if (this->isSelected()) {
this->setZValue(4);
}
else
{
this->setZValue(3);
}
if(isSimple == true)//简单显示
{