-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpg.m
102 lines (80 loc) · 2.46 KB
/
cpg.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
time = 30;
Omega_p(1) = 1.0;
D(1) = 2*pi/6;
Omega_p(2) = 3.0;
D(2) = 2*2*pi/6;
Omega_p(3) = 5.0;
D(3) = 3*2*pi/6;
h = 4;
T = 0.5;
S = 10;
L = 1.0;
phi = [0, 0, 0, 0, 0, 0];
theta = [0, 1, 0, -1, 0, 1];
%omega = 5;
dt = 0.01;
t = 0:dt:time;
rec_theta = [];
rec_phi = [];
rec_psi = [];
rec_omega = [];
psi_o=[];
for i=0:dt:time
% if 0 <= i & i < 20
% omega = Omega_p(1);
% elseif 20 <= i & i < 40
% omega = Omega_p(2);
% elseif 40 <= i & i <= 60
% omega = Omega_p(3);
% end
if 0 <= i & i < 10
omega = Omega_p(1);
elseif 10 <= i & i < 20
omega = Omega_p(2);
elseif 20 <= i & i <= 30
omega = Omega_p(3);
end
%omega = Omega_p(2);
phi(1) = theta(1) - theta(2);
phi(2) = theta(2) - theta(3);
phi(3) = theta(3) - theta(4);
phi(4) = theta(4) - theta(5);
phi(5) = theta(5) - theta(6);
psi(1) = -phi(1);
psi(2) = phi(1) - phi(2);
psi(3) = phi(2) - phi(3);
psi(4) = phi(3) - phi(4);
psi(5) = phi(4) - phi(5);
psi(6) = phi(5);
psi_o1 = -D;
psi_o2 = [0,0,0];
psi_o3 = [0,0,0];
psi_o4 = [0,0,0];
psi_o5 = [0,0,0];
psi_o6 = D;
d_theta(1) = omega + f_tilde(omega, Omega_p, psi(1), psi_o1, h, T, S, L);
d_theta(2) = omega + f_tilde(omega, Omega_p, psi(2), psi_o2, h, T, S, L);
d_theta(3) = omega + f_tilde(omega, Omega_p, psi(3), psi_o3, h, T, S, L);
d_theta(4) = omega + f_tilde(omega, Omega_p, psi(4), psi_o4, h, T, S, L);
d_theta(5) = omega + f_tilde(omega, Omega_p, psi(5), psi_o5, h, T, S, L);
d_theta(6) = omega + f_tilde(omega, Omega_p, psi(6), psi_o6, h, T, S, L);
%d_theta = d_theta;
theta = theta + dt * d_theta;
rec_theta = [rec_theta; theta];
rec_phi = [rec_phi; phi];
rec_psi = [rec_psi; psi];
rec_omega = [rec_omega; omega];
end
figure(1);
plot(t',cos(rec_theta(:,1)),t',cos(rec_theta(:,2)),t',cos(rec_theta(:,3)),t',cos(rec_theta(:,4)),t',cos(rec_theta(:,5)),t',cos(rec_theta(:,6)))
xlabel('t[sec]');ylabel('cos{(\theta)}');
legend('\theta_1','\theta_2','\theta_3','\theta_4','\theta_5','\theta_6')
figure(2);
plot(t',rec_phi(:,1),t',rec_phi(:,2),t',rec_phi(:,3),t',rec_phi(:,4),t',rec_phi(:,5))
xlabel('t[sec]');ylabel('\phi[rad]');
legend('\phi_1','\phi_2','\phi_3','\phi_4','\phi_5','\phi_6')
figure(3);
plot(t',rec_omega)
xlabel('t[sec]');ylabel('\omega[rad/s]');
xlim([0,time]),ylim([0,6])
%legend('\phi_1','\phi_2','\phi_3','\phi_4','\phi_5','\phi_6')