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 (which is put in matlab funcrion block):
function [theta1,theta2,theta3,theta4]=invkin(px,py,pz)
% code to find inverse kinematics solution for 4 dof rootic arm
preach = [px py pz]; % 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.