这个例子展示了如何加载一个包含MAVLink数据包的遥测日志(TLOG)到MATLAB®。提取消息的详细信息用于绘图。然后,为了再次模拟飞行,消息通过MAVLink通信接口重新发布。这个发布模拟了无人机(UAV)执行tlog中记录的飞行。
创建一个mavlinkdialect
对象使用“common.xml”
方言。使用mavlinktlog
使用这种方言来加载TLOG数据。
方言= mavlinkdialect (“common.xml”);logimport = mavlinktlog (“mavlink_flightlog.tlog”、方言);
从TLOG中提取GPS信息并使用geoplot
.
公司= readmsg (logimport,“MessageName”,“GPS_RAW_INT”,...“时间”100年[0]);latlon = msgs.Messages {1};%过滤掉零值消息latlon = latlon (latlon。Lat ~= 0 & latlon。= 0,:);图()geoplot(双(latlon.lat) / 1 e7,双(latlon.lon) / 1 e7);
从TLOG中提取态度消息。为态度消息指定消息名称。使用绘图横摇,俯仰,偏航数据stackedplot
.
公司= readmsg (logimport,“MessageName”,“态度”,“时间”100年[0]);图()stackedplot(公司。消息{1},{“滚”,“节”,“偏航”});
创建一个MAVLink通信接口,并将消息从TLOG发布到用户定义的UDP端口。创建发送方和接收方来传递MAVLink消息。这个通信系统的工作方式与真实硬件使用MAVLink通信协议发布消息的方式相同。
发送方= mavlinkio(方言,“SystemID”,1,“ComponentID”,1,...“AutopilotType”,“MAV_AUTOPILOT_GENERIC”,...的组件类型,“MAV_TYPE_QUADROTOR”);连接(发送者,UDP的);destinationPort = 14550;destinationHost =“127.0.0.1”;接收机= mavlinkio(方言);连接(接收机,UDP的,“LocalPort”, destinationPort);用户= mavlinksub(接收器,“态度”,“NewMessageFcn”@ (~ msg) disp (msg.Payload));
以50hz的频率发送前100条消息。
有效载荷= table2struct (msgs.Messages {1});attitudeDefinition = msginfo(方言,“态度”);为msgIdx = 1:100 sendudpmsg(sender,struct(“是否”, attitudeDefinition。消息id,“有效载荷”有效载荷(msgIdx))、destinationHost destinationPort);暂停(1/50);结束
断开两个MAVLink通信接口。
断开(接收器)断开(发送方)