本文内容来源于维基百科,仅供学习参考。
MAVLink(Micro Air Vehicle Link)是一种用于与小型无人机通信的协议。它被设计为一个header-only消息封送处理库。MAVLink由Lorenz Meier在LGPL许可下[2]于2009[1]年初发布。
PS. header-only库是一种“无需编译,包含头文件就可以用”的库。
MAVLink的应用
MAVLink主要用于地面控制站(GCS, Ground Control Station)与无人机之间的通信,以及载具内部子系统间的通信。它可以用来传输载具的方位、GPS位置以及速度。
MAVLink包结构
在1.0版本中包的结构如下:
PS. 0xFE = 254,即一个十进制值为254的字节标识着一个新的MAVLink消息包的开始。
版本2之后,包结构扩展为以下[3]:
PS. 0xFD = 253
CRC字段
详见原文。[4][5][6][7][8]
该字段主要用于确保消息包的完整性。MAVLink的循环冗余检查算法已经在Python和Java等多种语言中实现。
MAVLink消息
上述数据包中的有效负载就是MAVLink消息。每条消息都由包上的ID字段进行标识,有效负载包含来自消息的数据。MAVlink源码[9]中的XML文档定义了存储在此有效负载中的数据。
下面是从XML文档中提取的ID为24的消息。
The global position, as returned by the Global Positioning System (GPS). This is NOT the global position estimate of the system, but rather a RAW sensor value. See message GLOBAL_POSITION for the global position estimate. Coordinate frame is right-handed, Z-axis up (GPS frame).
Timestamp (microseconds since UNIX epoch or microseconds since system boot)
0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix.
Latitude (WGS84), in degrees * 1E7
Longitude (WGS84), in degrees * 1E7
Altitude (WGS84), in meters * 1000 (positive for up)
GPS HDOP horizontal dilution of position in cm (m*100). If unknown, set to: UINT16_MAX
GPS VDOP horizontal dilution of position in cm (m*100). If unknown, set to: UINT16_MAX
GPS ground speed (m/s * 100). If unknown, set to: UINT16_MAX
Course over ground (NOT heading, but direction of movement) in degrees * 100, 0.0..359.99 degrees. If unknown, set to: UINT16_MAX
Number of satellites visible. If unknown, set to 255
注意:XML文档描述了协议字段的逻辑顺序。实际的连线格式(以及典型的内存表示)对字段重新排序[10],以减少数据结构对齐问题。在阅读从消息定义生成的代码时,这可能会造成混淆。
MAVLink生态圈
MAVLink在很多项目中作为通信协议使用,这可能意味着它们之间存在一定的兼容性。有人已经编写了一个有趣的教程[11]来解释MAVLink的基础知识。
参考
原文:https://www.cnblogs.com/xkxf/p/12240346.html