1
$\begingroup$

I'm trying to make a model for a robotic arm on simulink and then excute it on arduino controller but i want also to use robotics toolbox to calculate forward and inverse kinematics so i need to add matlab function in my simulink model i tried it but it keeps giving errors but when i try it away from simulink it gives rsults ! is that because robotics toolbox works only with matlab but not with simulink?

my simulink model

the code in matlab function

 function [theta1, theta2, theta3, theta4] = fcn(x, z, y)


L(1)=Link([0,0.03,0,pi/2,0]);
L(2)=Link([0,0,0.12,0,0]);
L(3)=Link([0,0,0.1,-pi/2,0]);
L(4)=Link([0,0,0,0,0]);
robot = SerialLink(L,'name','robot');

robot.tool=transl(0,0,.08);
robot.base=transl(0,0,.07);


    T=transl(x,y,z);
    q=robot.ikine(T,[0,0,0,0], [1 1 1 0 0 1]);
    q(1)=fix(q(1)*(180/pi));
   q(2)=fix(q(2)*(180/pi));
    q(3)=fix(q(3)*(180/pi));
    q(4)=fix(q(4)*(180/pi));

          theta1=q(1)
    theta2=q(2)
    theta3=q(3)
    theta4=q(4)

errors when excuting

but when i try it in command window away from simulink it gives results for x=1 y=1 z=1 and higher values

   Warning: solution diverging at step 245, try reducing alpha 
 > In SerialLink/ikine (line 260) 
  Warning: solution diverging at step 459, try reducing alpha 
 > In SerialLink/ikine (line 260) 
 Warning: solution diverging at step 533, try reducing alpha 
 > In SerialLink/ikine (line 260) 
 Warning: ikine: iteration limit 1000 exceeded (row 1), final err 1.790820 
 > In SerialLink/ikine (line 179) 

 theta1 =

  -21996


theta2 =

-1050694


theta3 =

 2711696


theta4 =

 2848957

but for x=0.2 y=0.2 z=0.2 it gives that error

      .
      .
      .
      .
> In SerialLink/ikine (line 260) 
Warning: solution diverging at step 567, try reducing alpha 
> In SerialLink/ikine (line 260) 
Warning: solution diverging at step 570, try reducing alpha 
> In SerialLink/ikine (line 260) 
Warning: solution diverging at step 574, try reducing alpha 
> In SerialLink/ikine (line 260) 
Warning: solution diverging at step 578, try reducing alpha 
> In SerialLink/ikine (line 260) 
Error using tr2angvec (line 97)
matrix not orthonormal rotation matrix

Error in SerialLink/ikine (line 191)
        [th,n] = tr2angvec(Rq'*t2r(T));
$\endgroup$
3
$\begingroup$

The MATLAB function block in Simulink has some limitations. The fact that Link.m is referred to as a function not a class is a worry. I recreated your Simulink model and get similar error messages, basically Simulink can't convert these classes into C code which it needs to do in order to run the simulation. You could try putting all your code into a standalone m-file and then calling that from an "Interpreted MATLAB Fcn" block or writing an S-function.

It looks like you are using a very old version of the Robotics Toolbox which is clearly not converging on an IK solution. The one in RTB10.x is much better.

$\endgroup$
3
$\begingroup$

You appear to be using a third-party toolbox, the Robotics Toolbox. If it's not running in Simulink, then it might not run in Simulink. If you want something that does, try the official toolbox. Mathworks generally offers trials of all their toolboxes.

Your first error, "Simulink does not have enough information to determine the output size of this block," can typically be solved by initializing the variables before assignment and/or by setting their size in the properties menu for the function block (as opposed to leaving it set as "inherited").

That said, I'd like to point out that your results are not correct and you are get a lot of bad warnings that you seem to be ignoring when you show that it "works" when you're not using Simulink.

Diverging solutions mean something is wrong, iteration limits being exceeded mean something is wrong, and did you even look at the numbers you were given?

What does it mean to you when the output you're getting is something like theta4 = 2848957?? Does 2.8 million radians (or even degrees) seem like a quality answer?

If you really need to use this toolbox with Simulink then at least make sure you're using it correctly and getting correct answers first before you try to port to Simulink.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.