How can I receive a Mavlink message through a UDP connection and read it separately and perform convert on it?

8 visualizaciones (últimos 30 días)
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)

Respuestas (1)

Jianxin Sun
Jianxin Sun el 11 de En. de 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

Productos


Versión

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by