Professional Documents
Culture Documents
Communication-Via-Udp?s - Tid Answers - rc2-2 - p5 - MLT: Sample Fumctions: Msfun - Realtime - Elapsed (Block)
Communication-Via-Udp?s - Tid Answers - rc2-2 - p5 - MLT: Sample Fumctions: Msfun - Realtime - Elapsed (Block)
Plane10. This can be used to test control designs, that are implemented in
MATLAB/Simulink, in a flight simulator, specifically X-Plane 10.
It is tested successfully on both Mac OS 10.8 and Windows platforms.
Three files are included:
1- Setup model: sends commands to x-plane via UDP to choose/tell what data x-plane
10 should spit out. You can choose as many data indices as available in the 'Data Input
& Output' tab in x-plane 10.
2- Send model: Sends commands to control surfaces only via UDP.
3- Get model: receives data that was chosen by the 'setup model' from x-plane 10These
Simulink models allow communication between MATLAB/Simulink and X-Plane10. This
can be used to test control designs, that are implemented in MATLAB/Simulink, in a
flight simulator, specifically X-Plane 10.
1- Setup model: sends commands to x-plane via UDP to choose/tell what data x-plane
10 should spit out. You can choose as many data indices as available in the 'Data Input
& Output' tab in x-plane 10.
3- Get model: receives data that was chosen by the 'setup model' from x-plane 10
https://www.mathworks.com/matlabcentral/fileexchange/47144-simulink-xplane10-
communication-via-udp?s_tid=answers_rc2-2_p5_MLT
Sample Fumctions:
msfun_realtime_elapsed(block):
function msfun_realtime_elapsed(block)
% Help for Writing Level-2 M-File S-Functions:
% web([docroot '/toolbox/simulink/sfg/f7-67622.html']
% http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/sfg/f7-67622.html
% Copyright 2009, The MathWorks, Inc.
% instance variables
myRealTimeBaseline = 0;
setup(block);
%% ---------------------------------------------------
function setup(block)
% Register the number of ports.
block.NumInputPorts = 0;
block.NumOutputPorts = 1;
block.SetPreCompOutPortInfoToDynamic;
block.OutputPort(1).Dimensions = 1;
block.OutputPort(1).SamplingMode = 'sample';
%%
function Start(block) %#ok<INUSD>
myRealTimeBaseline = tic;
end
%%
function Output(block)
block.OutputPort(1).Data = toc(myRealTimeBaseline);
end
%%
function SimStatusChange(block, status) %#ok<INUSL>
if status == 1, % resume
myRealTimeBaseline = tic;
end
end
end