Error when using Matlab Function block in Simechanics (nested functions and parsing of Matlab function both error).
4 次查看(过去 30 天)
显示 更早的评论
Hello, I create a simple simulink model using Matlab Function block to calculate angles of 4 dof robotic arm using Robotic toolbox Matlab while input is x, y and z values. I used forward kinematics to calculate angles. Model and error is shown in below images:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/161876/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/161877/image.png)
My code is given below:
function [theta1,theta2,theta3,theta4]=invkin(px,py,pz)
% code to find inverse kinematics solution for 4 dof rootic arm
%preach = [0.2539 -0.1282 0.49985]; % reach point of end-effector
theta1 = 0; theta2 = 0; theta3 = 0; theta4 = 0;
% create links using D-H parameters
L(1) = Link([ 0 0 0 pi/2 0], 'standard');
L(2) = Link([ 0 .15005 .4318 0 0], 'standard');
L(3) = Link([0 .0203 0 -pi/2 0], 'standard');
L(4) = Link([0 .4318 0 pi/2 0], 'standard');
%define link mass
L(1).m = 4.43;
L(2).m = 10.2;
L(3).m = 4.8;
L(4).m = 1.18;
%define center of gravity
L(1).r = [ 0 0 -0.08];
L(2).r = [ -0.216 0 0.026];
L(3).r = [ 0 0 0.216];
L(4).r = [ 0 0.02 0];
%define link inertial as a 6-element vector
%interpreted in the order of [Ixx Iyy Izz Ixy Iyz Ixz]
L(1).I = [ 0.195 0.195 0.026 0 0 0];
L(2).I = [ 0.588 1.886 1.470 0 0 0];
L(3).I = [ 0.324 0.324 0.017 0 0 0];
L(4).I = [ 3.83e-3 2.5e-3 3.83e-3 0 0 0];
% set limits for joints
L(1).qlim=[deg2rad(-160) deg2rad(160)];
L(2).qlim=[deg2rad(-125) deg2rad(125)];
L(3).qlim=[deg2rad(-270) deg2rad(90)];
L(4).qlim=[deg2rad(-170) deg2rad(110)];
%build the robot model
rob = SerialLink(L, 'name','Puma56');
qready = [0 -pi/4 pi/4 0]; % initial position of robot
T1= transl(preach); % convert of reach point of 4x4 homogenous matrix
[qreach,err,exitflag] = rob.ikcon(T1, qready); % find inverse kinematics with error
%rob.fkine(qreach);
theta1 = qreach(1,1); theta2 = qreach(1,2); theta3 = qreach(1,3); theta4 = qreach(1,4);
end
How to solve these errors. Thanks.
0 个评论
回答(2 个)
qian yang
2018-9-19
Hi, have you solved this issue? I met the same error. And I wonder whether it is possible to use robotic toolbox in simulink.
Thanks.
0 个评论
Walter Roberson
2017-3-19
"Nested functions are not supported" is what you need to pay attention to here.
However, https://www.mathworks.com/help/simulink/ug/code-generation-for-nested-functions.html says that nested calls can be supported.
I saw a hint a month or so ago that might help: instead of having the nested functions directly in the MATLAB Function Block, have the MATLAB Function block call other code that has the nested functions.
2 个评论
Walter Roberson
2017-3-20
Sorry, I do not know what the difficulty is. I recommend that you contact Mathworks Support for this.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Publishers and Subscribers 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!