PID Control Con Matlab: Luis Sánchez
PID Control Con Matlab: Luis Sánchez
Luis Snchez
Control PID
we will consider the following unity feedback system:
PID en Matlab
We can define a PID controller in MATLAB using the transfer
function directly, for example:
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)
Let's convert the pid object to a transfer function to see that it
yields the same result as above:
tf(C)
RISE TIME
OVERSHO
OT
Kp
Decrease
Increase
Ki
Decrease
Increase
Eliminate
Small
Decrease
Decrease
No Change
correlations may
not be exactly
accurate,
because
Change
SETTLING
TIME
Small
Change
Increase
Kdthat these
Note
Kp, Ki, and Kd are dependent on each other.
S-S
ERROR
Decrease
(b)
(Ke)
(Kt)
(R)
(L)
Torque (T):
La fuerza electromotriz de
retroceso (e):
T Kti
.
e Ke
Requerimientos de diseo
For a 1-rad/sec step reference, the design criteria are the following.
Settling time less than 2 seconds
Overshoot less than 5%
Steady-state error less than 1%
PID control
The addiction an integral term will eliminate the steady-state error to a
step reference and a derivative term will often reduce the overshoot.
Let's try a PID controller with small Ki and Kd.
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')
Kp = 100; Ki = 200;
Kd = 1; C = pid(Kp,Ki,Kd);
sys_cl =
feedback(C*P_motor,1);
step(sys_cl, 0:0.01:4) grid on
title('PID Control with Large
Ki and Small Kd')
Kp = 100; Ki = 200; Kd =
10; C = pid(Kp,Ki,Kd);
sys_cl =
feedback(C*P_motor,1);
step(sys_cl, 0:0.01:4) grid
title('PID Control
with Large Ki
and Large Kd')
Requerimientos de diseo
Settling time less than 0.040 seconds
Overshoot less than 16%
No steady-state error, even in the presence of a
step disturbance input
Now let's design a PID controller and add it into the
system. First create a new m-file and type in the
following commands (refer to main problem for the
details of getting these commands).
J = 3.2284E-6;
b = 3.5077E-6;
K = 0.0274; R = 4;
L = 2.75E-6;
s = tf('s');
P_motor = K/(s*((J*s+b)*(L*s+R)+K^2));
Recall that the transfer function for a PID controller
has the following form.
Proportional control
Let's first try using a proportional controller with gain ranging
from 1 to 21. An array of LTI models, each with a different
proportional gain, can be built using a for loop. The closed-loop
transfer functions can be generated using the feedback
command. Add the following code to the end of your m-file and
run it in the MATLAB command window:
Kp = 1;
for i = 1:3
C(:,:,i) = pid(Kp);
Kp = Kp + 10;
end
sys_cl = feedback(C*P_motor,1);
Now let's see what the step responses look like. Add the following
code to the end of your m-file and again run it in the command
window. You should generate the plot shown in the figure below.
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('K_p = 1',
'K_p = 11', 'K_p = 21')
Let's also consider the system's response to a step disturbance. In this case, we
will assume a reference of zero and look at the how the system responds to the
disturbance by itself.
figure
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('K_p = 1',
'K_p = 11','K_p = 21')
PI control
Let's first try a PI controller to get rid of the steady-state error due to
the disturbance. We will set Kp = 21 and test integral gains
Ki ranging from 100 to 500. Change your m-file to the following and
run in the command window. You should generate a figure like the
one shown below.
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('K_i = 100', 'K_i = 300', 'K_i = 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 Kd ranging from 0.05 to 0.25. Go back to the m-file and
make the following changes. Running the altered m-file will
generate a graph like the one shown below.
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('Response to a Step Reference with K_p = 21, K_i = 500
and Different Values of K_d') legend('K_d = 0.05', 'K_d =
0.15', 'K_d = 0.25')
pidtool(P,'p')