## Dynamic Control Tuning

## Main.ControllerTuning History

Hide minor edits - Show changes to markup

- SOLVER
- 0=Try all available solvers
- 1=APOPT (MINLP, Active Set SQP)
- 2=BPOPT (NLP, Interior Point, SQP)
- 3=IPOPT (NLP, Interior Point, SQP)

- SOLVER

- COST = (+) minimize MV, (-) maximize MV

- COST = (+) minimize CV, (-) maximize CV

- STATUS = turn on (1) or off (0) MV

- STATUS = turn on (1) or off (0) CV

<iframe width="560" height="315" src="https://www.youtube.com/embed/yw_a9ektOqc?rel=0" frameborder="0" allowfullscreen></iframe>

<iframe width="560" height="315" src="https://www.youtube.com/embed/JnD6kpOul1c" frameborder="0" allowfullscreen></iframe>

In this case, the parameter *u* is the manipulated variable and *x* and *y* are the controlled variables. It is desired to maximize *x* and maintain values between 9 and 10. It is desired to maintain values of *y* between 2 and 5. For the first 10 minutes, the priority is to maintain the range for *y* and following this time period, it is desired to track the range for *x*. Tune the controller to meet these objectives while minimizing MV movement.

In this case, the parameter *u* is the manipulated variable and *x* and *y* are the controlled variables. It is desired to maximize *x* and maintain values between 9 and 10. It is desired to maintain values of *y* between 2 and 7. For the first 10 minutes, the priority is to maintain the range for *y* and following this time period, it is desired to track the range for *x*. Tune the controller to meet these objectives while minimizing MV movement.

- CV_TYPE = CV type with 1=l_1-norm, 2=squared error

- CV_TYPE = 1 for l
_{1}-norm and 2 for squared error

- CV_TYPE = 1 for l

- CV_TYPE = CV type with 1=l_1-norm, 2=squared error

#### Exercise

**Objective:** Design a model predictive controller with one manipulated variable and two controlled variables with competing objectives that cannot be simultaneously satisfied. Tune the controller to achieve best performance. *Estimated time: 2 hours.*

Use the following system of linear differential equations for this exercise by placing the model definition in the file *myModel.apm*.

Parameters u Variables x y Equations 5 * $x = -x + 1.5 * u 15 * $y = -y + 3.0 * u

In this case, the parameter *u* is the manipulated variable and *x* and *y* are the controlled variables. It is desired to maximize *x* and maintain values between 9 and 10. It is desired to maintain values of *y* between 2 and 5. For the first 10 minutes, the priority is to maintain the range for *y* and following this time period, it is desired to track the range for *x*. Tune the controller to meet these objectives while minimizing MV movement.

#### Solution

(:html:) <iframe width="560" height="315" src="https://www.youtube.com/embed/yw_a9ektOqc?rel=0" frameborder="0" allowfullscreen></iframe> (:htmlend:)

- SP = setpoint with CV_TYPE = 2
- SPLO = lower setpoint with CV_TYPE = 1
- SPHI = upper setpoint with CV_TYPE = 1

- SP = set point with CV_TYPE = 2
- SPLO = lower set point with CV_TYPE = 1
- SPHI = upper set point with CV_TYPE = 1

- TR_OPEN = opening at initial point of traj compared to end

- TR_OPEN = opening at initial point of trajectory compared to end

#### Common Tuning Parameters for MPC

Tuning typically involves adjustment of objective function terms or constraints that limit the rate of change (DMAX), penalize the rate of change (DCOST), or set absolute bounds (LOWER and UPPER). Measurement availability is indicated by the parameter (FSTATUS). The optimizer can also include (1=on) or exclude (0=off) a certain manipulated variable (MV) or controlled variable with STATUS. Below are common application, MV, and CV tuning constants that are adjusted to achieve desired model predictive control performance.

- Application tuning
- IMODE = 6 or 9 for model predictive control
- DIAGLEVEL = diagnostic level (0-10) for solution information
- MAX_ITER = maximum iterations
- MAX_TIME = maximum time before stopping
- MV_TYPE = Set default MV type with 0=zero-order hold, 1=linear interpolation

- Manipulated Variable (MV) tuning
- COST = (+) minimize MV, (-) maximize MV
- DCOST = penalty for MV movement
- DMAX = maximum that MV can move each cycle
- FSTATUS = feedback status with 1=measured, 0=off
- LOWER = lower MV bound
- MV_TYPE = MV type with 0=zero-order hold, 1=linear interpolation
- STATUS = turn on (1) or off (0) MV
- UPPER = upper MV bound

- Controlled Variable (CV) tuning
- COST = (+) minimize MV, (-) maximize MV
- CV_TYPE = CV type with 1=l_1-norm, 2=squared error
- FSTATUS = feedback status with 1=measured, 0=off
- SP = setpoint with CV_TYPE = 2
- SPLO = lower setpoint with CV_TYPE = 1
- SPHI = upper setpoint with CV_TYPE = 1
- STATUS = turn on (1) or off (0) MV
- TAU = reference trajectory time-constant
- TR_INIT = trajectory type, 0=dead-band, 1,2=trajectory
- TR_OPEN = opening at initial point of traj compared to end

There are several ways to change the tuning values. Tuning values can either be specified before an application is initialized or while an application is running. To change a tuning value before the application is loaded, use the *apm_option()* function such as the following example to change the lower bound in MATLAB or Python for the MV named *u*.

apm_option(server,app,'u.LOWER',0)

The upper and lower deadband targets for a CV named *y* are set to values around a desired set point of 10.0. In this case, an acceptable range for this CV is between 9.5 and 10.5.

sp = 10.0 apm_option(server,app,'y.SPHI',sp+0.5) apm_option(server,app,'y.SPHI',sp-0.5)

Application constants are modified by indicating that the constant belongs to the group *nlc*. IMODE is adjusted to either solve the MPC problem with a simultaneous (6) or sequential (9) method. In the case below, the application IMODE is changed to simultaneous mode.

apm_option(server,app,'nlc.IMODE',6)

(:title Dynamic Control Tuning:) (:keywords tuning, Python, MATLAB, Simulink, nonlinear control, model predictive control, tutorial:) (:description Tuning of an optimizing controller for improved following of a desired trajectory or to reach an optimal state:)

Dynamic controller tuning is the process of adjusting certain objective function terms to give more desirable solutions. As an example, a dynamic control application may either exhibit too aggressive manipulated variable movement or be too sluggish during set-point changes. Tuning is the iterative process of finding acceptable values that work over a wide range of operating conditions.