-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamics.m
62 lines (40 loc) · 1.22 KB
/
dynamics.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
function ret = dynamics(t,x,robotObj)
t
ndof = robotObj.ndof;
nAct = robotObj.nAct;
nBaseDof = robotObj.nBaseDof;
q = x(1:ndof);
qdot = x(ndof+1:end);
D_mat = D(x);
C_mat = C(x);
G_vec = G(x)';
J = Jfoot(x);
Jdot = Jdot_foot(x);
B =[zeros(nBaseDof,nAct);eye(nAct)];
Xi = inv(J * inv(D_mat) * J');
H = C_mat * qdot + G_vec;
% Writing the contact wrench in the form F = alpha + gamma * u
alpha = (J * inv(D_mat) * H - Jdot * qdot);
gamma = -J * inv(D_mat);
%f = [qdot ; -inv(D_mat) * H + J' * Xi * alpha];
%g = [zeros(size(B)) ; inv(D_mat)*(eye(size(D_mat)) - J' * Xi * gamma) * B];
%%%%
f = [qdot; D_mat \ ((J'*Xi*J*inv(D_mat) - eye(size(D_mat)))*H...
-J'*Xi*Jdot*qdot)];
g = [zeros(size(B)); D_mat \ (eye(size(D_mat)) - ...
J'*Xi*J*inv(D_mat))*B];
%%%%
mag = 0.3;
yd = mag*cos(t);
yd_dot = [0;0;0;0;0;0;-mag*sin(t);0;0];
jOutputs = [J;JCoM(x)];
qd_dot = pinv(jOutputs,1e-2)*yd_dot;
%qd = q + 0.05 * qd_dot;
uff = control(x,t,D_mat,C_mat,G_vec,J,ndof,nAct,nBaseDof,1);
%Kd = [20,0,0;0,20,0;0,0,2];
%Kp = [80,0,0;0,80,0;0,0,5];
%ufb = Kd * (qdot(nBaseDof+1:end) - qd_dot(nBaseDof+1:end));% + Kp * (q(nBaseDof+1:end) - qd(nBaseDof+1:end));
ufb = zeros(nAct,1);
u = uff + ufb;
ret = f + g * u;
endfunction