Error when using Matlab Function block in Simechanics (nested functions and parsing of Matlab function both error).

1 vue (au cours des 30 derniers jours)
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.

Réponses (2)

qian yang
qian yang le 19 Sep 2018
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.

Walter Roberson
Walter Roberson le 19 Mar 2017
"Nested functions are not supported" is what you need to pay attention to here.
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 commentaires
Naseeb Gill
Naseeb Gill le 20 Mar 2017
Thanks for reply @Walter Roberson, Can you please explain it little more. I have code which I put in matlab function block (same code I wrote above) but As you see in that code I'm using _ Matlab robotic toolbox by Peter Corke_. In that toolbox, there is one file _ link.m_ , in that mat file a function named * value* is present, due to that function simulink is showing error. I have doubt that wheteher I can used this toolbox in simulink or not. If yes, then how. Thanks.
Walter Roberson
Walter Roberson le 20 Mar 2017
Sorry, I do not know what the difficulty is. I recommend that you contact Mathworks Support for this.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Robotics dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by