-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcm_test.m
187 lines (165 loc) · 4.98 KB
/
dcm_test.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
clc; clear;
% Set Walking Params
g = 9.81;
z = 0.75;
b = sqrt(z/g);
% Temporal Parameters
% Commented temporal params are for the DRACO biped
t_transfer = 0.75; %0.1;
t_ss = 1.0; %0.4;
t_ds = 0.25; %0.05;
alpha = 0.5;
t_ds_ini = alpha*t_ds;
t_ds_end = (1-alpha)*t_ds;
% Set exponential settle time (so that when CoM is computed, it converges to
% the final DCM state)
percentage_settle = 0.99;
t_settle = -b*log(1.0 - percentage_settle);
% Initialize foot conditions
rfoot_y = -0.33;
lfoot_y = 0.0;
midfeet_y = (lfoot_y +rfoot_y)/2.0;
% Initial dcm_state
xi_init_state = [0.0; midfeet_y; z];
xi_vel_init_state = [0.0; 0.0; 0.0];
% Initialize DCM containers
r_vrp = zeros(3,4);
n = size(r_vrp, 2);
t_step = zeros(1, n);
xi_ini = zeros(3, n);
xi_eos = zeros(3, n);
% Initialize r_vrp
r_vrp(:,1) = [0, midfeet_y, z];
r_vrp(:,2) = [0, lfoot_y, z];
r_vrp(:,3) = [1, rfoot_y, z];
r_vrp(:,4) = [1, midfeet_y, z];
% Initialize t_step
t_step(:,1) = t_transfer + t_ds;
t_step(:,2) = t_ss + t_ds;
t_step(:,3) = t_ss + t_ds;
t_step(:,4) = (1-alpha)*t_ds;
% Polynomial Vectors
xi_ini_DS = zeros(3, n);
xi_ini_vel_DS = zeros(3, n);
xi_end_DS = zeros(3, n);
xi_end_vel_DS = zeros(3, n);
t_ds_vec = ones(1,n)*t_ds;
t_ds_vec(1) = t_transfer + t_ds + (1-alpha)*t_ds;
P_mats = zeros(4,3,n);
% Recursively find xi boundary conditions
xi_eos(:,end) = r_vrp(:,end);
for(j = 1:n)
i = n-j+1; % Reverse counter
xi_ini(:,i) = r_vrp(:,i) + exp( -(1/b)*t_step(i) ) * (xi_eos(:,i) - r_vrp(:,i));
if (i > 1)
xi_eos(:,i-1) = xi_ini(:,i);
end
end
% Define double support boundary conditions
% Initial Double Support Conditions
xi_ini_DS(:,1) = xi_init_state;
xi_ini_vel_DS(:,1) = xi_vel_init_state;
for(j = 1:n)
i = n-j+1; % Reverse counter
if (i > 1)
xi_ini_DS(:,i) = r_vrp(:,i-1) + exp((-1/b)*t_ds_ini)*(xi_ini(:,i) - r_vrp(:,i-1));
xi_ini_vel_DS(:,i) = (1/b)*exp((-1/b)*t_ds_ini)*(xi_ini(:,i) - r_vrp(:,i-1));
end
end
% Ending Double Support conditions
for(i = 1:n)
xi_end_DS(:,i) = r_vrp(:,i) + exp((1/b)*t_ds_end)*(xi_ini(:,i) - r_vrp(:,i));
xi_end_vel_DS(:,i) = (1/b)*exp((1/b)*t_ds_end)*(xi_ini(:,i) - r_vrp(:,i));
end
xi_end_DS(:,1) = xi_end_DS(:,2);
xi_end_vel_DS(:,1) = xi_end_vel_DS(:,2);
% Compute Polynomial Matrices
for (i = 1:n)
P_mats(:,:,i) = get_polynomial_matrix(t_ds_vec(i), xi_ini_DS(:,i), xi_ini_vel_DS(:,i), xi_end_DS(:,i), xi_end_vel_DS(:,i));
end
% Get DCM references ------------------------------------------------------
t = [0:0.01:get_trajectory_length(t_step) + t_settle];
% Exponential DCM references
xi_ref_d = get_xi_ref_d(t, t_step, b, r_vrp, xi_eos);
xi_vel_ref_d = get_xi_vel_ref_d(t, t_step, b, r_vrp, xi_eos);
% Exponential and Polynomial DCM references
xi_ref_hybrid_d = get_xi_ref_hybrid_d(t, t_step, b, r_vrp, xi_eos, t_ds_vec, alpha, P_mats);
xi_vel_ref_hybrid_d = get_xi_vel_ref_hybrid_d(t, t_step, b, r_vrp, xi_eos, t_ds_vec, alpha, P_mats);
r_vrp_disc = compute_rvrp_given_dcm(b, xi_ref_d, xi_vel_ref_d);
r_vrp_cont = compute_rvrp_given_dcm(b, xi_ref_hybrid_d, xi_vel_ref_hybrid_d);
% Set index to plot
figure(1)
subplot(2,3,1)
hold on
plot(t, xi_ref_hybrid_d(1,:),'s-');
plot(t, xi_vel_ref_hybrid_d(1,:),'s-');
scatter(t, xi_ref_d(1,:))
scatter(t, xi_vel_ref_d(1,:));
t_start = 0.0;
for(i = 1:size(t_step,2))
xline(t_start);
t_start = t_start + t_step(i);
end
xlabel('time(s)')
ylabel('dcm')
legend({'DCM poly x','DCM poly x vel', 'DCM x','DCM x vel'},'Location','northeast')
%figure(2)
subplot(2,3,2)
hold on
plot(t, xi_ref_hybrid_d(2,:),'s-');
plot(t, xi_vel_ref_hybrid_d(2,:),'s-');
scatter(t, xi_ref_d(2,:))
scatter(t, xi_vel_ref_d(2,:));
t_start = 0.0;
for(i = 1:size(t_step,2))
xline(t_start);
t_start = t_start + t_step(i);
end
xlabel('time(s)')
ylabel('dcm')
legend({'DCM poly y','DCM poly y vel', 'DCM y','DCM y vel'},'Location','southeast')
%figure(3)
subplot(2,3,3)
hold on
plot(t, xi_ref_hybrid_d(3,:),'s-');
plot(t, xi_vel_ref_hybrid_d(3,:),'s-');
scatter(t, xi_ref_d(3,:))
scatter(t, xi_vel_ref_d(3,:));
t_start = 0.0;
for(i = 1:size(t_step,2))
xline(t_start);
t_start = t_start + t_step(i);
end
xlabel('time(s)')
ylabel('dcm')
legend({'DCM poly z','DCM poly z vel', 'DCM z','DCM z vel'},'Location','east')
%figure(4)
subplot(2,3,4)
hold on
scatter(r_vrp_disc(1,:), r_vrp_disc(2,:))
plot(r_vrp_cont(1,:), r_vrp_cont(2,:))
plot(xi_ref_hybrid_d(1,:), xi_ref_hybrid_d(2,:), 's-')
xlabel('x (m)')
ylabel('y (m)')
legend({'r ecmp xy disc','r ecmp xy cont', 'dcm cont'},'Location','northeast')
%figure(5)
subplot(2,3,5)
hold on
scatter(t, r_vrp_disc(1,:))
plot(t, r_vrp_cont(1,:))
xlabel('time(s)')
ylabel('r ecmp x (m)')
legend({'discontinuous','continuous'},'Location','northeast')
%figure(6)
subplot(2,3,6)
hold on
scatter(t, r_vrp_disc(2,:))
plot(t, r_vrp_cont(2,:))
xlabel('time(s)')
ylabel('r ecmp y (m)')
legend({'discontinuous','continuous'},'Location','northeast')
%---
%figure(4)
%index_to_try = n;
%xi_vel_ds_poly_test = get_xi_vel_DS_poly(t, t_ds_vec(index_to_try), P_mats(:,:, index_to_try));
%plot(t, xi_vel_ds_poly_test(2,:))