-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemo.m
176 lines (139 loc) · 5.3 KB
/
emo.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
% Originally : Daniel Kawano, Rose-Hulman Institute of Technology
% Last modified: Feb 13, 2016
% Modified for a motion of disc with thickness L, and dissipative moment
clear all
close all
clc
% Load the symbolic function handles for the state equations in
% mass-matrix form, M(t,Y)*Y'(t) = F(t,Y):
load rolling_disk_ODEs
% Physical parameters:
m = 5; % kg
g = 9.81; % m/s^2
r = 0.5; % m
lambdat = 1/4*m*r^2; % kg-m^2
lambdaa = 1/2*m*r^2; % kg-m^2
L = 0.1; % m
R = 0; % N
% coefficients of dissipative frictional moment added
k1 = 0.05;
k2 = 0.05;
k3 = 0.05;
% Simulation parameters:
dt = 0.001; % s
tf = 3.83; % s
tsim = [0 : dt : tf]'; % s
tol = 1e-5;
psidot0 = 0; % rad/s
thetadot0 = 0; % rad/s
phidot0 = pi; % rad/s
psi0 = 0*(pi/180); % rad
theta0 = 90*(pi/180); % rad
phi0 = 0*(pi/180); % rad
x10 = 0; % m
x20 = 0; % m
Y0 = [psidot0, thetadot0, phidot0, psi0, theta0, phi0, x10, x20]';
% Plotting parameters:
span = [0.8, 1.2];
% Initial conditions for steady motion of the rolling disk. Specify the
% rate of precession and the nutation angle to determine the required spin
% rate:
% R = 0; % To be extra careful, set the applied force R = 0 here.
%
psidot0 = -0.15*(2*pi); % rad/s
theta0 = 70*(pi/180); % rad
%
% phidot0 = ((lambdat - lambdaa - m*r^2)*sin(theta0)* ... % rad/s
% psidot0^2 - m*g*r)/((lambdaa + m*r^2)* ...
% tan(theta0)*psidot0);
%
Y0 = [psidot0, 0, phidot0, 0, theta0, 0, 0, 0]';
% Convert M(t,Y) and F(t,Y) to purely numeric function handles for
% numerical integration:
M = @(t, Y) M(t, Y, m, g, r, lambdat, lambdaa, L, R, k1, k2, k3);
F = @(t, Y) F(t, Y, m, g, r, lambdat, lambdaa, L, R, k1, k2, k3);
% Numerically integrate the state equations:
options = odeset('mass', M, 'abstol', tol, 'reltol', tol);
[t, Y] = ode45(F, tsim, Y0, options);
% Extract the results:
psidot = Y(:,1); % rad/s
thetadot = Y(:,2); % rad/s
phidot = Y(:,3); % rad/s
psi = Y(:,4); % rad
theta = Y(:,5); % rad
phi = Y(:,6); % rad
x1 = Y(:,7); % m
x2 = Y(:,8); % m
% Plot the precession rate, nutation angle, and spin rate over time:
figure
set(gcf, 'color', 'w')
subplot(311)
plot(t, psidot/(2*pi), '-b', 'linewidth', 2)
xlabel('Time (s)')
ylabel('Precession rate (rev/s)')
ylim([min(min(psidot/(2*pi))*span), max(max(psidot/(2*pi))*span)])
subplot(312)
plot(t, theta*(180/pi), '-r', 'linewidth', 2)
xlabel('Time (s)')
ylabel('Nutation angle (deg)')
ylim([min(min(theta*(180/pi))*span), max(max(theta*(180/pi))*span)])
subplot(313)
plot(t, phidot/(2*pi), '-k', 'linewidth', 2)
xlabel('Time (s)')
ylabel('Spin rate (rev/s)')
ylim([min(min(phidot/(2*pi))*span), max(max(phidot/(2*pi))*span)])
% Calculate the vertical position of the disk's mass center, and then plot
% the mass center location over time:
x3 = r*sin(theta); % m
figure
set(gcf, 'color', 'w')
subplot(311)
plot(t, x1, '-b', 'linewidth', 2)
xlabel('Time (s)')
ylabel('\itx\rm_{1} (m)')
subplot(312)
plot(t, x2, '-r', 'linewidth', 2)
xlabel('Time (s)')
ylabel('\itx\rm_{2} (m)')
subplot(313)
plot(t, x3, '-k', 'linewidth', 2)
xlabel('Time (s)')
ylabel('\itx\rm_{3} (m)')
ylim([0, 2*r])
% Calculate the normal force and the magnitude of the friction force over
% time to check for slipping:
x1dot = -r*cos(psi).*cos(theta).*psidot + ... % m/s
r*sin(psi).*sin(theta).*thetadot - r*cos(psi).*phidot;
x2dot = -r*sin(psi).*cos(theta).*psidot - ... % m/s
r*cos(psi).*sin(theta).*thetadot - r*sin(psi).*phidot;
x3dot = r*cos(theta).*thetadot; % m/s
x1ddot = gradient(x1dot,dt); % m/s^2
x2ddot = gradient(x2dot,dt); % m/s^2
x3ddot = gradient(x3dot,dt); % m/s^2
F1 = m*x1ddot + R*cos(psi); % N
F2 = m*x2ddot + R*sin(psi); % N
Ff = sqrt(F1.^2 + F2.^2); % N
N = m*x3ddot + m*g; % N
% Plot the minimum coefficient of static friction over time needed to
% prevent slipping:
figure
set(gcf, 'color', 'w')
plot(t, Ff./N, '-b', 'linewidth', 2)
xlabel('Time (s)')
ylabel('Coefficient of static friction')
ylim([min(min(Ff./N)*span), max(max(Ff./N)*span)])
% Calculate and plot the disk's total mechanical energy over time:
omega1 = psidot.*sin(theta).*sin(phi) + thetadot.*cos(phi); % rad/s
omega2 = psidot.*sin(theta).*cos(phi) - thetadot.*sin(phi); % rad/s
omega3 = psidot.*cos(theta) + phidot; % rad/s
E = 1/2*m*(x1dot.^2 + x2dot.^2 + x3dot.^2) + ... % J
1/2*(lambdat*omega1.^2 + lambdat*omega2.^2 + ...
lambdaa*omega3.^2) + m*g*x3;
figure
set(gcf, 'color', 'w')
plot(t, E, '-b', 'linewidth', 2)
xlabel('Time (s)')
ylabel('Total mechanical energy (J)')
ylim([min(min(E)*span), max(max(E)*span)])
% Animate the motion of the disk:
animate_rolling_disk(r, psi, theta, phi, x1, x2, x3, dt);