Model Predictive Control Toolbox™ Getting Started Guide Alberto Bemporad Manfred Morari N.
How to Contact MathWorks Latest news: www.mathworks.com Sales and services: www.mathworks.com/sales_and_services User community: www.mathworks.com/matlabcentral Technical support: www.mathworks.com/support/contact_us Phone: 508-647-7000 The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098 Model Predictive Control Toolbox™ Getting Started Guide © COPYRIGHT 2005–2015 by The MathWorks, Inc. The software described in this document is furnished under a license agreement.
Revision History October 2004 March 2005 September 2005 March 2006 September 2006 March 2007 September 2007 March 2008 October 2008 March 2009 September 2009 March 2010 September 2010 April 2011 September 2011 March 2012 September 2012 March 2013 September 2013 March 2014 October 2014 March 2015 First printing Online only Online only Online only Online only Online only Online only Online only Online only Online only Online only Online only Online only Online only Online only Online only Online only Online
Contents 1 2 Introduction Model Predictive Control Toolbox Product Description . . . . Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 1-2 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Building Models MPC Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Plant Model . . . . . . . . .
3 vi Contents CSTR Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19 Linearize Simulink Models . . . . . . . . . . . . . . . . . . . . . . . . . . . Linearization Using MATLAB Code . . . . . . . . . . . . . . . . . . Linearization Using Linear Analysis Tool in Simulink Control Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21 2-21 Identify Plant from Data . . . . . . . . . . . . . . . . . . . . . . . . . . . .
More Manipulated Variables Than Outputs . . . . . . . . . . . . 4 3-59 Designing Controllers Using the Command Line Design Controller at the Command Line . . . . . . . . . . . . . . . . Create a Controller Object . . . . . . . . . . . . . . . . . . . . . . . . . . View and Alter Controller Properties . . . . . . . . . . . . . . . . . . Review Controller Design . . . . . . . . . . . . . . . . . . . . . . . . . . . Perform Linear Simulations . . . . . . . . . . . . . . . . . . . . . . . . .
5 Designing and Testing Controllers in Simulink Design Controller in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . viii Contents 5-2 Test an Existing Controller . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15 Schedule Controllers at Multiple Operating Points . . . . . . A Two-Model Plant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Animation of the Multi-Model Example . . . . . . . . . . . . . . . . Designing the Two Controllers . . . . . . . . . . . . . . . . .
1 Introduction • “Model Predictive Control Toolbox Product Description” on page 1-2 • “Acknowledgments” on page 1-3 • “Bibliography” on page 1-4
1 Introduction Model Predictive Control Toolbox Product Description Design and simulate model predictive controllers Model Predictive Control Toolbox™ provides functions, an app, and Simulink® blocks for systematically analyzing, designing, and simulating model predictive controllers. You can specify plant and disturbance models, horizons, constraints, and weights.
Acknowledgments Acknowledgments MathWorks would like to acknowledge the following contributors to Model Predictive Control Toolbox. Alberto Bemporad Professor of Control Systems, IMT Institute for Advanced Studies Lucca, Italy. Research interests include model predictive control, hybrid systems, optimization algorithms, and applications to automotive, aerospace, and energy systems. Fellow of the IEEE®. Author of the Model Predictive Control Simulink library and commands.
1 Introduction Bibliography [1] Allgower, F., and A. Zheng, Nonlinear Model Predictive Control, Springer-Verlag, 2000. [2] Camacho, E. F., and C. Bordons, Model Predictive Control, Springer-Verlag, 1999. [3] Kouvaritakis, B., and M. Cannon, Non-Linear Predictive Control: Theory & Practice, IEE Publishing, 2001. [4] Maciejowski, J. M., Predictive Control with Constraints, Pearson Education POD, 2002. [5] Prett, D., and C. Garcia, Fundamental Process Control, Butterworths, 1988. [6] Rossiter, J. A.
2 Building Models • “MPC Modeling” on page 2-2 • “Signal Types” on page 2-8 • “Construct Linear Time Invariant (LTI) Models” on page 2-9 • “Specify Multi-Input Multi-Output (MIMO) Plants” on page 2-17 • “CSTR Model” on page 2-19 • “Linearize Simulink Models” on page 2-21 • “Identify Plant from Data” on page 2-31 • “Design Controller for Identified Plant” on page 2-33 • “Design Controller Using Identified Model with Noise Channel” on page 2-35 • “Working with Impulse-Response Models” on page 2-37 • “Bibliogr
2 Building Models MPC Modeling In this section... “Plant Model” on page 2-2 “Input Disturbance Model” on page 2-4 “Output Disturbance Model” on page 2-5 “Measurement Noise Model” on page 2-6 The model structure used in the MPC controller appears in the illustration below. This section explains how the models connect for prediction and state estimation.
MPC Modeling • Identified models (requires System Identification Toolbox™): idss, idtf, idproc, and idpoly. The MPC controller performs all the estimation and optimization calculations using a discrete-time, delay-free, state-space system, with dimensionless input and output variables. Therefore, when you specify a plant model in the MPC controller, the following model-conversion steps are automatically carried out, if needed: 1 Conversion to state-space.
2 Building Models • up — Dimensionless plant input variables. • up — Dimensionless plant output variables. The resulting plant model has the following equivalent form: x p ( k + 1 ) = A p x p ( k ) + Bpu u ( k ) + Bpv v ( k ) + B pd d ( k ) y p ( k ) = Cp x p ( k ) + D pu u ( k ) + D pv v ( k ) + D pd d ( k ) . Here, C p = So-1C , Bpu, Bpv and Bpd are the corresponding columns of BSi. Also, Dpu, Bpv and Bpd are the corresponding columns of So-1 DSi .
MPC Modeling You can provide the input disturbance model as an LTI state-space (ss), transfer function (tf), or zero-pole-gain (zpk) object. See “Controller State Estimation” for more details about the input disturbance model. The MPC controller converts the input disturbance model to a discrete-time, delay-free, LTI state-space system using the same steps used to convert the plant model (see “Plant Model” on page 2-2).
2 Building Models Here, Aod, Bod, Cod, and Dod are constant state space matrices and: • xod(k) — nxod ≥ 1 output disturbance model states. • yod(k) — ny dimensionless output disturbances to be added to the dimensionless plant outputs. • wod(k) — nod dimensionless white noise inputs, assumed to have zero mean, unity variance. Measurement Noise Model One of the controller design objectives is to distinguish disturbances, which require a response, from measurement noise, which should be ignored.
MPC Modeling Note: If the minimum eigenvalue of Dn DnT is less than 1x10–8, the MPC controller adds 1x10–4 to each diagonal element of Dn. This adjustment makes it more likely that the default Kalman gain calculation will succeed.
2 Building Models Signal Types Inputs The plant inputs are the independent variables affecting the plant. As shown in “MPC Modeling” on page 2-2, there are three types: Measured disturbances The controller can't adjust them, but uses them for feedforward compensation. Manipulated variables The controller adjusts these in order to achieve its goals. Unmeasured disturbances These are independent inputs of which the controller has no direct knowledge, and for which it must compensate.
Construct Linear Time Invariant (LTI) Models Construct Linear Time Invariant (LTI) Models In this section... “Transfer Function Models” on page 2-9 “Zero/Pole/Gain Models” on page 2-10 “State-Space Models” on page 2-10 “LTI Object Properties” on page 2-12 “LTI Model Characteristics” on page 2-15 Model Predictive Control Toolbox software supports the same LTI model formats as does Control System Toolbox™ software. You can use whichever is most convenient for your application.
2 Building Models Gtf1 = tf([1 2], [1 1 10], 'OutputDelay', 1.5) Control System Toolbox software builds and displays it as follows: Transfer function: s + 2 exp(-1.5*s) * -----------s^2 + s + 10 Zero/Pole/Gain Models Like the TF, the zero/pole/gain (ZPK) format relates an input/output pair. The difference is that the ZPK numerator and denominator polynomials are factored, as in G ( s) = 2 .5 s + 0.45 ( s + 0 .3)( s + 0 .1 + 0 .7 i)( s + 0 .1 - 0.7i) (zeros and/or poles are complex numbers in general).
Construct Linear Time Invariant (LTI) Models CSTR Schematic Measurement of reactant concentrations is often difficult, if not impossible. Let us assume that T is a measured output, CA is an unmeasured output, Tc is a manipulated variable, and CAi is an unmeasured disturbance.
2 Building Models C = [0 1 1 0]; D = zeros(2,2); CSTR = ss(A,B,C,D); This defines a continuous-time state-space model. If you do not specify a sampling period, a default sampling value of zero applies. You can also specify discrete-time state-space models. You can specify delays in both continuous-time and discrete-time models. Note In the CSTR example, the D matrix is zero and the output does not instantly respond to change in the input.
Construct Linear Time Invariant (LTI) Models output. (See “Signal Types” on page 2-8 for definitions.) For example, the code specifies that input 2 of model CSTR is an unmeasured disturbance. The last line causes the LTI object to be displayed, generating the following lines in the MATLAB Command Window: a = C_A T C_A -0.0285 -0.0371 T -0.0014 -0.1476 b = C_A T T_c -0.085 0.0802 C_Ai 0.0238 0.
2 Building Models Input and Output Types General Case As mentioned in “Signal Types” on page 2-8, Model Predictive Control Toolbox software supports three input types and two output types. In a Model Predictive Control Toolbox design, designation of the input and output types determines the controller dimensions and has other important consequences.
Construct Linear Time Invariant (LTI) Models Use setmpcsignals to make type definition. For example CSTR = setmpcsignals(CSTR, 'UD', 2, 'UO', 2); sets InputGroup and OutputGroup to the same values as in the previous example. The CSTR display would then include the following lines: Input groups: Name Unmeasured Manipulated Output groups: Name Unmeasured Measured Channels 2 1 Channels 2 1 Notice that setmpcsignals sets unspecified inputs to Manipulated and unspecified outputs to Measured.
2 Building Models 2-16 Example Intended Result zero(CSTR) Compute CSTR model's transmission zeros.
Specify Multi-Input Multi-Output (MIMO) Plants Specify Multi-Input Multi-Output (MIMO) Plants Most Model Predictive Control Toolbox applications involve plants having multiple inputs and outputs. You can use ss, tf, and zpk to represent a MIMO plant model. For example, consider the following model of a distillation column [11], which has been used in many advanced control studies: È 12.8 e-s Í È y1 ˘ Í 16.7 s + 1 = Í ˙ Í Î y2 ˚ 6 .6 e-7 s Í Î 10.9 s + 1 - 18 .9 e-3 s 21 .0 s + 1 -19.4 e-3 s 14.4 s + 1 3.
2 Building Models Distillate Purity: Bottoms Purity: exp(-1*s) * ---------16.7 s + 1 6.6 exp(-7*s) * ---------10.9 s + 1 From input "Steam Rate" to output... -18.9 Distillate Purity: exp(-3*s) * -------21 s + 1 Bottoms Purity: -19.4 exp(-3*s) * ---------14.4 s + 1 From input "Feed Rate" to output... Distillate Purity: Bottoms Purity: Input groups: Name Measured Manipulated Output groups: Name Measured 3.8 exp(-8.1*s) * ---------14.9 s + 1 4.9 exp(-3.4*s) * ---------13.
CSTR Model CSTR Model The linearized model of a continuous stirred-tank reactor (CSTR) involving an exothermic (heat-generating) reaction is represented by the following differential equations:[9] dC¢A dt = a11C¢A + a12 T ¢ + b11Tc¢ + b12C¢Ai dT ¢ = a21C¢A + a22 T ¢ + b21Tc¢ + b22 C¢Ai dt where CA is the concentration of a key reactant, T is the temperature in the reactor, Tc is the coolant temperature, CAi is the reactant concentration in the reactor feed, and aij and bij are constants. The primes (e.
2 Building Models ÈC¢ ˘ È T¢ ˘ È T¢ ˘ x = Í A˙ u= Í c ˙ y = Í ˙ , Î T¢ ˚ Î C¢Ai ˚ ÎC¢A ˚ Èa A = Í 11 Î a21 a12 ˘ b12 ˘ Èb B = Í 11 ˙ ˙ C= a22 ˚ Î b21 b22 ˚ È0 1 ˘ È0 0 ˘ Í1 0 ˙ D = Í0 0 ˙ Î ˚ Î ˚ The following code shows how to define such a model for some specific values of the aij and bij constants: A = [-0.0285 -0.0014 -0.0371 -0.1476]; B = [-0.0850 0.0238 0.0802 0.4462]; C = [0 1 1 0]; D = zeros(2,2); CSTR = ss(A,B,C,D); The following code sets some of the CSTR model's optional properties: CSTR.
Linearize Simulink Models Linearize Simulink Models Generally, real systems are nonlinear. To design an MPC controller for a nonlinear system, you must model the plant in Simulink. Although an MPC controller can regulate a nonlinear plant, the model used within the controller must be linear. In other words, the controller employs a linear approximation of the nonlinear plant. The accuracy of this approximation significantly affects controller performance.
2 Building Models opspec = operspec('CSTR_OpenLoop'); opspec = addoutputspec(opspec,'CSTR_OpenLoop/CSTR',2); opspec.Outputs(1).Known = true; opspec.Outputs(1).y = 2; op1 = findop('CSTR_OpenLoop',opspec); Operating Point Search Report: --------------------------------Operating Report for the Model CSTR_OpenLoop. (Time-Varying Components Evaluated at time t=0) Operating point specifications were successfully met. States: ---------(1.) CSTR_OpenLoop/CSTR/C_A x: 2 dx: -4.6e-12 (0) (2.
Linearize Simulink Models For example, the following code specifies the coolant temperature as 305 K and initial guess values of the C_A and T_K states before calculating the steady-state operating point: opspec = operspec('CSTR_OpenLoop'); opspec.States(1).x = 1; opspec.States(2).x = 400; opspec.Inputs(1).Known = true; opspec.Inputs(1).u = 305; op2 = findop('CSTR_OpenLoop',opspec); Operating Point Search Report: --------------------------------Operating Report for the Model CSTR_OpenLoop.
2 Building Models io(1) io(2) io(3) io(4) io(5) = = = = = linio('CSTR_OpenLoop/Feed Concentration', 1, 'input'); linio('CSTR_OpenLoop/Feed Temperature', 1, 'input'); linio('CSTR_OpenLoop/Coolant Temperature', 1, 'input'); linio('CSTR_OpenLoop/CSTR', 1, 'output'); linio('CSTR_OpenLoop/CSTR', 2, 'output'); Linearize Model Linearize the model using the specified operating point, op1, and input/output signals, io. sys = linearize('CSTR_OpenLoop', op1, io) sys = a = C_A -5 47.68 C_A T_K T_K -0.3427 2.
Linearize Simulink Models For this example, the CSTR model, CSTR_OpenLoop, is linearized. Open Simulink Model sys = 'CSTR_OpenLoop'; open_system(sys) Open Linear Analysis Tool In the Simulink model window, select Analysis > Control Design > Linear Analysis. Specify Linearization Inputs and Outputs The linearization inputs and outputs are already specified for CSTR_OpenLoop. The input signals correspond to the outputs from the Feed Concentration, Feed Temperature, and Coolant Temperature blocks.
2 Building Models To specify a signal as a: • Linearization input, right-click the signal in the Simulink model window and select Linear Analysis Points > Input Perturbation. • Linearization output, right-click the signal in the Simulink model window and select Linear Analysis Points > Output Measurement. Specify Residual Concentration as Known Trim Constraint In the Simulink model window, right-click the CA output signal from the CSTR block. Select Linear Analysis Points > Trim Output Constraint.
Linearize Simulink Models Create and Verify Operating Point In the Trim the model dialog box, click Start trimming. The operating point op_trim1 displays in the Linear Analysis Workspace. Double click op_trim1 to view the resulting operating point.
2 Building Models In the Edit dialog box, select the Input tab. The coolant temperature at steady state is 299 K, as desired. Linearize Model In the Linear Analysis tab, in the Operating Point drop-down list, select op_trim1. Click Step to linearize the model. This creates the linear model linsys1 in the Linear Analysis Workspace and generates a step response for this model. linsys1 uses optrim1 as its operating point.
Linearize Simulink Models The step response from feed concentration to output CSTR/2 displays an interesting inverse response. An examination of the linear model shows that CSTR/2 is the residual CSTR concentration, C_A. When the feed concentration increases, C_A increases initially because more reactant is entering, which increases the reaction rate. This rate increase results in a higher reactor temperature (output CSTR/1), which further increases the reaction rate and C_A decreases dramatically.
2 Building Models 2-30 • “Design Controller in Simulink” • “Design Controller at the Command Line”
Identify Plant from Data Identify Plant from Data This example shows how to identify a linear plant model using measured data. When you have measured plant input/output data, you can use System Identification Toolbox software to estimate a linear plant model. Then, you can use the estimated plant model to create a model predictive controller. You can estimate the plant model either programmatically or by using the System Identification app. This example requires a System Identification Toolbox license.
2 Building Models dry_data_detrended = detrend(dry_data); Estimate a linear plant model. You can use System Identification Toolbox software to estimate a linear plant model in one of the following forms: • State-space model • Transfer function model • Polynomial model • Process model • Grey-box model For this example, estimate a third-order, linear state-space plant model using the detrended data.
Design Controller for Identified Plant Design Controller for Identified Plant This example shows how to design a model predictive controller for a linear identified plant model. This example uses only the measured input and output of the identified model for the model predictive controller plant model. This example requires a System Identification Toolbox license. Obtain an identified linear plant model. load dryer2; Ts = 0.
2 Building Models To view the structure of the model predictive controller, type controller at the MATLAB command prompt.
Design Controller Using Identified Model with Noise Channel Design Controller Using Identified Model with Noise Channel This example shows how to design a model predictive controller using an identified plant model with a nontrivial noise component. This example requires a System Identification Toolbox license. Obtain an identified linear plant model. load dryer2; Ts = 0.
2 Building Models When you use the 'augmented' input argument, ss creates two input groups, Measured and Noise, for the measured and noise inputs of plant_idss. mpc handles the measured and noise components of plant_ss and plant_idss identically.
Working with Impulse-Response Models Working with Impulse-Response Models You can use System Identification Toolbox software to estimate finite step-response or finite impulse-response (FIR) plant models using measured data. Such models, also known as nonparametric models (see [6] for example), are easy to determine from plant data ([3] and [7]) and have intuitive appeal. You use the impulseest function to estimate an FIR model from measured data.
2 Building Models Bibliography [1] Allgower, F., and A. Zheng, Nonlinear Model Predictive Control, Springer-Verlag, 2000. [2] Camacho, E. F., and C. Bordons, Model Predictive Control, Springer-Verlag, 1999. [3] Cutler, C., and F. Yocum, “Experience with the DMC inverse for identification,” Chemical Process Control — CPC IV (Y. Arkun and W. H. Ray, eds.), CACHE, 1991. [4] Kouvaritakis, B., and M. Cannon, Non-Linear Predictive Control: Theory & Practice, IEE Publishing, 2001. [5] Maciejowski, J. M.
3 Designing Controllers Using the Design Tool GUI • “Design Controller Using the Design Tool” on page 3-2 • “Test Controller Robustness” on page 3-48 • “Design Controller for Plant with Delays” on page 3-51 • “Design Controller for Nonsquare Plant” on page 3-58
3 Designing Controllers Using the Design Tool GUI Design Controller Using the Design Tool In this section...
Design Controller Using the Design Tool Model Predictive Control Toolbox Design Tool Initial View Load a Plant Model The first step in the design is to load a plant model. Its dimensions and signal characteristics set the context for the remaining steps. You can either load the model directly, as described in this section, or indirectly by importing a controller or a saved design (see “Load Your Saved Work” on page 3-46).
3 Designing Controllers Using the Design Tool GUI The following example uses the CSTR model described in “CSTR Model” on page 2-19. Verify that the LTI object CSTR is in your MATLAB workspace. Plant Model Importer Dialog Box In the design tool, click the Import Plant button (see Model Predictive Control Toolbox Design Tool Initial View). The Plant Model Importer dialog box appears. Plant Model Importer Dialog Box The Import from MATLAB workspace option button should be selected by default, as shown.
Design Controller Using the Design Tool Model Predictive Control Toolbox Design Tool's Signal Definition View Signal Property Specifications The figure's graphical display indicates that you've imported a plant model by showing the number of inputs and outputs, and the number in each subclass: measured disturbance, manipulated variables, etc.).
3 Designing Controllers Using the Design Tool GUI Note Once you leave this view, if you subsequently change a signal type, you will have to restart the design. Be sure the signal types are correct at the beginning. • The Description and Unit entries are optional. You can enter the values shown in Model Predictive Control Toolbox Design Tool's Signal Definition View manually. As you will see, the design tool uses them to label plots and other tables.
Design Controller Using the Design Tool Plant Models View with CSTR Model Selected Viewing Your Controllers Next, select Controllers. The view shown in Controllers View appears. A + sign to the left of Controllers indicates that it contains subnodes. You can click a + sign to expand the tree (as shown in Controllers View, where the + sign has changed to a – sign).
3 Designing Controllers Using the Design Tool GUI Controllers View The table at the top of Controllers View lists all the controllers you've defined. The design tool automatically creates a controller containing Model Predictive Control Toolbox defaults, naming it MPC1. It is a subnode of Controllers. Note If you define additional controllers, they will appear here.
Design Controller Using the Design Tool The buttons shown in Controllers View let you do the following: • Import a controller designed previously and stored either in your workspace or in a MAT-file. • Export the selected controller to your workspace. • Create a new controller initialized to Model Predictive Control Toolbox defaults. • Copy the selected controller, creating a duplicate you can modify. • Delete the selected controller.
3 Designing Controllers Using the Design Tool GUI Scenarios View Whenever you select the Scenarios node, you see a table summarizing your current scenarios (not shown). Its function is similar to the Controllers view described previously. Perform Linear Simulations You usually want to test your controller in simulations. The Model Predictive Control Toolbox design tool makes it easy to run closed-loop simulations involving a Model Predictive Control Toolbox controller and an LTI plant model.
Design Controller Using the Design Tool • “Running a Simulation” on page 3-12 • “Open-Loop Simulations” on page 3-15 Defining Simulation Conditions To define simulation conditions, select an existing scenario node or create a new one, and then edit its tabular fields to define your conditions. CSTR Temperature Setpoint Change Scenario shows the result of renaming the default Scenario1 node to T Setpoint and editing its default conditions.
3 Designing Controllers Using the Design Tool GUI CSTR Temperature Setpoint Change Scenario Running a Simulation To run a simulation, do one of the following: • Select the scenario you want to run, and click its Simulate button (see the bottom of CSTR Temperature Setpoint Change Scenario). • Click the toolbar's Simulation button, which is the triangular icon shown on the top left of CSTR Temperature Setpoint Change Scenario. The toolbar method runs the current scenario, i.e.
Design Controller Using the Design Tool Plant Outputs for T Setpoint Scenario with Added Data Markers 3-13
3 Designing Controllers Using the Design Tool GUI Plant Inputs for the T Setpoint Scenario Plant Outputs for T Setpoint Scenario with Added Data Markers shows that the reactor temperature setpoint increases suddenly by 2 degrees at t = 5, as you specified when defining the scenario in “Defining Simulation Conditions” on page 3-11. Unfortunately, the temperature does not track the setpoint very well, and there is a persistent error of about 1.6 degrees at the end of the simulation.
Design Controller Using the Design Tool it. Left-click in a graph's white space to erase its markers. For more information on data markers, see the Control System Toolbox documentation. Open-Loop Simulations By default, scenarios are closed loop, i.e., an active controller adjusts the manipulated variables entering your plant based on feedback from the plant outputs. You can also run open-loop simulations that test the plant model without feedback control.
3 Designing Controllers Using the Design Tool GUI Using one of these, simulate the scenario (click its Simulate button). The output response plot should be as shown below. This is the CSTR model's open-loop response to a unit step in the CAi disturbance input. You could also set up the table as shown below. This simulation would display the open-loop response to a unit step in the Tc manipulated variable input (try it). Finally, set it up as follows.
Design Controller Using the Design Tool This adds a pulse to the T output. The pulse begins at time t = 10, and lasts 20 time units. Its height is 0.95 degrees. Run the simulation. The output response plot displays the pulse (see Response Plot Showing Open-Loop Pulse Disturbance). In this case, the T output's nominal value is zero, so you only see the pulse. (If the T output had a nonzero nominal value, the pulse would add to that.
3 Designing Controllers Using the Design Tool GUI By default, each plant signal plots in its own graph area (as shown above). If the simulation is closed loop, each output signal plot include the corresponding setpoint.
Design Controller Using the Design Tool Data Marker Contents Each data marker provides information about the selected point, as follows: • Response – The scenario that generated the curve. • Time – The time value at the data marker location. • Amplitude – The signal value at the data marker location. • Output – The plant variable name (plant outputs only). • Input – Variable name for plant inputs and setpoints.
3 Designing Controllers Using the Design Tool GUI To delete a single data marker, right-click it and select the Delete option. Right-Click Options Right-click a data marker to use one of the following options: • Alignment – Relocate the marker's label. • Font Size – Change the label's font size. • Movable – On/off option that makes the marker movable or fixed. • Delete – Deletes the selected marker.
Design Controller Using the Design Tool Revising a Scenario If you modify and recalculate a scenario, its data are replotted, replacing the original curves. Viewing Selected Variables By default, the design tool plots all plant inputs in a single window, and plots all plant outputs in another. If your application involves many signals, the plots of each may be too small to view comfortably. Therefore, you can control the variables being plotted.
3 Designing Controllers Using the Design Tool GUI Normalizing Response Amplitudes When you're using the Channel Grouping: All option, you might find that the variables have very different scales, making it difficult to view them together. You can choose to normalize the curves, so that each expands or contracts to fill the available plot area. For example, the plot below shows two plant outputs together (Channel Grouping: All option). The outputs have very different magnitudes.
Design Controller Using the Design Tool Change Controller Settings The simulations shown in Plant Outputs for T Setpoint Scenario with Added Data Markers and Plant Inputs for the T Setpoint Scenario uses the default controller settings. These often work well, but the CSTR application is an exception. The following discussion covers the main controller options in detail, and shows how to tune a controller for better performance.
3 Designing Controllers Using the Design Tool GUI • Plant model specifies the LTI model to be used for controller predictions. • Control interval sets the elapsed time between successive adjustments of the controller's manipulated variables. • Prediction horizon is the number of control intervals over which the outputs are to be optimized. • Control horizon sets the number of control intervals over which the manipulated variables are to be optimized.
Design Controller Using the Design Tool • In the Output weights section, change the reactant concentration's Weight (last entry in the second row) from the default 1.0 to 0. Controller Options — Weight Tuning Tab Test the changes using the T Setpoint scenario (click the toolbar's Simulation button). Improved Setpoint Tracking for CSTR Temperature shows that the CSTR temperature now tracks the setpoint change smoothly, reaching the new value in about 10 time units with no overshoot.
3 Designing Controllers Using the Design Tool GUI Improved Setpoint Tracking for CSTR Temperature On the other hand, the reactant concentration, CA, exhibits a larger deviation from its setpoint, which is being held constant at zero (compare to Plant Outputs for T Setpoint Scenario with Added Data Markers, where the final deviation is about a factor of 4 smaller). This behavior reflects an unavoidable trade-off. The controller has only one adjustment at its disposal: the coolant temperature.
Design Controller Using the Design Tool the number of plant outputs, wyj is the weight for output j, and the term [rj(k + i) – yj(k + i)] is a predicted deviation for output j at interval k + 1. The weights must be zero or positive. If a particular weight is large, deviations for that output dominate Sy(k). One of the controller's objectives is to minimize Sy(k).
3 Designing Controllers Using the Design Tool GUI than the cumulative value. Increasing this weight forces the controller to make smaller, more cautious adjustments. Plant Inputs for Modified Rate Weight Plant Inputs for Modified Rate Weight shows that increasing the rate weight from 0.1 to 0.3 decreases the move sizes significantly, especially the initial move (compare to Plant Inputs for the T Setpoint Scenario). Setting the rate weight to 0.
Design Controller Using the Design Tool M nmv Su (k) = 2 Â Â {wuj [u j (k + i - 1) - u j ]} i =1 j =1 where wuj is the input weight and u j is the nominal value for input j. In the above simulations, you used the default, wuj = 0. This is the usual choice. When a sustained disturbance or setpoint change occurs, the manipulated variable must deviate permanently from its nominal value (as shown in Plant Inputs for the T Setpoint Scenario and Plant Inputs for Modified Rate Weight).
3 Designing Controllers Using the Design Tool GUI Set Number of moves computed per step to 2. Verify that Blocking allocation within prediction horizon is set to Beginning, the default. Select Controllers in the tree, and use its Copy button to create two controllers based on Blocking 1. Rename these Blocking 2 and Blocking 3. Edit their blocking options, setting Blocking allocation within prediction horizon to Uniform for Blocking 2, and to End for Blocking 3. Select Scenarios in the tree.
Design Controller Using the Design Tool Simulate each of the three scenarios. When you run the first, new plot windows open. Leave them open when you run the other two scenarios so all three results appear together, as shown in Blocking Comparison, Outputs and Blocking Comparison, Manipulated Variable. Blocking Comparison, Outputs Blocking Comparison, Manipulated Variable The numeric annotations on these figures refer to the three scenarios.
3 Designing Controllers Using the Design Tool GUI Results for T Setpoint 3 are very similar to those shown in Improved Setpoint Tracking for CSTR Temperature and Plant Inputs for Modified Rate Weight, where a penalty rate weight reduced the move sizes.
Design Controller Using the Design Tool Entering CSTR Manipulated Variable Constraints If any simulation plot windows are open, close them (to force fresh plots). Select the T Setpoint 1 scenario. If necessary, set its Controller option to Unconstrained. Change Duration to 15, and simulate the scenario. Select the T Setpoint 2 scenario, set its Controller option to MVconstraints, change its Duration to 15, and simulate it.
3 Designing Controllers Using the Design Tool GUI CSTR Outputs, Unconstrained (1) and MVconstraints (2) CSTR Manipulated Variable, Unconstrained (1) and MVconstraints (2) Disturbance Modeling and Estimation The previous sections tested the controller's response to setpoint changes. In process control, disturbances rejection is often more important. The Model Predictive Control Toolbox product allows you to tailor the controller's disturbance response.
Design Controller Using the Design Tool Copy this controller. Rename the copy OutputSteps. Click its Estimation tab. The initial view should be as in Default Output Disturbance Settings for CSTR. Note the following: • Model Predictive Control Toolbox default settings are being used. (The Use Model Predictive Control Defaults button restores these settings if you modify them.) • The Output Disturbances tab is selected, and the Signal-by-signal option is selected.
3 Designing Controllers Using the Design Tool GUI Default Input Disturbance Settings for CSTR In this case the disturbance magnitude is nonzero, and the disturbance type is Steps. Thus, the controller assumes that disturbances enter as random steps (integrated white noise) at the plant's unmeasured disturbance input. Click the Measurement Noise tab, verifying that the controller is assuming white noise, magnitude 1 (not shown).
Design Controller Using the Design Tool In general, if your plant model includes unmeasured disturbance inputs, the toolbox default strategy will assume that they are dominant and sustained, as in the above example. This forces the controller to include an integrating mode, intended to eliminate steady-state error. If the plant model contains no unmeasured input disturbances, the toolbox assumes sustained (integrated white noise) disturbances at the measured plant outputs.
3 Designing Controllers Using the Design Tool GUI CSTR Disturbance 1 Scenario Copy Disturbance 1. Rename the copy Disturbance 2, and set its Controller option to OutputSteps. If necessary, close any open simulation plot windows. Simulate both scenarios. CSTR Outputs for Disturbance Scenarios 1 and 2 and CSTR Inputs for Disturbance Scenarios 1 and 2 show the results.
Design Controller Using the Design Tool The default controller expects unmeasured disturbances to enter as defined in the scenarios, so it's not surprising that the default controller performs better. The point is that the difference can be large, so it merits design consideration.
3 Designing Controllers Using the Design Tool GUI For comparison, reset the two scenarios so that the only disturbance is a one-degree step increase added to the measured reactor temperature. The modified controller (case 2) is designed for such disturbances, and CSTR Outputs, Output Disturbance Scenarios 1 and 2 shows that it performs better, but the difference is less dramatic than in the previous scenario.
Design Controller Using the Design Tool Similarly, start with a single scenario identical to CSTR Disturbance 1 Scenario, except that its Controller setting should be Unconstrained. Name this scenario None. Right-click None in the tree and select Copy. Rename the copy Hard, and change its Controller setting to Yhard. Make another copy, naming it Soft and changing its Controller setting to Ysoft. Your tree should be as shown below. Select your Yhard controller.
3 Designing Controllers Using the Design Tool GUI Constraint Softening Dialog Box The Output constraints section lists the output limits and their relaxation bands. By default, the output constraints are soft. Make the CA upper limit hard by entering a zero as its relaxation band (as in Constraint Softening Dialog Box). Select the Ysoft controller. Define a soft upper bound on CA by using the same settings shown in Constraint Softening Dialog Box, but with a relaxation band of 100 instead of 0.
Design Controller Using the Design Tool Constraint Softening Scenarios: 1 = None, 2 = Hard, 3 = Soft Curve 1 is without output constraints, which is identical to curve 1 in CSTR Outputs for Disturbance Scenarios 1 and 2. This controller allows the CA output to vary freely, but the controlled temperature returns to its setpoint within 10 time units after the disturbance happens. Curve 2 shows the behavior with a hard upper limit at CA = 3.
3 Designing Controllers Using the Design Tool GUI In general, you'll have to experiment to determine the settings that provide appropriate trade-offs for your application. In particular, the relaxation band settings interact with those on the controller's Weight Tuning tab (see “Weight Tuning” on page 3-24). Another important factor is the expected numerical range for each variable. For example, if a particular variable stays within ±0.
Design Controller Using the Design Tool The default behavior is to export the selected controller to the workspace. Click Export to confirm. You can verify the export by typing whos at the MATLAB prompt. The resulting list should include an mpc object named MPC2. Type MPC2 to display the object's properties. Saving a Project To save your entire project, click the toolbar's Save button. The following dialog box appears.
3 Designing Controllers Using the Design Tool GUI Dialog Box for Saving a Controller Design Project The default behavior saves the current project (named Project - CSTR_MPC in this case) in a MAT-file (called CSTR_MPC here). If the design tool had contained other projects, they would appear in the list, and you could select the ones you wanted to save. The MAT-file will be saved in the default folder. To verify the location, click the Browse (...) button and change the folder if necessary.
Design Controller Using the Design Tool You could define the required MPC2 object in one of the following ways: • Import MPC2 from a MAT-file (assuming you had saved it as explained in “Exporting a Controller” on page 3-44). • Load the model's project file, which contains a copy of MPC2. To use the second approach, open the design tool by typing mpctool in the MATLAB Command Window. This creates a blank Model Predictive Control Toolbox project called MPC Design Task. Click Load on the toolbar.
3 Designing Controllers Using the Design Tool GUI Test Controller Robustness It's good practice to test your controller's sensitivity to prediction errors. Classical phase and gain margins are one way to quantify robustness for a SISO application. Robust Control Toolbox™ software provides sophisticated approaches for MIMO systems. It can also be helpful to run simulations. The following example illustrates the simulation approach. Plant Model Perturbation Create a perturbed version of a model.
Test Controller Robustness Copy Accurate Model. Rename the copy Perturbed Model, and set its Plant option to CSTRp. Thus, both scenarios use the same controller, which is based on the CSTR model, but the Perturbed Model scenario uses a different model to represent the “real” plant. This tests the controller's robustness to a change in plant parameters. Robustness Test, Accurate Plant Model Scenario Simulate the two scenarios.
3 Designing Controllers Using the Design Tool GUI Robustness Test, Accurate Model (1) and Perturbed Model (2) Note MIMO applications are usually more sensitive to model error than SISO applications, so robustness testing is especially recommended for MIMO cases.
Design Controller for Plant with Delays Design Controller for Plant with Delays This example shows how to design an MPC controller for a plant with delays. The Model Predictive Control Toolbox can handle models that include delays. A typical example is the distillation column model, which includes a delay in each input/output channel. The presence of delays influences controller performance, and your controller specifications should account for them. Create the distillation column plant model.
3 Designing Controllers Using the Design Tool GUI It is good practice to specify the prediction and control horizons such that P - M ? td,max / Dt Here, P is the prediction horizon, M is the control horizon, td,max is the maximum delay, and Δt is the control interval. In the Control interval (time units) box, which specifies Δt, enter 1. Then, because the maximum ioDelay for the DC model is 8.1 minutes, td,max/ Δt is 8.1. You can satisfy the inequality by setting P = 30 and M = 5.
Design Controller for Plant with Delays Specify the simulation settings as follows: • In the Duration box, enter 50. • In the Setpoints table, for the Distillate Purity setpoint, enter 1 in the Initial Value box. • In the Setpoints table, for the Bottoms Purity setpoint, from the Type list, select Step. In the Time box, enter 25. Click Simulate.
3 Designing Controllers Using the Design Tool GUI The plant outputs plot shows that the first output does not respond for the first minute, which corresponds to the delay from the first input. The first output reaches the setpoint in two minutes and settles quickly. Similarly, the second output does respond for three minutes, which corresponds to the delay from the second input, and settles rapidly afterwards.
Design Controller for Plant with Delays The plant inputs plot shows that the initial input moves are more than five times the final change. Also, there are periodic pulses in the control action as the controller attempts to counteract the delayed effects of each input on the two outputs. You can moderate these effects by tuning the controller weights or by specifying a custom blocking strategy. For this example, use the latter approach. In the tree, select MPC Design Task > Controllers > MPC1.
3 Designing Controllers Using the Design Tool GUI In the tree, select Scenarios > Scenario1. Click Simulate.
Design Controller for Plant with Delays The initial input moves are much smaller and the moves are less oscillatory. The tradeoff is a slower output response, with about 20% interaction between the outputs.
3 Designing Controllers Using the Design Tool GUI Design Controller for Nonsquare Plant A nonsquare plant has an unequal number of manipulated variables and output variables. This is common in practice, and the Model Predictive Control Toolbox software supports an excess of manipulated variables or outputs. In such cases you will usually need to modify default toolbox settings.
Design Controller for Nonsquare Plant More Manipulated Variables Than Outputs In this situation, default Model Predictive Control Toolbox settings should provide offsetfree output-setpoint tracking, but the manipulated variables are likely to drift. One way to avoid this is to use manipulated variable setpoints. If there are Ne excess manipulated variables and you hold Ne of them at target values, the rest should not drift. Rather, they will attain the values needed to eliminate output offset.
4 Designing Controllers Using the Command Line • “Design Controller at the Command Line” on page 4-2 • “Simulate Controller with Nonlinear Plant” on page 4-9 • “Control Based On Multiple Plant Models” on page 4-15 • “Compute Steady-State Gain” on page 4-24 • “Extract Controller” on page 4-25 • “Bibliography” on page 4-26 • “Signal Previewing” on page 4-27 • “Run-Time Constraint Updating” on page 4-28 • “Run-Time Weight Tuning” on page 4-29
4 Designing Controllers Using the Command Line Design Controller at the Command Line In this section... “Create a Controller Object” on page 4-2 “View and Alter Controller Properties” on page 4-3 “Review Controller Design” on page 4-5 “Perform Linear Simulations” on page 4-6 “Save Calculated Results” on page 4-8 “Design Controller Using the Design Tool” on page 3-2 shows how to use the Model Predictive Control Toolbox design tool to create a controller and test it.
Design Controller at the Command Line View and Alter Controller Properties Once you've defined an MPC object, it's easy to alter its properties.
4 Designing Controllers Using the Command Line Min: Max: MinECR: MaxECR: RateMin: RateMax: RateMinECR: RateMaxECR: Target: Name: Units: -Inf Inf 0 0 -Inf Inf 0 0 'nominal' 'T_c' '' This shows that the default controller has no constraints on the manipulated variable. To include constraints as shown in Entering CSTR Manipulated Variable Constraints, enter: MPCobj.MV.Min = -10; MPCobj.MV.Max = 10; MPCobj.MV.RateMin = -4; MPCobj.MV.RateMax = 4; There are two outputs in this case, so MPCobj.
Design Controller at the Command Line You can also specify time-varying weights and constraints. The time-varying weights and constraints are defined for the prediction horizon, which shifts at each time step. This implies that as long as the property is not changed, the set of time-varying parameters is the same at each time step. To learn how to specify time-varying constraints and weights in the GUI, see “Constraints Tab” and “Weight Tuning Tab”.
4 Designing Controllers Using the Command Line In this example, the review command found two potential issues in this design. The first warning asks whether the user intends to have zero weight on the C_A output. The second warning asks the user to avoid having hard constraints on both MV and MVRate. Perform Linear Simulations To run a linear simulation, use the sim function.
Design Controller at the Command Line T = 26; r = [2 0]; sim(MPCobj,T,r); This simulates the closed-loop response for a duration of 26 control intervals with a setpoint of 2 for the first output (the reactor temperature) and 0 for the second output (the residual concentration). Recall that the second output's tuning weight is zero (see the discussion in “Output Weights” on page 3-26), so its setpoint is ignored. By default, the same linear model is used for controller predictions and the plant, i.e.
4 Designing Controllers Using the Command Line Save Calculated Results If you'd like to save simulation results in your workspace, use the following sim function format: [y,t,u] = sim(MPCobj,T,r); This suppresses automatic plotting, instead creating variables y, t, and u, which hold the computed outputs, time, and inputs, respectively. A typical use is to create customized plots.
Simulate Controller with Nonlinear Plant Simulate Controller with Nonlinear Plant You can use sim to simulate a closed-loop system consisting of a linear plant model and an MPC controller. If your plant is a nonlinear Simulink model, you must linearize the plant (see “Linearization Using Linear Analysis Tool in Simulink Control Design”) and design a controller for the linear model (see “Design Controller in Simulink”).
4 Designing Controllers Using the Command Line Example Code for Successive Linearization In the following code, the simulation begins at the CSTR model's nominal operating point (concentration = 8.57) and moves to a lower point (concentration = 2) where the reaction rate is much higher. The required code is as follows: [sys, xp] = CSTR_INOUT([],[],[],'sizes'); up = [10 298.15 298.
Simulate Controller with Nonlinear Plant % Define MPC Toolbox controller for the latest model MPCobj = mpc(Model, Ts); MPCobj.W.Output = [0 1]; % Ramp the setpoint r = max([8.57 - 0.25*t, 2]); % Compute the control action if t <= 0 xd = [0; 0]; x = mpcstate(MPCobj, xp, xd, [], u); end u = mpcmove(MPCobj, x, yp, [0 r], []); % Simulate the plant for one control interval up(3) = u; simOptions.StartTime = num2str(t); simOptions.StopTime = num2str(t+Ts); simOptions.InitialState = 'xp'; simOptions.
4 Designing Controllers Using the Command Line figure(2) plot(tsave,usave(:,3)); title('Coolant Temperature') CSTR Results and Discussion The plotted results appear below. Note the following points: • The setpoint is being ramped from the initial concentration to the desired final value (see the step-wise changes in the reactor concentration plot below). The reactor concentration tracks this ramp smoothly with some delay (see the smooth curve), and settles at the final state with negligible overshoot.
Simulate Controller with Nonlinear Plant • Function linearize relinearizes the plant as its state evolves. This function was discussed previously in “Linearization Using MATLAB Code”. • The code also resets the linear model's nominal conditions to the latest values.
4 Designing Controllers Using the Command Line controller design, always have nominal zero values. As they are unmeasured, the controller cannot be informed of the true values. A non-zero value would cause an error. • Function mpc defines a new controller based on the relinearized plant model. The output weight tuning ignores the temperature measurement, focusing only on the concentration. • At t = 0, the mpcstate function initializes the controller's extended state vector, x, which is an mpcstate object.
Control Based On Multiple Plant Models Control Based On Multiple Plant Models The “Nonlinear CSTR Application” on page 4-9 shows how updates to the prediction model can improve MPC performance. In that case the model is nonlinear and you can obtain frequent updates by linearization. A more common situation is that you have several linear plant models, each of which applies at a particular operating condition and you can design a controller based on each linear model.
4 Designing Controllers Using the Command Line Animation of the Multi-Model Example In order to achieve its objective, the controller can adjust the applied force magnitude (the length of the red arrow). It receives continuous feedback on the M1 location. There is also a contact sensor to signal collisions. The M2 location is unmeasured. If M1 were isolated, this would be a routine control problem.
Control Based On Multiple Plant Models variable, and a spring constant calibration signal, which is a measured disturbance input. A1=[0 1;-k1/M1 -b1/M1]; B1=[0 0;-1/M1 k1*yeq1/M1]; C1=[1 0]; D1=[0 0]; sys1=ss(A1,B1,C1,D1); sys1=setmpcsignals(sys1, 'MV', 1, 'MD', 2); The setmpcsignals command specifies the input type for the two inputs.
4 Designing Controllers Using the Command Line Simulating Controller Performance Block Diagram of the Two-Model Example shows the Simulink block diagram for this example. The upper portion simulates the movement of the two masses, plots the signals as a function of time, and animates the example. Block Diagram of the Two-Model Example The lower part contains three key elements: • A pulse generator that supplies the desired M1 position (the controller reference signal).
Control Based On Multiple Plant Models • A simulation of a contact sensor. When the two masses have the same position, the Compare to Constant block evaluates to true, and the Add1 block converts this to a 2. Otherwise, the Add1 output is 1. • The Multiple MPC Controller block. It has four inputs. The measured output (mo), reference (ref), and measured disturbance (md) inputs are as for a standard MPC Controller block. The distinctive feature is the switch input.
4 Designing Controllers Using the Command Line When the switch input is 1 the block automatically activates the first controller listed (MPC1), which is appropriate when the masses are separated. When the switch input is 2 the block automatically enables the second controller (MPC2).
Control Based On Multiple Plant Models In the upper plot, the cyan curve is the desired position. It starts at –5. The M1 position (yellow) starts at 0 and under the control of MPC1, M1 moves rapidly toward the desired position. M2 (magenta) starts at 10 and begins moving in the same direction. At about t = 13 seconds, M2 collides with M1. The switching signal (lower plot) changes at this instant from 1 to 2, so controller MPC2 has taken over.
4 Designing Controllers Using the Command Line When the desired position changes step-wise to 5, the two masses separate briefly (with appropriate switching to MPC1) but for the most part move together and settle rapidly at the desired position. The transition back to –5 is equally well behaved. Now suppose we force MPC2 to operate under all conditions. The figure below shows the result.
Control Based On Multiple Plant Models If we put MPC1 in charge exclusively, we instead see sluggish movements that fail to settle at the desired position before the next transition occurs (not shown but you can run mpcswitching). In this case, at least, two controllers are better than one.
4 Designing Controllers Using the Command Line Compute Steady-State Gain This example shows how to analyze a Model Predictive Controller using cloffset. The function computes the closed-loop, steady-state gain for each output when subjected to a sustained, 1-unit disturbance added to each output. It assumes that no constraints will be encountered. For example, consider the controller operating at the final steady-state of the nonlinear CSTR of the previous section.
Extract Controller Extract Controller This example shows how to obtain an LTI representation of an unconstrained Model Predictive Control Toolbox controller using ss. You can use this to analyze the controller's closed-loop frequency response, etc. For example, consider the controller designed in “Create a Controller Object” on page 4-2.
4 Designing Controllers Using the Command Line Bibliography [1] Lee, J. H. and N. L. Ricker, “Extended Kalman Filter Based Nonlinear Model Predictive Control,” Ind. Eng. Chem. Res., Vol. 33, No. 6, pp. 1530–1541 (1994). [2] Ricker, N. L., and J. H. Lee “Nonlinear Model Predictive Control of the Tennessee Eastman Challenge Process,” Computers & Chemical Engineering, Vol. 19, No. 9, pp. 961–981 (1995).
Signal Previewing Signal Previewing By default, a Model Predictive Controller assumes the current reference and measured plant disturbance signals will remain constant for the duration of the controller’s prediction horizon. This emulates conventional feedback control. As shown in “Optimization Problem”, however, the MPC Toolbox optimization problem allows these signals to vary within the prediction horizon.
4 Designing Controllers Using the Command Line Run-Time Constraint Updating Constraint bounds can change during controller operation. The mpcmove, mpcmoveAdaptive, and mpcmoveExplicit commands allow for this possibility. In Simulink, all the MPC Controller blocks allow for it as well. Both of these simulation approaches give you the option to update all specified bounds at each control interval. You cannot constrain a variable for which the corresponding controller object property is unbounded.
Run-Time Weight Tuning Run-Time Weight Tuning There are two ways to perform tuning experiments using Model Predictive Control Toolbox software: • Modify your controller object off line (by changing weights, etc.) and then test the modified object. • Change tuning weights as the controller operates. This topic describes the second approach. You can adjust the following tuning weights as the controller operates (see “Tuning Weights”): • Plant output variable (OV) reference tracking, wy.
4 Designing Controllers Using the Command Line More About • 4-30 “Signal Previewing” on page 4-27
5 Designing and Testing Controllers in Simulink • “Design Controller in Simulink” on page 5-2 • “Test an Existing Controller” on page 5-15 • “Schedule Controllers at Multiple Operating Points” on page 5-16 The Model Predictive Control Toolbox provides a controller block library for use in Simulink. This allows you to test controller performance in nonlinear simulations. The procedure depends on whether you have already designed a controller.
5 Designing and Testing Controllers in Simulink Design Controller in Simulink This example shows how to design a model predictive controller in Simulink. Suppose you have built a nonlinear plant model in Simulink. You want to design an MPC controller at a specific equilibrium operating point. This example shows that model-based design workflow. You linearize the plant at the desired operating point, design the MPC controller and validate it with nonlinear simulation.
Design Controller in Simulink • CSTR Temperature — Temperature of the limiting reactant in the product stream. • Concentration — Concentration of the limiting reactant in the product stream, also referred to as residual concentration. The MPC controller regulates this state to satisfy the desired setpoint. MPC Controller The MPC Controller block, which requires a supported C or C++ compiler, represents the model predictive controller.
5 Designing and Testing Controllers in Simulink The MPC Controller box is blank. No controller has been designed yet. Click Design. The MPC Question dialog box opens.
Design Controller in Simulink For this example, use the default values of this dialog box. Click OK. The software performs multiple tasks to design an initial MPC controller. These tasks include finding an equilibrium operating point, linearizing the plant model, and building the MPC controller. Finally, the Control and Estimation Tools Manager opens, containing an MPC design task node (MPC Design Task - MPC Controller). This node includes the linearized plant model, MPC open loop plant 1.
5 Designing and Testing Controllers in Simulink In the MPC open loop plant 1 node of the tree, click Operating Point. The software found a steady-state operating point (derivatives are close to zero). However, the reactor temperature (CSTR_ClosedLoop/CSTR/T_K) is very low, yielding a low reaction rate. Compare the values of the residual concentration state (9.9919 kmol/ m3) and the feed concentration (10 kmol/m3) to confirm the low reaction rate.
Design Controller in Simulink In the tree of the Control and Estimation Tools Manager, click Operating Points. Then, click the Compute Operating Points tab. Specify the desired operating point states: • CSTR_ClosedLoop/CSTR/C_A (residual concentration) — Enter 2 in the Value box. • CSTR_ClosedLoop/CSTR/T_K (reactor temperature) — Enter 370 in the Value box. • CSTR_ClosedLoop/MPC Controller/MPC/last_mv — Clear the Steady State check box.
5 Designing and Testing Controllers in Simulink Click Compute Operating Points. The Computation Results tab displays the operating point search result. The new operating point, Operating Point, appears in the Operating Points node. Tip If an operating point computation fails, you can: • Specify better initial estimates of the unknown quantities. • Select a different optimization algorithm for the operating point search.
Design Controller in Simulink Confirm that Operating Point is the desired operating point. In the tree, click Operating Point in the Operating Points node. As desired, the reactor temperature is close to 370 K at steady state. Similarly, the reactor concentration is 2 kmol/m3 at steady state. Operating Point is verified as the desired operating point. Linearize Plant at Desired Operating Point In the tree, click MPC Design Task - MPC Controller. Click Import Plant.
5 Designing and Testing Controllers in Simulink Click OK. The software calculates the linearized plant model, MPC open loop plant 2. This model is visible in the Control and Estimation Tools Manager, in the Plant models node. (Optional) Close the Plant Model Importer dialog box by clicking Close. (Optional) To see the nominal values of the input and output signals, in the tree, click MPC Design Task - MPC Controller.
Design Controller in Simulink These values correspond to the desired operating point. Update Controller to Use New Plant Model In the tree, click Controllers. Then, in the Plant Model list, select MPC open loop plant 2.
5 Designing and Testing Controllers in Simulink Alternatively, delete MPC open loop plant 1, the model computed at default operating point. Deleting this plant forces the controller to use the new model and eliminates the potential for confusion. In the tree, click Plant models. Then, in the Plant models imported for this project list box, select MPC open loop plant 1. Click Delete.
Design Controller in Simulink Tip After you export the controller, you can examine it for design errors and stability problems using the review function. Verify Steady-State Operation for Plant-Controller Combination To simulate the model at the desired operating point, export Operating Point to the MATLAB workspace and initialize the model with it. In the Control and Estimation Tools Manager, expand the Operating Points node and right-click Operating Point. Select Export to Workspace.
5 Designing and Testing Controllers in Simulink The decrease in feed concentration reduces heat generation. If the controller were absent, the reactor temperature would drop significantly, reducing the reaction rate, and the CSTR concentration would increase to roughly 3 kmol/m3. To counteract these effects, the controller raises the coolant temperature, which returns the CSTR temperature to a value slightly below the nominal condition.
Test an Existing Controller Test an Existing Controller If you have already designed a model predictive controller to use with a Simulink plant, to test it in Simulink: 1 Open Simulink model. 2 Add an MPC Controller block to the model and connect it. 3 Specify the controller. Open the MPC Controller and enter the name of your controller in the MPC Controller box. The string you enter here must be the name of an mpc object in the workspace. 4 (Optional) Modify the controller.
5 Designing and Testing Controllers in Simulink Schedule Controllers at Multiple Operating Points In this section... “A Two-Model Plant” on page 5-16 “Animation of the Multi-Model Example” on page 5-17 “Designing the Two Controllers” on page 5-18 “Simulating Controller Performance” on page 5-19 If your plant is nonlinear, a controller designed to operate in a particular target region may perform poorly in other regions.
Schedule Controllers at Multiple Operating Points In the above, mass M2 is uncontrollable. It responds solely to the spring pulling it to the left. If the two masses collide, however, they stick together until a change in the applied force separates them. The control objective is to make M1 track a reference signal. The blue triangle in the above indicates the desired location, which varies with time. At the instant shown, the desired numeric location is -5.
5 Designing and Testing Controllers in Simulink Define the system parameters. M1 = M2 = k1 = k2 = b1 = b2 = yeq1 yeq2 1; % mass 5; % mass 1; % spring constant 0.1; % spring constant 0.3; % friction coefficient 0.8; % friction coefficient = 10; % wall mount position = -10; % wall mount position Define a model of M1 when the masses are separated. Its states are the position and velocity of M1.
Schedule Controllers at Multiple Operating Points Ts = 0.2; p = 20; m = 1; MPC1 = mpc(sys1,Ts,p,m); % Controller for M1 detached from M2 MPC2 = mpc(sys2,Ts,p,m); % Controller for M1 connected to M2 The applied force also have the same constraints in each case. The lower bound for the applied force is zero because it cannot reverse direction. The maximum rate of change for the applied force is 1000 per second (increasing or decreasing). MPC1.MV = struct('Min',0,'RateMin',-1e3,'RateMax',1e3); MPC2.
5 Designing and Testing Controllers in Simulink The lower part contains the following key elements: • A pulse generator that supplies the desired M1 position (the controller reference signal). The output of the pulse generator is a square wave that varies between —5 and 5, with a frequency of 0.015 per second. • Simulation of a contact sensor. When the two masses have the same position, the Compare to Constant block evaluates to true and the Add1 block converts this to a 2. Else, the output of Add1 is 1.
Schedule Controllers at Multiple Operating Points When the switch input is 1, the block automatically activates the first controller that is listed (MPC1), which is appropriate when the masses are separated. When the switch input is 2, the block automatically enables the second controller (MPC2). Simulate the controller performance using Simulink commands.
5 Designing and Testing Controllers in Simulink y2initial = 10; open('mpc_switching'); sim('mpc_switching',Tstop); The figure below shows the signals scope output.
Schedule Controllers at Multiple Operating Points 5-23
5 Designing and Testing Controllers in Simulink In the upper plot, the cyan curve is the desired position. It starts at -5. The M1 position (yellow) starts at 0. Under the control of MPC1, M1 moves rapidly towards the desired position. M2 (magenta) starts at 10 and begins moving in the same direction. At about t = 13 seconds, M2 collides with M1. The switching signal (lower plot) changes at this instant from 1 to 2, so MPC2 takes over.
Schedule Controllers at Multiple Operating Points 5-25
5 Designing and Testing Controllers in Simulink When the masses are disconnected, as at the start, MPC2 applies excessive force and then over-compensates, resulting in oscillatory behavior. Once the masses join, the move more smoothly, as would be expected. The last transition causes especially severe oscillations. The masses collide frequently and M1 never reaches the desired position.