% L91_cruise.m - cruise control example for Lecture 9.1 % RMM, 24 Nov 02 % Parameter definitions m = 1000; % mass of the car, kg b = 50; % damping coefficient, N sec/m a = 0.2; % engine lag coefficient r = 5; % transmission gain % Dynamics veh = tf([1/m], [1 b/m]); % vehicle eng = tf([r], [1 a]); % engine %% Slide 6: PID design for cruise controller % Compute the step response and slope of the step response [y, t] = step(veh*eng, 50); slope = (y(2:length(y))-y(1:length(y)-1))./(t(2:length(y))-t(1:length(y)-1)); plot(t, y, t(1:length(y)-1), slope*10); % Add the axis lines hold on; plot([-10 40], [0 0], 'k-', [0 0], [-0.1 0.5], 'k-'); % Figure out the Nichols lines [easier to do by hand, but I need the plot] [smax, imax] = max(slope); % find point of max slope line = y(imax) + slope(imax)*([0:0.1:50]-t(imax)); hold on; plot([0:0.1:50], line, 'r-'); axis([0 50 -0.1 0.5]); print -dmeta L9_7a.wmf hold off; % Now compute the PID controller L = t(imax) - y(imax)/slope(imax); % x-axis intercept a = -(y(imax) - slope(imax)*t(imax)); % y-axis intercept % Use Ziegler-Nichols rules to choose gains Kc = 1.2/a; Ti = 2*L; Td = 0.5*L; pid = Kc * (1 + tf([1], [Ti 0]) + tf([Td 0], [1])); % Now plot out the closed loop response curves L = veh*eng*pid; T = L/(1+L); bode(veh*eng, pid, veh*eng*pid); print -dmeta L9_7b.wmf step(T, 60); print -dmeta L9_7c.wmf %% Slide 11 - rlocus for cruise %% Note: for the plots used in L9.1, many were generated with rltool L = veh*eng*pid; rlocus(L); print -dmeta L9_11a.wmf % rltool(veh*eng, pid); print -dmeta L9_11b.wmf