From 1e6f07c92014aebe6e6beff24f62aab20ffeb7e3 Mon Sep 17 00:00:00 2001 From: Auralius Manurung Date: Sat, 12 Jun 2021 15:45:39 +0700 Subject: [PATCH] Documenting --- demo1.m | 31 ++++++++++++++++++++++--------- demo2.m | 3 +++ sim_stick_slip.m | 4 ++-- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/demo1.m b/demo1.m index 86f09ad..ab438ef 100644 --- a/demo1.m +++ b/demo1.m @@ -88,8 +88,8 @@ [F(j), z] = lugref(z, v(j), Fc, Fs, vs, sigma_0, sigma_1, sigma_2, ts); end - % Start from t = 5, at the begining, the F response is unconsistent - % since we don't know hwo to initialize z. + % Start from t = 5, at the begining, the F response is inconsistent + % since we don't know how to initialize z. Here, we initialize z with 0. plot(v(5/ts:end), F(5/ts:end), color(i)); end @@ -112,7 +112,7 @@ M = 1; % a unit mass -u_max = 0.95 * Fs; +u_max = 0.95 * Fs; % 95 % u1 = generate_ramp_signal(0, u_max, 10, ts); u2 = generate_ramp_signal(u_max, u_max, 5, ts); u3 = generate_ramp_signal(u_max, -u_max, 20, ts); @@ -120,13 +120,15 @@ u5 = generate_ramp_signal(-u_max, u_max, 20, ts); u6 = generate_ramp_signal(u_max, u_max, 5, ts); -u = [u1 u2 u3 u4 u5 u6]; +u = [u1 u2 u3 u4 u5 u6]; % put them together +% Some initializations F = 0; z = 0; x_0 = 0; v = 0; +% Do the simulation for all input u for i = 1:length(u) [F(i), z] = lugref(z, v, Fc, Fs, vs, sigma_0, sigma_1, sigma_2, ts); @@ -151,19 +153,24 @@ clear F v u u1 u2 u3 u4 u5 u6; -k = 2; +k = 2; % stiffness k = 2 N/m -ts = 1e-6; % 1e-4 fails!, very stiff system, needs a better ODE solver +ts = 1e-6; % 1e-4 fails, this is very stiff system, we need a better ODE solver time_span = 30; t = 0 : ts : time_span; +% generate_ramp_signal(min_val, max_val, t_max, ts) +% The velocity is 0.1 m/s, it means if we start from t=0 to t=time_span +% then our travel distace is 0.1*time_span y = generate_ramp_signal(0, time_span*0.1, time_span, ts); -x = 0; +% Some initializations +x = 0; z = 0; x_0 = 0; v = 0; +% Do the simulation for i = 1:length(y) [F(i), z] = lugref(z, v, Fc, Fs, vs, sigma_0, sigma_1, sigma_2, ts); u_spring = k*(y(i) - x(i)); @@ -175,7 +182,7 @@ x_0 = x(i+1); end -% compute the speed of the unit-mass +% Compute the speed of the unit-mass x_dot = gradient(x)/ts; figure @@ -218,16 +225,18 @@ % As soon as we detect the first negative gradient of the force, we must % stop. -ts = 1e-6; % very stiff system, needs a better ODE solver +ts = 1e-6; % very stiff system, we need a better ODE solver time_span = 2; t = 0 : ts : time_span; M = 1; % a unit mass +% I am just guessing from Fig. 4 F_rate = [1 2 3 4 5 10 20 30 40 45 50]; for j = 1 : length(F_rate) + % Always clear up the old values clear F v x x_dot u = generate_ramp_signal(0, F_rate(j)*time_span, time_span, ts); @@ -246,6 +255,8 @@ x_0 = x(i); + % When motion occurs, the resulting force suddenly drops + % See Fig. 6 (bottom figure) if i > 1 && (F(i)-F(i-1)) < 0 break; end @@ -278,11 +289,13 @@ % Desired position for the mass, its intial position is x = 0 xd = 1; +% Some initializations z = 0; x_0 = 0; v = 0; x = x_0; +% The integral of error with respect to time int_e = 0; for i = 1:length(t) diff --git a/demo2.m b/demo2.m index 3cc3156..bf11c4a 100644 --- a/demo2.m +++ b/demo2.m @@ -189,6 +189,9 @@ zdot = q_sol(k,2) - ( (q_sol(k,3)*abs(q_sol(k,2))*sigma_0) / ... (Fc+(Fs-Fc)*exp(-(q_sol(k,2)/vs)^2)) ); F(k) = sigma_0*q_sol(k,3) + sigma_1 * zdot + sigma_2*q_sol(k,2); + + % When motion occurs, the resulting force suddenly drops + % See Fig. 6 (bottom figure) if (k>1) && (F(k)-F(k-1)<0) break; end diff --git a/sim_stick_slip.m b/sim_stick_slip.m index 9fbd8e3..cc0c065 100644 --- a/sim_stick_slip.m +++ b/sim_stick_slip.m @@ -1,6 +1,6 @@ function xdot = sim_stick_slip(t, q, M, Fs, Fc, sigma_0, sigma_1, sigma_2, vs) - k = 2; % stiffness of the spring - y = 0.1*t; % 0.1 m/s + k = 2; % stiffness of the spring + y = 0.1*t; % y is moving with 0.1 m/s of speed u = k * (y - q(1)); % force by the spring zdot = q(2) - ( (q(3)*abs(q(2))*sigma_0) / (Fc+(Fs-Fc)*exp(-(q(2)/vs)^2)) );