# Electric Winder Control Problem

Solution

% PID Controller

tmax = 20;

K = 1;

dt = 0.1;

lowerp = 0.1;

upperp = 0.9;

t = [0:dt:tmax]’;

G0 = tf(1,[1, 15, 50, 0]);

y0 = step(G0,t);

figure;

plot(t, y0,’b’)

hold on;

% Ziegler-Nichols

% —————

% Kp = 50.0;

% T0 = 6;

% Kp = 0.6*Kp

% Ki = 2/T0

% Kd = T0/8

Kp = 73.5;

Ki = 0.002;

Kd = 5.93;

Gpid = tf([1, 15, 50, 0, 0],[1, 15, 50+Kd, Kp, Ki]);

ypid = step(Gpid,t);

plot(t, ypid+y0, ‘g’)

title(‘Response, PID controller’)

legend(‘Original system’,’PID controller’,’Location’,’southeast’)

hold off;

yresp = ypid+y0;

offset = 1;

tmp = max(yresp);

for tau = 5:length(t)

if ( tmp > abs(yresp(tau)/y0(tau)-1) && yresp(tau)/y0(tau) > 1)

tmp = abs(yresp(tau)/y0(tau)-1);

offset = tau;

end

end

OS = 0;

for tau = offset:length(t)

if ( OS < abs(yresp(tau)/y0(tau)-1) )

OS = abs(yresp(tau)/y0(tau)-1);

end

end

disp(sprintf(‘PID parameters: Kp = %0.3f, Ki = %0.3f, Kd = %0.3f’, Kp, Ki, Kd));

disp(sprintf(‘Overshoot: %0.2f%s’, (100*OS), char(37)))

sserr = ypid(length(ypid));

stime = offset;

tmp = 0;

while tmp < 0.05

tmp = abs(yresp(stime)/y0(stime)-1);

stime = stime – 1;

end

disp(sprintf(‘Settling time: %0.1f seconds’, stime*dt))

figure;

plot(t, ypid,’b’)

title(‘PID controller, gain’)