# Problem with inverse kinematics in robotic arm using Matlab

I define my robotic arm with following code

% Link('d', 0.15005, 'a', 0.0203, 'alpha', -pi/2)
L(1) = Link([0  0.15   0    pi/2     0], 'standard');
L(2) = Link([0  0     0.15   0       0], 'standard');
L(3) = Link([0  0     0.15   0       0], 'standard');
L(4) = Link([0  0     0.15   0       0], 'standard');
% set limits for joints
L(1).qlim=[deg2rad(-45) deg2rad(45)];
L(2).qlim=[deg2rad(-45) deg2rad(45)];
L(3).qlim=[deg2rad(-60) deg2rad(60)];
L(4).qlim=[deg2rad(-50) deg2rad(50)];
%build the robot model
rob = SerialLink(L, 'name','rob');
qready = [0 0 0 0]; % initial position of robot


And I solve inverse kinematic and plot robotic arm with code

 Td = transl([0.05 0 -0.20]);
q = rob.ikine(Td, qready,[1 1 1 0 0 0]);
plot(rob,q,'noname');


Its results are 0 -139.0348635 82.65184319 -1.286384217 which is four angles named theta1, theta2, theta3 and theta4 respectively. Now the point is I gave joint limit for theta2 as -45 to 45 degree but result output is -139 degree. Same case with theta3. Why it is so? Another thing is when I plot these angles robotic arm cross each other as shown in figure. I want to know what is wrong with code or I'm missing any thing.

## 1 Answer

In the documentation of the Robotics Toolbox by Peter Corke it is stated that the ikine() method does not regard motion limits. (Notes -> Joint limits are not considered in this solution.)

You can cosider using ikcon() instead.

Solving the inverse kinematics does not guarentee a colision free pose of the robot. That is only guaranteed if a colision check is carried out or if the joint limits are respected (adn set correctly).

Furthermore I would advise to check the exit flag of the method solving the inverse kinematics to make sure that indeed it has found a solution

• Thanks @50k4, When I used ikcon(), angles are within limit but the points I entered and points at which finally end-effector reached is different. I tried to use mask matrix [1 1 1 0 0 0] with ikcon(), but it shows error Error using optimset (line 76) Cannot use OPTIMSET to alter options created using OPTIMOPTIONS. Use OPTIMOPTIONS instead. Error in SerialLink/ikcon (line 92) problem.options = optimset(problem.options, options); How to solve error prolblem using ikcon(). – Naseeb Gill Jan 17 '17 at 8:56