Simulink Design Optimization - Getting Started Guide
Simulink Design Optimization - Getting Started Guide
Product enhancement suggestions Bug reports Documentation error reports Order status, license renewals, passcodes Sales, pricing, and general information
508-647-7000 (Phone) 508-647-7001 (Fax) The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site. Simulink Design Optimization Getting Started Guide COPYRIGHT 19932010 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathWorks, Inc. FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through the federal government of the United States. By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern the use, modification, reproduction, release, performance, display, and disclosure of the Program and Documentation by the federal government (or other entity acquiring for or through the federal government) and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the governments needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to The MathWorks, Inc.
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders.
Patents
The MathWorks products are protected by one or more U.S. patents. Please see www.mathworks.com/patents for more information.
Revision History
March 2009 Online only September 2009 Online only March 2010 Online only
New for Version 1 (Release 2009a) Revised for Version 1.1 (Release 2009b) Revised for Version 1.1.1 (Release 2010a)
Contents
Product Overview
1
What You Can Accomplish Using This Product . . . . . . . Learn More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Required and Related Products . . . . . . . . . . . . . . . . . . . . . Documentation and Demos . . . . . . . . . . . . . . . . . . . . . . . . . Accessing Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . Accessing Demos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 1-4 1-5 1-6 1-6 1-6
Parameter Estimation
2
Types of Data for Parameter Estimation . . . . . . . . . . . . . Quick Start Estimating Model Parameters . . . . . . . . . Parallel Computing for Parameter Estimation . . . . . . . 2-2 2-3 2-11
Parameter Optimization
3
Types of Time-Domain Design Requirements for Optimizing Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . Quick Start Optimizing Model Parameters 3-2 3-3
........
iii
3-11
4
When to Use Optimization-Based Linear Control Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Types of Time- and Frequency-Domain Design Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Quick Start Optimization-Based Linear Control Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
4-3
4-4
5
About This Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About the Sample Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Configuring a Project for Parameter Estimation 5-2 5-2 5-2 5-4 5-6 5-6 5-11 5-14 5-16 5-16 5-22
.....
Importing Data into the GUI . . . . . . . . . . . . . . . . . . . . . . . . Importing Input Data and Time Vector . . . . . . . . . . . . . . . . Importing Output Data and Time Vector . . . . . . . . . . . . . . Analyzing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Selecting Data for Estimation . . . . . . . . . . . . . . . . . . . . . . . Selecting Output Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Selecting Input Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
iv
Contents
Removing Outliers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Why Remove Outliers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . How to Remove Outliers . . . . . . . . . . . . . . . . . . . . . . . . . . . . Filtering Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Filtering Output Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Filtering Input Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Interpolating Missing Data . . . . . . . . . . . . . . . . . . . . . . . . . Saving the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6
About This Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 6-2 6-3
Estimating Model Parameters Using Default Estimation Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-7 Overview of the Estimation Process . . . . . . . . . . . . . . . . . . . 6-7 Specifying Parameters and Estimation Data . . . . . . . . . . . 6-8 Validating Model Parameters . . . . . . . . . . . . . . . . . . . . . . . 6-13 Improving Estimation Results Using Parameter Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Strategy for Improving the Estimation Results . . . . . . . . . How to Specify Parameter Bounds . . . . . . . . . . . . . . . . . . . . Validating Estimated Model Parameters . . . . . . . . . . . . .
7
About This Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Design Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Configuring a Model for Optimizing Parameters 7-2 7-2 7-2 7-4 7-5
.....
Optimizing Model Parameters to Meet Step Response Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Specify Time-Domain Design Requirements . . . . . . . . . . . . Specifying Parameters to Optimize . . . . . . . . . . . . . . . . . . . Optimizing the Parameters . . . . . . . . . . . . . . . . . . . . . . . . . Refining Model Parameters to Track a Reference Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Saving the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7-25 7-31
Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the Command Line
8
About This Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Design Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Configuring a Model for Optimizing Parameters 8-2 8-2 8-2 8-4 8-5
.....
8-8
vi
Contents
8-15
9
About This Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Design Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Configuring a Project for Optimization-Based Control Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Designing an Initial PID Controller to Meet Bode Magnitude and Phase Margins Requirements . . . . . . Specifying the Controller Parameters . . . . . . . . . . . . . . . . . Specifying Bode Magnitude and Phase Margin Design Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Designing the Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . Refining the Controller Design to Meet Controller Output Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Saving the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2 9-2 9-2 9-4
9-5
9-32 9-48
Examples
A
Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-2
vii
Index
viii
Contents
1
Product Overview
What You Can Accomplish Using This Product on page 1-2 Learn More on page 1-4 Required and Related Products on page 1-5 Documentation and Demos on page 1-6
Product Overview
1-2
1-3
Product Overview
Learn More
The Simulink Design Optimization documentation provides information to use this product. Although this product employs optimization methods for parameter estimation and optimization, using the product does not require you to have a strong background in optimization theory. You may find it helpful to consult the Optimization Toolbox documentation to learn more about optimization theory, and minimizing an objective function.
1-4
1-5
Product Overview
Accessing Documentation
The Simulink Design Optimization documentation contains the following components: Getting Started Guide Provides information for mapping your problem to the capabilities of the Simulink Design Optimization software. Step-by-step tutorials walk you through the most common tasks for estimating parameters, optimizing parameters, and designing controllers using optimization methods. Users Guide Describes estimation and optimization tasks for using the Simulink Design Optimization software. Reference Describes commands and blocks for design optimization. Release Notes Describes important changes in the current product version and compatibility considerations. If you are new to using this product, the Getting Started Guide helps you begin using this product quickly. You can follow the steps in the tutorials to perform design optimization using the graphical user interface (GUI) or the MATLAB Command Window. You can also search or browse the documentation for information about specific design optimization tasks.
Accessing Demos
The Simulink Design Optimization software provides demo files that show you how to estimate and optimize parameters of Simulink models, design compensators using optimization methods, and model systems using Adaptive Lookup Tables.
1-6
To access demos in the Help browser, type the following command at the MATLAB prompt:
demo('Simulink', 'Simulink Design Optimization')
1-7
Product Overview
1-8
2
Parameter Estimation
Types of Data for Parameter Estimation on page 2-2 Quick Start Estimating Model Parameters on page 2-3 Parallel Computing for Parameter Estimation on page 2-11
Parameter Estimation
2-2
Prerequisites for parameter estimation include: Simulink model that contains inport or outport blocks, or signal logging For more information, see Configuring a Model for Importing Data in the Simulink Design Optimization Users Guide. Transient data in the MATLAB workspace To estimate model parameters:
1 Start a parameter estimation task by selecting Tools > Parameter
2-3
Parameter Estimation
2-4
2 Import the input and output data for estimating and validating model
parameters.
a Select the Transient Data node, and click New. b Select the New Data node. c In the Input Data tab, select the Data cell corresponding to the model
channel, and click Import. Select the variable to import in the Data Import dialog box.
Model channel for which you import data Select and Select and click Import to click Import to import data import time vector
Import variable
d Select the Time /Ts cell, and click Import. Select the time vector to
2-5
Parameter Estimation
For more information, see Importing Data into the GUI in the Simulink Design Optimization Users Guide.
3 Specify parameters to estimate by selecting the Variables node, and
clicking Add. Select the parameters in the Select Parameters dialog box.
Select parameters to estimate
Specify parameters
2-6
For more information, see Specifying Parameters to Estimate in the Simulink Design Optimization Users Guide.
4 Estimate the parameters. a Select the Estimation node, and click New. b Select the New Estimation node. c In the Data Sets tab, select the estimation data set.
Lists imported data sets Select data set for estimation
2-7
Parameter Estimation
Start estimation Select to view measured and simulated response plots Estimation report
2-8
In the Parameters tab, examine the estimated parameter values. The Simulink model also gets updated with the estimated parameter values.
Estimated parameter values
For more information, see Estimating Parameters in the GUI in the Simulink Design Optimization Users Guide.
5 Validate the estimated parameters. a Select the Validation node, and click New. b Select the New Validation node.
2-9
Parameter Estimation
For more information, see Validating Parameters in the GUI in the Simulink Design Optimization Users Guide. See Also: Chapter 6, Tutorial Estimating Parameters from Measured Data Using the GUI
2-10
2-11
Parameter Estimation
2-12
3
Parameter Optimization
Types of Time-Domain Design Requirements for Optimizing Parameters on page 3-2 Quick Start Optimizing Model Parameters on page 3-3 Parallel Computing for Parameter Optimization on page 3-11
Parameter Optimization
3-2
Prerequisites for optimizing model parameters include: Simulink model Time-domain design requirements To optimize model parameters:
1 In the Simulink model, specify an input signal to the system. For example,
3-3
Parameter Optimization
Optimization.
b Drag and drop the Signal Constraint block into the model. c Connect the Signal Constraint block to the signal that should meet the
design requirements.
3-4
Design requirements appear as line segments in the Block Parameters: Signal Constraint block window. By default, the design requirements are step-response characteristics.
3-5
Parameter Optimization
e Double-click the lower yellow region on the plot. Specify the design
For more information, see Specifying Design Requirements in the Simulink Design Optimization Users Guide.
3-6
Parameters, and click Add. Select the parameters to optimize in the Add Parameters dialog box.
Lists parameters selected for optimization Select parameters
. For more information, see Specifying Parameters to Optimize in the Simulink Design Optimization Users Guide.
4 In the Block Parameters window, start the optimization by selecting
Optimization > Start. The Optimization Progress window opens where you see the optimization progress.
3-7
Parameter Optimization
For more information, see Running the Optimization in the Simulink Design Optimization Users Guide.
3-8
5 Evaluate the optimization results after the optimization completes. a In the Block Parameters window, compare the response of the system
3-9
Parameter Optimization
values.
Optimization report
See Also: Chapter 7, Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the GUI.
3-10
3-11
Parameter Optimization
3-12
4
Optimization-Based Linear Control Design
When to Use Optimization-Based Linear Control Design on page 4-2 Types of Time- and Frequency-Domain Design Requirements on page 4-3 Quick Start Optimization-Based Linear Control Design on page 4-4
4-2
4-3
Note The same workflow applies to optimization-based control design for LTI models created at the command line using Control System Toolbox software. To learn how to create LTI models, see Linear (LTI) Models in the Control System Toolbox documentation. Prerequisites for optimization-based linear control design include: Simulink Compensator Design Task that contains a linearized version of the Simulink model and, optionally, any response plots you configure. For more information on how to linearize a Simulink model for control design, see Designing Compensators in the Simulink Control Design documentation. Time- and frequency-domain design requirements To design a controller using optimization methods:
4-4
1 Open a SISO Design Tool session by typing the following command at the
MATLAB prompt:
sisotool(projectname.mat)
The command also opens a SISO Design for SISO Design Task window by default and any response plots you configured when you linearized the Simulink model using Simulink Control Design software.
4-5
Optimize Compensators in the Automated Tuning tab of the SISO Design Task.
4-6
This action creates a new Response Optimization node in the Control and Estimation Tools Manager.
4-7
4-8
4 Specify the design requirements. a In the Design requirements tab, click Add new design requirement.
Specify the design requirements, for example Bode magnitude lower limit, in the New Design Requirement dialog box.
Requirement values
Add requirement
4-9
In the SISO Design window, the yellow region with the black line segment represents the design requirement on the response plot.
4-10
requirements.
4-11
Optimization progress
Optimization status
4-12
6 Evaluate the controller design. a Examine the systems response in the response plot, for example the
Bode plot, to see if it meets the requirements. The systems response must lie in the white region in order to meet the design requirement.
4-13
7 Write the controller parameter values into the Simulink model. To do so,
click Update Simulink Block Parameters in the SISO Design Task node. See Also: Chapter 9, Tutorial Designing a PID Controller Using Optimization-Based Tuning.
4-14
5
Tutorial Preparing Data for Parameter Estimation Using the GUI
About This Tutorial on page 5-2 Configuring a Project for Parameter Estimation on page 5-4 Importing Data into the GUI on page 5-6 Analyzing Data on page 5-14 Selecting Data for Estimation on page 5-16 Removing Outliers on page 5-25 Filtering Data on page 5-29 Interpolating Missing Data on page 5-34 Saving the Project on page 5-37
Objectives
In this tutorial, you learn how to import, analyze, and prepare measured input and output (I/O) data for estimating parameters of a Simulink model. Note Simulink Design Optimization software estimates parameters from real, time-domain data only. You learn to perform the following tasks using the GUI: Import data from the MATLAB workspace. Analyze data quality using a time plot. Select a subset of data for estimation. Remove outliers. Filter high-frequency noise. Compute missing data using interpolation.
5-2
Note The number of input and output data samples must be equal to the length of the corresponding time vector. The engine throttle system controls the flow of air and fuel mixture to the engine cylinders. The throttle body contains a butterfly valve which opens when a driver presses the accelerator pedal. Opening this valve increases the amount of fuel mixture entering the cylinders, which increases the engine speed. A DC motor controls the opening angle of the butterfly valve in the throttle system. The input to the throttle system is the motor current (in amperes), and the output is the angular position of the butterfly valve (in degrees).
spe_engine_throttle1.mdl contains the Simulink model of the engine throttle system. For more information on building models, see Creating a Simulink Model in the Simulink documentation.
5-3
MATLAB prompt:
spe_engine_throttle1
This command opens the Simulink model, and loads the data into the MATLAB workspace.
5-4
This action opens a new project named Project - spe_engine_throttle1 in the Control and Estimation Tools Manager GUI. This project contains the Estimation Task, as shown in the next figure.
Note The Simulink model must remain open to perform parameter estimation tasks.
5-5
5-6
1 In the Control and Estimation Tools Manger GUI, select Transient Data
under the Estimation Task node, and click New. This action creates a New Data node under the Transient Data node.
5-7
3 In the Input Data tab, select the Data cell for Channel - 1, and click
5-8
4 In the Data Import dialog box, select input1, and click Import.
This action assigns the input data input1 to the model input signal spe_engine_throttle1/Input.
5-9
5 Select the Time / Ts cell for Channel - 1. 6 In the Data Import dialog box, select time1, and click Import.
This action assigns the time vector to the model input signal spe_engine_throttle1/Input.
5-10
5-11
3 In the Data Import dialog box, select position1, and click Import.
This action assigns the output data position1 to the model output signal spe_engine_throttle1/Position.
5-12
4 Select the Time / Ts cell for Channel - 1. 5 In the Data Import dialog box, select time1, and click Import.
This action assigns the time vector to the model output signal spe_engine_throttle1/Position.
You have now imported the I/O data into the Control and Estimation Tools Manager GUI, and assigned the data to the corresponding model signals.
5-13
Analyzing Data
In this portion of the tutorial, you analyze the output data quality by viewing the data characteristics on a time plot. Based on the analysis, you decide whether to preprocess the data before estimating parameters. For example, if the data contains noise, you might want to filter the noise from the system dynamics before estimating parameters. You must have already imported the data into the Control and Estimation Tools Manager GUI, as described in Importing Data into the GUI on page 5-6. If you have not imported the data, click here. To plot the output data on a time plot, select the position1(:,1) cell in the Output Data tab, and click Plot Data.
5-14
Analyzing Data
This action plots the measured output data position1(:,1), as shown in the next figure.
The time plot shows the output data in response to a step input, as described in About the Sample Data on page 5-2. The plot shows a rapid decrease in the response after t = 0.5 s because the system is shut down. To focus parameter estimation on the time period when the system is active, you select the data samples between t = 0 s and t = 0.5 s, as described in Selecting Data for Estimation on page 5-16 section of this tutorial. The spikes in the data indicate outliers, defined as data values that deviate from the mean by more than three standard deviations. They may be caused by measurement errors or sensor problems. The response also contains noise. Before estimating model parameters from this data, you remove the outliers and filter the noise, as described in Removing Outliers on page 5-25, and Filtering Data on page 5-29 sections of this tutorial. Tip You can also plot the input data on a time plot by selecting the input1(:,1) cell in the Input Data tab, and clicking Plot Data.
5-15
5-16
2 Select the position1(:,1) cell in the Output Data tab, and click
The Data Editing area of the Data Preprocessing Tool GUI shows the output data and time vector in the position1(:,1) and Time (seconds) columns, respectively. The Data Preprocessing Tool GUI lets you perform the following types of preprocessing operations: Excluding data Detrending and filtering data Handling missing data
3 To exclude the output data beyond t = 0.5 s: a In the Exclusion Rules tab, select the Bounds check box.
5-17
b In the Exclude X
field, where X corresponds to the time vector, select > from the drop-down list. Enter 0.5 in the adjacent field to specify the upper limit of the data to select for estimation. The Data Preprocessing Tool GUI resembles the next figure.
5-18
c Click Add.
This action adds a new Dataset1 node under the Transient Data node in the Control and Estimation Tools Manager GUI. The Dataset1 node contains the modified output data position1(:,1)* in the Output Data tab.
5-19
This operation also replaces the output data samples beyond t = 0.5 s in position1(:,1)* with NaNs. You can view the NaNs by selecting the Modified data tab in the Data Preprocessing Tool GUI, as shown in the next figure.
4 To remove the NaNs: a In the Control and Estimation Tools Manager GUI, select the Output
This action updates the Data Preprocessing Tool GUI with the selected data position1(:,1)*.
5-20
Tip You can view the results of this operation in the Modified data tab.
option.
e Click Add.
The Update table data dialog box appears. Click Yes to overwrite the position1(:,1)* data set with the modified data.
5-21
5 To plot the data, select the position1(:,1)* cell in the Output Data tab
of the Dataset1 node, and click Plot Data. The selected output data from t = 0 s to t = 0.5 s is shown in the next figure.
This action updates the Data Preprocessing Tool GUI with the selected data input1(:,1).
5-22
3 To exclude the data beyond t = 0.5 s: a In the Exclusion Rules tab, select the Bounds check box. b In the Exclude X
field, where X corresponds to the time vector, select > from the drop-down list. Enter 0.5 in the adjacent field to specify the upper limit of the input data to select for estimation. existing dataset option remains selected.
d Click Add.
This action adds the modified data input1(:,1)* to the Input Data tab of the Dataset1 node. This operation also replaces the input data samples beyond t = 0.5 s in input1(:,1)* with NaNs.
4 To remove the NaNs: a In the Control and Estimation Tools Manager GUI, select the
input1(:,1)* cell in the Input Data tab of the Dataset1 node, and
click Pre-process. This action updates the Data Preprocessing Tool GUI with the selected data input1(:,1)*.
b In the Missing Data Handling area, select the
The Update table data dialog box appears. Click Yes to overwrite the input1(:,1)* data set with the modified data.
5-23
5 To plot the data, select the input1(:,1)* cell in the Input Data tab of the
Dataset1 node, and click Plot Data. The selected input data from t = 0 s to t = 0.5 s is shown in the next figure.
5-24
Removing Outliers
Removing Outliers
In this section... Why Remove Outliers on page 5-25 How to Remove Outliers on page 5-25
cell in the Output Data tab of the Dataset1 node, and click Pre-process. This action updates the Data Preprocessing Tool GUI with the selected data position1(:,1)*.
5-25
By default, the Window length and Confidence limits fields are set to 10 and 95 respectively. The Window length field specifies the number of successive data samples the software uses to compute the mean and standard deviation. The Confidence limits field specifies the threshold number for identifying outliers. In this example, the mean and standard deviation of 10 successive data samples are computed, and data values that exceed 95% of standard deviation are identified as outliers.
Note The data samples containing outliers are replaced with NaNs.
5-26
Removing Outliers
4 Click Add.
The Update table data dialog box appears. Click Yes to overwrite the position1(:,1)* data set with the modified data.
5 To plot the data, select the position1(:,1)* cell in the Output Data tab
of the Dataset1 node, and click Plot Data. The spikes, which indicate outliers, no longer appear on the time plot, as shown in the next figure.
5-27
The missing data samples, represented by NaNs, appear as gaps on the time plot. To see an example, zoom in to the bottom-left corner of the plot. As shown in the next figure, the data values corresponding to t = 0.009 s and t = 0.019 s are missing.
5-28
Filtering Data
Filtering Data
In this section... Filtering Output Data on page 5-29 Filtering Input Data on page 5-32
position1(:,1)* cell in the Output Data tab of the Dataset1 node, and click Pre-process.
This action updates the Data Preprocessing Tool GUI with the selected data position1(:,1)*.
5-29
By default, First order is selected as the filter type. To learn more about the filters, see Filtering Data.
b Specify 0.001 in the First order filter with time constant field.
This field specifies the time constant for the first-order filter. Tip For calculating the time constant, you can visually inspect the time plot to determine the frequency components.
5-30
Filtering Data
4 Click Add.
The Update table data dialog box appears. Click Yes to overwrite the position1(:,1)* data set with the modified data.
5 To plot the data, select the position1(:,1)* cell in the Output Data tab
of the Dataset1 node, and click Plot Data. The noise is filtered and the output data appears smooth, as shown in the next figure.
5-31
input1(:,1)* cell in the Input Data tab of the Dataset1 node, and click
Pre-process. This action updates the Data Preprocessing Tool GUI with the selected data input1(:,1)*.
2 In the Detrend/Filtering tab: a Select the Filtering check box.
The Update table data dialog box appears. Click Yes to overwrite the input1(:,1)* data set with the modified data.
5-32
Filtering Data
5 To plot the data, select the input1(:,1)* cell in the Input Data tab of the
5-33
position1(:,1)* cell in the Output Data tab of the Dataset1 node, and click Pre-process.
This action updates the Data Preprocessing Tool GUI with the selected data position1(:,1)*.
5-34
values using interpolation method check box. By default, zoh is selected as the interpolation method. This method fills the missing data sample with the data value immediately preceding it.
Tip You can view the interpolated data samples in the Modified data tab.
The Update table data dialog box appears. Click Yes to overwrite the position1(:,1)* data set with the modified data.
5-35
5 To plot the data, select the position1(:,1)* cell in the Output Data tab
of the Dataset1 node, and click Plot Data. The new estimation data, prepared by removing outliers, filtering noise, and interpolating missing data, is shown the next figure.
5-36
The Control and Estimation Tools Manager GUI resembles the next figure.
5-37
5 Save the Control and Estimation Tools Manager project: a In the Control and Estimation Tools Manager GUI, select File > Save.
the File name field, and click Save. The action saves the project as a MAT-file. To learn how to estimate parameters from this data, see Chapter 6, Tutorial Estimating Parameters from Measured Data Using the GUI.
5-38
6
Tutorial Estimating Parameters from Measured Data Using the GUI
About This Tutorial on page 6-2 Estimating Model Parameters Using Default Estimation Settings on page 6-7 Improving Estimation Results Using Parameter Bounds on page 6-20 Validating Estimated Model Parameters on page 6-26
Objectives
In this tutorial, you learn how to estimate parameters of a single-input single-output (SISO) Simulink model from measured input and output (I/O) data. Note Simulink Design Optimization software estimates parameters from real, time-domain data only. You learn to perform the following tasks using the GUI: Load a saved project containing data. Estimate model parameters using default settings. Validate the model, and refine the estimation results.
6-2
The throttle system controls the flow of air and fuel mixture to the engine cylinders. The throttle body contains a butterfly valve which opens when a driver presses the accelerator pedal. Opening this valve increases the amount of fuel mixture entering the cylinders, which increases the engine speed. A DC motor controls the opening angle of the butterfly valve in the throttle system. The models for these components are described in Motor Subsystem on page 6-4, and Throttle Subsystem on page 6-5. The input to the throttle system is the motor current (in amperes), and the output is the angular position of the butterfly valve (in degrees).
6-3
Motor Subsystem
The Motor subsystem contains the DC motor model. To open the model, double-click the corresponding block.
The following table describes the variables, parameters, equation, input, and output of the Motor subsystem. Variables Parameters U is the input current to the motor. T is the torque applied by the motor.
Kt is the torque gain of the motor, represented by Kt in the
model.
td is the input time delay of the motor, represented by input_delay in the model.
Equation
T (t) = K tU (t td )
where t is time. Input Output U T
6-4
Throttle Subsystem
The Throttle subsystem contains the butterfly valve model. To open the model, right-click the corresponding block, and select Look Under Mask.
The Hard Stops block models the valve angular position limit of 15 to 90. The following table describes the variables, parameters, states, differential equations, inputs, and outputs of the Throttle subsystem. Variables T is the torque applied by the DC motor. is the angular position of the valve, represented by x in the model. Thardstop is the torque applied by the hard stop. Parameters
J is the inertia. c is the viscous friction. k is the spring constant.
States
6-5
Equations
The mathematical system for the butterfly valve is described in the following equation:
J + c + k = T + Thardstop
where 15 90 , with initial conditions
Hard Stops block is described in the following
equation:
Thardstop
Input Output
6-6
6-7
This MAT-file contains the estimation data. To learn more about the data and how to prepare it, see Chapter 5, Tutorial Preparing Data for Parameter Estimation Using the GUI. To load the preconfigured project:
a Open the engine throttle system Simulink model by typing the following
This action opens a new project named Project - spe_engine_throttle1 in the Control and Estimation Tools Manager GUI.
c In the Control and Estimation Tools Manager GUI, select File > Load.
Browse to the matlabroot\toolbox\sldo\sldodemos\estim directory, and select spe_engine_throttle1p.mat. The Confirm Node Replace dialog box appears. Click Yes to load the project into the Control and Estimation Tools Manager GUI.
6-8
The Control and Estimation Tools Manager GUI opens as shown in the next figure.
6-9
2 Specify parameters for estimation. a Select the Variables node under the Estimation Task node.
b Click Add.
This action opens the Select Parameters dialog box, which shows the model parameters for the Simulink model.
c Select the parameters J, c, input_delay, and k by pressing the Ctrl key
while clicking each name, and then click OK. This action adds the selected parameters to the Estimated Parameters tab.
6-10
Tip When estimating a large number of parameters, you can select a subset of parameters to estimate. To learn more, see the Inverted Pendulum Parameter Estimation demo.
d Select the Estimation node, and click New.
This action adds a New Estimation node under the Estimation node.
e Select the New Estimation node.
6-11
In the Parameters tab, select the Estimate check box for all the parameters. This action specifies the selected parameters for estimation.
The Parameters tab, as shown in the previous figure, displays the following information for each parameter: Value: Current parameter value. By default, it is equal to the value specified in the Simulink model. During estimation, the optimization method might change a parameter value to minimize the error between the measured and simulated output. Initial Guess: Initial parameter value. By default, it is equal to the value in the Value field and is used at the start of estimation.
6-12
Minimum and Maximum: Bounds on the parameter value. By default, they are set to -Inf, and +Inf, respectively. This means that the optimization method searches for a solution in the range [-Inf, +Inf]. Typical Value: Order of magnitude of the parameter value. By default, it is equal to the value in the Initial Guess field.
3 Specify data for estimation by checking the Selected check box for
6-13
1 Create plots to view the estimation results. a Select the Views node under the Estimation node, and click New.
This action creates a New View node under the Views node.
b Select the New View node. c In the View Setup tab, select the following plots from the drop-down
list in the Plot Type column: For Plot 1, select Measured and simulated. For Plot 2, select Cost function.
6-14
d In the Options area, select the Plot 1 and Plot 2 check boxes, and
Clicking Show Plots opens the following figures: New View - Plot 1 (Measured and simulated): Displays the measured output data Estim_Prep_Data. During estimation, this plot updates to display the simulated response at each iteration. New View - Plot 2 (Cost function): Displays the error between the measured and simulated output, computed at each iteration. By default, the error is computed using sum- of- squared- errors, which is a least-squares method.
2 Estimate the parameters by selecting the Estimation tab of the New
6-15
The Estimation tab updates at each iteration, and provides information about the estimation progress. When the estimation completes, the Estimation tab resembles the next figure.
Note The results of the optimization may differ slightly because of different numerical precision across platforms. The table displays the following information for each iteration: Cost Function: Error between the simulated and measured output. During estimation, the default optimization method Nonlinear least squares, lsqnonlin, minimizes the cost function by changing the parameter values. As shown in the previous figure, the cost function decreases by only 27% from 2.69e5 to 1.95e5.
6-16
Step Size: Displacement of the optimization method in the current search direction when minimizing the cost function. A final value close to zero indicates that the method has found a local minimum. As shown in the previous figure, the final step size in the last iteration is 5.96e-7.
3 View the estimated parameter values in the Value column of the
Parameters tab.
6-17
4 Examine the simulated response plot to see how well the simulated output
matches the measured output. The simulated response with the estimated parameters is shown in blue on the New View - Plot 1 (Measured and simulated) plot, and significantly differs from the measured data. This difference indicates that the estimated parameters are not accurate.
6-18
5 Examine the cost function plot to see how the cost function changes during
the estimation. The cost function values shown in step 2 are plotted on the New View Plot 2(Cost function) plot. The cost function decreases by only 27% from its initial value, and in conjunction with the measured and simulated output plot, indicates that the estimated parameters are not accurate.
To improve the estimation results, you apply bounds on the parameter values, as described in Improving Estimation Results Using Parameter Bounds on page 6-20.
6-19
6-20
corresponding Maximum cell and replacing +Inf with 0.1. The Parameters tab resembles the next figure.
6-21
The Estimation tab updates at each iteration, and provides information about the estimation progress. When the estimation completes, the Estimation tab resembles the next figure.
Note The results of the optimization may differ slightly because of different numerical precision across platforms. The cost function decreases by 99% from 1.95e5 to 239.94. The final step size 8.75e-7 is close to 0, which indicates that the optimization method has found a local minimum.
6-22
Parameters tab.
6-23
6 Examine the simulated response plot to see how well the simulated output
matches the measured output. The simulated response plot, shown in blue on the New View - Plot 1 (Measured and simulated) plot, is overlaid on the measured output data. The simulated output closely matches the measured data.
6-24
7 Examine the cost function plot to see how the cost function changes during
the estimation. The cost function values shown in step 4 are plotted on the New View - Plot 2(Cost function) plot. The cost function also decreases by 99% from its initial value, and in conjunction with the measured and simulated response plot indicates a good fit of the simulated response with the measured data.
6-25
This MAT-file contains a validation data set already imported into the GUI, and the estimated parameters as described in Improving Estimation Results Using Parameter Bounds on page 6-20. Tip To learn how to import data and time vector into the Control and Estimation Tools Manager GUI, see Importing Data into the GUI on page 5-6. To load the preconfigured project:
a In the Control and Estimation Tools Manager GUI, select File > Load. b Browse to the matlabroot\toolbox\sldo\sldodemos\estim directory,
and select spe_engine_throttle1_importValData1.mat. The Confirm Node Replace dialog box appears. Click Yes to load the project into the Control and Estimation Tools Manager GUI. The Control and Estimation Tools Manager GUI now has a node that contains the validation data, as shown in the next figure.
6-26
The validation data contains the input data, output data and time vector in the MATLAB variables input2, position2 and time2 respectively.
2 Plot the measured and simulated response, and residuals. a Select the Validation node, and click New.
Type column. For Plot 1, select Measured and simulated. For Plot 2, select Residuals.
d In the Options area, select the Plot 1, and Plot 2 check boxes.
6-27
e Select Validation Data1 from the Validation data set drop-down list.
Click Show Plots. This action opens the following figures: New Validation - Plot 1 (Measured and simulated): Displays the validation data and simulated response. New Validation - Plot 2(Residuals): Displays the difference between the measured data and simulated response.
3 Examine the simulated response plot to see how well the simulated output
6-28
The simulated response, as shown in blue on the New Validation - Plot 1 (Measured and simulated) plot, is overlaid on the measured output data, and closely matches the measured data Validation Data 1.
simulated response and measured data. The difference between the simulated and measured data, as shown in the New Validation - Plot 2(Residuals) plot, varies between 2 and -2.5. The residuals lie within 6% of the maximum output variation, and do not display any systematic patterns. This indicates a good fit between the simulated output and measured data.
6-29
5 Save the Control and Estimation Tools Manager project. a In the Control and Estimation Tools Manager GUI, select File > Save.
name field, and click Save. This action saves the project as a MAT-file.
6-30
Tip You can load a project by selecting File > Load in the Control and Estimation Tools Manager GUI. To view the estimated parameter values, select the Parameters tab of New Estimation node.
6-31
6-32
7
Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the GUI
About This Tutorial on page 7-2 Configuring a Model for Optimizing Parameters on page 7-5 Optimizing Model Parameters to Meet Step Response Requirements on page 7-8 Refining Model Parameters to Track a Reference Signal on page 7-25 Saving the Project on page 7-31
Objectives
In this tutorial, you learn how to use the GUI to optimize the parameters of a Simulink model to meet time-domain design requirements. You accomplish the following tasks using the GUI: Specify step response requirements on the models output. Specify a reference signal for the models output to track. Optimize and refine the parameters to meet the design requirements. Tip To learn how to optimize model parameters to meet time-domain design requirements using command line functions, see Chapter 8, Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the Command Line.
7-2
Tip To open the model, type sldo_model1 at the MATLAB command prompt. The model contains a Controller block, which is a PID controller. This block controls the output of the Plant subsystem. The Unit Step block applies a step input to the system. Note This tutorial uses a step input to produce the models response and optimize the model parameters to meet step response requirements. You can also use other types of inputs, such as ramp, and optimize parameters to meet requirements on the models response to these inputs. Double-click the Plant subsystem to open it. The plant is a second-order system with delay. It contains Transfer Function and Transport Delay blocks, as shown in the next figure.
7-3
To learn more about the blocks, see Transfer Fcn and Transport Delay block reference pages.
Design Requirements
The models output must meet the following design requirements: Overshoot less than 10% Rise time less than 10 seconds Settling time less than 30 seconds Track a reference signal specified by 1e(-0.3*t), where t is time
7-4
To learn more about the model, see About the Model on page 7-2.
2 Add a Signal Constraint block to the model. a In the Simulink model, select View > Library Browser to open the
7-5
c Drag and drop the Signal Constraint block into the Simulink model
window. To learn more about the block, see the Signal Constraint block reference page.
7-6
Note You must connect the Signal Constraint block to the signal to which you want to add design requirements. To learn more, see Constraining Model Signals in the Simulink Design Optimization Users Guide.
7-7
7-8
Tip To view the line segment that extends from 0 to 15 seconds, set the upper limit of the Amplitude axis to 1.3. To do so, right-click in the plot, and select Axes Limits.
7-9
The Block Parameters window shows an amplitude versus time plot. The line segments map to the step response requirements shown in the next figure.
% Overshoot
% Settling
% Undershoot
Rise time
Settling time
By default, the line segments represent the following step response requirements: Amplitude less than or equal to 0.01 up to the rise time of 5 seconds for 1% undershoot Amplitude between 0.9 and 1.2 up to the settling time of 15 seconds Amplitude equal to 1.2 for 20% overshoot up to the settling time of 15 seconds Amplitude between 0.99 and 1.01 beyond the settling time for 2% settling To specify the design requirements described in Design Requirements on page 7-4, you must modify the time and amplitude values of the line segments, as described in the next steps.
7-10
This action opens the Edit Design Requirement dialog box, as shown in the following figure.
The rows in the dialog box define the lower bound on the signal. The time span, displayed in the Design requirement drop-down list, is same as the simulation time specified in the Simulink model. The rows correspond to the following three line segments in the Block Parameters window: First row Lower-line segment that extends from 0 to 5 seconds. Second row Lower-line segment that extends from 5 to 15 seconds. Third row Lower-line segment that extends from 15 to 50 seconds. The default amplitude and time values specified in the rows appear in the Block Parameters window, as shown in the next figure.
7-11
3 Specify the rise time requirement: a In the first row of the Edit Design Requirement dialog box, double-click
This action also updates the Block Parameters window to show the rise time requirement. This requirement is represented by the line segment at the bottom left of the window that extends from 0 to 10 seconds, as shown in the next figure.
7-12
4 Specify the settling time requirement: a In the second row of the Edit Design Requirement dialog box,
7-13
This action also updates the Block Parameters window to show the settling time requirement on the lower bound. This requirement is represented by the line segment that extends from 10 to 30 seconds, as shown in the next figure.
7-14
drop-down list.
The rows in the dialog box define the upper bound on the signal, and correspond to the following two line segments in the Block Parameters window: First row Upper-line segment that extends from 0 to 15 seconds. Second row Upper-line segment that extends from 15 to 50 seconds. The default amplitude and time values specified in the rows appear in the Block Parameters window, as shown in the next figure.
7-15
d In the first row, double-click the Time field in the End column. e Type 30, and press Enter.
This action also updates the Block Parameters window to show the settling time requirement on the upper-bound. This requirement is represented by the line segment that extends from 0 to 30 seconds, as shown in the next figure.
5 Specify the overshoot requirement: a In the Edit Design Requirement dialog box, verify that Upper time
7-16
d Double-click the Amplitude field of the End column. e Type 1.1, and press Enter.
The Block Parameters window updates to show the overshoot requirement. This requirement is represented by the amplitude value of 1.1 for the line segment that extends from 0 to 30 seconds, as shown in the following figure.
When you optimize the model parameters, the models final response must lie in the white region bounded by the line segments in order to meet the design requirements.
6 In Edit Design Requirement dialog box, click Close.
7-17
7-18
7-19
3 In the Add Parameters dialog box, select the PID controller parameters
The Optimization Settings area displays the following parameter settings: Value Current parameter value Initial Guess Initial parameter value Minimum and Maximum Parameter bounds Typical Value Scaling factor for the parameter To learn more about the parameter settings, see Changing Tuned Parameter Specifications in the Simulink Design Optimization Users Guide.
7-20
each parameter as 0 in the corresponding Minimum field. After you enter these values, the Tuned Parameters window resembles the next figure.
5 Click OK to apply the parameter settings and close the Tuned Parameters
window.
7-21
the optimization. This action opens the optimization progress window as shown in the next figure.
During each optimization iteration, the software simulates the model, and the default optimization method Gradient descent modifies the controller parameters to reduce the distance between the simulated response and the design requirement line segments. To learn more about the optimization method, see Selecting Optimization Methods in the Simulink Design Optimization Users Guide.
7-22
After the optimization completes, the Optimization Progress window resembles the next figure.
The message Successful termination indicates that the optimization method found a solution that meets the design requirements within the parameter bounds. For more information about the outputs displayed in the optimization progress window, see Displaying Iterative Output in the Optimization Toolbox documentation. The optimized parameter values are displayed in the Optimization Progress window, and also written into the Simulink model.
2 In the Block Parameters window, examine the models response to see if
the response meets the step response requirements. The final response of the system with the optimized parameter values appears in black, as shown in the next figure.
7-23
The plot also displays the initial response of the system in blue. The remaining responses show the simulated response at each optimization iteration. The optimized response of the system lies in the white region bounded by the design requirement line segments and thus meets the specified requirements. Next, you refine the model parameters by specifying a reference signal that the system response must track, as described in Refining Model Parameters to Track a Reference Signal on page 7-25.
7-24
y = 1 exp(0.3 t)
You must have already optimized the model parameters to meet the step response requirements, as described in Optimizing Model Parameters to Meet Step Response Requirements on page 7-8. To optimize the parameters to track a reference signal:
1 In the Block Parameters window, select Goals > Desired Response.
7-25
a In the Time vector field of the Desired Response dialog box, enter
linspace(0,50,200).
b In the Amplitude field, enter 1-exp(-0.3*linspace(0,50,200)).
After you make these changes, the Desired Response dialog box resembles the following figure.
7-26
c Click OK to add the reference signal to the block and close the Desired
Response dialog box. The Block Parameters window updates to display the reference signal, shown as the gray dashed curve, in the next figure.
check box.
7-27
start the optimization. This action restarts the optimization using the optimized parameters values computed in Optimizing Model Parameters to Meet Step Response Requirements on page 7-8. The Optimization Progress window opens, as shown in the next figure.
7-28
At each iteration, the optimization method modifies the controller parameters to minimize the error between the simulated response and the reference signal. Simultaneously, the method satisfies the step response requirements by reducing the distance between the simulated response and the design requirement line segments. After the optimization completes, the Optimization Progress window resembles the following figure.
The message, Optimization terminated due to slow progress in parameter or objective values appears in the Optimization Progress window. This message indicates that the optimization method cannot minimize the error between the simulated response and the reference signal any further. You must examine the optimized response of the model to check if the response tracks the reference signal, as described in the next step.
7-29
5 In the Block Parameters window, examine the models response to see how
well the response tracks the reference signal. The models response before you began the optimization appears as the blue curve. After the optimization completes, the final response, shown as the black curve, tracks the reference signal.
Note To refine the parameters further to track the reference signal more closely, change the parameter and function tolerances, as described in Selecting Optimization Termination Options in the Simulink Design Optimization Users Guide.
7-30
2 In the Save Project dialog box, enter a variable name in the Model
7-31
Tip You can load the response optimization project by loading the Simulink model.
7-32
8
Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the Command Line
About This Tutorial on page 8-2 Configuring a Model for Optimizing Parameters on page 8-5 Optimizing Model Parameters to Meet Step Response Requirements on page 8-8 Refining Model Parameters to Track a Reference Signal on page 8-15
Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the Command Line
Objectives
In this tutorial, you learn how to use Simulink Design Optimization functions to optimize the parameters of a Simulink model to meet time-domain design requirements. You accomplish the following tasks using the command line: Specify step response requirements on the models output. Specify a reference signal for the models output to track. Optimize the parameters to meet the design requirements. Tip To learn how to optimize model parameters to meet time-domain design requirements using the GUI, see Chapter 7, Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the GUI.
8-2
Tip To open the model, type sldo_model1 at the MATLAB command prompt. The model contains a Controller block, which is a PID controller. This block controls the output of the Plant subsystem. The Unit Step block applies a step input to the system. Note This tutorial uses a step input to produce the models response and optimize the model parameters to meet step response requirements. You can also use other types of inputs, such as ramp, and optimize parameters to meet requirements on the models response to these inputs. Double-click the Plant subsystem to open it. The plant is modeled as a second-order system with delay. It contains Transfer Function and Transport Delay blocks, as shown in the next figure.
8-3
Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the Command Line
To learn more about the blocks, see Transfer Fcn, and Transport Delay block reference pages.
Design Requirements
The models output must meet the following design requirements: Overshoot less than 10% Rise time less than 10 seconds Settling time less than 30 seconds Track a reference signal specified by
y = 1 exp(0.3 t)
, where t is time
8-4
To learn more about the model, see About the Model on page 8-2.
2 Add a Signal Constraint block to the model. a In the Simulink model, select View > Library Browser to open the
8-5
Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the Command Line
c Drag and drop the Signal Constraint block into the Simulink model
window. To learn more about the block, see Signal Constraint block reference page.
8-6
Note You must connect the Signal Constraint block to the signal to which you want to add design requirements. To learn more, see Constraining Model Signals in the Simulink Design Optimization Users Guide.
8-7
Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the Command Line
proj=newsro('sldo_model1',{'Kd','Ki','Kp'})
This command creates a new project object, proj, that contains instructions to optimize the parameters Kp, Ki, and Kd.
Name: Parameters: OptimOptions: Tests: Model: 'sldo_model1' [3x1 ResponseOptimizer.Parameter] [1x1 sroengine.OptimOptions] [1x1 ResponseOptimizer.SimTest] 'sldo_model1'
8-8
LowerBoundY: LowerBoundWeight: UpperBoundX: UpperBoundY: UpperBoundWeight: ReferenceX: ReferenceY: ReferenceWeight: Signal Constraint.
The LowerBoundX, LowerBoundY, UpperBoundX, and UpperBoundY properties of the constr object represent the numeric values of design requirements on a signal. Tip You can view the default design requirements by double-clicking the Signal Constraint block in the sldo_model1 Simulink model. The LowerBoundX, and LowerBoundY properties define the lower bound, and the UpperBoundX and UpperBoundY define the upper bound on the signal. These properties are matrices, whose elements represent the values of the bounds as shown in the following table. Property Name
LowerBoundX
Purpose Time values of the lower-bound line segments Amplitude values of the lower-bound line segments Time values of the upper-bound line segments Amplitude values of the upper-bound line segments
8-9
Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the Command Line
For example, the elements of the LowerBoundX, and LowerBoundY matrices map to the following values.
Time of all lower design requirement line segments Time of beginning point of first line segment Time of end point of first line segment Time of beginning and end points of second line segment Amplitudes of all lower design requirement line segments Amplitude of beginning point of first line segment Amplitude of end point of first line segment Amplitude of beginning and end points of second line segment
The line segments that correspond to the elements of LowerBoundX, and LowerBoundY matrices appear in the next figure.
(lx (lx ,ly ) b2 b2 b3 ,ly b3 ) (lx ,ly ) e3 e3
(lx ,ly ) e2 e2
(lx
b1
,ly
b1
(lx ,ly ) e1 e1
8-10
Similarly, the elements of UpperBoundX and UpperBoundY map to the time and amplitude values of the upper-bound line segments, respectively. To specify the step response requirements, as described in Design Requirements on page 8-4, you must edit these properties as shown in the next step. Note When you add or modify design requirements using functions, the Block Parameters window does not update to display the new requirements. To view the values of the LowerBoundY matrix, type the following command:
constr.LowerBoundY
3 Specify the step response requirements using the following commands:
% Rise time requirement constr.LowerBoundX=[0 10;10 15;15 50]; % Settling time requirement on lower line segments; constr.LowerBoundX=[0 10;10 30;30 50]; % Settling time requirement on upper line segments constr.UpperBoundX=[0 30;30 50]; % Overshoot requirement on upper bound constr.UpperBoundY=[1.1 1.1;1.01 1.01];
Tip You can type constr.PropertyName to view the updated values of the properties.
4 Specify the parameters to optimize: a Retrieve the vector of parameter objects from the project object, proj,
example:
8-11
Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the Command Line
param(1)
Tip To view the updated value of the Minimum property for Kd, type param(1).Minimum.
5 Optimize the parameters using the optimize command:
opt=optimize(proj)
28 -9.19412e-020 35 0
8-12
Successful termination. Found a feasible or optimal solution within the specified tolerances.
Kd =
0.0468
Ki =
0.1455
Kp =
0.1853
ans =
At each optimization iteration, the software simulates the model and the default optimization method Gradient descent modifies the controller parameters to reduce the distance between the simulated response and the design requirements. To learn more about the optimization method, see Selecting Optimization Methods in the Simulink Design Optimization Users Guide. After the optimization completes, you see the messages Successful termination, and ExitFlag:1 at the MATLAB prompt. These messages indicate that the optimization method found a solution that meets the design requirements within the parameter bounds. For more information about the outputs displayed during the optimization, see Displaying Iterative Output in the Optimization Toolbox documentation. The optimized values of the parameters, Kp, Ki and Kd, are displayed at the command line, and are also written into the Simulink model.
8-13
Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the Command Line
Next, you refine the parameters by specifying a reference signal, as described in Refining Model Parameters to Track a Reference Signal on page 8-15.
8-14
y = 1 exp(0.3 t)
You must have already optimized the model parameters to meet the step response requirements, as described in Optimizing Model Parameters to Meet Step Response Requirements on page 8-8. To optimize the parameters to track a reference signal:
1 Specify the reference signal to track using the following commands:
% Enable reference tracking constr.CostEnable='on'; % Specify the time values of the reference signal constr.ReferenceX=linspace(0,50,200)'; % Specify the amplitude values of the reference signal constr.ReferenceY=1-exp(-0.3*linspace(0,50,200))';
Tip To verify that the reference signal has been added to the signal constraint object, type constr=findconstr(proj,'sldo_model1/Signal Constraint'). The ReferenceX and ReferenceY properties now contain the reference signal.
2 Initialize the parameters in proj for optimization. a Set the initial guess of the parameters using the initpar command.
8-15
Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the Command Line
To learn more about the scaling factor, see Changing Tuned Parameter Specifications in the Simulink Design Optimization Users Guide. When you optimize the model parameters after this initialization, the optimization method uses the updated parameter settings to recompute new parameter values.
3 Start the optimization using the optimize command.
opt=optimize(proj)
Optimization terminated due to slow progress in parameter or objective values. To optimize further, go to Optimization Options and decrease the parameter and/or function tolerances.
Kd = 1.5821 Ki =
0.2876
Kp =
8-16
0.6311
ans =
At each iteration, the optimization method modifies the controller parameters to minimize the error between the simulated response and the reference signal. Simultaneously, the method satisfies the step response requirements by reducing the distance between the simulated response and the design requirement line segments. After the optimization completes, you see the message Optimization
terminated due to slow progress in parameter or objective values. This message indicates that the optimization method cannot
minimize the error between the simulated response and the reference signal any further. If you want to refine the parameters further to track the reference signal more closely, change the parameter and function tolerances, as described in Selecting Optimization Termination Options in the Simulink Design Optimization Users Guide. Tip To view the updated response of the model, connect a Scope block to the model and simulate the model to view the response.
4 Save the project by typing the following command:
save('proj');
8-17
Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the Command Line
8-18
9
Tutorial Designing a PID Controller Using Optimization-Based Tuning
About This Tutorial on page 9-2 Configuring a Project for Optimization-Based Control Design on page 9-5 Designing an Initial PID Controller to Meet Bode Magnitude and Phase Margins Requirements on page 9-11 Refining the Controller Design to Meet Controller Output Bounds on page 9-32 Saving the Project on page 9-48
Objectives
In this tutorial, you learn to use optimization methods to design a PID controller to meet frequency-domain design requirements on a systems response. You accomplish the following tasks using the GUI: Specify frequency-domain Bode magnitude and phase margin requirements. Design an initial controller to meet the frequency-domain requirements. Refine the initial controller design to limit the controllers output signal.
9-2
The model contains a Controller block, which is a PID Controller. This block controls the output of the Plant subsystem. Using the Simulink Control Design software has linearized the Simulink model at the operating point specified in the model. The sldo_model2.mat file contains a preconfigured SISO Design Tool session saved after linearizing the model. To learn more about linearizing Simulink models for control design, see Designing Compensators in the Simulink Control Design Users Guide. Double-click the Plant subsystem to open it. The plant is modeled as a second-order system with delay. It contains Transfer Function and Transport Delay blocks, as shown in the next figure.
9-3
To learn more about the blocks, see Transfer Fcn and Transport Delay block reference pages.
Design Requirements
The compensator you design in this tutorial must meet the following design requirements: Bode lower magnitude bound of 0 in the frequency range 1e-3 to 1 rad/sec Phase margin greater than 60 degrees Controller output bounds in the range [-250 550]
9-4
Note sldo_model2.mat file contains a preconfigured SISO Design Tool session. This session was saved after Simulink Control Design software linearized the sldo_model2 Simulink model. This command opens the following windows: Simulink model
To learn more about the model, see About the Model on page 9-2.
9-5
Control and Estimation Tools Manager GUI, which contains a SISO Design Task node under the Simulink Compensator Design Task node.
9-6
LTI Viewer for SISO Design Task window, which contains the following plots: Closed-loop step response of the system in the top plot Output of the Controller block in the bottom plot
9-7
9-8
2 In the Control and Estimation Tools Manager GUI, select the Automated
9-9
9-10
Designing an Initial PID Controller to Meet Bode Magnitude and Phase Margins Requirements
Designing an Initial PID Controller to Meet Bode Magnitude and Phase Margins Requirements
In this section... Specifying the Controller Parameters on page 9-11 Specifying Bode Magnitude and Phase Margin Design Requirements on page 9-15 Designing the Controller on page 9-25
9-11
The controller parameters appear as poles and zeros in the Compensator elements column and represent the following: Gain Overall gain of the controller Real zeros Zeros resulting from the differentiator and integrator Real pole Pole resulting from the low-pass filter of the differentiator Tip To view the structure of the Controller block, right-click the block and select Look Under Mask.
9-12
Designing an Initial PID Controller to Meet Bode Magnitude and Phase Margins Requirements
mask parameters format. To do so, right-click the sldo_model2/Controller column, and select Parameterized format.
9-13
This action displays the controller parameters as Simulink block mask parameters P, I, and D, as shown in the next figure. To learn more about mask parameters, see Mask Parameters in the Simulink documentation.
The Compensators tab displays the following parameter settings: Value Current controller parameter value Initial Guess Initial controller parameter value Minimum and Maximum Controller parameter bounds Typical Value Scaling factor for the controller parameter To learn more about the parameter settings, see Changing Tuned Parameter Specifications in the Simulink Design Optimization Users Guide.
9-14
Designing an Initial PID Controller to Meet Bode Magnitude and Phase Margins Requirements
9-15
9-16
Designing an Initial PID Controller to Meet Bode Magnitude and Phase Margins Requirements
9-17
3 Specify the Bode magnitude lower limit requirement: a In the New Design Requirement dialog box, select Bode magnitude
This action updates the New Design Requirement dialog box, as shown in the next figure.
9-18
Designing an Initial PID Controller to Meet Bode Magnitude and Phase Margins Requirements
The New Design Requirement dialog box resembles the following figure.
9-19
The Bode lower magnitude limit is added to the Design requirements tab, as shown in the next figure.
9-20
Designing an Initial PID Controller to Meet Bode Magnitude and Phase Margins Requirements
The SISO Design for SISO Design task window also updates to show the Bode plot with the design requirement displayed as the black line segment.
9-21
4 Add the phase margin requirement: a In the SISO Design window, right-click the white area on the top plot,
9-22
Designing an Initial PID Controller to Meet Bode Magnitude and Phase Margins Requirements
This action opens the New Design Requirement dialog box, as shown in the next figure.
b In the New Design Requirement dialog box, select Gain & phase
The New Design Requirement dialog box updates to display the Gain Margin > and Phase Margin > options, as shown in the next figure.
c Select the Phase margin > check box, and enter 60 in the adjacent field.
9-23
The Design requirements tab in the Control and Estimation Tools Manager GUI updates. It now displays the phase margin requirement, as shown in the next figure.
9-24
Designing an Initial PID Controller to Meet Bode Magnitude and Phase Margins Requirements
The SISO Design window also updates to display the phase margin requirement.
9-25
9-26
Designing an Initial PID Controller to Meet Bode Magnitude and Phase Margins Requirements
At every optimization iteration, the default optimization method Gradient descent reduces the distance between the current response and the magnitude requirement line segment by modifying the controller parameters. Simultaneously, the software also computes the phase margin and reduces the distance between the current response and the phase margin. To learn more about the optimization method, see Selecting Optimization Methods in the Simulink Design Optimization Users Guide. After the optimization completes, the Optimization tab displays the optimization iterations and status, as shown in the next figure.
9-27
The message Successful termination indicates that the optimization method found a solution that meets the design requirements. For more information about the outputs displayed in the Optimization progress table, see Displaying Iterative Output in the Optimization Toolbox documentation.
9-28
Designing an Initial PID Controller to Meet Bode Magnitude and Phase Margins Requirements
2 Examine the controller parameters and the systems response: a View the optimized parameter values in the Value field of the
Compensator tab.
9-29
The top plot shows that the magnitude of the system, displayed as the blue curve, lies outside the yellow region. This plot indicates that the system has met the Bode magnitude requirement. The bottom plot displays the phase margin (P.M.) value of 86.1 degrees. This indicates that the system has met the phase margin design requirement of >60 degrees.
9-30
Designing an Initial PID Controller to Meet Bode Magnitude and Phase Margins Requirements
The top plot shows that the closed-loop response of the system is stable. The system with the designed controller thus meets both the magnitude and phase margin requirements. The bottom plot in the LTI Viewer shows that the peak value of the controllers output is 1000, which is very large and can cause damage to the plant. To limit the controller output, you apply lower and upper bounds on the signal, as described in Refining the Controller Design to Meet Controller Output Bounds on page 9-32.
9-31
9-32
To tune the compensator parameters to meet the bounds on the controllers signal:
1 Add the upper-bound on the controllers output: a In the LTI Viewer, right-click the white area on the bottom plot, and
9-33
b In the New Design Requirement dialog box, select Upper time response
c In the Time field of the End column, enter Inf. d In the Amplitude field of the Start column, enter 550.
9-34
The New Design Requirements dialog box resembles the following figure.
9-35
The Design requirements tab in the Control and Estimation Tools Manager GUI updates. It now displays the upper-bound requirement, as shown in the next figure.
9-36
The LTI Viewer also updates to show the design requirement, as shown in the next figure.
2 Add the lower-bound on the controllers output: a Right-click the white area in the bottom plot in the LTI Viewer, and
select Design requirement > New. This action opens the New Design Requirement dialog box.
9-37
type drop-down list. The New Design Requirement dialog box updates to show the lower bound, as shown in the next figure.
c In the Time field of the End column, enter Inf. d In the Amplitude field of the Start column, enter -250.
9-38
The New Design Requirement dialog box resembles the next figure. Click OK to close the dialog box.
9-39
The Design requirements tab in the Control and Estimation Tools Manager GUI updates. It now displays the lower-limit requirement, as shown in the next figure.
9-40
The LTI Viewer also updates to show the lower-bound on the controllers output, as shown in the next figure.
9-41
output:
a In the Compensators tab, select the rows containing P, I, and D, and
9-42
When you run the optimization again, the optimization method uses the updated parameter values as the starting point for refining the values. Clicking Use Value as Initial Guess updates the values in the Initial Guess column, as shown in the next figure.
9-43
At every optimization iteration, the optimization method reduces the distance between the current response and the upper and lower bounds on the signal. After the optimization completes, the Optimization tab resembles the next figure.
9-44
4 Examine the parameter values refined controller and the systems response: a Examine the following response plots:
The bottom plot shows that the controller output lies between 550 and -250, and thus meets the design requirement on the controllers output. Note You must also check that the closed-loop response, shown in the top plot, remains stable after refining the controller design.
9-45
The plots show that after refining the design, the system continues to meet the magnitude and phase margin requirements specified in Design Requirements on page 9-4.
9-46
b View the optimized controller parameter values in the Value field in the
Compensators tab.
5 Select the SISO Design Task node, and click Update Simulink Block
Parameters. This action writes the optimized controller parameter values to the Controller block in the Simulink model.
9-47
2 In the Save Projects dialog box, select Project - sldo_model2, and click
File name field, and click Save. The action saves the project as a MAT-file. Tip You can reload this project by typing sisotool('sldo_model2_optimized') at the MATLAB prompt.
9-48
A
Examples
Use this list to find examples in the documentation.
Examples
Getting Started
Chapter 5, Tutorial Preparing Data for Parameter Estimation Using the GUI Chapter 6, Tutorial Estimating Parameters from Measured Data Using the GUI Chapter 7, Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the GUI Chapter 8, Tutorial Optimizing Parameters to Meet Time-Domain Requirements Using the Command Line Chapter 9, Tutorial Designing a PID Controller Using Optimization-Based Tuning
A-2
Index
A
Index
N
newsro function
example 8-8
B
block parameters window 7-10
O
optimization-based control design 9-1 optimize function example 8-12
C
configure for parameter optimization 7-5 configuring control design 9-5 Control and Estimation Tools Manager 9-5
P
parameter settings 7-20 plots 9-15
D
design requirement line segments 7-8 design requirements time-domain 7-4 designing optimization-based linear controller 9-25
R
response optimization tutorial using functions 8-1 tutorial using GUI 7-1
E
Edit Design Requirement dialog box rows 7-11
S
signal constraints objects 8-8 Simulink Design Optimization product related products 1-5 required products 1-5 SISO Design Task 9-5 specify reference signal using GUI 7-25 specifying controller parameters 9-11 specifying design requirements 9-15
F
findconstr function
L
linear control design 9-5
T
time-domain design requirements 8-4 track reference signal 8-15
Index-1