可视化和回放MAVLink飞行日志
将包含MAVLink数据包的遥测日志(TLOG)加载到MATLAB中。将提取消息的详细信息用于绘图。然后,为了再次模拟飞行,消息通过MAVLink通信接口重新发布。此发布模拟了一个无人驾驶飞行器(UAV)执行tlog中记录的飞行。
加载MAVLink TLOG
创建一个mavlinkdialect
对象使用“common.xml”
方言。使用mavlinktlog
使用这种方言来加载TLOG数据。
方言= mavlinkdialect(“common.xml”);Logimport = mavlinktlog(“mavlink_flightlog.tlog”、方言);
从TLOG中提取GPS消息并将其可视化geoplot
.
MSGS = readmsg(logimport,“MessageName”,“GPS_RAW_INT”,...“时间”100年[0]);latlon = msgs.Messages{1};%过滤掉零值的消息拉特兰=拉特兰(拉特兰。Lat ~= 0 & latlon。Lon ~= 0,:);Figure () geoplot(double(latton .lat)/1e7, double(latton .lon)/1e7);
从TLOG中提取姿态消息。为姿态消息指定消息名。绘制滚动,俯仰,偏航数据使用stackedplot
.
MSGS = readmsg(logimport,“MessageName”,“态度”,“时间”100年[0]);图()stackedplot(公司。消息{1},{“滚”,“节”,“偏航”});
回放MAVLink日志条目
创建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));
以50赫兹的速率发送前100条消息。
payloads = table2struct(msgs.Messages{1});attitudeDefinition = msginfo(方言,“态度”);为msgIdx = 1:100 sendudpmsg(sender,struct(“是否”, attitudeDefinition。消息id,“有效载荷”有效载荷(msgIdx))、destinationHost destinationPort);暂停(1/50);结束
断开与两个MAVLink通信接口的连接。
断开(接收器)断开(发送方)