将现有的.m文件集成到.mdl simulink中

时间:2014-01-11 11:02:38

标签: matlab simulink robotics

我将上面的.m文件转换为下面的函数,我的输入是什么,我的输出是q。但我有一个问题。当我将创建的功能块放到simulink并连接到显示屏时,matlab给了我一些错误,如;

* 代码生成不支持Try和catch。 函数'tb_optparse.m'(#80.5667.6083),第157行,第25列: “尝试” 启动诊断报告。*

函数调用失败。 功能'MATLAB功能'(#94.848.897),第37行,第3栏: “mstraj(路径,[15 15 15],[],[1 0 1],0.02,0.2)” 启动诊断报告。

解析MATLAB函数'MATLAB函数'(#93)时出错

如何修复这些错误?感谢

function output = fcn()


%mdl_puma560    %to create puma robot

for type=1:3  % main for loop. It turns 3 times. At first, it sets the path
    %           to x-y plane and draw the robot, at second for y-z plane
    %           and then for x-z plane

  if type==1 

% The path of robot for x-y plane    
path=[0 0 1;0 0 0;0 2 0 ;0.5 1 0 ;1 2 0;1 0 0;1.5 0 1;1.5 0 0;
      1.5 2 0;2.2 2 0;2.5 1.6 0;2.5 0.4 0;2.2 0 0;1.5 0 0;0 0 1];


 elseif type==2   

% Same thing as first part    
path=[-0.5 0 0;0 0 0;0 0 1;0 -0.5 0.5;0 -1 1;0 -1 0;-0.5 -1.2 0;0 -1.2 0;
    0 -1.2 1;0 -1.7 1;0 -2 0.7;0 -2 0.3;0 -1.7 0;0 -1.2 0];


 elseif type==3

 % Same thing as first and second part     
path=[0 -0.5 0;0 0 0;0 0 1;0.5 0 0.5;1 0 1;1 0 0;1.3 -0.5 0;1.3 0 0;
    1.3 0 1;1.7 0 1;2 0 0.7;2 0 0.3;1.7 0 0;1.3 0 0];


  end



% I created a trajectory

p=mstraj(path, [15 15 15], [], [1 0 1], 0.02 , 0.2);

% [15 15 15] means the maximum speed in x,y,z directions.
% [1 0 1] means the initial coordinates
% 0.02 means acceleration time
% 0.2 means smoothness of robot


numrows(p)*0.2;    % 200 ms sample interval
Tp=transl(0.1*p);  % Scale factor of robot
Tp=homtrans( transl(0.4,0,0),Tp);  % Origin of the letter
q=p560.ikine6s(Tp) ;  % The inverse kinematic


% for i=1:length(q)
% %q matrix has 280 rows and 6 columns. So this for loop turns 280 times
% % At every turns , it plots one part of movement. q(1,:), q(2,:), ...  
% 
%     p560.plot(q(i,:))
% 
% end

end

output=q;

1 个答案:

答案 0 :(得分:0)

正如错误消息所示,看起来您的函数mstraj正在调用try/catch,这不支持代码生成(Simulink中的MATLAB函数在运行时首先转换为C代码模型)。

请查看文档中的Call MATLAB Functions,了解使用coder.extrinsic解决此问题的方法。外部函数返回mxArray类型的数据,因此您需要将其转换为p的数据类型(请参阅上面文档页面中的将mxArrays转换为已知类型)。

在你的情况下,它可能看起来像:

function output = fcn()

coder.extrinsic('mstraj');

% etc...

p = 0; % Define p as a scalar of type double (change to required data type if not appropriate)
p=mstraj(path, [15 15 15], [], [1 0 1], 0.02 , 0.2);

% etc...
相关问题