visualize and play back mavlink flight log -凯发k8网页登录
load a telemetry log (tlog) containing mavlink packets into matlab. details of the messages are extracted for plotting. then, to simulate the flight again, the messages are republished over the mavlink communication interface. this publishing mimics an unmanned aerial vehicle (uav) executing the flight recorded in the tlog.
load mavlink tlog
create a mavlinkdialect
object using the "common.xml"
dialect. use mavlinktlog
with this dialect to load the tlog data.
dialect = mavlinkdialect('common.xml'); logimport = mavlinktlog('mavlink_flightlog.tlog',dialect);
extract the gps messages from the tlog and visualize them using geoplot
.
msgs = readmsg(logimport, 'messagename', 'gps_raw_int', ... 'time',[0 100]); latlon = msgs.messages{1}; % filter out zero-valued messages latlon = latlon(latlon.lat ~= 0 & latlon.lon ~= 0, :); figure() geoplot(double(latlon.lat)/1e7, double(latlon.lon)/1e7);
extract the attitude messages from the tlog. specify the message name for attitude messages. plot the roll, pitch, yaw data using stackedplot
.
msgs = readmsg(logimport,'messagename','attitude','time',[0 100]); figure() stackedplot(msgs.messages{1},{'roll','pitch','yaw'});
play back mavlink log entries
create a mavlink communication interface and publish the messages from the tlog to user defined udp port. create a sender and receiver for passing the mavlink messages. this communication system works the same way that real hardware would publish messages using the mavlink communication protocols.
sender = mavlinkio(dialect,'systemid',1,'componentid',1,... 'autopilottype',"mav_autopilot_generic",... 'componenttype',"mav_type_quadrotor"); connect(sender,'udp'); destinationport = 14550; destinationhost = '127.0.0.1'; receiver = mavlinkio(dialect); connect(receiver,'udp','localport',destinationport); subscriber = mavlinksub(receiver,'attitude','newmessagefcn',@(~,msg)disp(msg.payload));
send the first 100 messages at a rate of 50 hz.
payloads = table2struct(msgs.messages{1}); attitudedefinition = msginfo(dialect, 'attitude'); for msgidx = 1:100 sendudpmsg(sender,struct('msgid', attitudedefinition.messageid, 'payload', payloads(msgidx)),destinationhost,destinationport); pause(1/50); end
disconnect from both mavlink communication interfaces.
disconnect(receiver) disconnect(sender)