闫刚 qgroundcontrol地面站通信流代码架构

2023-05-16

qgroundcontrol开发者文档中说明了qgc中的各个链路流向在文档中说明的很清楚,下面配套源代码进行讲解整个qgc地面站的数据流向过程.

qgroundcontrol通信

在 https://dev.qgroundcontrol.com/en/communication_flow.html 中描述如下

Description of the high level communication flow which takes place during a vehicle auto-connect.

    LinkManager always has a UDP link open waiting for a Vehicle heartbeat
    LinkManager detects a new known device (Pixhawk, SiK Radio, PX4 Flow) connected to computer
        Creates a new SerialLink connected to the device
    Bytes comes through Link and are sent to MAVLinkProtocol
    MAVLinkProtocol converts the bytes into a MAVLink message
    If the message is a HEARTBEAT the MultiVehicleManager is notified
    MultiVehicleManager is notifed of the HEARTBEAT and creates a new Vehicle object based on the information in the HEARTBEAT message
    The Vehicle instantiates the plugins which match the vehicle type
    The ParameterLoader associated with the vehicle sends a PARAM_REQUEST_LIST to the vehicle to load params using the parameter protocol
    Once parameter load is complete, the MissionManager associated with the Vehicle requests the mission items from the Vehicle using the mission item protocol
    Once parameter load is complete, the VehicleComponents display their UI in the Setup view

qgroundcontrol实现

qgroundcontrol进程中线程

  1. 搜索QGC地面站的进程ID
yangang@yangang-ubuntu:~/work/github_proj/picture$ ps -ef |grep "QG" |grep -v "grep"
yangang   8353  8340  6 14:06 ?        00:00:01 /home/yangang/work/github_proj/build-qgroundcontrol-Desktop_Qt_5_11_3_GCC_64bit-Debug/debug/QGroundControl -qmljsdebugger=port:35601,block,services:DebugMessages,QmlDebugger,V8Debugger,QmlInspector
  1. 查找QGC进程中的线程
    其实整个GGC的进程中,GUI是1个线程,UDPLINK是1个独立的线程
yangang@yangang-ubuntu:~/work/github_proj/picture$ ps -T -p 8353
  PID  SPID TTY          TIME CMD
 8353  8353 ?        00:00:01 QGroundControl
 8353  8368 ?        00:00:00 QXcbEventReader
 8353  8369 ?        00:00:00 gmain
 8353  8370 ?        00:00:00 gdbus
 8353  8386 ?        00:00:00 QGroundControl
 8353  8414 ?        00:00:00 QDBusConnection
 8353  8415 ?        00:00:00 Qt bearer threa
 8353  8416 ?        00:00:00 QGCCacheWorker
 8353  8417 ?        00:00:00 Thread (pooled)
 8353  8418 ?        00:00:00 QQmlThread
 8353  8419 ?        00:00:00 QQmlDebugServer
 8353  8423 ?        00:00:00 disk_cache:0
 8353  8426 ?        00:00:00 UDPLink
 8353  8427 ?        00:00:00 QNetworkAccessM
 8353  8457 ?        00:00:00 QNetworkAccessM
  1. UDPlink对象创建过程
    在main入口中创建QGCApplication对象,在对象的构造函数中创建QGCtoolbox,
    注册一个定时器事件,用来自动连接设备,UDPLink是默认启动的,创建过程如下
int main(int argc, char *argv[])
->QGCApplication* app = new QGCApplication(argc, argv, runUnitTests);
   -> _toolbox = new QGCToolbox(this);
   ->  _toolbox->setChildToolboxes();
        -> _linkManager->setToolbox(this);
            ->  connect(_mavlinkProtocol, &MAVLinkProtocol::messageReceived, this, &LinkManager::_mavlinkMessageReceived);
            ->  connect(&_portListTimer, &QTimer::timeout, this, &LinkManager::_updateAutoConnectLinks);
            _portListTimer.start(1000); 
          
->exitCode = app->exec();
     -> void LinkManager::_updateAutoConnectLinks(void)
               -> if (!foundUDP && _autoConnectSettings->autoConnectUDP()->rawValue().toBool()) {
               ->  SharedLinkConfigurationPointer config = addConfiguration(udpConfig);
               -> createConnectedLink(config);
                   case LinkConfiguration::TypeUdp:
        		pLink = new UDPLink(config);

UDPLINK工作原理

  1. 连接完成,进行事件循环
UDPLink::UDPLink(SharedLinkConfigurationPointer& config)
    -> moveToThread(this);
  1. 通过连接,进行启动线程
bool UDPLink::_connect(void)
    start(NormalPriority);
  1. 在run中,连接完成后,进行exec循环
void UDPLink::run()
    if(_hardwareConnect()) {
        exec();
    }
  1. UDP信号多线程执行
    测试LinkInterface::bytesReceived信号的发生,MAVLinkProtocol::receiveBytes的slot执行线程
main: 0x7efe09670800
Adding target QHostAddress("127.0.0.1") 14556
UDPLink: 0x7efdb246e700
UDPLink: 0x7efdb246e700
MAVLinkProtocol: 0x7efe09670800
Switching outbound to mavlink 2.0 due to incoming mavlink 2.0 packet: 0x55a77c48ca48 1 2
MAVLinkProtocol: 0x7efe09670800

SerialLink工作原理

  1. 串口link的数据收发都是使用signal和slot进行处理的
bool SerialLink::_connect(void)
if (!_hardwareConnect(error, errorString)) {
    -> _port = new QSerialPort(_serialConfig->portName(), this);
    -> QObject::connect(_port, &QIODevice::readyRead, this, &SerialLink::_readBytes);
      -> _port->read(buffer.data(), buffer.size());
        emit bytesReceived(this, buffer);

void SerialLink::_writeBytes(const QByteArray data)
  ->  _port->write(data);
  1. 测试LinkInterface::bytesReceived信号的发生,MAVLinkProtocol::receiveBytes的slot执行线程
main:id 0x7fb3aca56800
"v3.5.2"
QGCMessageBox (unit testing) "New Version Available" "There is a newer version of QGroundControl available. You can download it from qgroundcontrol.com."
MAVLINK:id 0x7fb3aca56800
Switching outbound to mavlink 2.0 due to incoming mavlink 2.0 packet: 0x564613ce9a70 2 2
serialLINK:id 0x7fb3aca56800
MAVLINK:id 0x7fb3aca56800

mavlink解析

字节的收发和MAVLinkProtocol的槽函数进行连接,
void LinkManager::_addLink(LinkInterface* link)
-> connect(link, &LinkInterface::bytesReceived, _mavlinkProtocol, &MAVLinkProtocol::receiveBytes);

-> void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b)
-> uint8_t mavlinkChannel = link->mavlinkChannel();
-> if (mavlink_parse_char(mavlinkChannel, static_cast<uint8_t>(b[position]), &_message, &_status)) {
-> emit messageReceived(link, _message);

qgroundcontrol总结

qgroundcontrol设计很优秀。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

闫刚 qgroundcontrol地面站通信流代码架构 的相关文章

随机推荐

  • Python安装时import matplotlib.pyplot as plt报错

    安装matplotlib的时候可能会出现输入import matplotlib pyplot as plt出现报错的现象 xff0c 如下图所示 xff1a gt gt gt import matplotlib gt gt gt impor
  • 回文数和回文素数

    34 回文数 34 是一种数字 如 xff1a 98789 这个数字正读是98789 倒读也是98789 正读倒读一样 xff0c 所以这个数字就是回文数 1千以内 在自然数中 xff0c 最小的回文数是0 xff0c 其次是1 2 3 4
  • pragma pack对齐方式详细介绍

    为了加快读写数据的速度 xff0c 编译器采用数据对齐的方式来为每一个结构体分配空间 写在开头 本文有自己的原创也有转载的博文 xff0c 转载的部分一一列出来 xff0c 可能不全请见谅这里这里这里这里等等 更详细的解说 xff1a 在用
  • Qt学习笔记——打开并显示图片

    使用控件QLabel mainwindow h ifndef MAINWINDOW H define MAINWINDOW H include lt QMainWindow gt include lt QFileDialog gt incl
  • 可调恒流驱动LED电路分析

    https www icxbk com article detail aid 61 884 常规使用的pwm调亮度不仅会导致频闪 xff0c 而且在长时间使用的时候 xff0c 有损坏led的风险 xff0c 所以这次设计了一个恒流调亮度电
  • 如何在雷电模拟器里使用YiLu代理的动态ip?

    1在易路 程序 页面里随意添加一个应用 xff0c 请不要添加 雷电 到YiLu程序里 xff1b 2 YiLu设置 xff1a 点击YiLu 设置 页面 xff1b 选择 YiLu便携代理引擎 xff1b 选择 仅代理YiLu程序选项卡中
  • Freeman链码,差分码,归一化链码,归一化差分码

    Freeman链码是指用曲线起始点的坐标和边界点方向代码来描述曲线或边界的方法 xff0c 常被用来在图像处理 计算机图形学 模式识别等领域中表示曲线和区域边界 它是一种边界的编码表示法 xff0c 用边界方向作为编码依据 xff0c 为简
  • Matlab关联m文件与m文件关联设置

    MATLAB安装后经常出现m文件不能关联到matlab打开 xff0c 很烦恼 网上有一些设置教程 xff0c 比如 xff1a 链接一 按照链接方式一方式二设置后出现报错 修改注册表亦没用 下面链接 链接二 链接三 链接四 都没有效果 代
  • 图像处理形态学椭圆形模板结构元素的设计与实现

    在图像处理中 xff0c 经常要用到形态学操作 xff0c 形态学操作中的结构元素有很多 xff0c 如点结构 十字架结构 圆结构 矩形结构 椭圆形结构等等 本文将介绍椭圆形结构的实现 主要结合OpenCV实现 具体如下 xff1a inc
  • 3维空间旋转3维空间矩阵旋转及旋转变换

    本文将实现三维空间中的旋转和平移变换 xff0c 即将三维空间中的一个向量 或者一个空间图形 移动到另一个位置 如下图所示 xff1a 如上图所示 xff0c 由矢量一移动到矢量二 三维空间中的移动可以分为旋转和平移 设矢量一在坐标位置 X
  • 回归方程推导

  • Mac终端代理设置

    title Mac终端代理设置 tags mac 终端设置代理 打开终端执行 export http proxy 61 http 127 0 0 1 1087 export https proxy 61 http 127 0 0 1 108
  • Unity3D游戏作品大盘点

    原文链接 xff1a http www unitymanual com 404 html 经典重现 新仙剑OL 新仙剑OL 采用跨平台Unity3D引擎 xff0c 耗资数千万 xff0c 历时三年多 xff0c 由台湾大宇正版授权 xff
  • IAR编译器的ICF链接脚本

    测试代码如下 xff1a task c span class token macro property span class token directive keyword pragma span default variable attr
  • 2020-10-24

    PendSV中断控制器地址 NVIC INT CTRL EQU 0xE000Ed04 触发PendSV NVIC PENDSV SET EQU 0x10000000 PendSV优先级控制地址 NVIC SYSPRI2 EQU 0xE000
  • Linux下如何配置Vlan

    VLAN是虚拟局域网的缩写 一个物理交换机上可以共存多个VLAN xff0c 这些交换机通过Linux软件配置 xff0c 而不是通过硬件接口 xff08 您仍然需要配置实际的硬件交换机 xff09 VLAN作为名称建议一次组合多个LAN
  • 附加项-linux下ssh的config文件讲解-闫刚

    在 ssh 下创建 config文件 xff0c 可以添加多个账号 xff0c 减少认证的问题 并以如下格式编辑配置文件 vi config HostName xff1a 是目标主机的主机名 xff0c 也就是平时我们使用ssh后面跟的地址
  • 第一章 第九节 如何Doxygen为代码生成html文档-闫刚

    Doxygen是一款文档生成工具 xff0c 它可以从代码中提取出相应的文档 xff0c 并组织 xff0c 输出成各种漂亮的文档 xff08 如HTML xff0c PDF xff0c RTF等 xff09 doxygen让你变成一位有品
  • 第二章 第二节 px4的uORB工作原理分析 闫刚

    px4中的uorb是px4非常核心的数据通信机制 xff0c 所有线程的通信都是靠uorb完成 xff0c 用过的人可能 xff0c 仅仅知道在想要获取orb数据的时候 xff0c 先进行订阅 xff0c 在发送orb消息之前 xff0c
  • 闫刚 qgroundcontrol地面站通信流代码架构

    qgroundcontrol开发者文档中说明了qgc中的各个链路流向在文档中说明的很清楚 xff0c 下面配套源代码进行讲解整个qgc地面站的数据流向过程 qgroundcontrol通信 在 https dev qgroundcontro