2024-01-23 13:42:25 +00:00
|
|
|
function robot = get_Kinematics(robot, opt)
|
|
|
|
|
if(opt.Isreal)
|
|
|
|
|
switch opt.KM_method
|
2024-09-28 13:45:14 +00:00
|
|
|
case 'SCREW'
|
|
|
|
|
thetalist = robot.theta;
|
|
|
|
|
Slist = robot.slist;
|
|
|
|
|
% TODO:move to lib
|
|
|
|
|
for j = 1:length(thetalist)
|
|
|
|
|
T=robot.Home.M(:,:,j);
|
|
|
|
|
for i = j: -1: 1
|
|
|
|
|
T = MatrixExp6(VecTose3(Slist(:, i) * thetalist(i))) * T;
|
|
|
|
|
end
|
|
|
|
|
robot.TW(:,:,j) = T;
|
|
|
|
|
end
|
2024-09-28 17:22:41 +00:00
|
|
|
for i = 1:length(thetalist)
|
2024-09-28 13:45:14 +00:00
|
|
|
if i == 1
|
|
|
|
|
robot.T(:,:,i) = robot.TW(:,:,i);
|
|
|
|
|
else
|
|
|
|
|
robot.T(:,:,i) = TransInv(robot.TW(:,:,i-1))*robot.TW(:,:,i);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
robot.Fkine = robot.TW(:,:,end);
|
2024-01-23 13:42:25 +00:00
|
|
|
case 'SDH'
|
|
|
|
|
theta = robot.theta;
|
|
|
|
|
alpha = robot.alpha;
|
|
|
|
|
a = robot.a;
|
|
|
|
|
d = robot.d;
|
|
|
|
|
robot.Fkine = eye(4,4);
|
|
|
|
|
ndof = length(theta); % special for MDH
|
|
|
|
|
% init transform matrix
|
|
|
|
|
robot.R = zeros([3,3,ndof]);
|
|
|
|
|
robot.t = zeros([3,1,ndof]);
|
|
|
|
|
robot.T = zeros([4,4,ndof]);
|
|
|
|
|
for i = 1:ndof
|
|
|
|
|
robot.R(:,:,i) = [cos(theta(i)) -sin(theta(i))*cos(alpha(i)) sin(theta(i))*sin(alpha(i));...
|
|
|
|
|
sin(theta(i)) cos(theta(i))*cos(alpha(i)) -cos(theta(i))*sin(alpha(i));...
|
|
|
|
|
0 sin(alpha(i)) cos(alpha(i))];
|
|
|
|
|
robot.t(:,:,i) = [a(i)*cos(theta(i));a(i)*sin(theta(i));d(i)];
|
|
|
|
|
Transform = eye(4,4);
|
|
|
|
|
Transform(1:3,1:3) = robot.R(:,:,i);
|
|
|
|
|
Transform(1:3,4) = robot.t(:,:,i);
|
|
|
|
|
robot.T(:,:,i) = Transform;
|
|
|
|
|
robot.Fkine = robot.Fkine*robot.T(:,:,i);
|
|
|
|
|
end
|
|
|
|
|
case 'MDH'
|
|
|
|
|
theta = robot.theta;
|
|
|
|
|
alpha = robot.alpha;
|
|
|
|
|
a = robot.a;
|
|
|
|
|
d = robot.d;
|
|
|
|
|
robot.Fkine = eye(4,4);
|
|
|
|
|
ndof = length(theta); % special for MDH
|
|
|
|
|
% init transform matrix
|
|
|
|
|
robot.R = zeros([3,3,ndof]);
|
|
|
|
|
robot.t = zeros([3,1,ndof]);
|
|
|
|
|
robot.T = zeros([4,4,ndof]);
|
|
|
|
|
for i = 1:ndof
|
|
|
|
|
robot.R(:,:,i) = [cos(theta(i)) -sin(theta(i)) 0;...
|
|
|
|
|
sin(theta(i))*cos(alpha(i)) cos(theta(i))*cos(alpha(i)) -sin(alpha(i));...
|
|
|
|
|
sin(theta(i))*sin(alpha(i)) cos(theta(i))*sin(alpha(i)) cos(alpha(i))];
|
|
|
|
|
robot.t(:,:,i) = [a(i);-d(i)*sin(alpha(i));d(i)*cos(alpha(i))];
|
|
|
|
|
Transform = eye(4,4);
|
|
|
|
|
Transform(1:3,1:3) = robot.R(:,:,i);
|
|
|
|
|
Transform(1:3,4) = robot.t(:,:,i);
|
|
|
|
|
robot.T(:,:,i) = Transform;
|
|
|
|
|
robot.Fkine = robot.Fkine*robot.T(:,:,i);
|
|
|
|
|
end
|
|
|
|
|
otherwise
|
|
|
|
|
disp('Bad opt.KM_method!')
|
|
|
|
|
return;
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
switch opt.KM_method
|
|
|
|
|
case 'SDH'
|
|
|
|
|
case 'MDH'
|
|
|
|
|
theta = robot.theta;
|
|
|
|
|
alpha = robot.alpha;
|
|
|
|
|
a = robot.a;
|
|
|
|
|
d = robot.d;
|
|
|
|
|
robot.Fkine = eye(4,4);
|
|
|
|
|
ndof = length(theta); % special for MDH
|
|
|
|
|
% init transform matrix
|
|
|
|
|
robot.R = sym(zeros([3,3,ndof]));
|
|
|
|
|
robot.t = sym(zeros([3,1,ndof]));
|
|
|
|
|
robot.T = sym(zeros([4,4,ndof]));
|
|
|
|
|
for i = 1:ndof
|
|
|
|
|
robot.R(:,:,i) = [cos(theta(i)) -sin(theta(i)) 0;...
|
|
|
|
|
sin(theta(i))*cos(alpha(i)) cos(theta(i))*cos(alpha(i)) -sin(alpha(i));...
|
|
|
|
|
sin(theta(i))*sin(alpha(i)) cos(theta(i))*sin(alpha(i)) cos(alpha(i))];
|
|
|
|
|
robot.t(:,:,i) = [a(i);-d(i)*sin(alpha(i));d(i)*cos(alpha(i))];
|
|
|
|
|
Transform = sym(eye(4,4));
|
|
|
|
|
Transform(1:3,1:3) = robot.R(:,:,i);
|
|
|
|
|
Transform(1:3,4) = robot.t(:,:,i);
|
|
|
|
|
robot.T(:,:,i) = Transform;
|
|
|
|
|
robot.Fkine = robot.Fkine*robot.T(:,:,i);
|
|
|
|
|
end
|
|
|
|
|
otherwise
|
|
|
|
|
disp('Bad opt.KM_method!')
|
|
|
|
|
return;
|
|
|
|
|
end
|
|
|
|
|
end
|