# 9.5: PID tuning via optimization

- Page ID
- 22416

Authors: Andrew MacMillan, David Preston, Jessica Wolfe, Sandy Yu

Stewards: YooNa Choi, Yuan Ma, Larry Mo, Julie Wesely

## 5.1 Introduction

Tuning a controller is a method used to modify the effect a process change will have on the piece of equipment being controlled. The goal of tuning a system is to construct the most robust process possible. The method chosen for tuning a system varies depending on the parameter being measured, the sensitivity of the materials, the scale of the process, and many other variables unique to each process. This chapter discusses the basics of tuning a controller using predictive methods. To learn more about using an effect based method see the Classical Tuning section.

## 5.2 Optimization

When tuning a PID controller, constants K_{c}, T_{i}, and T_{d} need to be optimized. This can be accomplished using the following equation, Equation 1, from the Classical Tuning section:

\[M V=K_{c}\left(e(t)+\frac{1}{T_{i}} \int_{0}^{t} e(\tau) d \tau+T_{d} \frac{d e(t)}{d t}\right) \label{1}\]

where

- \(MV\) is the manipulated variable (i.e. valve position) that the controller will change
- \(K_c\) accounts for the gain of the system
- \(T_i\) accounts for integrated error of the system
- \(T_d\) accounts for the derivative error of the system

Tuning by optimization uses computer modeling programs, such as Microsoft Excel, to find the optimal values for the coefficients K_{c}, T_{i}, and T_{d} to yield the minimum error. The Solver function in Excel can be used in this situation.

For more information about the use of these parameters and their overall effects on the control system see the P, I, D, PI, PD, and PID control section.

## 5.3 Excel Modeling

For instructions on how to install Solver in Excel, see the Adding in the Solver Application in Excel 2007 section.

For instruction on how to use Solver in Excel, see the Excel's Solver Tool section.

Equation \ref{1} can be used in Excel to optimize the values of K_{c}, T_{i}, and T_{d}. The following are the steps to optimize these constants:

- Pick a set point. Examples of set points include the temperature at which a reaction is expected to stay and the flow rate of a cooling stream.
- Make a column for error. Create a function in each cell so that the error is equal to the set point minus the actual value.
- Make a column that will calculate Equation 1.
- At the end of the error column, use the sum function to add up all of the errors in the column.
- Make three cells for K
_{c}, T_{i}, and T_{d}, and insert the initial values. - Open the Solver function in Excel.
- In Solver, set the target cell to the summed errors cell. Set the target cell equal to the minimum value possible. Set the changing cells to K
_{c}, T_{i}, and T_{d}. - Click 'Solve' to minimize the sum of the error and therefore optimize the K
_{c}, T_{i}, and T_{d}constants.

Tips for using Excel Solver to optimize PID controller parameters:

- When choosing initial values for your parameters, try starting with K
_{c}=1, T_{i}=1000, and T_{d}=1. Since Solver only does a limited number of iterations (usually set at 100), it may settle on an incorrect answer. - Change the values for K
_{c}manually and optimize with Solver until you get the lowest value in the target cell. This is the most efficient as K_{c}usually has the largest effect on a PID controller. - Make sure to set constraints on your parameters in the 'Subject to the Constraints:' box in Solver (e.g. K
_{c}> 0). - Make sure you incorporate any physical limitations (e.g. maximum heater temperature) into your Excel model. Even though your system may not be close to the limit initially, Solver may try and go past that limit if it is not programmed into your model.

## 5.4 Industrial Application

The parameters (K_{c}, T_{i}, T_{d}) found through optimization will not necessarily give the best control. To optimally tune a controller, a technician must adjust equipment to tune the process. So why is it necessary to tune by optimization? The parameters found by optimization give an accurate starting point for the technician.

## 5.5 Example of PID Tuning by Optimization

This example is based on the example in the CSTR Heat Exchange Model section.

The goal is to optimize the PID controller for the coolant temperature.

Follow the fully worked out example at: [Media:Optimal PID.xls Optimal PID]

As shown in the Excel file, the coolant temperature changes in response to variations from the set point by a PID type controller. Changing the K_{c}, T_{i}, and T_{d} values using Solver, to minimize the total error, provided the values in the green box. On the second sheet, labeled 'disturbances', it can be seen that once optimized, the parameters should be fit to the system, regardless of changes in operating conditions.

It is important to note that the starting values you choose for the PID parameters will greatly affect your final results from using an excel solver. So you should always use your intuition to judge whether your starting values are reasonable or not. According to ExperTune , starting PID settings for common PID control loops are:

- Loop Type: Flow ; P = 50 to 100 ; I = 0.005 to 0.05 ; D = none ;
- Loop Type: Liquid Pressure ; P = 50 to 100 ; I = 0.005 to 0.05 ; D = none
- Loop Type: Gas Pressure ; P = 1 to 50 ; I = 0.005 to 0.05 ; D = 0.02 to 0.1 ;
- Loop Type: Liquid Level ; P = 1 to 50 ; I = 1 to 100 ; D = 0.01 to 0.05 ;
- Loop Type: Temperature ; P = 2 to 100 ; I = 0.2 to 50 ; D = 0.1 to 20 ;

The above values are rough, assume proper control loop design, ideal or series algorithm and do not apply to all controllers. These information should only be used as a possible consideration and should not be taken as an absolute starting value for all PID controls. For more information about the above values please go to www.expertune.com/tutor.html

As mentioned before, to optimize the parameters in a PID-controlled system the solver function can be used in excel. However the solver function can sometimes run into its own problems because of the process it uses to solve for these “optimal” values. To ensure that solver gives you the correct optimal values, some manual “optimization” is needed. Using your excel sheet, the controller on the system can be separated into its different components P, I, and D. The behavior of each component can be monitored as the parameters are changed manually. Theoretically you would choose values that have every component reach steady-state over time. The excel solver can then be used as a precision tool. If your values are already closer to the optimal values, then solver should have no problem making them more precise. It is recommended that the graphs of the components be checked after using solver with your initial guesses. You may not have to go through this long and most of the time painful process. This is an example of how the P, I, and D plots change with different parameters. Note that the combined PID plot will also reach steady-state if each of the components reach steady-state.

(Parameters are not optimized)

(Optimized parameters)

## 5.6 Example: Optimization of a Heat Exchanger

This example is based on the ODE Modeling in Excel of the Heat Exchange Model.

Find the best values of K_{c}, T_{i}, and T_{d} in the given spreadsheet Media:PID_HeatExchange.xls.

Note the three different tabs:

- the first tab shows the problem to be solved
- the second is a step by step method for creating this sheet on your own
- the third is the answer to the problem

After using Solver:

- Click through the cells in one row to determine which parameters are affected by MV changes
- Change the values of K
_{c}, T_{i}, and T_{d}to see how they will effect the overall temperature profile. Which parameter has the greatest effect? Based on the equation, does this make sense?

## 5.7 Multiple Choice Question

What do you want to minimize when optimizing the constants K_{c}, T_{i}, and T_{d}?

- time
- response period
- error
- nothing

## 5.8 Answers

### 5.8.1 Example

Look at the third tab on the Excel file to find the optimization answer. K_{c} (gain) will have the greatest effect on the output of the controller.

### 5.8.2 Multiple Choice Question

c) error

Tuning by optimization uses computer modeling programs to find the optimal values for the coefficients Kc, Ti, and Td to yield the *minimum error*.

## 5.9 Sage's Corner

A walkthrough of the Heat Exchanger Example above

video.google.com/googleplayer...61635696386040

slides for this talk

## 5.10 References

- Svrcek, William Y., Mahoney, Donald P., Young, Brent R. "A Real Time Approach to Process Control", 2nd Edition. John Wiley & Sons, Ltd.