|
1 |
| -function [L_d_n, L_dot_d, int_L_ang, x_com_des, s_des_k, s_dot_des_k] = ComputeReferencesController(M,L,desired_pos_vel_COM, joint_pos, joint_pos_desired,joint_vel_desired, L_ang_des,L_d) |
| 1 | +% function [L_d_n, L_dot_d, int_L_ang, x_com_des, s_des_k, s_dot_des_k] = ComputeReferencesController(M,L,desired_pos_vel_COM, joint_pos, joint_pos_desired,joint_vel_desired, L_ang_des,L_d) |
| 2 | + |
| 3 | +% persistent L_0; |
| 4 | +% |
| 5 | +% if(isempty(L_0)) |
| 6 | +% L_0 = L; |
| 7 | +% end |
| 8 | +% |
| 9 | +% persistent joint_pos_0; |
| 10 | +% |
| 11 | +% if(isempty(joint_pos_0)) |
| 12 | +% joint_pos_0 = joint_pos; |
| 13 | +% end |
| 14 | +% |
| 15 | +% L_d_n = zeros(6,1); |
| 16 | +% L_dot_d = zeros(6,1); |
| 17 | +% L_d_n(1:3) = M(1,1)*desired_pos_vel_COM(:,2)'; |
| 18 | +% %L_d_n(4:6) = L_d(4:6); |
| 19 | +% int_L_ang = zeros(3,1); |
| 20 | +% x_com_des = desired_pos_vel_COM(:,1); |
| 21 | +% s_des_k = joint_pos_desired; |
| 22 | +% s_dot_des_k = joint_vel_desired; |
| 23 | +function [L_d_n, L_dot_d, int_L_ang, x_com_des, s_des_k, s_dot_des_k, vel_feet_correction] = ComputeReferencesController(M,L,desired_pos_vel_COM, joint_pos, joint_pos_desired,joint_vel_desired, L_ang_des,L_d, w_H_l, w_H_r,Cs, Gains) |
2 | 24 |
|
3 | 25 | persistent L_0;
|
4 | 26 |
|
| 27 | +persistent w_H_l_0; |
| 28 | + |
| 29 | +persistent w_H_r_0; |
| 30 | + |
| 31 | +persistent z_0; |
| 32 | + |
| 33 | +persistent joint_pos_0; |
| 34 | + |
| 35 | +persistent Cs_old ; |
| 36 | + |
5 | 37 | if(isempty(L_0))
|
6 | 38 | L_0 = L;
|
7 | 39 | end
|
8 | 40 |
|
9 |
| -persistent joint_pos_0; |
| 41 | +if(isempty(Cs_old)) |
| 42 | + Cs_old = Cs; |
| 43 | +end |
10 | 44 |
|
11 | 45 | if(isempty(joint_pos_0))
|
12 | 46 | joint_pos_0 = joint_pos;
|
13 | 47 | end
|
14 | 48 |
|
| 49 | +%%TODO could also check on the contact status,to update it each time the |
| 50 | +%%contact is restored. |
| 51 | + |
| 52 | + |
| 53 | +if (isempty(w_H_r_0)) |
| 54 | + w_H_r_0 = w_H_r; |
| 55 | +end |
| 56 | + |
| 57 | +if(isempty(w_H_l_0)) |
| 58 | + w_H_l_0 = w_H_l; |
| 59 | +end |
| 60 | + |
| 61 | +if(isempty(z_0)) |
| 62 | + z_0 = w_H_l(3,4); |
| 63 | +end |
| 64 | + |
| 65 | +% For now we are assuming that one foot is always in contact, we will |
| 66 | +% discard this assumption for performing the jump |
| 67 | +% Updating only the position, we want to keep the original orientation |
| 68 | +if(~Cs_old(1) && Cs(1)) |
| 69 | +w_H_l_0(1,4) = w_H_l(1,4); |
| 70 | +w_H_l_0(2,4) = w_H_l(2,4); |
| 71 | +w_H_l_0(3,4) = z_0; |
| 72 | +end |
| 73 | + |
| 74 | +% Updating only the position, we want to keep the original orientation |
| 75 | +if(~Cs_old(2) && Cs(2)) |
| 76 | +w_H_r_0(1,4) = w_H_r(1,4); |
| 77 | +w_H_r_0(2,4) = w_H_r(2,4); |
| 78 | +w_H_r_0(1:3,1:3) |
| 79 | +w_H_r_0(3,4) = z_0; |
| 80 | +end |
| 81 | + |
| 82 | +vel_feet_correction = zeros(12,1); |
| 83 | +if(Cs(1)) |
| 84 | + vel_feet_correction(1:3) = diag(Gains.Kp_feet_correction)*(w_H_l(1:3,4)- w_H_l_0(1:3,4)); |
| 85 | + vel_feet_correction(4:6) = Gains.Kp_feet_correction_angular* wbc.skewVee(w_H_l(1:3,1:3)*transpose(w_H_l_0(1:3,1:3))); |
| 86 | +end |
| 87 | + |
| 88 | +if(Cs(2)) |
| 89 | + vel_feet_correction(7:9) = diag(Gains.Kp_feet_correction)*(w_H_r(1:3,4)- w_H_r_0(1:3,4)); |
| 90 | + vel_feet_correction(10:12) = Gains.Kp_feet_correction_angular* wbc.skewVee(w_H_r(1:3,1:3)*transpose(w_H_r_0(1:3,1:3))); |
| 91 | +end |
15 | 92 | L_d_n = zeros(6,1);
|
16 | 93 | L_dot_d = zeros(6,1);
|
17 | 94 | L_d_n(1:3) = M(1,1)*desired_pos_vel_COM(:,2)';
|
|
21 | 98 | s_des_k = joint_pos_desired;
|
22 | 99 | s_dot_des_k = joint_vel_desired;
|
23 | 100 |
|
| 101 | +Cs_old = Cs; |
24 | 102 |
|
25 | 103 | end
|
| 104 | + |
0 commit comments