mavlink2.0开发手记(一) mavlink消息的特点

mavlink消息的特点

  • mavlink是一个用于资源和带宽受限的二进制遥测协议
  • 支持多播传输(multicast transmission)
  • 支持稳定的点对点传输重发(point-to-point tetransmission) 比如mission protocol parameter protocol

- 

  • mavlink_versionV1.0 2013年发布
  • mvalink_versionV2.0 2017年发布
  • V2.0极大地简化了传输
  • V2.0向下兼容V1.0

v2.0
- Support for more than 256 message IDs
- Packet signing (authentication)
- Support for extending existing messages
- Support for variable length arrays


序列化的消息帧格式

//mavlink_V1.0
uint8_t magic;               ///< protocol magic marker
uint8_t len;                 ///< Length of payload
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;               ///< ID of message in payload
uint8_t payload[max 255];    ///< A maximum of 255 payload bytes
uint16_t checksum;           ///< X.25 CRC
  • V1.0 帧数据除去payload长度,有8bit的数据冗余
  • V2.0 帧数据除去payload和可选字节,有12bit的冗余
//mavlinkg_V2.0
uint8_t magic;              ///< protocol magic marker
uint8_t len;                ///< Length of payload
uint8_t incompat_flags;     ///< flags that must be understood(NEW)
uint8_t compat_flags;       ///< flags that can be ignored if not understood(NEW)
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(由8bit 扩展到24bit)
uint8_t msgid 8:15;         ///< middle 8 bits of the ID of the message(NEW)
uint8_t msgid 16:23;        ///< last 8 bits of the ID of the message (NEW)
uint8_t target_sysid;       ///< Optional field for point-to-point messages, used for payload elseNEW 可选)
uint8_t target_compid;      ///< Optional field for point-to-point messages, used for payload elseNEW 可选)
uint8_t payload[max 253];   ///< A maximum of 253 payload bytes
uint16_t checksum;          ///< X.25 CRC
uint8_t signature[13];      ///< Signature which allows ensuring that the link is tamper-proof(NEW 可选)
  • [V1.0心跳] fe 09 ce 01 01 00 00 00 01 00 02 0c 41 03 03 25 5d
  • [V2.0心跳] fd 09 00 00 80 01 c8 00 00 00 00 00 00 00 04 00 d8 04 03 f1 bf

mavlink的消息序列化(serialization)使用stable sorting algorithm 算法,避免重复排序


Receiving

  • mavlink_helper.h :mavlink_parse_char()

Transmitting

  • 在library中mavlink_msg_**.h 定义每一个消息的结构 mavlink_msg_*_pack()
  • mavlink_helpers.h:mavlink_msg_to_send_buffer(buf, &msg) 将消息序列化存入buf
  • 然后通过合适的接口发送出去 串口/socket_UDP/socket_TCP

多播传输(Topic mode)&点播传输(Point-to-Point mode)混合动力

  • Mavlink是建立在高速率数据流的混合网络上, data sources(Drones) – data sinks(GCS)

  • Multicast Streams 接收遥测数据( telemetry streams ),通常有机载计算机、地面站、还有云端系统

    • Topic Mode (publish-subscribe) 消息不会发送到指定的system和component,以节约带宽,避免不必要的的额外开销.
    • 而多个订阅者都可以订阅这些数据
    • 通常如position、attitude 等autopilot data streams都采用这种形式
  • Guaranteed Delivery ,像mission、parameters数据,为了确保安全,需要点对点传输

    • point-to-point 会指定target system ID & component ID
    • mission、parameter、控制commands,为了确保安全送达,都会采用这种方式

特殊消息

  • version handsharking(地面站和飞控 版本握手信息)

    [148] common/mavlink_msg_autopilot_version.h 定义发送版本信息
    [76] common/mavlink_msg_commandl_long/int.h QGC用(commonID 519)MAV_CMD_REQUEST_PROTOCOL_VERSION发送握手信息
    [300] common/mavlink_msg_protocol_version.h Drone response

你可能感兴趣的:(mavlink2.0开发手记(一) mavlink消息的特点)