Experiment 6
Experiment 6
where K is the variable constant and G(s) is the plant consideration. The gain margin is
defined as the change in open-loop gain required to make the closed-loop system unstable.
Systems with greater gain margins can withstand greater changes in system parameters
before becoming unstable in closed-loop. The phase margin is defined as the change in
open-loop phase shift required to make the closed-loop system unstable.
We can have MATLAB calculate and display the gain and phase margins using the margin(G)
command. This command returns the gain and phase margins, the gain and phase crossover
frequencies, and a graphical representation of these quantities on the Bode plot.
Bandwidth Frequency:
The bandwidth frequency is defined as the frequency at which the closed-loop magnitude
drops 3 dB below its magnitude at DC (magnitude as the frequency approaches 0).
Task1: Cruise Control
The transfer fuction for the cruise control car is
Code:
m = 1000;
b = 50;
r = 10;
u = 500;
s = tf('s');
P_cruise = 1 / (m*s + b);
K = 1;
C = K;
T_open = C * P_cruise;
T_closed = feedback(T_open, 1);
figure;
step(T_closed);
title('Step Response (K = 1)');
grid on;
figure;
bode(T_open);
title('Open-loop Bode Plot (K = 1)');
grid on;
Kp = dcgain(T_open);
ess = 1 / (1 + Kp);
figure;
bode(T_new_open);
title('Open-loop Bode Plot (K = 500)');
grid on;
figure;
step(T_new_closed);
title('Closed-loop Step Response (K = 500)');
grid on;
Kp_new = dcgain(T_new_open);
ess_new = 1 / (1 + Kp_new);
fprintf('Steady-State Error (K=500): %.4f\n', ess_new);
z = 0.02;
p = 0.002;
C_lag = tf([1 z], [1 p]);
K_lag = 1000;
C_total = K_lag * C_lag;
figure;
bode(T_lag_open);
title('Open-loop Bode Plot with Lag Compensator (K = 1000)');
grid on;
figure;
step(T_lag_closed);
title('Closed-loop Step Response with Lag Compensator (K = 1000)');
grid on;
Kp_lag = dcgain(T_lag_open);
ess_lag = 1 / (1 + Kp_lag);
fprintf('Steady-State Error with Lag Compensator: %.4f\n', ess_lag);
Now we add a real zero to our plot and observe the changes, zero pulls down the response.
Now we add a lead compensator to our design with delta phase 50 and freq set at 250
through the compensator editor. The plot appears to change as this;
After adding a frequency of 350 for the compensator and a phase margin of 70 trhough hit
and trial, we adjust the gain to 670, and the final compensated plots are observed.
Task4: Suspension control
The dynamics equations from the transfer function are given as
where
Now we design 2 lead controllers and add them to our system. The positive phase needed is
140 degrees (70 degrees from each controller). The frequency should be 5.0 rad/sec. The
required space between the zero and the pole is calculated to be a=0.031091 .The corner
frequency and the maximum phase are T =1.13426 and aT =0.035265 . The plots observed as
shown below.
Now we plot the step response with 0.1-m step as disturbance.
The amplitude of the response is smaller than the percent overshoot. Since we can see that
an amplitude of the output's response less than 0.0001 m or 1% of input magnitude after 4
seconds. Therefore we can say that the settling time is 4 seconds from the above plot. From
the Bode plot above, we see that increasing the gain will increase the crossover frequency
and thus make the response faster. We will increase the gain and see if we can get a better
response.
The source code used for this task is given below.
m1 = 2500;
m2 = 320;
k1 = 80000;
k2 = 500000;
b1 = 350;
b2 = 15020;
s = tf('s');
Delta = (m1*s^2 + b1*s + k1)*(m2*s^2 + b2*s + k2) - (b1*s + k1)*(b1*s + k1);
G1 = ((m1 + m2)*s^2 + b2*s + k2)/Delta;
G2 = (-m1*b2*s^3 - m1*k2*s^2)/Delta;
F = G2/G1;
L_original = F * G1;
figure;
margin(L_original);
title('Original Open-Loop Bode Plot');
grid on;
K_norm = 1e5;
L_scaled = K_norm * L_original;
figure;
margin(L_scaled);
title('Normalized Open-Loop Bode Plot (K = 100,000)');
grid on;
phi_max = 70;
alpha = (1 - sind(phi_max)) / (1 + sind(phi_max));
wc = 5;
T = 1 / (wc * sqrt(alpha));
Lead1 = (T*s + 1) / (alpha*T*s + 1);
Lead2 = Lead1;
Kc = 1e5;
C = Kc * Lead1 * Lead2;
L_new = C * F * G1;
figure;
margin(L_new);
title('Bode Plot with 2-Lead Controller');
grid on;
T_cl = feedback(L_new, 1);
figure;
step(0.1 * T_cl);
title('Step Response with 2-Lead Controller (0.1 m Step Input)');
ylabel('Output X_1 - X_2 [m]');
grid on;
Kc_improved = 2e5;
C_improved = Kc_improved * Lead1 * Lead2;
L_improved = C_improved * F * G1;
T_improved = feedback(L_improved, 1);
figure;
step(0.1 * T_improved);
title('Improved Step Response (K increased)');
ylabel('Output X_1 - X_2 [m]');
grid on;
info = stepinfo(0.1 * T_improved)
Where
We generate the final response of the pendulum by running the following script in matlab.
M = 0.5;
m = 0.2;
b = 0.1;
I = 0.006;
g = 9.8;
l = 0.3;
q = (M+m)*(I+m*l^2) - (m*l)^2;
s = tf('s');
P_pend = (m*l*s/q) /(s^3 + (b*(I + m*l^2))*s^2/q - ((M + m)*m*g*l)*s/q - b*m*g*l/q);
K = 10;
C = K*(s+1)^2/s;
T = feedback(P_pend,C);
t = 0:0.01:10;
impulse(T,t), grid
title({'Response of Pendulum Position to an Impulse Disturbance';'under Closed-loop Control'});
K = 35;
C = K*(s+1)*(s+2)/s;
T = feedback(P_pend,C);
t = 0:0.01:10;
impulse(T, t), grid
title({'Response of Pendulum Position to an Impulse Disturbance';'under Closed-loop Control'});
P_cart = (((I+m*l^2)/q)*s^2 - (m*g*l/q))/(s^4 + (b*(I + m*l^2))*s^3/q - ((M + m)*m*g*l)*s^2/q -
b*m*g*l*s/q);
T2 = feedback(1,P_pend*C)*P_cart;
T2 = minreal(T2);
t = 0:0.01:10;
impulse(T2, t), grid
title({'Response of Cart Position to an Impulse Disturbance';'under Closed-loop Control'});
Result:
We now design a controller. We now set the new gain crossover and T.
Result:
The phase-lead compensator will add positive phase to our system over the corner
frequencies. The maximum added phase for one lead compensator is 90 degrees. For our
controller design we need a percent overshoot of less than 5%. We require a phase margin
greater than 70 degrees. We need at least 70 degrees from our controller. We need to
determine the frequency where the phase should be added (center frequency). In our case
this is difficult to determine because the phase vs. frequency graph in the bode plot is a flat
line. However, we have a relation between bandwidth frequency and settling time which tells
us that is approximately 1.92 rad/s. Therefore, we want a center frequency just before this.
For now we will choose 1 rad/sec. We need “a” that can be calculated from
where phi refers to the desired phase margin. For 70 degrees, a = 0.0311.
For 70 degrees and center frequency = 1, aT= 0.176 and T= 5.67.The plot after adding the
compensator can be observed
We can increase our phase-lead compensator to decrease the overshoot.