-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw4_q2.m
51 lines (45 loc) · 1.47 KB
/
hw4_q2.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
clc, clear all, close all
%init vars
M1 = 10; %kg
M2 = 10; %kg
K1 = 20; %N/m
B = 0.1; %Ns/m (ideal pivot)
L1 = 0.25; %m
L2 = 0.25; %m
L = L1 + L2; %m
g = 9.8; %gravitational acceleration
theta1_init = 45 * pi / 180; %radians
theta2_init = 30 * pi / 180; %radians
tau1_init = 35; %N/m
tau2_init = 25; %N/m
tau1_final = 0; %N/m
tau2_final = 0; %N/m
stepInputTime = 3; % sec
stopTime = 150; %sec
% run model
sim('hw4_sim');
%define horizontal line
y1 = 5 * pi / 180;%5 degrees converted to radians
y2 = - y1;%-5 degrees converted to radians
%plot graph
yyaxis left
plot(theta1.Time, theta1.Data, '-r', 'LineWidth', 3),hold on
plot(theta2.Time, theta2.Data, '-b', 'LineWidth', 3)
yline(y1,'-y','LineWidth', 5);
yline(y2,'-m','LineWidth', 5);
hold off
xticks([0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150])
xticklabels({'0','10','20','30','40','50','60','70','80','90','100','110','120','130','140','150'})
yticks([-0.09 0.09])
yticklabels({'-0.09' '0.09'})
ylabel('Angle (rad)')
yyaxis right
plot(inputTau1.Time, inputTau1.Data, '-k', 'LineWidth',4), hold on
plot(inputTau2.Time, inputTau2.Data, '-g', 'LineWidth',3)
legend('\theta_1 Displacement', '\theta_2 Displacement','+5 degrees','-5 degrees','input \tau_1', 'input \tau_2', 'location', 'bestoutside');
ylabel('Applied Torque (N/m)')
%labeling horizontal axis and title
xlabel('Time (s)')
name = sprintf('B=%.2f Ns/m, k=%.2f N/m, L_1=%.2f m, L_2=%.2f m, M_1=%.2f kg, M_2=%.2f kg', B , K1 , L1 , L2 , M1 , M2 );
title(name);
ylim([-1 36])