forked from Modi1987/KST-Kuka-Sunrise-Toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateTransform.m
More file actions
39 lines (33 loc) · 802 Bytes
/
updateTransform.m
File metadata and controls
39 lines (33 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function [ Tt ] = updateTransform(T,w,v,dt)
% Copyright Mohammad SAFEEA, 17th-Aug-2017
% This function takes the input of the
normw=norm(w);
if norm(w)>0
c=cos(normw*dt/2);
s=sin(normw*dt/2);
quat=[c,s*w'/normw];
R=T(1:3,1:3);
dR=quat2rot(quat);
Rt=R*dR;
else
Rt=T(1:3,1:3);
end
dx=v*dt;
xt=T(1:3,4)+dx;
Tt=[Rt,xt];
Tt=[Tt;
0 0 0 1];
Tt=normalizeTransformMatrix(Tt);
end
function R=quat2rot(q)
R=[(1-2*q(3)*q(3)-2*q(4)*q(4)), 2*(q(1)*q(3)-q(1)*q(4)), 2*(q(2)*q(4)+q(1)*q(3));
2*(q(2)*q(3)+q(1)*q(4)), (1-2*q(2)*q(2)-2*q(4)*q(4)), 2*(q(3)*q(4)-q(1)*q(2));
2*(q(2)*q(4)-q(1)*q(3)), 2*(q(3)*q(4)+q(1)*q(2)), (1-2*q(2)*q(2)-2*q(3)*q(3))];
end
function T=normalizeTransformMatrix(t)
T=zeros(4,4);
T(:,4)=t(:,4);
for i=1:3
T(1:3,i)=t(1:3,i)/norm(t(1:3,i));
end
end