Home > arte3.2.0 > robots > KUKA > KR6_2 > inversekinematic_kuka_kr6_2.m

inversekinematic_kuka_kr6_2

PURPOSE ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS ^

function q = inversekinematic_kuka_kr6_2(robot, T)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   Q = INVERSEKINEMATIC_KUKA_KR6_2(robot, T)    
   Solves the inverse kinematic problem for the KUKA KR6_2 robot
   where:
   robot stores the robot parameters.
   T is an homogeneous transform that specifies the position/orientation
   of the end effector.

   A call to Q=INVERSEKINEMATIC__KUKA_KR6_2 returns 8 possible solutions, thus,
   Q is a 6x8 matrix where each column stores 6 feasible joint values.

   
   Example code:

   robot=load_robot('kuka', 'KR6_2');
   q = [0 0 0 0 0 0];    
   T = directkinematic(robot, q);
   %Call the inversekinematic for this robot
   qinv = inversekinematic(robot, T);
   check that all of them are feasible solutions!
   and every Ti equals T
   for i=1:8,
        Ti = directkinematic(robot, qinv(:,i))
   end
    See also DIRECTKINEMATIC.
   Author: C.Escoto, E.Leon, V. Martinez & L. Mijares
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0002 %   Q = INVERSEKINEMATIC_KUKA_KR6_2(robot, T)
0003 %   Solves the inverse kinematic problem for the KUKA KR6_2 robot
0004 %   where:
0005 %   robot stores the robot parameters.
0006 %   T is an homogeneous transform that specifies the position/orientation
0007 %   of the end effector.
0008 %
0009 %   A call to Q=INVERSEKINEMATIC__KUKA_KR6_2 returns 8 possible solutions, thus,
0010 %   Q is a 6x8 matrix where each column stores 6 feasible joint values.
0011 %
0012 %
0013 %   Example code:
0014 %
0015 %   robot=load_robot('kuka', 'KR6_2');
0016 %   q = [0 0 0 0 0 0];
0017 %   T = directkinematic(robot, q);
0018 %   %Call the inversekinematic for this robot
0019 %   qinv = inversekinematic(robot, T);
0020 %   check that all of them are feasible solutions!
0021 %   and every Ti equals T
0022 %   for i=1:8,
0023 %        Ti = directkinematic(robot, qinv(:,i))
0024 %   end
0025 %    See also DIRECTKINEMATIC.
0026 %   Author: C.Escoto, E.Leon, V. Martinez & L. Mijares
0027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0028 
0029 
0030 % Copyright (C) 2012, by Arturo Gil Aparicio
0031 %
0032 % This file is part of ARTE (A Robotics Toolbox for Education).
0033 %
0034 % ARTE is free software: you can redistribute it and/or modify
0035 % it under the terms of the GNU Lesser General Public License as published by
0036 % the Free Software Foundation, either version 3 of the License, or
0037 % (at your option) any later version.
0038 %
0039 % ARTE is distributed in the hope that it will be useful,
0040 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0041 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0042 % GNU Lesser General Public License for more details.
0043 %
0044 % You should have received a copy of the GNU Leser General Public License
0045 % along with ARTE.  If not, see <http://www.gnu.org/licenses/>.
0046 function q = inversekinematic_kuka_kr6_2(robot, T)
0047 
0048 %initialize q,
0049 %eight possible solutions are generally feasible
0050 q=zeros(6,8);
0051 
0052 % %Evaluate the parameters
0053 % theta = eval(robot.DH.theta);
0054 d = eval(robot.DH.d);
0055 L6=abs(d(6));
0056 
0057 
0058 %T= [ nx ox ax Px;
0059 %     ny oy ay Py;
0060 %     nz oz az Pz];
0061 Px=T(1,4);
0062 Py=T(2,4);
0063 Pz=T(3,4);
0064 
0065 %Compute the position of the wrist, being W the Z component of the end effector's system
0066 W = T(1:3,3);
0067 
0068 % Pm: wrist position
0069 Pm = [Px Py Pz]' - L6*W; 
0070 
0071 %first joint, two possible solutions admited:
0072 % if q(1) is a solution, then q(1) + pi is also a solution
0073 q1=atan2(Pm(2), Pm(1));
0074 %q1=atan2(Py, Px);
0075 
0076 
0077 %solve for q2
0078 q2_1=solve_for_theta2(robot, [q1 0 0 0 0 0 0], Pm);
0079 %the other possible solution is q1 + pi
0080 q2_2=solve_for_theta2(robot, [q1+pi 0 0 0 0 0 0], Pm);
0081 
0082 %solve for q3
0083 q3_1=solve_for_theta3(robot, [q1 0 0 0 0 0 0], Pm);
0084 %solver for q3 for both cases
0085 q3_2=solve_for_theta3(robot, [q1+pi 0 0 0 0 0 0], Pm);
0086 
0087 
0088 %the next matrix doubles each column. For each two columns, two different
0089 %configurations for theta4, theta5 and theta6 will be computed. These
0090 %configurations are generally referred as wrist up and wrist down solution
0091 q = [q1         q1         q1        q1       q1+pi   q1+pi   q1+pi   q1+pi;   
0092      q2_1(1)    q2_1(1)    q2_1(2)   q2_1(2)  q2_2(1) q2_2(1) q2_2(2) q2_2(2);
0093      q3_1(1)    q3_1(1)    q3_1(2)   q3_1(2)  q3_2(1) q3_2(1) q3_2(2) q3_2(2);
0094      0          0          0         0         0      0       0       0;
0095      0          0          0         0         0      0       0       0;
0096      0          0          0         0         0      0       0       0];
0097 
0098 %leave only the real part of the solutions
0099 q=real(q);
0100 
0101 %Note that in this robot, the joint q3 has a non-simmetrical range. In this
0102 %case, the joint ranges from 60 deg to -219 deg, thus, the typical normalizing
0103 %step is avoided in this angle (the next line is commented). When solving
0104 %for the orientation, the solutions are normalized to the [-pi, pi] range
0105 %only for the theta4, theta5 and theta6 joints.
0106 
0107 %normalize q to [-pi, pi]
0108 q(1,:) = normalize(q(1,:));
0109 q(2,:) = normalize(q(2,:));
0110 
0111 % solve for the last three joints
0112 % for any of the possible combinations (theta1, theta2, theta3)
0113 for i=1:2:size(q,2),
0114     qtemp = solve_spherical_wrist(robot, q(:,i), T, 1,'geometric'); %wrist up
0115     qtemp(4:6)=normalize(qtemp(4:6));
0116     q(:,i)=qtemp;
0117     
0118     qtemp = solve_spherical_wrist(robot, q(:,i), T, -1, 'geometric'); %wrist down
0119     qtemp(4:6)=normalize(qtemp(4:6));
0120     q(:,i+1)=qtemp;
0121 end
0122 
0123 
0124 
0125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0126 % solve for second joint theta2, two different
0127 % solutions are returned, corresponding
0128 % to elbow up and down solution
0129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0130 function q2 = solve_for_theta2(robot, q, Pm)
0131 
0132 %Evaluate the parameters
0133 theta = eval(robot.DH.theta);
0134 d = eval(robot.DH.d);
0135 a = eval(robot.DH.a);
0136 alpha = eval(robot.DH.alpha);
0137 
0138 %See geometry
0139 L2=abs(a(2));
0140 L3=abs(d(4));
0141 A2 = abs(a(3));
0142 
0143 %See geometry of the robot
0144 %compute L4
0145 L4 = sqrt(A2^2 + L3^2);
0146 
0147 %The inverse kinematic problem can be solved as in the IRB 140 (for example)
0148 
0149 %given q1 is known, compute first DH transformation
0150 T01=dh(robot, q, 1);
0151 
0152 %Express Pm in the reference system 1, for convenience
0153 p1 = inv(T01)*[Pm; 1];
0154 
0155 r = sqrt(p1(1)^2 + p1(2)^2);
0156 
0157 beta = atan2(-p1(2), p1(1));
0158 gamma = real(acos((L2^2+r^2-L4^2)/(2*r*L2)));
0159 
0160 %return two possible solutions
0161 %elbow up and elbow down
0162 %the order here is important and is coordinated with the function
0163 %solve_for_theta3
0164 q2(1) = pi/2 - beta - gamma; %elbow up
0165 q2(2) = pi/2 - beta + gamma; %elbow down
0166 
0167 
0168 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0169 % solve for third joint theta3, two different
0170 % solutions are returned, corresponding
0171 % to elbow up and down solution
0172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0173 function q3 = solve_for_theta3(robot, q, Pm)
0174 
0175 %Evaluate the parameters
0176 d = eval(robot.DH.d);
0177 a = eval(robot.DH.a);
0178 
0179 %See geometry
0180 L2=abs(a(2));
0181 L3=abs(d(4));
0182 
0183 A2 = abs(a(3));
0184 
0185 %See geometry of the robot
0186 %compute L4
0187 L4 = sqrt(A2^2 + L3^2);
0188 
0189 %the angle phi is fixed
0190 phi=acos((A2^2+L4^2-L3^2)/(2*A2*L4));
0191 
0192 %given q1 is known, compute first DH transformation
0193 T01=dh(robot, q, 1);
0194 
0195 %Express Pm in the reference system 1, for convenience
0196 p1 = inv(T01)*[Pm; 1];
0197 
0198 r = sqrt(p1(1)^2 + p1(2)^2);
0199 
0200 eta = real(acos((L2^2 + L4^2 - r^2)/(2*L2*L4)));
0201 
0202 %return two possible solutions
0203 %elbow up and elbow down solutions
0204 %the order here is important
0205 q3(1) =  atan(L3/ A2)-eta;
0206 q3(2) =  atan(L3/ A2)+ eta;
0207 
0208

Generated on Fri 03-Jan-2014 12:20:01 by m2html © 2005