-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.m
49 lines (44 loc) · 1005 Bytes
/
main.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
clear;
clc;
ts = 0;
tf = 20;
Fext=[0 0]';
X0(:,1)=[pi/8; -pi/8; pi/6; 1.6; -1.6; 0];
yout = [;];
tout = [];
i = 2;
options = odeset('Events',@impactFunction);
while i <= 5
if tf-ts < 0.01
break;
end
X0(:,i) = stateUpdate(X0(:,i-1));
[t,y,t0,y0] = ode45(@(t,x) controlFunction(t,x,Fext),[ts:0.01:tf],X0(:,i),options);
X0(:,i)= y0';
n = length(t);
ts = t(n);
yout = [yout; y];
tout = [tout; t];
i = i + 1;
end
figure
plot(tout,yout(:,1)*180/pi,'LineWidth',2)
ylabel('\theta_1(degrees)','FontSize',16)
xlabel('t(sec)','FontSize',16)
grid on
figure
plot(tout,yout(:,2)*180/pi,'LineWidth',2)
ylabel('\theta_2(degrees)','FontSize',16)
xlabel('t(sec)','FontSize',16)
grid on
figure
plot(tout,yout(:,3)*180/pi,'LineWidth',2)
ylabel('\theta_3(degrees)','FontSize',16)
xlabel('t(sec)','FontSize',16)
grid on
figure
plot3(yout(:,1),yout(:,4),yout(:,6));
xlabel('Theta1');
ylabel('Omega1');
zlabel('Omega3');
grid on