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?
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)
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));