Home > arte3.2.0 > robots > ABB > IRB140 > inversekinematic_irb140.m

inversekinematic_irb140

PURPOSE ^

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

SYNOPSIS ^

function q = inversekinematic_irb140(robot, T)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   Q = INVERSEKINEMATIC_IRB140(robot, T)    
   Solves the inverse kinematic problem for the ABB IRB 140 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_IRB140 returns 8 possible solutions, thus,
   Q is a 6x8 matrix where each column stores 6 feasible joint values.

   
   Example code:

   >>abb=load_robot('ABB', 'IRB140');
   >>q = [0 0 0 0 0 0];    
   >>T = directkinematic(abb, q);

   %Call the inversekinematic for this robot

   >> qinv = inversekinematic(abb, T);

   check that all of them are feasible solutions!
   and every Ti equals T

   for i=1:8,
        Ti = directkinematic(abb, qinv(:,i))
   end

    See also DIRECTKINEMATIC.

   Author: Arturo Gil Aparicio
           Universitas Miguel Hernandez, SPAIN.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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

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