0% found this document useful (0 votes)
15 views17 pages

Chapter 4

The document discusses the design of PID controllers for cruise control and DC motor speed and position control using MATLAB. It provides transfer functions, MATLAB code snippets for implementing proportional, integral, and derivative control strategies, and examples of tuning controller gains for optimal performance. The document also includes step response analysis for different controller configurations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views17 pages

Chapter 4

The document discusses the design of PID controllers for cruise control and DC motor speed and position control using MATLAB. It provides transfer functions, MATLAB code snippets for implementing proportional, integral, and derivative control strategies, and examples of tuning controller gains for optimal performance. The document also includes step response analysis for different controller configurations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Cruise Control: PID Controller Design

The transfer function model for the cruise control problem:


V (s) 1
P(s)= U ( s) = ms+ b

The block diagram of a typical unity feedback system is shown below.

the transfer function of a PID controller is:


Ki
C ( s )=K p + +Kd s
s

We can define a PID controller in MATLAB using the transfer function directly:
Kp = 1;
Ki = 1;
Kd = 1;

s = tf('s');
C = Kp + Ki/s + Kd*s

Alternatively, we may use MATLAB's pid controller object to generate an


equivalent continuous time controller as follows:
C = pid(Kp,Ki,Kd)
Proportional control
By reducing the unity feedback block diagram, the closed-loop transfer function
with a proportional controller becomes:
Kp
T ( s )=
ms+ b+ K p

For now, use K p equal to 100 and a reference speed of 10 m/s


m = 1000;
b = 50;
r = 10;

s = tf('s');
P_cruise = 1/(m*s + b);

Kp = 100;
C = pid(Kp);

T = feedback(C*P_cruise,1)

t = 0:0.1:20;
step(r*T,t)
axis([0 20 0 10])
You can increase the proportional gain, K p, to reduce the rise time and the steady-
state error. Change the existing m-file so that K p equals 5000 and rerun it in the
MATLAB command window
Kp = 5000;
C = pid(Kp);
T = feedback(C*P_cruise,1);

step(r*T,t)
axis([0 20 0 10])
PI control

The closed-loop transfer function of this cruise control system with a PI controller
K p s+ K i
T ( s )= 2
m s + ( b+ K p ) s+ K i

For now, let K p equal 600 and K i equal 1


Kp = 600;
Ki = 1;
C = pid(Kp,Ki);

T = feedback(C*P_cruise,1);

step(r*T,t)
When K p equals 800 and K p equals 40
Kp = 800;
Ki = 40;
C = pid(Kp,Ki);

T = feedback(C*P_cruise,1);

step(r*T,t)
PID control
2
K p s+ K i + K d s
T ( s )= 2
(m+ K d )s + ( b+ K p ) s+ K i

For now, let K p K i K d equal 1


Kp = 1;
Ki = 1;
Kd = 1;
C = pid(Kp,Ki,Kd);

T = feedback(C*P_cruise,1);

DC Motor Speed: PID Controller Design


From the main problem, the dynamic equations in the Laplace domain and the open-loop
transfer function of the DC Motor are the following.
s ( Js +b ) θ ( s ) =KI ( s )

( Ls+ R ) I ( s )=V ( s )−Ksθ ( s )


θ(s) K
P ( s )= =
V (s) ( Js+ b ) ( Ls+ R ) + K 2

design a controller using the methods


J = 0.01;
b = 0.1;
K = 0.01;
R = 1;
L = 0.5;
s = tf('s');
P_motor = K/((J*s+b)*(L*s+R)+K^2)

Recall that the transfer function for a PID controller is:


Ki
C ( s )=K p + +Kd s
s

Proportional control
employing a proportional controller with a gain of 100, that is, C(s) = 100
Kp = 100;
C = pid(Kp);
sys_cl = feedback(C*P_motor,1)

t = 0:0.01:5;
step(sys_cl,t)
grid
title('Step Response with Proportional Control')

PID control
Kp = 75;
Ki = 1;
Kd = 1;
C = pid(Kp,Ki,Kd);
sys_cl = feedback(C*P_motor,1);
step(sys_cl,[0:1:200])
title('PID Control with Small Ki and Small Kd')
Tuning the gains
This process can be sped up by increasing the value of . Go back to your m-file
and change to 200 as in the following
Kp = 100;
Ki = 200;
Kd = 1;
C = pid(Kp,Ki,Kd);
sys_cl = feedback(C*P_motor,1);
step(sys_cl)
grid
title('PID Control with Large Ki and Small Kd')
Stepinfo:

As we had hoped, the increased Kd reduced the resulting overshoot. Now we know
that if we use a PID controller with Kp = 100, Ki = 200, and Kd = 10, all of our
design requirements will be satisfied.

DC Motor Position: PID Controller Design


From the main problem, the open-loop transfer function of the DC Motor is given
as follows.
s ( Js +b ) θ ( s ) =KI ( s )

( Ls+ R ) I ( s )=V ( s )−Ksθ ( s )


θ(s) K
P ( s )= =
V (s) s ( ( Js +b )( Ls+ R )+ K 2)

J = 0.01;
b = 0.1;
K = 0.01;
R = 1;
L = 0.5;
s = tf('s');
P = K/(s*((J*s+b)*(L*s+R)+K^2))

Proportional control

Let's first try using a proportional controller with gain ranging from 1 to 21.
Kp = 1;
for i = 1:3
C(:,:,i) = pid(Kp);
Kp = Kp + 10;
end
sys_cl = feedback(C*P_motor,1);

sys_cl = feedback(C*P_motor,1);
t = 0:0.001:0.2;
step(sys_cl(:,:,1), sys_cl(:,:,2), sys_cl(:,:,3), t)
ylabel('Position, \theta (radians)')
title('Response to a Step Reference with Different Values of K_p')
legend('Kp = 1', 'Kp = 11', 'Kp = 21')

dist_cl = feedback(P_motor,C);
step(dist_cl(:,:,1), dist_cl(:,:,2), dist_cl(:,:,3), t)
ylabel('Position, \theta (radians)')
title('Response to a Step Disturbance with Different Values of K_p')
legend('Kp = 1', 'Kp = 11','Kp = 21')
PI control
We will set = 21 and test integral gains ranging from 100 to 500.
Kp = 21;
Ki = 100;
for i = 1:5
C(:,:,i) = pid(Kp,Ki);
Ki = Ki + 200;
end

sys_cl = feedback(C*P_motor,1);
t = 0:0.001:0.4;
step(sys_cl(:,:,1), sys_cl(:,:,2), sys_cl(:,:,3), t)
ylabel('Position, \theta (radians)')
title('Response to a Step Reference with K_p = 21 and Different Values of
K_i')
legend('Ki = 100', 'Ki = 300', 'Ki = 500')
step disturbance response.
dist_cl = feedback(P_motor,C);
step(dist_cl(:,:,1), dist_cl(:,:,2), dist_cl(:,:,3), t)
ylabel('Position, \theta (radians)')
title('Response to a Step Disturbance with K_p = 21 and Different Values of
K_i')
legend('Ki = 100', 'Ki = 300', 'Ki = 500')
PID control
Adding a derivative term to the controller means that we now have all three terms
of the PID controller. We will investigate derivative gains ranging from 0.05 to
0.25.
Kp = 21;
Ki = 500;
Kd = 0.05;

for i = 1:3
C(:,:,i) = pid(Kp,Ki,Kd);
Kd = Kd + 0.1;
end

sys_cl = feedback(C*P_motor,1);
t = 0:0.001:0.1;
step(sys_cl(:,:,1), sys_cl(:,:,2), sys_cl(:,:,3), t)
ylabel('Position, \theta (radians)')
title('Step Response with K_p = 21, K_i = 500 and Different Values of K_d')
legend('Kd = 0.05', 'Kd = 0.15', 'Kd = 0.25')
see what happened to the step disturbance response
dist_cl = feedback(P_motor,C);
t = 0:0.001:0.2;
step(dist_cl(:,:,1), dist_cl(:,:,2), dist_cl(:,:,3), t)
ylabel('Position, \theta (radians)')
title('Step Response with K_p = 21, K_i = 500 and Different values of K_d')
legend('Kd = 0.05', 'Kd = 0.15', 'Kd = 0.25')

You might also like