Dynamic Control Objectives

Main.ControllerObjective History

Hide minor edits - Show changes to markup

November 17, 2021, at 12:47 AM by 10.35.117.248 -
Changed line 71 from:

plt.plot(m.time,p.value,'b-',LineWidth=2,label='MV')

to:

plt.plot(m.time,p.value,'b-',lw=2,label='MV')

Changed line 77 from:

plt.plot(m.time,v.value,'r--',LineWidth=2,label='CV')

to:

plt.plot(m.time,v.value,'r--',lw=2,label='CV')

Changed line 244 from:

plt.plot(m.time,p.value,'b-',LineWidth=2,label='MV')

to:

plt.plot(m.time,p.value,'b-',lw=2,label='MV')

Changed line 250 from:

plt.plot(m.time,v.value,'r--',LineWidth=2,label='CV')

to:

plt.plot(m.time,v.value,'r--',lw=2,label='CV')

Changed line 256 from:

plt.plot(m.time,e.value,'r--',LineWidth=2,label='Error')

to:

plt.plot(m.time,e.value,'r--',lw=2,label='Error')

Changed line 141 from:

$$y,x,u=\mathrm{outputs\,states\,and\,inputs}$$

to:

$$y,x,u=\mathrm{outputs,\,states,\,and\,inputs}$$

Changed lines 91-92 from:

$$\min_{x,y,u} \Phi = \left(y-y_t\right)^T W_t \left(y-y_t\right) + y^T c_y + u^T c_u + \Delta u^T c_{\Delta u} \Delta u$$

to:

$$\min_{x,y,u} \Phi = \left(y-y_t\right)^T W_t \left(y-y_t\right) + y^T w_y + u^T w_u + \Delta u^T W_{\Delta u} \Delta u$$

Changed lines 105-106 from:

$$\min_{x,y,u} \Phi = w_{hi}^T e_{hi} + w_{lo}^T e_{lo} + y^T c_y + u^T c_u + w_{\Delta u}^T \left(\Delta u_U+\Delta u_L\right)$$

to:

$$\min_{x,y,u} \Phi = w_{hi}^T e_{hi} + w_{lo}^T e_{lo} + y^T w_y + u^T w_u + w_{\Delta u}^T \left(\Delta u_U+\Delta u_L\right)$$

Changed lines 137-139 from:

$$c_{\Delta u}=\mathrm{manipulated\,variable\,movement\,penalty\,(DCOST)}$$

to:

$$W_{\Delta u}, w_{\Delta u}=\mathrm{manipulated\,variable\,movement\,penalty\,(DCOST)}$$

$$w_{u}, w_{y}=\mathrm{weight\,on\,input\,and\,output\,(COST)}$$

Changed lines 109-111 from:

$$0 = f\left(\frac{dx}{dt},x,y,p\right)$$

$$0 \le g\left(\frac{dx}{dt},x,y,p\right)$$

to:

$$0 = f\left(\frac{dx}{dt},x,y,u\right)$$

$$0 \le g\left(\frac{dx}{dt},x,y,u\right)$$

Changed line 133 from:

$$y_t,y_{t,hi},y_{t,lo}=\mathrm{reference trajectory or range}$$

to:

$$y_t,y_{t,hi},y_{t,lo}=\mathrm{reference\,trajectory\,or\,range}$$

Added lines 113-116:

$$\tau_c \frac{dy_{t,hi}}{dt} + y_{t,hi} = sp_{hi}$$

$$\tau_c \frac{dy_{t,lo}}{dt} + y_{t,lo} = sp_{lo}$$

Changed lines 129-147 from:
to:

$$\Phi=\mathrm{Objective\,Function}$$

$$y=\mathrm{model\,predictions}$$

$$y_t,y_{t,hi},y_{t,lo}=\mathrm{reference trajectory or range}$$

$$W_t,w_{hi}, w_{lo}=\mathrm{penalty\,outside\,reference\,trajectory\,(WSP,WSPHI,WSPLO)}$$

$$c_{\Delta u}=\mathrm{manipulated\,variable\,movement\,penalty\,(DCOST)}$$

$$y,x,u=\mathrm{outputs\,states\,and\,inputs}$$

$$\Delta u=\mathrm{manipulated\,variable\,change}$$

$$f,g=\mathrm{equality\,and\,inequality\,constraints}$$

$$e_{hi},e_{lo}=\mathrm{upper\,and\,lower\,error\,outside\,dead-band}$$

$$\Delta u_U,\Delta u_L=\mathrm{upper\,and\,lower\,manipulated\,variable\,change}$$

Changed lines 117-121 from:

$$\Delta p_U \ge p - \hat p$$

$$\Delta p_L \ge \hat p - p$$

$$e_{hi}, e_{lo}, \Delta p_U, \Delta p_L \ge 0$$

to:

$$\Delta u_U \ge u_i - u_{i-1}$$

$$\Delta u_L \ge u_{i-1} - u_i$$

$$e_{hi}, e_{lo}, \Delta u_U, \Delta u_L \ge 0$$

Changed lines 105-121 from:
to:

$$\min_{x,y,u} \Phi = w_{hi}^T e_{hi} + w_{lo}^T e_{lo} + y^T c_y + u^T c_u + w_{\Delta u}^T \left(\Delta u_U+\Delta u_L\right)$$

$$\mathrm{subject\;\;to}$$

$$0 = f\left(\frac{dx}{dt},x,y,p\right)$$

$$0 \le g\left(\frac{dx}{dt},x,y,p\right)$$

$$e_{hi} \ge y - y_{t,hi}$$

$$e_{lo} \ge y_{t,lo} - y$$

$$\Delta p_U \ge p - \hat p$$

$$\Delta p_L \ge \hat p - p$$

$$e_{hi}, e_{lo}, \Delta p_U, \Delta p_L \ge 0$$

Changed lines 95-99 from:

$$0 = f\left(\frac{d\;x}{d\;t},x,y,u\right)$$

$$0 \le g\left(\frac{d\;x}{d\;t},x,y,u\right)$$

$$\tau_c \frac{d\;y_t}{d\;t} + y_t = sp$$

to:

$$0 = f\left(\frac{dx}{dt},x,y,u\right)$$

$$0 \le g\left(\frac{dx}{dt},x,y,u\right)$$

$$\tau_c \frac{dy_t}{dt} + y_t = sp$$

Changed lines 91-99 from:
to:

$$\min_{x,y,u} \Phi = \left(y-y_t\right)^T W_t \left(y-y_t\right) + y^T c_y + u^T c_u + \Delta u^T c_{\Delta u} \Delta u$$

$$\mathrm{subject\;\;to}$$

$$0 = f\left(\frac{d\;x}{d\;t},x,y,u\right)$$

$$0 \le g\left(\frac{d\;x}{d\;t},x,y,u\right)$$

$$\tau_c \frac{d\;y_t}{d\;t} + y_t = sp$$

December 28, 2018, at 10:34 PM by 10.37.144.156 -
Added lines 126-127:

Some applications require a custom reference trajectory that does not fit a standard form. A custom reference trajectory is specified by creating a new error (e) variable that is the difference between the specified trajectory (sinusoidal, sawtooth, random, etc) and the model output. This error is specified as a controlled variable (CV) with an upper and lower dead-band denoted as SPHI and SPLO. The CV can also be a value of zero with a squared error objective (e.SP=0, m.options.CV_TYPE=2) to drive to a target instead of a dead-band range.

Changed line 180 from:

e.TR_INIT = 1 #setpoint trajectory

to:

e.TR_INIT = 0 #setpoint trajectory

December 28, 2018, at 10:28 PM by 10.37.144.156 -
Changed lines 124-128 from:

Reactor Tuning Example

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

to:

Custom Reference Trajectory

(:toggle hide gekko_traj button show="Custom Reference Trajectory with GEKKO":) (:div id=gekko_traj:) (:source lang=python:) import numpy as np from random import random from gekko import GEKKO import matplotlib.pyplot as plt

  1. initialize GEKKO model

m = GEKKO()

  1. time

m.time = np.linspace(0,20,41)

  1. constants

mass = 500

  1. Parameters

b = m.Param(value=50) K = m.Param(value=0.8)

  1. Manipulated variable

p = m.MV(value=0, lb=-100, ub=100)

  1. Reference trajectory

sine = 10*np.sin(m.time/20*4*np.pi) traj = m.Param(value=sine)

  1. Controlled Variable

v = m.SV(value=0,name='v')

  1. Error

e = m.CV(value=0,name='e')

  1. Equations

m.Equation(mass*v.dt() == -v*b + K*b*p) m.Equation(e==v-traj)

m.options.IMODE = 6 # control

  1. MV tuning

p.STATUS = 1 #allow optimizer to change p.DCOST = 0.1 #smooth out MV p.DMAX = 50 #slow down change of MV

  1. CV tuning

e.STATUS = 1 #add the CV to the objective m.options.CV_TYPE = 1 #Dead-band db = 2 e.SPHI = db #set point e.SPLO = -db #set point e.TR_INIT = 1 #setpoint trajectory e.TAU = 5 #time constant of setpoint trajectory

  1. Solve

m.solve()

  1. get additional solution information

import json with open(m.path+'//results.json') as f:

    results = json.load(f)
  1. Plot solution

plt.figure() plt.subplot(3,1,1) plt.plot(m.time,p.value,'b-',LineWidth=2,label='MV') plt.legend(loc='best') plt.ylabel('MV') plt.subplot(3,1,2) plt.plot(m.time,sine+db,'k-',label='SPHI') plt.plot(m.time,sine-db,'k-',label='SPLO') plt.plot(m.time,v.value,'r--',LineWidth=2,label='CV') plt.legend(loc='best') plt.ylabel('CV') plt.subplot(3,1,3) plt.plot(m.time,results['e.tr_hi'],'k-',label='SPHI') plt.plot(m.time,results['e.tr_lo'],'k-',label='SPLO') plt.plot(m.time,e.value,'r--',LineWidth=2,label='Error') plt.legend(loc='best') plt.ylabel('Error') plt.xlabel('time') plt.show() (:sourceend:) (:divend:)

December 28, 2018, at 09:29 PM by 10.37.144.156 -
Changed lines 40-41 from:

v = m.CV(value=0)

to:

v = m.CV(value=0,name='v')

Changed lines 75-76 from:

plt.plot(m.time,results['v1.tr_lo'],'k-',label='SPHI') plt.plot(m.time,results['v1.tr_hi'],'k-',label='SPLO')

to:

plt.plot(m.time,results['v.tr_lo'],'k-',label='SPHI') plt.plot(m.time,results['v.tr_hi'],'k-',label='SPLO')

Added lines 12-83:

(:toggle hide gekko_mpc button show="Model Predictive Control with GEKKO":) (:div id=gekko_mpc:)

(:source lang=python:) import numpy as np from random import random from gekko import GEKKO import matplotlib.pyplot as plt

  1. initialize GEKKO model

m = GEKKO()

  1. time

m.time = np.linspace(0,20,41)

  1. constants

mass = 500

  1. Parameters

b = m.Param(value=50) K = m.Param(value=0.8)

  1. Manipulated variable

p = m.MV(value=0, lb=0, ub=100)

  1. Controlled Variable

v = m.CV(value=0)

  1. Equations

m.Equation(mass*v.dt() == -v*b + K*b*p)

m.options.IMODE = 6 # control

  1. MV tuning

p.STATUS = 1 #allow optimizer to change p.DCOST = 0.1 #smooth out MV p.DMAX = 20 #slow down change of MV

  1. CV tuning

v.STATUS = 1 #add the CV to the objective m.options.CV_TYPE = 1 #Dead-band v.SPHI = 42 #set point v.SPLO = 38 #set point v.TR_INIT = 1 #setpoint trajectory v.TAU = 5 #time constant of setpoint trajectory

  1. Solve

m.solve()

  1. get additional solution information

import json with open(m.path+'//results.json') as f:

    results = json.load(f)
  1. Plot solution

plt.figure() plt.subplot(2,1,1) plt.plot(m.time,p.value,'b-',LineWidth=2,label='MV') plt.legend(loc='best') plt.ylabel('gas') plt.subplot(2,1,2) plt.plot(m.time,results['v1.tr_lo'],'k-',label='SPHI') plt.plot(m.time,results['v1.tr_hi'],'k-',label='SPLO') plt.plot(m.time,v.value,'r--',LineWidth=2,label='CV') plt.legend(loc='best') plt.ylabel('velocity') plt.xlabel('time') plt.show() (:sourceend:) (:divend:)

Added lines 51-52:

Reactor Tuning Example

Added lines 8-11:

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

Changed lines 5-9 from:

The dynamic control objective function is a mathematical statement that is minimized or maximized to find a best solution among all possible feasible solutions for a controller. The form of this objective function is critical to give desirable solutions for driving a system to a desirable state or along a desired trajectory. Common objective statements relate to economic, safety, operability, environmental, or related objectives. Two common objective functions are shown below as squared error and l1-norm forms1.

to:

The dynamic control objective function is a mathematical statement that is minimized or maximized to find a best solution among all possible feasible solutions for a controller. The form of this objective function is critical to give desirable solutions for driving a system to a desirable state or along a desired trajectory. Common objective statements relate to economic, safety, operability, environmental, or related objectives.

Two common objective functions are shown below as squared error and l1-norm forms1.

Changed line 21 from:
to:
Changed lines 11-12 from:
to:
Changed lines 17-18 from:
to:
Changed line 21 from:
to:
Changed lines 11-12 from:
to:
Changed lines 15-17 from:

The l1-norm objective is the absolute value of the difference between the current measured value of the controlled variable and the desired target value. The absolute value operator is

to:

The l1-norm objective is the absolute value of the difference between the current measured value of the controlled variable and the desired target value. The absolute value operator (abs(x)) does not have a continuous first and second derivative at x=0 (see absolute value function alternatives). Slack variables give the same absolute value function but with continuous first and second derivatives.

Added lines 9-10:

The squared error objective is the most common form used in the literature. It penalizes deviation of the current measured value of the controlled variable from the desired target value.

Added lines 15-16:

The l1-norm objective is the absolute value of the difference between the current measured value of the controlled variable and the desired target value. The absolute value operator is

Added lines 22-42:

In formulating an objective function and model equations follow the following tips for improved convergence.

  1. Rearrange to equation in residual form to:
    1. Avoid divide by zero
    2. Minimize use of functions like sqrt, log, exp, etc.
    3. Have continuous first and second derivatives
    4. Fit the equation into a linear or quadratic form
  2. Bounds
    1. Include variable bounds to exclude infeasible solutions
    2. Variable bounds to avoid regions of strong nonlinearity
    3. Caution: watch for infeasible solutions
  3. Scaling:
    1. Scale absolute value of variables to 1e-3 to 1e3
    2. Scale absolute value of equation residuals to 1e-3 to 1e3
    3. Better that 1st derivative values are closer to 1.0
  4. Good initial conditions:
    1. Starting near a solution can improve convergence
    2. Try multiple initial conditions to verify global solution (non-convex problems)
    3. Explicitly calculate intermediate values
  5. Check iteration summary for improved convergence
Added lines 18-21:

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

Deleted lines 18-42:

Exercise

Objective: Set up and solve several dynamic optimization benchmark problems2. Create a program to optimize and display the results. Estimated Time (each): 30 minutes

  • Example 1a - Nonlinear, unconstrained, minimize final state
  • Example 1b - Nonlinear, unconstrained, minimize final state with terminal constraint
  • Example 2 - Nonlinear, constrained, minimize final state
  • Example 3 - Tubular reactor with parallel reaction
  • Example 4 - Batch reactor with consecutive reactions A->B->C

Example 5 - Catalytic reactor with A<->B->C

Solution

(:html:) <iframe width="560" height="315" src="https://www.youtube.com/embed/mmCFF3-6sGg" frameborder="0" allowfullscreen></iframe> (:htmlend:)

Deleted line 22:
  1. M. Čižniar, M. Fikar, M.A. Latifi: A MATLAB Package for Dynamic Optimisation of Processes, 7th International Scientific – Technical Conference – Process Control 2006, June 13 – 16, 2006, Kouty nad Desnou, Czech Republic. Article
Added lines 39-42:

(:html:) <iframe width="560" height="315" src="https://www.youtube.com/embed/mmCFF3-6sGg" frameborder="0" allowfullscreen></iframe> (:htmlend:)

Changed line 33 from:

Example 5 - Catalytic plug flow reactor with A->B->C

to:

Example 5 - Catalytic reactor with A<->B->C

May 18, 2015, at 03:29 PM by 45.56.3.184 -
Added lines 19-39:

Exercise

Objective: Set up and solve several dynamic optimization benchmark problems2. Create a program to optimize and display the results. Estimated Time (each): 30 minutes

  • Example 1a - Nonlinear, unconstrained, minimize final state
  • Example 1b - Nonlinear, unconstrained, minimize final state with terminal constraint
  • Example 2 - Nonlinear, constrained, minimize final state
  • Example 3 - Tubular reactor with parallel reaction
  • Example 4 - Batch reactor with consecutive reactions A->B->C

Example 5 - Catalytic plug flow reactor with A->B->C

Solution

Changed line 44 from:
to:
  1. M. Čižniar, M. Fikar, M.A. Latifi: A MATLAB Package for Dynamic Optimisation of Processes, 7th International Scientific – Technical Conference – Process Control 2006, June 13 – 16, 2006, Kouty nad Desnou, Czech Republic. Article
May 18, 2015, at 03:21 PM by 45.56.3.184 -
Deleted lines 18-35:

Exercise

Objective: Design a model predictive controller with a custom objective function that satisfies a specific problem criterion. Simulate and optimize a pendulum system with an adjustable overhead cart. Estimated time: 3 hours.

A pendulum is described by the following dynamic equations:

where epsilon is m2/(m1+m2), y is the position of the overhead cart, v is the velocity of the overhead cart, theta is the angle of the pendulum relative to the cart, and q is the rate of angle change2.

The objective of the controller is to adjust the force on the cart to move the pendulum mass to a new final position. Ensure that initial and final velocities and angles of the pendulum are zero. The position of the pendulum mass is initially at -1 and it is desired to move it to the new position of 0 within 6.2 seconds. Demonstrate controller performance with changes in the pendulum position and that the final pendulum mass remains at the final position without oscillation.

Solution

Deleted line 22:
  1. Bryson, A.E., Dynamic Optimization, Addison-Wesley, 1999.
May 13, 2015, at 06:36 PM by 10.5.113.160 -
Changed lines 27-28 from:

where epsilon is m2/(m1+m2), y is the position of the overhead cart, v is the velocity of the overhead cart, theta is the angle of the pendulum relative to the cart, and q is the rate of angle change.

to:

where epsilon is m2/(m1+m2), y is the position of the overhead cart, v is the velocity of the overhead cart, theta is the angle of the pendulum relative to the cart, and q is the rate of angle change2.

Deleted lines 30-31:
Added lines 35-36:
Added lines 40-41:
  1. Bryson, A.E., Dynamic Optimization, Addison-Wesley, 1999.
May 13, 2015, at 06:22 PM by 10.5.113.160 -
Added lines 19-36:

Exercise

Objective: Design a model predictive controller with a custom objective function that satisfies a specific problem criterion. Simulate and optimize a pendulum system with an adjustable overhead cart. Estimated time: 3 hours.

A pendulum is described by the following dynamic equations:

where epsilon is m2/(m1+m2), y is the position of the overhead cart, v is the velocity of the overhead cart, theta is the angle of the pendulum relative to the cart, and q is the rate of angle change.

The objective of the controller is to adjust the force on the cart to move the pendulum mass to a new final position. Ensure that initial and final velocities and angles of the pendulum are zero. The position of the pendulum mass is initially at -1 and it is desired to move it to the new position of 0 within 6.2 seconds. Demonstrate controller performance with changes in the pendulum position and that the final pendulum mass remains at the final position without oscillation.

Solution

Added line 40:
May 11, 2015, at 10:58 PM by 10.5.113.160 -
Changed line 21 from:
  1. Hedengren, J. D. and Asgharzadeh Shishavan, R., Powell, K.M., and Edgar, T.F., Nonlinear Modeling, Estimation and Predictive Control in APMonitor, Computers and Chemical Engineering, Volume 70, pg. 133–148, 2014. https://dx.doi.org/10.1016/j.compchemeng.2014.04.013?
to:
  1. Hedengren, J. D. and Asgharzadeh Shishavan, R., Powell, K.M., and Edgar, T.F., Nonlinear Modeling, Estimation and Predictive Control in APMonitor, Computers and Chemical Engineering, Volume 70, pg. 133–148, 2014. Article
May 11, 2015, at 10:57 PM by 10.5.113.160 -
Changed lines 5-21 from:

The dynamic control objective function is a mathematical statement that is minimized or maximized to find a best solution among all possible feasible solutions for a controller. The form of this objective function is critical to give desirable solutions for driving a system to a desirable state or along a desired trajectory. Common objective statements relate to economic, safety, operability, environmental, or related objectives.

to:

The dynamic control objective function is a mathematical statement that is minimized or maximized to find a best solution among all possible feasible solutions for a controller. The form of this objective function is critical to give desirable solutions for driving a system to a desirable state or along a desired trajectory. Common objective statements relate to economic, safety, operability, environmental, or related objectives. Two common objective functions are shown below as squared error and l1-norm forms1.

Squared Error Objective

l1-norm Objective

Nomenclature

References

  1. Hedengren, J. D. and Asgharzadeh Shishavan, R., Powell, K.M., and Edgar, T.F., Nonlinear Modeling, Estimation and Predictive Control in APMonitor, Computers and Chemical Engineering, Volume 70, pg. 133–148, 2014. https://dx.doi.org/10.1016/j.compchemeng.2014.04.013?
Added lines 1-5:

(:title Dynamic Control Objectives:) (:keywords objective function, MATLAB, Simulink, predictive control, time horizon, tutorial:) (:description Objective function forms for improved control performance with nonlinear models:)

The dynamic control objective function is a mathematical statement that is minimized or maximized to find a best solution among all possible feasible solutions for a controller. The form of this objective function is critical to give desirable solutions for driving a system to a desirable state or along a desired trajectory. Common objective statements relate to economic, safety, operability, environmental, or related objectives.