MAVLink是一种非常轻量级的消息传递协议,用于与无人机通信(以及在无人机机载组件之间)。
MAVLink遵循现代混合发布-订阅和点对点设计模式。
消息是在XML文件中定义的。每个XML文件定义特定MAVLink系统支持的消息集,也称为“dialect(方言)”。大多数地面控制站和自动驾驶仪实现的参考消息集在common.xml中定义(大多数dialect都建立在这个定义的基础上)。
代码生成器根据这些XML消息定义创建特定编程语言的软件库,然后无人机、地面控制站和其他MAVLink系统可以使用这些软件库进行通信。生成的库通常是MIT许可的,因此可以在任何闭源应用程序中无限制地使用,而无需发布闭源应用的源代码。
针对不同的编程语言生成mavlink库文件。
协议1和协议2,向后兼容。
uint8_t magic; ///< protocol magic marker
uint8_t len; ///< Length of payload
uint8_t incompat_flags; ///< flags that must be understood
uint8_t compat_flags; ///< flags that can be ignored if not understood
uint8_t seq; ///< Sequence of packet
uint8_t sysid; ///< ID of message sender system/aircraft
uint8_t compid; ///< ID of the message sender component
uint8_t msgid 0:7; ///< first 8 bits of the ID of the message
uint8_t msgid 8:15; ///< middle 8 bits of the ID of the message
uint8_t msgid 16:23; ///< last 8 bits of the ID of the message
uint8_t payload[max 255]; ///< A maximum of 255 payload bytes
uint16_t checksum; ///< CRC-16/MCRF4XX
uint8_t signature[13]; ///< Signature which allows ensuring that the link is tamper-proof (optional)
MAVLink 1数据包格式类似,但省略了这些字段:compatt_flags、compat_flags和signature,并且只有一个字节用于消息地址。有关详细信息,请参阅序列化>数据包格式。
为了优化而重新排序Mavlink包的字段;
发布、订阅;
节省链路带宽;
多个订户都可以接收这些数据;
保证发送能够到达;
发送“任务、参数、命令”等一般用这个模式;
https://mavlink.io/en/about/faq.html
These projects have some activity but are not as well maintained:
以C MAVLink库为例:
文档
MavLink系统收发data,这data有两种形式message、conmmand;
conmmand本质上是一种特殊的enums;
什么时候发送message什么时候发送command?或者说什么时候将data定义成message什么时候定义成command?
所有的message和command都定义在XML文件中;
一些通用的message和command都定义在common.XML中,此外还有
若需要定义自己的message或command,如***.XML,这些文件被称为Dialect File,即方言(翻译自Dialect ),这些XML必须遵循这些格式:xml_schema;
https://mavlink.io/en/guide/define_xml_element.html
The MAVLink common message set contains standard definitions that are managed by the MAVLink project. The definitions cover functionality that is considered useful to most ground control stations and autopilots. MAVLink-compatible systems are expected to use these definitions where possible (if an appropriate message exists) rather than rolling out variants in their own dialects.
The original definitions are defined in common.xml.
可以查询所有通用的message、command、enums的定义和作用,有哪些参数,Id或value是几:
https://mavlink.io/en/messages/common.html
MAVLink“微服务”定义了MAVLink系统可以采用的更高级别协议,以便更好地相互操作。例如,QGroundControl、ArduPilot和PX4自动驾驶都共享一个通用的命令协议,用于发送需要确认的点对点消息。
微服务用于交换多种类型的数据,包括:参数、任务、轨迹、图像和其他文件。如果数据可能远大于单个消息所能容纳的数据,那么服务将定义如何拆分和重新组装数据,以及如何确保任何丢失的数据被重新传输。其他服务提供命令确认和/或错误报告。
大多数服务使用客户端-服务器模式,因此地面军事系统(客户端)发起请求,车辆(服务器)用数据进行响应。
主要的微服务显示在侧边栏中(下面列出了大多数):
https://mavlink.io/en/services/
广播本大爷(MavLink系统)已经上线,可以进行数据收发。
心跳包数据包括:系统和组件id、车辆类型、飞行堆栈、组件类型和飞行模式。
举个栗子:
枚举MAV_MODE的取值和描述如下:
下面的command和massage就使用到了这个枚举:
下面的massage就用到了 command 和 enum :
…
。。。。。。
本质上是基于现有的massage,按照以下约定来发送massage的一个过程:
【1】https://ardupilot.org/dev/docs/mavlink-commands.html
【2】http://mavlink.io/zh/services/