Error when using Matlab Function block in Simechanics (nested functions and parsing of Matlab function both error).
조회 수: 1 (최근 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:
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에서 Robotics에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!