forked from s-kajita/IntroductionToHumanoidRobotics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInverseDynamics.m
More file actions
32 lines (26 loc) · 917 Bytes
/
InverseDynamics.m
File metadata and controls
32 lines (26 loc) · 917 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
function [f,t] = InverseDynamics(j)
global uLINK
if j == 0
f=[0,0,0]';
t=[0,0,0]';
return;
end
c = uLINK(j).R * uLINK(j).c + uLINK(j).p; % center of mass
I = uLINK(j).R * uLINK(j).I * uLINK(j).R'; % inertia in world frame
c_hat = hat(c);
I = I + uLINK(j).m * c_hat * c_hat';
P = uLINK(j).m * (uLINK(j).vo + cross(uLINK(j).w,c)); % linear momentum
L = uLINK(j).m * cross(c,uLINK(j).vo) + I * uLINK(j).w; % angular momentum
f0 = uLINK(j).m * (uLINK(j).dvo + cross(uLINK(j).dw,c)) + cross(uLINK(j).w,P);
t0 = uLINK(j).m * cross(c,uLINK(j).dvo) + I * uLINK(j).dw + cross(uLINK(j).vo,P) + cross(uLINK(j).w,L);
% from child link
[f1,t1] = InverseDynamics(uLINK(j).child);
f = f0 + f1;
t = t0 + t1;
if j ~= 1
uLINK(j).u = uLINK(j).hv' * f + uLINK(j).hw' * t; % joint driving force
end
% return force to mother, with sisters
[f2,t2] = InverseDynamics(uLINK(j).sister);
f = f + f2;
t = t + t2;