主要内容

createmsg

创建mavlink消息

描述

例子

味精= createmsg(方言MSGID根据指定的消息定义返回空白消息结构mavlinkdialect目的,方言和输入消息ID,MSGID

例子

全部收缩

此示例显示如何解析Mavlink XML文件并从定义中创建邮件和命令。

笔记:这个例子要求你安装的机器人系统Toolbox®无人机库。称呼roboticsAddons打开加载项资源管理器并安装该库。

解析和存储MAVLink方言XML。指定XML路径。默认值“common.xml”提供方言。此XML文件包含了所有的信息和枚举定义。

方言= mavlinkdialect(“common.xml”);

创建从一个MAVLink命令mav_cmd.枚举,它是发送到UAV的Mavlink命令的枚举。指定设置为“int”要么“长”,以及作为整数或字符串的类型。

cmdmsg = createcmd(方言,“长”,22)
cmdMsg =结构与字段:的MsgID:76有效载荷:[1x1的结构]

验证命令名称使用num2enum。命令22是用于UAV起飞命令。您可以使用转换回一个IDenum2num。您可以方言包含具有不同的名称和ID许多不同的枚举。

cmdName = num2enum(方言,“MAV_CMD”,22)
cmdName = “MAV_CMD_NAV_TAKEOFF”
cmdID = enum2num(方言,“MAV_CMD”,cmdName)
cmdID = 22

采用enumenfo.查看的表mav_cmd.枚举条目。

信息= enuminfo(方言,“MAV_CMD”);info.Entries {:}
ans =.133×3表名称值说明_____________________________________ _____ _______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________“MAV_CMD_NAV_WAYPOINT” 16“导航到航点。”“mav_cmd_nav_loiter_unlim”17“在此航路点围绕此航路点无限的时间”“mav_cmd_nav_loiter_turns”18“loits围绕此航点x转动”mav_cmd_nav_loiter_time“19”在此航路点围绕此航路点“mav_cmd_nav_return_to_launch”20“返回启动位置“Mav_Cmd_nav_land”21“地点”“”mav_cmd_nav_takeoff“22”从地面/手中起飞“”mav_cmd_nav_land_local“23”在本地位置(仅限本地帧)“”mav_cmd_nav_takeoff_local“24”从本地位置开始起飞(仅限本地帧)" "MAV_CMD_NAV_FOLLOW" 25 "Vehicle following, i.e. this waypoint represents the position of a moving vehicle" "MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT" 30 "Continue on the current course and climb/descend to specified altitude. When the altitude is reached continue to the next command (i.e., don't proceed to the next command until the desired altitude is reached." "MAV_CMD_NAV_LOITER_TO_ALT" 31 "Begin loiter at the specified Latitude and Longitude. If Lat=Lon=0, then loiter at the current position. Don't consider the navigation command complete (don't leave loiter) until the altitude has been reached. Additionally, if the Heading Required parameter is non-zero the aircraft will not leave the loiter until heading toward the next waypoint. " "MAV_CMD_DO_FOLLOW" 32 "Being following a target" "MAV_CMD_DO_FOLLOW_REPOSITION" 33 "Reposition the MAV after a follow target command has been sent" "MAV_CMD_DO_ORBIT" 34 "Start orbiting on the circumference of a circle defined by the parameters. Setting any value NaN results in using defaults." "MAV_CMD_NAV_ROI" 80 "Sets the region of interest (ROI) for a sensor set or the vehicle itself. This can then be used by the vehicles control system to control the vehicle attitude and the attitude of various sensors such as cameras." ⋮

查询特定消息ID的方言。使用消息ID创建空白MAVLINK消息。

信息= msginfo(方言,“心跳”
信息=1×4表MessageID MessageName Description Fields _________ ___________ ___________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________ ___________ 0 "HEARTBEAT" "The heartbeat message shows that a system is present and responding. The type of the MAV and Autopilot hardware allow the receiving system to treat further messages from this system appropriate (e.g. by laying out the user interface based on the autopilot)." {6x6 table}
MSG = createmsg(方言,info.MessageID);

输入参数

全部收缩

Mavlink Dialect,指定为amavlinkdialect目的。语句指定MAVLINK协议的消息结构。

消息ID,指定为正整数或字符串。如果指定为一个整数,与来自匹配的ID的消息定义方言被退回。如果指定为字符串,则返回与名称相符的消息。

输出参数

全部收缩

MAVLink消息,返回与该字段的结构:

  • 的MsgID:用于消息ID正整数。

  • 有效载荷:用于特定消息定义含有结构域。

在R2019A介绍