mavlink协议解析_jlink 串口
MAVLink是為微型飛行器MAV(Micro Air Vehicle)設(shè)計(jì)的(LGPL)開源的通訊協(xié)議。是無人飛行器和地面站(Ground Control Station ,GCS)之間,以及無人飛行器之間通訊常用的協(xié)議。APM、PIXHAWK飛控,Mission Planner、QGroundControl地面站均使用了MAVLink協(xié)議進(jìn)行通訊。
MAVLink源碼下載地址(現(xiàn)已更新至v2.0):https://github.com/mavlink/qgroundcontrol
用戶手冊(cè):https://docs.qgroundcontrol.com/en/
https://mavlink.io/zh/(開發(fā)手冊(cè))
1、 common文件夾:原始的MAVLink消息,包括各種消息的頭文件
common.h:定義MAVLink各個(gè)消息包中用到的枚舉類型,各個(gè)消息包對(duì)應(yīng)的CRC—EXTRA值、LENGTH值,包含(include)各個(gè)消息包的頭文件
各個(gè)消息的頭文件:1)定義消息內(nèi)容對(duì)應(yīng)的數(shù)據(jù)結(jié)構(gòu),2)打包、發(fā)送消息的便捷函數(shù),3)消息包解析并獲取各個(gè)參數(shù)
2、 autopilotmega,ASLUAV,pixhawk等文件夾:這些文件夾包含各個(gè)飛控自定義的MAVLink消息類型
3、checksum.h:計(jì)算校驗(yàn)碼的代碼
4、 mavlink_conversions.h:dcm,歐拉角,四元數(shù)之間的轉(zhuǎn)換
5、mavlink_helper.h:提供各種便捷函數(shù):
1)將各個(gè)消息包補(bǔ)充完整并發(fā)送。將數(shù)據(jù)載荷加上消息幀的頭部,如sysid和compid等,計(jì)算校驗(yàn)碼,補(bǔ)充成為完整的mavlink消息包后發(fā)送;
2)MAVLink消息包解析。
6、 mavlink_types.h:定義用到的各種基本結(jié)構(gòu)體(如mavlink_message_t)、枚舉類型(如 mavlink_param_union_t)
MAVLink消息包結(jié)構(gòu)
MAVLink傳輸時(shí),以消息包作為基本單位,數(shù)據(jù)長度為8~263字節(jié)。消息數(shù)據(jù)包的結(jié)構(gòu)如下:
注:校驗(yàn)(checksum)功能。加入MAVLINK_CRC_EXTRA,當(dāng)兩個(gè)通訊終端之間(飛行器和地面站,或飛行器和飛行器)使用不同版本的MAVLink協(xié)議時(shí),雙方計(jì)算得到的校驗(yàn)碼會(huì)不同,則不同版本的MAVLink協(xié)議之間將無法通訊。MAVLINK_MESSAGE_CRCS中存儲(chǔ)了每種消息包對(duì)應(yīng)的MAVLINK_CRC_EXTRA。這個(gè)MAVLINK_CRC_EXTRA在用python生成MAVLink代碼時(shí)在common.h頭文件中自動(dòng)生成。
MAVLink數(shù)據(jù)包的結(jié)構(gòu)在mavlink_types.h中用mavlink_message_t結(jié)構(gòu)體定義:
MAVLINK Common Message Set
MAVLink通用消息集可以在《MAVLLINK Common Message set specifications》文檔中查看。這些消息定義了通用消息集,這是大多數(shù)地面控制站和自動(dòng)駕駛儀實(shí)現(xiàn)的參考消息集,頭文件包含在common文件夾中。
分為兩部分:MAVLink Type Enumerations(MAVLink類型枚舉 )和MAVLink Messages(MAVLink消息包)。
MAVLink Type Enumerations
MAVLink Type Enumerations在common.h文件中定義。如下,枚舉變量定義了飛行器的類型MAV_AUTOPILOT。
typedef enum MAV_AUTOPILOT
{
MAV_AUTOPILOT_GENERIC=0, /* Generic autopilot, full support for everything | */
MAV_AUTOPILOT_RESERVED=1, /* Reserved for future use. | */
MAV_AUTOPILOT_SLUGS=2, /* SLUGS autopilot, http://slugsuav.soe.ucsc.edu | */
MAV_AUTOPILOT_ARDUPILOTMEGA=3, /* ArduPilotMega / ArduCopter, http://diydrones.com | */
MAV_AUTOPILOT_OPENPILOT=4, /* OpenPilot, http://openpilot.org | */
MAV_AUTOPILOT_GENERIC_WAYPOINTS_ONLY=5, /* Generic autopilot only supporting simple waypoints | */
MAV_AUTOPILOT_GENERIC_WAYPOINTS_AND_SIMPLE_NAVIGATION_ONLY=6, /* Generic autopilot supporting waypoints and other simple navigation commands | */
MAV_AUTOPILOT_GENERIC_MISSION_FULL=7, /* Generic autopilot supporting the full mission command set | */
MAV_AUTOPILOT_INVALID=8, /* No valid autopilot, e.g. a GCS or other MAVLink component | */
MAV_AUTOPILOT_PPZ=9, /* PPZ UAV - http://nongnu.org/paparazzi | */
MAV_AUTOPILOT_UDB=10, /* UAV Dev Board | */
MAV_AUTOPILOT_FP=11, /* FlexiPilot | */
MAV_AUTOPILOT_PX4=12, /* PX4 Autopilot - http://pixhawk.ethz.ch/px4/ | */
MAV_AUTOPILOT_SMACCMPILOT=13, /* SMACCMPilot - http://smaccmpilot.org | */
MAV_AUTOPILOT_AUTOQUAD=14, /* AutoQuad -- http://autoquad.org | */
MAV_AUTOPILOT_ARMAZILA=15, /* Armazila -- http://armazila.com | */
MAV_AUTOPILOT_AEROB=16, /* Aerob -- http://aerob.ru | */
MAV_AUTOPILOT_ASLUAV=17, /* ASLUAV autopilot -- http://www.asl.ethz.ch | */
MAV_AUTOPILOT_ENUM_END=18, /* | */
} MAV_AUTOPILOT;
心跳包的內(nèi)容存放在payload數(shù)據(jù)載荷中。以心跳包為例:
typedef struct __mavlink_heartbeat_t
{
uint32_t custom_mode; /*< A bitfield for use for autopilot-specific flags.*/
uint8_t type; /*< Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM)*/
uint8_t autopilot; /*< Autopilot type / class. defined in MAV_AUTOPILOT ENUM*/
uint8_t base_mode; /*< System mode bitfield, see MAV_MODE_FLAG ENUM in mavlink/include/mavlink_types.h*/
uint8_t system_status; /*< System status flag, see MAV_STATE ENUM*/
uint8_t mavlink_version; /*< MAVLink version, not writable by user, gets added by protocol because of magic data type: uint8_t_mavlink_version*/
} mavlink_heartbeat_t;
心跳包一般用來表明發(fā)出該消息的設(shè)備是否活躍(一般以1Hz發(fā)送),消息接收端會(huì)根據(jù)是否及時(shí)收到了心跳包來判斷是否和消息發(fā)送端失去了聯(lián)系。
心跳包由6個(gè)數(shù)據(jù)成員組成,占用9個(gè)字節(jié)。
1、 type:飛行器類型,表示了當(dāng)前發(fā)消息的是什么飛行器,如四旋翼,直升機(jī)等。type的取值對(duì)應(yīng)枚舉類型MAV_TYPE(如四旋翼,對(duì)應(yīng)數(shù)值2)。
2、autopilot:飛控類型,如apm,Pixhawk等,發(fā)送心跳包的飛行器的飛控類型。autopilot的取枚舉類型MAV_AUTOPILOT。
3、base mode(基本模式):飛控現(xiàn)在所處的飛行模式,這個(gè)參數(shù)要看各個(gè)飛控自己的定義方式,會(huì)有不同的組合、計(jì)算方式。
4、custom mode(用戶模式):飛控現(xiàn)在所處的飛行模式,這個(gè)參數(shù)要看各個(gè)飛控自己的定義方式,會(huì)有不同的組合、計(jì)算方式。
5、system status:系統(tǒng)狀態(tài),見MAV_STATE枚舉變量。
6、mavlink version:消息發(fā)送端的MAVLink版本。
其余的消息也是類似的結(jié)構(gòu),基本消息的定義可以查看官方網(wǎng)頁的說明(具體說明以各個(gè)飛控為準(zhǔn)),也可查看各個(gè)消息包頭文件的定義。
Mavlink 2.0協(xié)議:
MavLink協(xié)議目前網(wǎng)上可以找到的中文版資料只有1.0的。現(xiàn)在開發(fā)使用的固件版本號(hào)是1.7.3.串口抓的的包全部與1.0版本都不一致。爬到官方去看了下。有2.0的包結(jié)構(gòu)。
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 target_sysid; ///< Optional field for point-to-point messages, used for payload else
uint8_t target_compid; ///< Optional field for point-to-point messages, used for payload else
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
包結(jié)構(gòu)大致如下:
2.0包的總長為10+n+3(+2),其中括號(hào)的2為可選內(nèi)容。抓包未發(fā)現(xiàn)。
抓包獲得來自飛控的Msgind如下。
0,36,74,105,30,31,32,140,1,147,65,70,141,230,241,111,83,69,24
這些都是飛控?zé)o請(qǐng)求時(shí)主動(dòng)發(fā)送過來的數(shù)據(jù)。
根據(jù)msgid:
mavlink協(xié)議源碼:mavlink
總結(jié)
以上是生活随笔為你收集整理的mavlink协议解析_jlink 串口的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [蓝桥杯]算法训练 The Red Bu
- 下一篇: [蓝桥杯]算法提高 vertex cov