-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtform2delta.m
140 lines (129 loc) · 4.01 KB
/
tform2delta.m
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
%tform2delta Convert SE(3) homogeneous transform to differential motion
%
% D = tform2delta(T0, T1) is the differential motion (6x1) corresponding to
% infinitessimal motion (in the T0 frame) from pose T0 to T1 which are homogeneous
% transformations (4x4) or SE3 objects.
%
% The vector D=(dRx, dRy, dRz, dx, dy, dz, ) represents infinitessimal translation
% and rotation, and is an approximation to the instantaneous spatial velocity
% multiplied by time step.
%
% D = tform2delta(T) as above but the motion is from the world frame to the SE3
% pose T.
%
% D = tform2delta(___, "fliptr") will flip the order of the
% translational and rotational components in D. When fliptr is set to true,
% the output vector will be D=(dRx, dRy, dRz, dx, dy, dz)
%
% Notes::
% - D is only an approximation to the motion T, and assumes
% that T0 ~ T1 or T ~ eye(4,4).
% - Can be considered as an approximation to the effect of spatial velocity over a
% a time interval, average spatial velocity multiplied by time.
%
% Reference::
% - Robotics, Vision & Control: Second Edition, P. Corke, Springer 2016; p67.
%
% See also delta2tform, delta2se.
% Copyright 2022-2023 Peter Corke, Witold Jachimczyk, Remo Pillat
function delta = tform2delta(T0, T1, options)
arguments
T0
T1 = []
options.fliptr (1,1) logical = true
end
if isa(T0, 'se3')
T0 = T0.tform;
elseif ~istform(T0)
error('RVC3:tform2delta:badarg', 'T0 should be SE(3) matrix or se3 instance');
end
if isempty(T1)
% SYNTAX: tform2delta(T0, T1)
T1 = T0;
T0 = eye(4,4);
else
% SYNTAX: tform2delta(T0, T1)
if isa(T1, 'se3')
T1 = T1.tform;
elseif ~istform(T1)
error('RVC3:tform2delta:badarg', 'T1 should be SE(3) matrix or se3 instance');
end
end
% compute incremental transformation from T0 to T1 in the T0 frame
TD = inv(T0) * T1; %#ok<MINV>
% build the delta vector
translVec = tform2trvec(TD);
rotVec = skew2vec(tform2rotm(TD) - eye(3,3));
if options.fliptr
% Put rotation first
delta = [rotVec translVec];
else
% Put translation first
delta = [translVec rotVec];
end
% if nargin == 2
% if isnumeric(varargin{1}) || isa(varargin{1}, "se3")
% % SYNTAX: tform2delta(T0, T1)
% B = varargin{1};
%
% T0 = T1;
% if isa(B, 'se3')
% T1 = B.tform;
% elseif all(size(B) == 4)
% T1 = B;
% else
% error('SMTB:tform2delta:badarg', 'T0 should be a homogeneous transformation');
% end
% else
% % SYNTAX: tform2delta(T0, "fliptr")
% flip = convertStringsToChars(varargin{1});
% if strcmp(flip,'fliptr')
% fliptr = true;
% end
% end
% end
%
% if nargin == 3
% % SYNTAX: tform2delta(T0, T1, "fliptr")
% B = varargin{1};
% T0 = T1;
% if isa(B, 'se3')
% T1 = B.tform;
% elseif all(size(B) == 4)
% T1 = B;
% else
% error('SMTB:tform2delta:badarg', 'T0 should be a homogeneous transformation');
% end
%
% flip = convertStringsToChars(varargin{2});
% if strcmp(flip,'fliptr')
% fliptr = true;
% end
% end
%
% % compute incremental transformation from T0 to T1 in the T0 frame
% TD = inv(T0) * T1; %#ok<MINV>
%
% % build the delta vector
% translVec = tform2trvec(TD);
% rotVec = skew2vec(tform2rotm(TD) - eye(3,3));
% if fliptr
% % Put rotation first
% delta = [rotVec translVec];
% else
% % Put translation first
% delta = [translVec rotVec];
% end
% R0 = tform2rotm(T0); R1 = tform2rotm(T1);
% % in world frame
% %[th,vec] = tr2angvec(R1*R0');
% dR = skew2vec(R1*R0');
% %delta = [ (T1(1:3,4)-T0(1:3,4)); th*vec' ];
% delta = [ (T1(1:3,4)-T0(1:3,4)); dR];
% same as above but more complex
% delta = [ T1(1:3,4)-T0(1:3,4);
% 0.5*( cross(T0(1:3,1), T1(1:3,1)) + ...
% cross(T0(1:3,2), T1(1:3,2)) + ...
% cross(T0(1:3,3), T1(1:3,3)) ...
% )];
end