无人机Mavlink+offboard模式指令概述

来源:互联网 发布:游戏辅助软件制作 编辑:程序博客网 时间:2024/05/21 10:25

     无人机如今越来越多,如果你想深入了解无人机,那么了解和应用无人机mavlink指令是应该的。

     接下来就介绍一波,下面的内容都是费了很长时间整理的,如有不妥,还请见谅。



先介绍一波学习网站:

 

Mavlink各个指令:https://pixhawk.ethz.ch/mavlink/

 

Mavlink crc_extra的计算:http://qgroundcontrol.org/mavlink/crc_extra_calculation





1】下面开始说介绍mavlink所发送的数据结构

Mavlink传输时的基本单位是消息帧。


如图所示,每个消息帧都是上述的结构,除了灰色外,其他的格子都代表了一个字节的数据。

红色的是起始标志位(stx),在v1.0版本中以“FE”作为起始标志。这个标志位在mavlink消息帧接收端进行消息解码时有用处。

第二个格子代表的是灰色部分(payload,称作有效载荷,要用的数据在有效载荷里面)的字节长度(len),范围从0255之间。在mavlink消息帧接收端可以用它和实际收到的有效载荷的长度比较,以验证有效载荷的长度是否正确。

第三个格子代表的是本次消息帧的序号(seq),每次发完一个消息,这个字节的内容会加1,加到255后会从0重新开始。这个序号用于mavlink消息帧接收端计算消息丢失比例用的,相当于是信号强度。

第四个格子代表了发送本条消息帧的设备的系统编号(sys),使用PIXHAWKPX4固件时默认的系统编号为1,用于mavlink消息帧接收端识别是哪个设备发来的消息。

第五个格子代表了发送本条消息帧的设备的单元编号(comp),使用PIXHAWKPX4固件时默认的单元编号为50,用于mavlink消息帧接收端识别是设备的哪个单元发来的消息(暂时没什么用) 。

第六个格子代表了有效载荷中消息包的编号(msg),注意它和序号是不同的,这个字节很重要,mavlink消息帧接收端要根据这个编号来确定有效载荷里到底放了什么消息包并根据编号选择对应的方式来处理有效载荷里的信息包。

最后两个字节是16位校验位,ckb是高八位,cka是低八位。校验码由crc16算法得到,算法将整个消息(从起始位1开始到有效载荷结束,还要额外加上个MAVLINK_CRC_EXTRA字节)进行crc16计算,得出一个16位的校验码。之前提到的每种有效载荷里信息包(由消息包编号来表明是哪种消息包)会对应一个MAVLINK_CRC_EXTRA,这个MAVLINK_CRC_EXTRA 是由生成mavlink代码的xml文件生成的,加入这个额外的东西是为了当飞行器和地面站使用不同版本的mavlink协议时,双方计算得到的校验码会不同,这样不同版本间的mavlink协议就不会在一起正常工作,避免了由于不同版本间通讯时带来的重大潜在问题。

为了方便叙述,消息包将称作包,包所代表的信息称作消息。上图中的sys将称为sysidcomp将称为compidmsg将称为msgid

官方的介绍如下图:

   

Supported data types

MAVLink supports fixed-size integer data types, IEEE 754 single precision floating point numbers, arrays of these data types (e.g. char[10]) and the special mavlink_version field, which is added automatically by the protocol. These types are available:

char - Characters / strings

uint8_t - Unsigned 8 bit

int8_t - Signed 8 bit

uint16_t - Unsigned 16 bit

int16_t - Signed 16 bit

uint32_t - Unsigned 32 bit

int32_t - Signed 32 bit

uint64_t - Unsigned 64 bit

int64_t - Signed 64 bit

float - IEEE 754 single precision floating point number

double - IEEE 754 double precision floating point number

uint8_t_mavlink_version - Unsigned 8 bit field automatically filled on sending with the current MAVLink version - it cannot be written, just read from the packet like a normal uint8_t field


先看一段指令示例,这个指令是#82号指令:


各个mavlink指令对应的 crc_extra值表和LEN长度在 mavlink 1.0 库中的ardupilotmega.h头文件里,具体可以去https://github.com/mavlink/里面查找。

 

Checksum使用CRC16 CCITT ITU x.25

 

帧中都是16进制数据,要把十进制转成十六进制,例如255是 FF

 

Float二进制储存方式:http://blog.csdn.net/gjw198276/article/details/6956244

指令示例:#82      FE 27 00 01 01 52 00 00 00 00 01 01 00 00 00 00 00 00 00 00

 

00 00 00 00  00 00  3F 80 00 00 3F C0 00 00 3F C0 00 00 3F C0 00 00

 

3F 00 00 00  (31) A8 2B

 

len27

sequence00

system:01

component:01

cmd id52

time boot ms :00 00 00 00

target system01

target component01

type mask:00

q:00 00 00 00   00 00 00 00  00 00 00 00  3F 80 00 00 (z轴旋转180

 

)

body roll rate3F C0 00 001.5弧度每秒)

body pitch rate3F C0 00 001.5弧度每秒)

body yaw rate3F C0 00 001.5弧度每秒)

thrus3F 00 00 00(0.5)

CRC: A8 2B


Offboard模式用到两种命令:

 

 

#82


姿态变换以无人机坐标为准,无人机重心为原点坐标,无人机前方向为x轴,右方为y轴,z轴向下。Q=cosθ/2,(x,y,z)sin(θ/2),四元数具体介绍:http://blog.csdn.net/candycat1992/article/details/41254799

 

time_boot_ms:可以设置成0吧??这个好像不重要。

target_system01(从串口返回的飞控数据得到)

target_component01(同上)

其它参数介绍具体参见官网:https://pixhawk.ethz.ch/mavlink/

#84

 

 

NED坐标以无人机重心为原点,x轴为north方向,y轴为east方向,z轴指向地心。

 

 

#65  此指令有可能控制云台

 

 

附录:

LEN AND CRC_EXTRA TABLES:


#ifndef MAVLINK_MESSAGE_LENGTHS

#define MAVLINK_MESSAGE_LENGTHS {9, 31, 12, 0, 14, 28, 3, 32, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 20, 2, 25, 23, 30, 101, 22, 26, 16, 14, 28, 32, 28, 28, 22, 22, 21, 6, 6, 37, 4, 4, 2, 2, 4, 2, 2, 3, 13, 12, 37, 4, 0, 0, 27, 25, 0, 0, 0, 0, 0, 68, 26, 185, 229, 42, 6, 4, 0, 11, 18, 0, 0, 37, 20, 35, 33, 3, 0, 0, 0, 22, 39, 37, 53, 51, 53, 51, 0, 28, 56, 42, 33, 0, 0, 0, 0, 0, 0, 0, 26, 32, 32, 20, 32, 62, 44, 64, 84, 9, 254, 16, 12, 36, 44, 64, 22, 6, 14, 12, 97, 2, 2, 113, 35, 6, 79, 35, 35, 22, 13, 255, 14, 18, 43, 8, 22, 14, 36, 43, 41, 32, 243, 14, 93, 0, 100, 36, 60, 30, 42, 8, 4, 12, 15, 13, 6, 15, 14, 0, 12, 3, 8, 28, 44, 3, 9, 22, 12, 18, 34, 66, 98, 8, 48, 19, 3, 20, 24, 29, 45, 4, 40, 2, 206, 7, 29, 0, 0, 0, 0, 27, 44, 22, 25, 0, 0, 0, 0, 0, 42, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 3, 3, 6, 7, 2, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 42, 40, 63, 182, 0, 0, 0, 0, 0, 0, 0, 32, 52, 53, 6, 2, 38, 0, 254, 36, 30, 18, 18, 51, 9, 0}

#endif


#ifndef MAVLINK_MESSAGE_CRCS

#define MAVLINK_MESSAGE_CRCS {50, 124, 137, 0, 237, 217, 104, 119, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 0, 214, 159, 220, 168, 24, 23, 170, 144, 67, 115, 39, 246, 185, 104, 237, 244, 222, 212, 9, 254, 230, 28, 28, 132, 221, 232, 11, 153, 41, 39, 78, 196, 0, 0, 15, 3, 0, 0, 0, 0, 0, 153, 183, 51, 59, 118, 148, 21, 0, 243, 124, 0, 0, 38, 20, 158, 152, 143, 0, 0, 0, 106, 49, 22, 143, 140, 5, 150, 0, 231, 183, 63, 54, 0, 0, 0, 0, 0, 0, 0, 175, 102, 158, 208, 56, 93, 138, 108, 32, 185, 84, 34, 174, 124, 237, 4, 76, 128, 56, 116, 134, 237, 203, 250, 87, 203, 220, 25, 226, 46, 29, 223, 85, 6, 229, 203, 1, 195, 109, 168, 181, 47, 72, 131, 127, 0, 103, 154, 178, 200, 134, 219, 208, 188, 84, 22, 19, 21, 134, 0, 78, 68, 189, 127, 154, 21, 21, 144, 1, 234, 73, 181, 22, 83, 167, 138, 234, 240, 47, 189, 52, 174, 229, 85, 159, 186, 72, 0, 0, 0, 0, 92, 36, 71, 98, 0, 0, 0, 0, 0, 134, 205, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 69, 101, 50, 202, 17, 162, 0, 0, 0, 0, 0, 0, 207, 0, 0, 0, 163, 105, 151, 35, 0, 0, 0, 0, 0, 0, 0, 90, 104, 85, 95, 130, 184, 0, 8, 204, 49, 170, 44, 83, 46, 0}





0 0
原创粉丝点击