How can I receive a Mavlink message through a UDP connection and read it separately and perform convert on it?
Show older comments
I have written the following codes to monitor gimbal variables for UAV through Mavlink codes in MATLAB:
dialect = mavlinkdialect('common.xml');
sender = mavlinkio(dialect,'SystemID',1,'ComponentID',1,...
'AutopilotType',"MAV_AUTOPILOT_GENERIC",...
'ComponentType',"MAV_TYPE_FIXED_WING");
connect(sender,'UDP');
destinationPort = 14551;
destinationHost = '127.0.0.1';
receiver = mavlinkio(dialect);
connect(receiver,'UDP','LocalPort',destinationPort);
info = msginfo(dialect,"GIMBAL_DEVICE_ATTITUDE_STATUS");
msg = createmsg(dialect,info.MessageName);
info.Fields{:};
subscriber = mavlinksub(receiver,'GIMBAL_DEVICE_ATTITUDE_STATUS',...
'NewMessageFcn',@(~,msg)disp(msg.Payload));
for msgIdx = 1:10
sendudpmsg(sender,msg,destinationHost,destinationPort);
pause(1/50);
end
--------- But how can I show only 'q' in the command window?
Because I want to convert it to Euler angles = quat2eul(q)
Answers (1)
Jianxin Sun
on 11 Jan 2023
You'll need to create a function to process the payload:
subscriber = mavlinksub(receiver,'GIMBAL_DEVICE_ATTITUDE_STATUS',...
'NewMessageFcn',@(~,msg)handleGimbalPayload(msg.Payload));
function handleGimbalPayload(payload)
q = payload.q;
ypr = quat2eul(q);
end
Categories
Find more on MAVLink Support in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!