-1

I convert my .m file above as a function like below , my input is nothing and my output is q. But I have a problem. When I put my created function block to the simulink and connect to the display screen , matlab gives me some errors like;

*Try and catch are not supported for code generation. Function 'tb_optparse.m' (#80.5667.6083), line 157, column 25: "try" Launch diagnostic report.*

Function call failed. Function 'MATLAB Function' (#94.848.897), line 37, column 3: "mstraj(path, [15 15 15], [], [1 0 1], 0.02 , 0.2)" Launch diagnostic report.

Errors occurred during parsing of MATLAB function 'MATLAB Function'(#93)

How can I fix these errors? Thanks

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;
DMD
  • 43
  • 2
  • 7

1 Answers1

0

Well as the error message says, it looks like your function mstraj is calling try/catch which isn't supported for code generation (MATLAB functions in Simulink are first converted to C code when you run the model).

Have a look at Call MATLAB Functions in the documentation for ways to work around this using coder.extrinsic. Extrinsic functions return data of type mxArray so you will need to convert it to whatever the data type of p (see Converting mxArrays to Known Types in the documentation page above).

In you case, it would probably look something like:

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...
am304
  • 13,758
  • 2
  • 22
  • 40