You are on page 1of 17

DC Motor Position: PID Controller Design

Key MATLAB commands used in this tutorial are: tf , step , feedback

Contents
Proportional control
PI control
PID control
From the main problem, the open-loop transfer function of the DC Motor is given as follows.

(1)
The structure of the control system has the form shown in the figure below.

For the original problem setup and the derivation of the above equations, please refer to the DC Motor Position:
System Modeling page.
For a 1-radian step reference, the design criteria are the following.

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.
(2)
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. The feedback command can still be
employed for generating the closed-loop transfer function where there is still negative feedback, however, now
only the plant transfer function P(s) is in the forward path and the controller C(s) is considered to be in the
feedback path. Refer back to the block diagram at the top of this page to see the structure of the system. Add
the following to the end of your m-file and run it in the command window. You should generate the plot shown in
the figure below.

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')

The above plots show that the system has no steady-state error in response to the step reference by itself, no
matter the choice of proportional gain Kp. This is due to the fact that the plant has an integrator, that is, the
system is type 1. However, the system has significant steady-state error when the disturbance is added.
Specifically, the response due to the reference and disturbance applied simultaneously is equal to the sum of
the two graphs shown above. This follows from the property of superposition that holds for linear systems.
Therefore, to have zero steady-state error in the presence of a disturbance, we need the disturbance response
to decay to zero. The larger the value of Kpthe smaller the steady-state error is due to the disturbance, but it
never reaches zero. Furthermore, employing increasingly larger values of Kp has the adverse effect of increasing
the overshoot and settle time as can be seen from the step reference plot. Recall from the DC Motor Position:
System Modeling page that adding an integral term will eliminate the steady-state error and a derivative term
can reduce the overshoot and settling time.
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')

Now let's see what happened to the step disturbance response. Change the following commands in your m-file
and re-run in the command window. You should generate a plot like the one shown in the figure below.

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('K_i = 100', 'K_i = 300', 'K_i = 500')
The integral control has reduced the steady-state error to zero, even when a step disturbance is present; that
was the goal for adding the integral term. For the response to the step reference, all of the reponses look similar
with the amount of oscillation increasing slightly as Ki is made larger. However, the response due to the
disturbance changes significantly as the integral gain Ki is changed. Specifically, the larger the value
of Ki employed, the faster the error decays to zero. We will choose Ki = 500 because the error due to the
disturbance decays to zero quickly, even though the response to the reference has a longer settling time and
more overshoot. We will attempt to reduce the settling time and overshoot by adding a derivative term to the
controller.
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')

Let's see what happened to the step disturbance response, change the following commands in your m-file and
re-run at the command line.

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('Response to a Step Disturbance 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')
It looks like when Kd = 0.15, we can meet our design requirements. To determine the precise characteristics of
the step response you can use the right-click menu of the step response plot, or you can use the MATLAB
command stepinfo as shown below.

stepinfo(sys_cl(:,:,2))

ans =

RiseTime: 0.0046

SettlingTime: 0.0338

SettlingMin: 0.9183

SettlingMax: 1.1211

Overshoot: 12.1139

Undershoot: 0

Peak: 1.1211

PeakTime: 0.0121

From the above, we see that the response to a step reference has a settling time of roughly 34ms (< 40 ms),
overshoot of 12% (< 16%), and no steady-state error. Additionally, the step disturbance response also has no
steady-state error. So now we know that if we use a PID controller with
Kp = 21, Ki = 500, and Kd = 0.15,
all of our design requirements will be satisfied.
Motor Position PID Control
Publish Date: dic 13, 2010 | 6 Calificaciones | 2.33 fuera de 5 | Print | Submit your review

Overview
This tutorial shows the characteristics of the proportional (P), the integral (I), and the derivative (D) controls,
and how to use them to obtain a desired response for the position of a DC motor. This tutorial uses LabVIEW
and the LabVIEW Control Design and Simulation Module.

These tutorials are based on the Control Tutorials developed by Professor Dawn Tilbury of the Mechanical
Engineering department at the University of Michigan and Professor Bill Messner of the Department of
Mechanical Engineering at Carnegie Mellon University and were developed with their permission.

Modeling DC Motor Position Controls Tutorials Menu Motor Position Root Locus

Table of Contents
1. PID Design Method for DC Motor Position
2. Proportional Control
3. Step Disturbance Response
4. PID Control
5. Tuning the Gains
1. PID Design Method for DC Motor Position
From the main problem, the dynamic equation in transfer function form is the following:

The system schematic looks like:

For the original problem setup and the derivation of the above equations, please refer to the Modeling DC
Motor Position page.
With a 1 rad/sec step reference, the design criteria are:
Settling time less than 0.04 seconds
Overshoot less than 16%
No steady-state error
No steady-state error due to a disturbance
Back to Top
2. Proportional Control
Now let's design a PID controller and add it into the system. Recall that the transfer function for a PID
controller is:

Let's first try using a proportional controller with a gain of 1.7.


LabVIEW Graphical Approach
Start by creating a VI to model the transfer function for the motor. For an explanation of how to create this
model, refer to the Modeling DC Motor Position page.

Figure 1: Construct Motor Transfer Function


Next, create a transfer function for the controller. Add a second CD Construct Transfer Function Model VI from
the Model Construction section of the Control Design palette. Create controls for the Symbolic Numerator and
Variables inputs.

Figure 2: Construct Controller Transfer Function


Put these models in series using a CD Series VI.
Figure 3: Models in Series
Now add a CD Feedback VI, and connect the output from the CD Series VI to the Model 1 input of the
CD Feedback VI. We use the Feedback VI to determine the closed-loop transfer function.
Next, create another transfer function model. Create a constant input for the numerator, and set this equal to 1.
Connect this new transfer function to the Model 2 input of the CD Feedback VI.

Figure 4: Models in Series with Feedback VI


Now add a CD Step Response VI, connect the output from the CD Feedback VI to the input of the CD Step
Response VI, and create a Time Response input and a Step Response Graph output for the CD Step
Response VI. On the front panel, set the Time Info so that t0 = 0, dt = 0.001, and tf = 0.2.
Figure 5: Finished Block Diagram for Proportional Control
When you run the VI, you should see the following plot on the front panel:

Figure 6: Response to Step Input, Kp = 1.7


Hybrid Graphical/MathScript Approach
Alternatively, you can achieve the same results using a hybrid graphical/MathScript approach. Begin by
creating a blank VI, and add a MathScript Node. Paste the following code into your MathScript Node:
J=3.2284E-6;
b=3.5077E-6;
K=0.0274;
R=4;
L=2.75E-6;
num=K;
den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2) 0];
motor=tf(num,den);

Kp=1.7;
contr=Kp;

sys_cl=feedback(contr*motor,1);
We use the 'feedback' command to determine the closed-loop transfer function.
Create an output called sys_cl, and change its type to a TF Object. Add the CD Step Response VI to your
block diagram, and connect the sys_cl output to the Transfer Function Model input of the Step Response VI.
Finally, create a control for the Time Response terminal and an indicator for the Step Response Graph output.
On the front panel, set t0 to 0, dt to .001, and tf to 0.2.
The block diagram should look like this:

Figure 7: Proportional Control, Hybrid Approach (Download)


Running this VI should result in a graph similar to the one in Figure 6.
LabVIEW MathScript Approach
To achieve this result using MathScript, open the MathScript Window and paste the above code into the
Command Window. Add the following lines of code to the end:
t=0:0.001:0.2;
step(sys_cl,t)
Running this code should result in a graph similar to Figure 6.
Back to Top
3. Step Disturbance Response
To look at the step disturbance response for the system, and if you are using a graphical approach, connect
the motor and controller models to the inputs of another CD Feedback VI, then create inputs and outputs to the
VI as we did before.

Figure 8: Block Diagram for Proportional Control with Step Disturbance (Download)
If you are using a hybrid or MathScript approach, add the following code to your MathScript Node, and create
an output for dist_cl:
dist_cl=feedback(motor,contr);
All of these methods should result in the following plot:
Figure 9: Response to Step Disturbance, Kp = 1.7
Back to Top
4. PID Control
From the plots above, we see that although the steady-state error looks good, the settling time is too large, as
is the overshoot. We also see that the steady-state error to a disturbance is large.
Recall from the PID tutorial page that adding an integral term will eliminate the steady-state error and a
derivative term will reduce the overshoot. Let's first try a PI controller to get rid of the disturbance steady state
error.
LabVIEW Graphical Approach
To achieve this with a graphical approach, add on to the VI that we created earlier. Create a control for the
Symbolic Denominator input for the controller transfer function VI.

[+] Enlarge Image


Figure 10: PID Control Block Diagram with Step Disturbance (Download)
Change your front panel values so that the values for the controller numerator are "Ki Kp" and the values for
its denominator are "0 1". Change the controller variables on the front panel so that the variable Kp has a
value of 1.7, and Ki has a value of 20.
Running this VI should give you the following Step Response plot:
Figure 11: Response to Step Input, Kp = 1.7, Ki = 20
Also, you should see the following Step Disturbance plot:

Figure 12: Response to Step Disturbance, Kp = 1.7, Ki = 20


The integral control has reduced the steady state error to zero.
Hybrid Graphical/MathScript Approach
If you are using a hybrid approach, change your MathScript code so that it looks like the following:
J=3.2284E-6;
b=3.5077E-6;
K=0.0274;
R=4;
L=2.75E-6;
num=K;
den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2) 0];
motor=tf(num,den);

Kp=1.7;
Ki=20;
contr=tf([Kp Ki],[1 0]);

sys_cl=feedback(contr*motor,1);
Running this VI should result in a similar response to Figure 11.
To see what happened to the step disturbance response, add the following code to your MathScript Node:
dist_cl=feedback(motor,contr);
Change the sys_cl output name to dist_cl and run the VI. You should see a plot similar to Figure 12.
Back to Top
5. Tuning the Gains
Although the steady state error has been removed, the settling time is still too long. Let's increase the gains in
order to speed up the response. Change Ki to 200 and Kp to 17. Rerun your VI, and you should get plots like
these:

Figure 13: Response to Step Input, Kp = 17, Ki = 200

Figure 14: Response to Step Disturbance, Kp = 17, Ki = 200


Now we see that the response is faster than before, but the large Ki has worsened the transient response (big
overshoot). Let's now try adding a derivative term to reduce the overshoot.
If you are using a graphical approach, change your front panel values so that the controller numerator has
"Ki Kp Kd", the denominator has "0 1", and the variables have Kp = 17, Ki = 200, and Kd = 0.15.
To do this with the hybrid approach, make the following changes to your MathScript code:
Kp=17;
Ki=200;
Kd=0.15;
contr=tf([Kd Kp Ki],[1 0]);
sys_cl=feedback(contr*motor,1);
You should now get this plot:

Figure 15: Response to Step Input, Kp = 17, Ki = 200, Kd = 0.15


And your step disturbance plot should look like this:
Figure 16: Response to Step Disturbance, Kp = 17, Ki = 200, Kd = 0.15
We now see that our step response looks really good. It has less than 16% overshoot, the settling time is
roughly 40 ms, and there is no steady-state error.
However, the step disturbance response is now really slow. Lets increase Ki to speed up the disturbance
response. Change Ki to 600 and rerun your VI. You should get the following plots:

Figure 17: Response to Step Input, Kp = 17, Ki = 600, Kd = 0.15

Figure 18: Response to Step Disturbance, Kp = 17, Ki = 600, Kd = 0.15


We now can see that the step response has a settling time of roughly 40 ms, it has less than 16% overshoot,
and it has no steady state error. The step disturbance response also has no steady state error. So now we
know that if we use a PID controller with
Kp=17
Ki=600
Kd=.15

You might also like