How can I receive a Mavlink message through a UDP connection and read it separately and perform convert on it?
3 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
回答(1 个)
Jianxin Sun
2023-1-11
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!