-
Notifications
You must be signed in to change notification settings - Fork 2
/
NEBackwards.m
77 lines (51 loc) · 1.9 KB
/
NEBackwards.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
function tau = NEBackwards(N,m,I,mm,Im,kri,q,qd,qdd,fv,fc,W,Wd,Wmd,Pcdd,Rij,Rici,Rot)
%% backwards
z0 = [0;0;1];
prev_f = zeros(3,1);
prev_u = zeros(3,1);
curr_f = zeros(3,1);
curr_u = zeros(3,1);
F = {};
U = {};
zm = z0;
tau = zeros(N,1);
constructS = @(v) [0 -v(3) v(2);
v(3) 0 -v(1);
-v(2) v(1) 0];
qd(N+1) = 0;
qdd(N+1) = 0;
for i = (N:-1:1),
if( i == N )
R = eye(3,3);
else
R = rotz(q(i+1));
end
Rt = Rot{i};
Rt = Rt';
pcdd = Pcdd{i};
rij = Rij{i};
rici = Rici{i};
w = W{i};
wd = Wd{i};
wmd = Wmd{i};
%% Force. Equation 7.112 (Siciliano)
curr_f = R*prev_f + m*pcdd;
%Skewed symmetric matrix
S = constructS(rici);
%% Link inertia tensor. Steiner Theorem, equation 7.60 (Siciliano)
I_tensor = eye(3,3)*I;% + m*((S')*S);
% The rotor is localised in the COM
S = constructS(rici);
% I'm assuming the motor is positioned at the origin.
Im_tensor = eye(3,3)*Im; %+ mm*((S')*S);
%% Equation 7.113 (Siciliano). Depending on the book edition there might be a typo error with a double cross(w,I_tensor*w)
curr_u = cross(-curr_f,rij+rici) + R*prev_u + cross(R*prev_f,rici) ...
+ I_tensor*wd + cross(w,I_tensor*w) ...
+ kri*qdd(i+1)*(Im_tensor*zm) + kri*qd(i+1)*(cross(Im_tensor*w,zm)); % The final result doesn't agree with Siciliano's derivation for a 2-link robot arm if you don't comment this line
%There seems to be some kind of typo error in the line above.
%I didn't have time to prove it, though.
%% Equation 7.114 for a revolute joint (Siciliano)
tau(i) = curr_u'*(Rt*z0) + kri*(Im_tensor*wmd)'*zm + fv*qd(i) + fc*sign(qd(i));
prev_f = curr_f;
prev_u = curr_u;
end