How to generate a function which can give the transformation matrix for given DH parameters?
Show older comments
I want to generate a function which can give transformation matrix for given DH parameters. The cache is the function should valid for any number of links. It means number of links are variable. Like if I want take 4 ,5 or6 any no of links it should take dh parameters for all the links and should give the final transformation matrix.
Accepted Answer
More Answers (1)
Pushpendra Gupta
on 22 Jul 2019
Edited: Pushpendra Gupta
on 26 Dec 2021
syms L1 L2 L3 L4 L5 Q1 Q2 Q3 Q4 Q5
alphaa = [0,0,-90,0,+90]; % this is the alpha value for all the link
a=[L1,L2, L3, L4, L5]; % Length of the Link
d=[0,0,0,0,0]; %Offset
Q=[Q1,Q2,Q3,Q4,Q5]; % joint angle variation
%% Transformation Matrices
for i = 1:5
switch i
case 1
T01= [cos(Q(1,i)),-sin(Q(1,i))*cosd(alphaa(1,i)),sind(alphaa(1,i))*sin(Q(1,i)),a(1,i)*cos(Q(1,i));sin(Q(1,i)),cos(Q(1,i)).*cosd(alphaa(1,i)),-sind(alphaa(1,i))*cos(Q(1,i)),sin(Q(1,i))*a(1,i);0,sind(alphaa(1,i)),cosd(alphaa(1,i)),d(1,i);0,0,0,1];
case 2
T12= [cos(Q(1,i)),-sin(Q(1,i))*cosd(alphaa(1,i)),sind(alphaa(1,i))*sin(Q(1,i)),a(1,i)*cos(Q(1,i));sin(Q(1,i)),cos(Q(1,i)).*cosd(alphaa(1,i)),-sind(alphaa(1,i))*cos(Q(1,i)),sin(Q(1,i))*a(1,i);0,sind(alphaa(1,i)),cosd(alphaa(1,i)),d(1,i);0,0,0,1];
case 3
T23= [cos(Q(1,i)),-sin(Q(1,i))*cosd(alphaa(1,i)),sind(alphaa(1,i))*sin(Q(1,i)),a(1,i)*cos(Q(1,i));sin(Q(1,i)),cos(Q(1,i)).*cosd(alphaa(1,i)),-sind(alphaa(1,i))*cos(Q(1,i)),sin(Q(1,i))*a(1,i);0,sind(alphaa(1,i)),cosd(alphaa(1,i)),d(1,i);0,0,0,1];
case 4
T34= [cos(Q(1,i)),-sin(Q(1,i))*cosd(alphaa(1,i)),sind(alphaa(1,i))*sin(Q(1,i)),a(1,i)*cos(Q(1,i));sin(Q(1,i)),cos(Q(1,i)).*cosd(alphaa(1,i)),-sind(alphaa(1,i))*cos(Q(1,i)),sin(Q(1,i))*a(1,i);0,sind(alphaa(1,i)),cosd(alphaa(1,i)),d(1,i);0,0,0,1];
case 5
T45= [cos(Q(1,i)),-sin(Q(1,i))*cosd(alphaa(1,i)),sind(alphaa(1,i))*sin(Q(1,i)),a(1,i)*cos(Q(1,i));sin(Q(1,i)),cos(Q(1,i)).*cosd(alphaa(1,i)),-sind(alphaa(1,i))*cos(Q(1,i)),sin(Q(1,i))*a(1,i);0,sind(alphaa(1,i)),cosd(alphaa(1,i)),d(1,i);0,0,0,1];
end
end
T01 % First Link with respect to base
T02 = T01*T12 % Second Link with respect to base
%% You can simplify it too
simplify(T02)
%% you can find the position and Orientation of 5th Link with respect to Base Link using
T05 = T01*T12*T23*T34*T45;
simplify(T05)
This is for symbolic form in case of numeric evaluation use makehgtform
Categories
Find more on Manipulator Modeling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



