You are on page 1of 22

ISLAMIC UNIVERSITY OF TECHNOLOGY

PID control project

This document will walk you through all the steps necessary to complete the assignment. You have
been provided all the necessary files in the folder named “BTM PID Project”. The necessary MATLAB
version is R18a or higher (installation file has been provided to you). You need to follow this
document to complete this assignment and submit a report on it.

The Problem Statement:

Consider the following case where you have two reservoirs or tanks stacked on top of one another.
Both the reservoirs have liquid level sensors built into them. A pump supplies the upper
reservoir/tank with fluid. The upper reservoir drains into the lower reservoir and lower reservoir into
the rest of the system. A certain industrial process requires a fixed liquid level in the lower
reservoir/tank at any given time. The task is to develop a PID control system to automatically adjust
the pump output to maintain a desired liquid level in the lower tank.

UPPER TANK
(TANK 1)

LOWER TANK
PUMP (TANK 2)

Executing in MATLAB Simulink:

To get started, open up MATLAB. You will be invited by the following screen as shown in ‘image 1’.
Fig: Image 1

To the left of the screen, you have the “Current folder” section. We need to specify the working
directory here. Working directory is the folder where you placed the “BTM PID Project” folder on
your computer.
To specify the working directory click on the following folder Icon with a green arrow:

The following screen will pop up. Navigate to the folder where you placed “BTM PID Project” as
follows and select the folder.
Once you select the folder, your “current folder section” should look like the following screenshot.
From there select “Initialize.m” (Marked by orange rectangle below) by double clicking on it.

This will initialize all the necessary variables and parameters necessary to run the Simulink file, you
don’t need to make any changes to these values. You should see something like the following image:
Now you are ready to start the Simulink file. Double click on the “Gravity_Drained_Tanks.slx” and
wait for a few minutes depending on your specs.

You should see the following block diagram appear. We have a block named “tank_dynamics” which
is in fact our “Plant” in this case. We also have a “Level Setpoint” which is the desired liquid level in
the lower tank. You can see that it is currently set to 0.5 or 50% of the total height. There is also a
block named “Pump Output” which goes from 0 to a maximum value of 1 or 100%. You can ignore
the rest of the blocks for the time being. You can click, hold and drag to rearrange any of the blocks
according to your need. Observe that, initially we have no PID control in the loop. You will be
including the PID control by following the steps in this document.
You can change and play around with the values of any block by double clicking on it. Double click on
the blue colored “pump output” block.

You should see the following box appear, where you can change the pump output value between 0
and 1 corresponding to 0% and 100%.
Use the slider or use your keyboard to set the pump output to a value greater than 0 and click OK. In
this case it is set to 0.45 or 45%.

Now you should see the “Pump Output” block changed to 0.45. Now, we can simulate the scenario
by clicking on the green play button shown below.
You should see the following window appear, which will simulate the process. You should see the
liquid level rise in both the tanks with time. You can exit the simulation any time by clicking the cross
button.
Simulink will automatically supply you with the following graphs plotted against time. The 2nd graph
shows the pump output throughout the whole time which is seen to be constant at 0.45. You can
change this value in the middle of the run and see how it affects the 3rd and 4th graph which plots the
liquid level in both tank1 and tank 2 with time.
So far we have been changing the water level in the 2nd tank by controlling the pump output
ourselves. But now you will develop a PID control which will do that automatically for you once you
set the desired level by changing the “level setpoint”. To do that select, View > Library Browser.

Once you click on Library Browser, the following window will appear. Type PID in the search box and
hit enter.
The Library browser will automatically look for the PID block and provide you a list of relevant blocks
to choose from. Choose PID(s) by dragging and dropping it into the model window. To do that,
simply click hold and drag.
You can click hold and drag to rearrange any of the blocks. We won’t be needing the Pump output
block any longer as we will have the PID control do that task for us now. So we will delete the block
and rearrange as follows. To delete just click on the desired blocks and lines and hit delete key.

We already have the PID block. But we will need a summing block to calculate the error between the
Level Setpoint and measured liquid level. This error will be fed into the PID controller which will
adjust the pump output accordingly to reduce the error. To add the summing block follow the same
steps as before, go to View>Library Browser, and search for Sum.
Drag and drop into the block diagram window. You should now see both PID and Sum block in the
model window. Click Hold and Drag to rearrange.

One thing that can be noticed is that the sum block has two + signs. But as you may recall from the
block diagrams in the lecture silde, the sum block had a + sign coming from the setpoint and a
negative sign coming from the sensor from the output. So we need to change one of the + signs to a
– sign. To do that, double click on the summing block.

Double click here


The following window will appear. Type ‘+-‘ in place of ‘++’ and hit OK to change one of the signs to -.
Now we need to connect the ‘PID’ and ‘Sum’ blocks to the rest of the block diagram. You can Right
click at the desired point of the existing lines to create new lines and connect them to the blocks as
follows.

RIGHT CLICK HERE FOR STARTING


NEW LINE. SIMILARLY DO THIS AT
OTHER POINTS TO CREATE NEW
LINES.

Now we are ready to set the PID values in the PID controller. Double click on the PID block.
The following window will appear. You need to change the values in the red box. You are free to play
around with the values and see how the system responds to different values.

But setting the PID to the following values will result in a fairly stable and good system. How the
values came about is actually complex and outside the scope of this course. The main objective is to
get an idea about how a PID control affects the closed loop control system in this case.
In the PID Advanced tab, select Limit output and set Upper saturation limit to 1 and Lower saturation
limit to 0. This will tell the PID controller that the maximum pump output value is 1 and minimum
value is 0 (as we already observed). Set the Anti-windup method to ‘Clamping’. This will clamp the
value and stop winding up the integral term once the saturation limit is reached.

Once that is done, click OK and run the simulation!


You should now see the PID controller automatically adjusting the pump output for you, to achieve
the desired Level setpoint which is currently 0.5. You can change the set point to any value during
the simulation which will trigger the PID controller to adjust the pump output to achieve the new set
setpoint.
During the simulation click on the ‘measured levels’ block shown below, to see the sensor output of
liquid levels in both tanks plotted against time.

You should see the following graph which will update with time as the simulation progresses.

LIQUID LEVEL

Liquid level vs time at time T=55.150 units


Liquid level at time T=329.150 units

Once you exit the simulation by clicking the cross button, you will be presented with the following
four graphs. The first graph (valve position vs time) is not needed. Observe how the PID control
adjusted the pump power to smoothly reach the desired liquid level. If you change the liquid level in
the middle of the run, the PID controller will adjust the pump output to achieve the new liquid level
automatically.

2) Pump output vs time; 3) level1 vs time; 4) level2 set point and level 2 vs time
Your Tasks:

1) Follow the steps mentioned in this document to complete the project and run the PID
control successfully with the actual values of P I and D mentioned in this document. Show
the graphs (A) Liquid Level vs Time at 3 different times; B) The four graphs obtained after
exiting the simulation namely, pump output vs time; level1 vs time;level2 set point and level
2 vs time) you obtain in the report.
2) Try out different values of P I and D other than the actual values and report the changes you
observe in your report with the graphs and compare the graphs.
3) With the correct P I and D value run the simulation with 0.5 level setpoint initially and after a
certain amount of time according to your wish(before 500 time units, the simulation will
stop at 500 time units), set the “Level Setpoint “ to (3 times the last 2 digits of your student
ID after decimal point). For eg. If the last 2 digits of your student ID is “03”. Multiply that by
3 to get (3*03=09). So the new level set point should be 0.09
Similarly, if the last 2 digits of your student ID is “30”. Multiply that by 3 to get (3*30=90). So
the new level set point should be 0.90

You might also like