Get Start CS
Get Start CS
Get Start CS
R2011b
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. Control System Toolbox Getting Started Guide COPYRIGHT 20002011 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
MathWorks products are protected by one or more U.S. patents. Please see www.mathworks.com/patents for more information.
Revision History
November 2002 June 2001 July 2002 June 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
First printing Second printing Online only Online only Online only Online only Online only Online only Online only Online only Online only Third printing Online only Online only Online only Online only Online only Online only
New Version 5.0 (Release 12) Revised for Version 5.1 (Release 12.1) Revised for Version 5.2 (Release 13) Revised for Version 6.0 (Release 14) Revised for Version 6.2 (Release 14SP2) Revised for Version 6.2.1 (Release 14SP3) Revised for Version 7.0 (Release 2006a) Revised for Version 7.1 (Release 2006b) Revised for Version 8.0 (Release 2007a) Revised for Version 8.0.1 (Release 2007b) Revised for Version 8.1 (Release 2008a) Revised for Version 8.2 (Release 2008b) Revised for Version 8.3 (Release 2009a) Revised for Version 8.4 (Release 2009b) Revised for Version 8.5 (Release 2010a) Revised for Version 9.0 (Release 2010b) Revised for Version 9.1 (Release 2011a) Revised for Version 9.2 (Release 2011b)
Contents
Product Overview
1
Why Use This Toolbox? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . Related Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 1-3 1-4
Building Models
2
Linear (LTI) Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What Is a Plant? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Linear Model Representations . . . . . . . . . . . . . . . . . . . . . . . SISO Example: The DC Motor . . . . . . . . . . . . . . . . . . . . . . . Building SISO Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Constructing Discrete Time Systems . . . . . . . . . . . . . . . . . . Adding Delays to Linear Models . . . . . . . . . . . . . . . . . . . . . LTI Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . MIMO Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . MIMO Example: State-Space Model of Jet Transport Aircraft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Constructing MIMO Transfer Functions . . . . . . . . . . . . . . . Accessing I/O Pairs in MIMO Systems . . . . . . . . . . . . . . . . Arrays of Linear Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . Model Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Interconnecting Linear Models . . . . . . . . . . . . . . . . . . . . . 2-2 2-2 2-2 2-3 2-6 2-9 2-10 2-10 2-13 2-13 2-15 2-17 2-18 2-21 2-23
Arithmetic Operations for Interconnecting Models . . . . . . Feedback Interconnections . . . . . . . . . . . . . . . . . . . . . . . . . . Converting Between Continuous- and Discrete- Time Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Available Commands for Continuous/Discrete Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Available Methods for Continuous/Discrete Conversion . . Digitizing the Discrete DC Motor Model . . . . . . . . . . . . . . . Reducing Model Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Model Order Reduction Commands . . . . . . . . . . . . . . . . . . . Techniques for Reducing Model Order . . . . . . . . . . . . . . . . . Example: Gasifier Model . . . . . . . . . . . . . . . . . . . . . . . . . . .
2-23 2-24
Analyzing Models
3
Quick Start for Performing Linear Analysis Using the LTI Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . LTI Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Plot Types Available in the LTI Viewer . . . . . . . . . . . . . . . . Example: Time and Frequency Responses of the DC Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Right-Click Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displaying Response Characteristics on a Plot . . . . . . . . . . Changing Plot Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Showing Multiple Response Types . . . . . . . . . . . . . . . . . . . . Comparing Multiple Models . . . . . . . . . . . . . . . . . . . . . . . . . Simulating Models with Arbitrary Inputs and Initial Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is the Linear Simulation Tool? . . . . . . . . . . . . . . . . . . Opening the Linear Simulation Tool . . . . . . . . . . . . . . . . . . Working with the Linear Simulation Tool . . . . . . . . . . . . . . Importing Input Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . Example: Loading Inputs from a Microsoft Excel Spreadsheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 3-7 3-7 3-8 3-10 3-11 3-14 3-16 3-17
vi
Contents
Example: Importing Inputs from the Workspace . . . . . . . . Designing Input Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . Specifying Initial Conditions . . . . . . . . . . . . . . . . . . . . . . . . Functions for Time and Frequency Response . . . . . . . . When to Use Functions for Time and Frequency Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Time and Frequency Response Functions . . . . . . . . . . . . . . Plotting MIMO Model Responses . . . . . . . . . . . . . . . . . . . . . Data Markers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Plotting and Comparing Multiple Systems . . . . . . . . . . . . . Creating Custom Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3-29 3-33 3-35 3-37 3-37 3-37 3-40 3-42 3-44 3-47
Designing Compensators
4
Designing PID Controllers . . . . . . . . . . . . . . . . . . . . . . . . . Designing PID Controllers with the PID Tuner GUI . . . . . Designing PID Controllers at the Command Line . . . . . . . SISO Design Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Quick Start for Tuning Compensator Parameters Using the SISO Design Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Components of the SISO Tool . . . . . . . . . . . . . . . . . . . . . . . . Design Options in the SISO Tool . . . . . . . . . . . . . . . . . . . . . Opening the SISO Design Tool . . . . . . . . . . . . . . . . . . . . . . . Using the SISO Design Task Node in the Control and Estimation Tools Manager . . . . . . . . . . . . . . . . . . . . . . . . Importing Models into the SISO Design Tool . . . . . . . . . . . Feedback Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Analysis Plots for Loop Responses . . . . . . . . . . . . . . . . . . . . Using the Graphical Tuning Window . . . . . . . . . . . . . . . . . Exporting the Compensator and Models . . . . . . . . . . . . . . . Storing and Retrieving Intermediate Designs . . . . . . . . . . . Bode Diagram Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What Is Bode Diagram Design? . . . . . . . . . . . . . . . . . . . . . . Example: DC Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adjusting the Compensator Gain . . . . . . . . . . . . . . . . . . . . . 4-2 4-2 4-14 4-15 4-15 4-25 4-25 4-26 4-28 4-29 4-33 4-35 4-41 4-48 4-50 4-54 4-54 4-54 4-55
vii
Adjusting the Bandwidth . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding an Integrator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding a Lead Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . Moving Compensator Poles and Zeros . . . . . . . . . . . . . . . . . Adding a Notch Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Modifying a Prefilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Root Locus Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What Is Root Locus Design? . . . . . . . . . . . . . . . . . . . . . . . . . Example: Electrohydraulic Servomechanism . . . . . . . . . . . Changing the Compensator Gain . . . . . . . . . . . . . . . . . . . . . Adding Poles and Zeros to the Compensator . . . . . . . . . . . . Editing Compensator Pole and Zero Locations . . . . . . . . . . Viewing Damping Ratios . . . . . . . . . . . . . . . . . . . . . . . . . . . Nichols Plot Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What Is Nichols Plot Design? . . . . . . . . . . . . . . . . . . . . . . . . DC Motor Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Opening a Nichols Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adjusting the Compensator Gain . . . . . . . . . . . . . . . . . . . . . Adding an Integrator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding a Lead Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . Automated Tuning Design . . . . . . . . . . . . . . . . . . . . . . . . . . Supported Automated Tuning Methods . . . . . . . . . . . . . . . . Loading and Displaying the DC Motor Example for Automated Tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Applying Automated PID Tuning . . . . . . . . . . . . . . . . . . . . . Multi-Loop Compensator Design . . . . . . . . . . . . . . . . . . . . When to Use Multi-Loop Compensator Design . . . . . . . . . . Workflow for Multi-Loop Compensator Design . . . . . . . . . . Example: Position Control of a DC Motor . . . . . . . . . . . . . . Control Design Analysis of Multiple Models . . . . . . . . . . Multiple Models Represent System Variations . . . . . . . . . . Control Design Analysis Using the SISO Design Tool . . . . Specifying a Nominal Model . . . . . . . . . . . . . . . . . . . . . . . . . Frequency Grid for Multimodel Computations . . . . . . . . . . How to Analyze the Controller Design for Multiple Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4-56 4-58 4-62 4-67 4-70 4-75 4-80 4-80 4-81 4-87 4-90 4-95 4-99 4-102 4-102 4-102 4-103 4-104 4-107 4-109 4-113 4-113 4-113 4-115 4-119 4-119 4-119 4-119 4-131 4-131 4-131 4-132 4-135 4-136
viii
Contents
Functions for Compensator Design . . . . . . . . . . . . . . . . . . When to Use Functions for Compensator Design . . . . . . . . Root Locus Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pole Placement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Linear-Quadratic-Gaussian (LQG) Design . . . . . . . . . . . . . Example Designing an LQG Regulator . . . . . . . . . . . . . . Example Designing an LQG Servo Controller . . . . . . . . Example Designing an LQR Servo Controller in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Index
ix
Contents
1
Product Overview
Why Use This Toolbox? on page 1-2 Using the Documentation on page 1-3 Related Products on page 1-4
Product Overview
1-2
1-3
Product Overview
Related Products
The following table summarizes MathWorks products that extend and complement the Control System Toolbox software. For current information about these products and other MathWorks products, point your Web browser to:
www.mathworks.com
Product Simulink
Description Provides blocks for simulating models you create and analyze using the Control System Toolbox software. Complements Control System Toolbox software with tools for modeling complex systems based on fuzzy logic. Helps you design and simulate model predictive controllers for linear plant models created using Control System Toolbox functions. Helps you design robust control systems based on plant models created using the Control System Toolbox software. Enables you to assess robustness based on confidence bounds for your plant models. Lets you use Control System Toolbox linear control tools to analyze and tune Simulink models.
1-4
Related Products
Description Helps you improve controller designs by estimating and tuning model parameters using numerical optimization. Helps you estimate linear and nonlinear mathematical models of dynamic systems from measured data. Use the Control System Toolbox software to analyze and design controllers for resulting linear models.
1-5
Product Overview
1-6
2
Building Models
Linear (LTI) Models on page 2-2 MIMO Models on page 2-13 Arrays of Linear Models on page 2-18 Model Characteristics on page 2-21 Interconnecting Linear Models on page 2-23 Converting Between Continuous- and Discrete- Time Systems on page 2-26 Reducing Model Order on page 2-29
Building Models
What Is a Plant?
Typically, control engineers begin by developing a mathematical description of the dynamic system that they want to control. The system to be controlled is called a plant. As an example of a plant, this section uses the DC motor. This section develops the differential equations that describe the electromechanical properties of a DC motor with an inertial load. It then shows you how to use the Control System Toolbox functions to build linear models based on these equations.
dx = Ax + Bu dt y = Cx + Du
where A, B, C, and D are matrices of appropriate dimensions, x is the state vector, and u and y are the input and output vectors. Transfer functions (TF), for example,
2-2
H (s) =
s+2 s + s + 10
2
H ( z) = 3
Frequency response data (FRD) models, which consist of sampled measurements of a systems frequency response. For example, you can store experimentally collected frequency response data in an FRD model. Note The design of FRD models is a specialized subject that this guide does not address. See Frequency Response Data (FRD) Models for a discussion of this topic.
2-3
Building Models
In this model, the dynamics of the motor itself are idealized; for instance, the magnetic field is assumed to be constant. The resistance of the circuit is denoted by R and the self-inductance of the armature by L. If you are unfamiliar with the basics of DC motor modeling, consult any basic text on physical modeling. With this simple model and basic laws of physics, it is possible to develop differential equations that describe the behavior of this electromechanical system. In this example, the relationships between electric potential and mechanical force are Faradays law of induction and Ampres law for the force on a conductor moving through a magnetic field.
Mathematical Derivation
The torque seen at the shaft of the motor is proportional to the current i induced by the applied voltage,
(t) = K m i(t)
where Km, the armature constant, is related to physical properties of the motor, such as magnetic field strength, the number of turns of wire around the conductor coil, and so on. The back (induced) electromotive force, emf , is a voltage proportional to the angular rate seen at the shaft,
dw = i = K f (t) + K m i(t) dt
where K f is a linear approximation for viscous friction. Finally, the electrical part of the motor equations can be described by
2-4
di + Ri(t) dt
or, solving for the applied voltage and substituting for the back emf,
app (t) = L
di + Ri(t) + K b(t) dt
This sequence of equations leads to a set of two differential equations that describe the behavior of the motor, the first for the induced current,
d 1 1 = K f (t) + K m i(t) dt J J
R d i L = dt K m J
Kb 1 L i + L app (t) K f 0 J
2-5
Building Models
Given these values, you can construct the numerical state-space representation using the ss function.
A = [-R/L -Kb/L; Km/J -Kf/J] B = [1/L; 0]; C = [0 1]; D = [0]; sys_dc = ss(A,B,C,D)
b = u1
2-6
x1 x2
2 0
c = y1 x1 0 x2 1
d = y1 u1 0
Zero/Pole/Gain Representation. Similarly, the zpk function converts from state-space or transfer function representations to the zero/pole/gain format. Use this code to convert from the state-space representation to the zero/pole/gain form for the DC motor.
sys_zpk = zpk(sys_dc) Zero/pole/gain: 1.5
2-7
Building Models
------------------(s+4.004) (s+9.996)
Note The state-space representation is best suited for numerical computations. For highest accuracy, convert to state space prior to combining models and avoid the transfer function and zero/pole/gain representations, except for model specification and inspection. See Reliable Computations for more information on numerical issues.
For example, you can create the transfer function by specifying the numerator and denominator with this code.
sys_tf = tf(1.5,[1 14 40.02]) Transfer function: 1.5 -----------------s^2 + 14 s + 40.02
Alternatively, if you want to create the transfer function of the DC motor directly, use these commands.
s = tf('s'); sys_tf = 1.5/(s^2+14*s+40.02)
2-8
2-9
Building Models
This command constructs the DC motor transfer function, but adds a 0.05 second delay.
Transfer function: 1.5 exp(-0.05*s) * -----------------s^2 + 14 s + 40.02
For a complete description of adding time delays to models and closing loops with time delays, see Models with Time Delays.
LTI Objects
For convenience, the Control System Toolbox software uses custom data structures called LTI objects to store model-related data. For example, the variable sys_dc created for the DC motor example is called an SS object. There are also TF, ZPK, and FRD objects for transfer function, zero/pole/gain, and frequency data response models respectively. The four LTI objects encapsulate the model data and enable you to manipulate linear systems as single entities rather than as collections of vectors or matrices. To see what LTI objects contain, use the get command. This code describes the contents of sys_dc from the DC motor example.
2-10
get(sys_dc) a: b: c: d: e: StateName: InternalDelay: Ts: InputDelay: OutputDelay: InputName: OutputName: InputGroup: OutputGroup: Name: Notes: UserData: [2x2 double] [2x1 double] [0 1] 0 [] {2x1 cell} [0x1 double] 0 0 0 {''} {''} [1x1 struct] [1x1 struct] '' {} []
You can manipulate the data contained in LTI objects using the set command; see the Control System Toolbox online reference pages for descriptions of set and get. Another convenient way to set or retrieve LTI model properties is to access them directly using dot notation. For example, if you want to access the value of the A matrix, instead of using get, you can type
sys_dc.a
Similarly, if you want to change the values of the A matrix, you can do so directly, as this code shows.
A_new = [-4.5 -0.05; 0.8 -12.0];
2-11
Building Models
sys_dc.a = A_new;
For more information on LTI properties, type ltiprops at the MATLAB prompt. For a complete description of LTI objects, see Linear System Modeling.
2-12
MIMO Models
MIMO Models
In this section... MIMO Example: State-Space Model of Jet Transport Aircraft on page 2-13 Constructing MIMO Transfer Functions on page 2-15 Accessing I/O Pairs in MIMO Systems on page 2-17
Use the following commands to specify this state-space model as an LTI object and attach names to the states, inputs, and outputs.
2-13
Building Models
states = {'beta' 'yaw' 'roll' 'phi'}; inputs = {'rudder' 'aileron'}; outputs = {'yaw rate' 'bank angle'}; sys_mimo = ss(A,B,C,D,'statename',states,... 'inputname',inputs,... 'outputname',outputs);
b = beta yaw roll phi rudder 0.0073 -0.475 0.153 0 aileron 0 0.0077 0.143 0
Continuous-time model.
2-14
MIMO Models
The model has two inputs and two outputs. The units are radians for beta (sideslip angle) and phi (bank angle) and radians/sec for yaw (yaw rate) and roll (roll rate). The rudder and aileron deflections are in degrees. As in the SISO case, use tf to derive the transfer function representation.
tf(sys_mimo) Transfer function from input "rudder" to output... -0.475 s^3 - 0.2479 s^2 - 0.1187 s - 0.05633 yaw rate: --------------------------------------------------s^4 + 0.6358 s^3 + 0.9389 s^2 + 0.5116 s + 0.003674 0.1148 s^2 - 0.2004 s - 1.373 --------------------------------------------------s^4 + 0.6358 s^3 + 0.9389 s^2 + 0.5116 s + 0.003674
bank angle:
Transfer function from input "aileron" to output... 0.0077 s^3 - 0.0005372 s^2 + 0.008688 s + 0.004523 yaw rate: --------------------------------------------------s^4 + 0.6358 s^3 + 0.9389 s^2 + 0.5116 s + 0.003674 0.1436 s^2 + 0.02737 s + 0.1104 --------------------------------------------------s^4 + 0.6358 s^3 + 0.9389 s^2 + 0.5116 s + 0.003674
bank angle:
2-15
Building Models
H (s) = s2
+ 4s + 5
s 1 s+1 s+2
You can specify H(s) by concatenation of its SISO entries. For instance,
h11 = tf([1 -1],[1 1]); h21 = tf([1 2],[1 4 5]);
or, equivalently,
s = tf('s') h11 = (s-1)/(s+1); h21 = (s+2)/(s^2+4*s+5);
This syntax mimics standard matrix concatenation and tends to be easier and more readable for MIMO systems with many inputs and/or outputs. See Model Interconnections for more details on concatenation operations for LTI systems.
s 1 N (s) = s + 2
s+1 D(s) = 2 s + 4s + 5
2-16
MIMO Models
N = {[1 -1];[1 2]}; % Cell array for N(s) D = {[1 1];[1 4 5]}; % Cell array for D(s) H = tf(N,D)
#2:
Notice that both N and D have the same dimensions as H. For a general MIMO transfer matrix H(s), the cell array entries N{i,j} and D{i,j} should be row-vector representations of the numerator and denominator of Hij(s), the ijth entry of the transfer matrix H(s).
extracts the subsystem, mapping the first input to the third output. Row indices select the outputs and column indices select the inputs. Similarly,
sys_mimo(3,1) = tf(1,[1 0])
redefines the transfer function between the first input and third output as an integrator.
2-17
Building Models
The number of inputs and outputs must be the same for all linear models encapsulated by the LTI array, but the model order (number of states) can vary from model to model within a single LTI array. The LTI array sys_lti contains the state-space models for each value of K. Type sys_lti to see the contents of the LTI array.
Model sys_lti(:,:,1,1) ====================== a = x1 x2 . . . Model sys_lti(:,:,2,1) ====================== a = x1 x2 . . x1 -4 7.5 x2 -0.3 -10 x1 -4 5 x2 -0.2 -10
2-18
You can manipulate the LTI array like any other object. For example,
step(sys_lti)
produces a plot containing step responses for all three state-space models.
2-19
Building Models
LTI arrays are useful for performing batch analysis on an entire set of models. For more information, see Model Arrays.
2-20
Model Characteristics
Model Characteristics
You can use the Control System Toolbox commands to query model characteristics such as the I/O dimensions, poles, zeros, and DC gain. These commands apply to both continuous- and discrete-time models. Their LTI-based syntax is summarized in the table below. Commands to Query Model Characteristics Command
size(model_name) ndims(model_name) isct(model_name) isdt(model_name) hasdelay(model_name) pole(model_name) zero(model_name) dcgain(model_name) norm(model_name) covar(model_name,W)
Description Number of inputs and outputs Number of dimensions Returns 1 for continuous systems Returns 1 for discrete systems True if system has delays System poles System (transmission) zeros DC gain System norms (H2 and L) Covariance of response to white noise Frequency response bandwidth LTI model order Compute pole-zero map of LTI models Natural frequency and damping of system poles
bandwidth(model_name)
lti/order(model_name)
pzmap(model_name)
damp(model_name)
2-21
Building Models
Description Create object or return class of object Determine whether input is object of given class Determine whether LTI model is empty Determine whether LTI model is proper Determine whether LTI model is single-input/single-output (SISO)
isa(model_name)
isempty(model_name)
isproper(model_name)
issiso(model_name)
reshape(model_name)
2-22
If the operands are models of different types, the resulting model type is determined by precedence rules; see Precedence Rules That Determine Model Type for more information. For more information about model arithmetic functions, see Catalog of Model Interconnections.
2-23
Building Models
You can also use the series and parallel functions as substitutes for multiplication and addition, respectively. Equivalent Ways to Interconnect Systems Operator
sys1 + sys2 sys1 - sys2 sys1 * sys2
Function
parallel(sys1,sys2)
Feedback Interconnections
You can use the feedback and lft functions to derive closed-loop models. For example,
sys_f = feedback(tf(1,[1 0]), tf([1 1],[1 2])
computes the closed-loop transfer function from r to y for the feedback loop shown below. The result is
Transfer function: s + 2 ------------s^2 + 3 s + 1
Feedback Interconnection
2-24
You can use the lft function to create more complicated feedback structures. This function constructs the linear fractional transformation of two systems. See the reference page for more information.
2-25
Building Models
2-26
b = x1 x2 u1 0.019605 7.1595e-005
c = y1 x1 0 x2 1
To see the discrete-time zero-pole gain for the digital DC motor, use zpk to convert the model.
fd=zpk(sysd) Zero/pole/gain: 7.1595e-005 (z+0.9544) -----------------------(z-0.9608) (z-0.9049) Sampling time: 0.01
You can compare the step responses of sys_dc and sysd by typing
2-27
Building Models
step(sys_dc,sysd)
Note the step response match. Continuous and FOH-discretized step responses match for models without internal delays.
2-28
Compute Hankel singular values of LTI model Reduced-order model approximation Minimal realization (pole/zero cancellation) Compute input/output balanced realization State deletion in I/O balanced realization Structurally minimal realization
2-29
Building Models
at the MATLAB prompt; the gasifier example is stored in the variable named gasf. If you type
size(gasf)
Before attempting model order reduction, inspect the pole and zero locations by typing
pzmap(sys35)
Zoom in near the origin on the resulting plot using the zoom feature or by typing
axis([-0.2 0.05 -0.2 0.2])
2-30
Because the model displays near pole-zero cancellations, it is a good candidate for model reduction. To find a low-order reduction of this SISO model, perform the following steps:
1 Select an appropriate order for your reduced system by examining the
relative amount of energy per state using a Hankel singular value (HSV) plot. Type the command
hsvd(sys35)
to create the HSV plot. Changing to log scale using the right-click menu results in the following plot.
2-31
Building Models
Small Hankel singular values indicate that the associated states contribute little to the I/O behavior. This plot shows that discarding the last 10 states (associated with the 10 smallest Hankel singular values) has little impact on the approximation error.
2 To remove the last 10 states and create a 15th order approximation, type
rsys35 = balred(sys35,15);
You can type size(rsys35) to see that your reduced system contains only 15 states.
3 Compare the Bode response of the full-order and reduced-order models
2-32
As the overlap of the curves in the figure shows, the reduced model provides a good approximation of the original system. You can try reducing the model order further by repeating this process and removing more states. Reduce the gasf model to 5th, 10th, and 15th orders all at once by typing the following command
rsys35 = balred(sys35,[5 10 15]);
Plot a bode diagram of these three reduced systems along with the full order system by typing
bode(sys35,'b',rsys35,'r--')
2-33
Building Models
relative amount of energy per state using a Hankel singular value (HSV) plot. Type
hsvd(gasf)
2-34
Discarding the last 8 states (associated with the 8 smallest Hankel singular values) should have little impact on the error in the resulting 17th order system.
2 To remove the last 8 states and create a 17th order MIMO system, type
rsys=balred(gasf,17);
You can type size(gasf) to see that your reduced system contains only 17 states.
3 To facilitate visual inspection of the approximation error, use a singular
to create a singular value plot comparing the original system to the reduction error.
2-35
Building Models
The reduction error is small compared to the original system so the reduced order model provides a good approximation of the original model.
Acknowledgment
MathWorks thanks ALSTOM Power UK for permitting use of their gasifier model for this example. This model was issued as part of the ALSTOM Benchmark Challenge on Gasifier Control. For more details see Dixon, R., (1999), "Advanced Gasifier Control," Computing & Control Engineering Journal, IEE, Vol. 10, No. 3, pp. 9296.
2-36
3
Analyzing Models
Quick Start for Performing Linear Analysis Using the LTI Viewer on page 3-2 LTI Viewer on page 3-7 Simulating Models with Arbitrary Inputs and Initial Conditions on page 3-22 Functions for Time and Frequency Response on page 3-37
Analyzing Models
Quick Start for Performing Linear Analysis Using the LTI Viewer
In this Quick Start, you learn how to analyze the time- and frequency-domain responses of one or more linear models using the LTI Viewer GUI. Before you can perform the analysis, you must have already created linear models in the MATLAB workspace. For information on how to create a model, see Chapter 2, Building Models. To perform linear analysis:
1 Open the LTI Viewer showing one or more models using the following
syntax:
ltiview(model1,model2,...,modelN)
By default, this syntax opens a step response plot of your models, as shown in the following figure.
3-2
Quick Start for Performing Linear Analysis Using the LTI Viewer
3-3
Analyzing Models
2 Add more plots to the LTI Viewer. a Select Edit > Plot Configurations. b In the Plot Configurations dialog box, select the number of plots to open.
3-4
Quick Start for Performing Linear Analysis Using the LTI Viewer
type.
3-5
Analyzing Models
4 Analyze system performance. For example, you can analyze the peak
response in the Bode plot and settling time in the step response plot.
a Right-click to select performance characteristics. b Click on the dot that appears to view the characteristic value.
3-6
LTI Viewer
LTI Viewer
In this section... Plot Types Available in the LTI Viewer on page 3-7 Example: Time and Frequency Responses of the DC Motor on page 3-8 Right-Click Menus on page 3-10 Displaying Response Characteristics on a Plot on page 3-11 Changing Plot Type on page 3-14 Showing Multiple Response Types on page 3-16 Comparing Multiple Models on page 3-17
3-7
Analyzing Models
The next section presents an example that shows you how to import a system into the LTI Viewer and how to customize the viewer to fit your requirements.
at the MATLAB prompt. This loads several LTI models, including a state-space representation of the DC motor called sys_dc.
3-8
LTI Viewer
This opens an LTI Viewer with an empty step response plot window by default.
Import System Data Dialog Box with the DC Motor Model Selected
Select sys_dc from the list of available models and click OK to close the browser. This imports the DC motor model into the LTI Viewer. To select more than one model at a time, do the following: To select individual (noncontiguous) models, select one model and hold down the Ctrl key while selecting additional models. To clear any models, hold down the Ctrl key while you click the highlighted model names. To select a list of contiguous models, select the first model and hold down the Shift key while selecting the last model you want in the list.
3-9
Analyzing Models
The figure below shows the LTI Viewer with a step response for the DC motor example.
Alternatively, you can open the LTI Viewer and import the DC motor example directly from the MATLAB prompt.
ltiview('step', sys_dc)
Right-Click Menus
The LTI Viewer provides a set of controls and options that you can access by right-clicking your mouse. Once you have imported a model into the LTI Viewer, the options you can select include Plot Types Change the plot type. Available types include step, impulse, Bode, Bode magnitude, Nichols, Nyquist, and singular values plots.
3-10
LTI Viewer
Systems Select or clear any models that you included when you created the response plot. Characteristics Add information about the plot. The characteristics available change from plot to plot. For example, Bode plots have stability margins available, but step responses have rise time and steady-state values available. Grid Add grids to your plots. Normalize Scale responses to fit the view (only available for time-domain plot types). Full View Use automatic limits to make the entire curve visible. Properties Open the Property Editor.
You can use this editor to customize various attributes of your plot. See Customizing Plot Properties and Preferences for a full description of the Property Editor. Alternatively, you can open the Property Editor by double-clicking in an empty region of the response plot.
3-11
Analyzing Models
Using Right-Click Menus to Display the Rise Time for a Step Response
By default, the rise time is defined as the amount of time it takes the step response to go from 10% to 90% of the steady-state value. You can change this range in the options tab of the property editor. For more information on the property editor, see Customizing Plot Properties and Preferences. The LTI Viewer calculates and displays the rise time for the step response.
3-12
LTI Viewer
To display the values of any plot characteristic marked on a plot, place your mouse on the blue dot that marks the characteristic. This opens a data marker with the relevant information displayed. To make the marker persistent, left-click the blue dot. For example, this figure shows the rise time value for the DC motor step response.
3-13
Analyzing Models
Note that you can left-click anywhere on a particular plot line to see the response values of that plot at that point. You must either place your cursor over the blue dot or left-click, however, if you want to see the rise time value. For more information about data markers, see Data Markers on page 3-42.
3-14
LTI Viewer
Selecting Bode changes the step response to a Bode plot for the DC motor model.
3-15
Analyzing Models
3-16
LTI Viewer
Using the Plot Configurations Dialog Box to Reconfigure the LTI Viewer
You can select up to six plots in one viewer. Choose the Response type for each plot area from the right-side menus. There are nine available plot types: Step Impulse Linear Simulation Initial Condition Bode (magnitude and phase) Bode Magnitude (only) Nyquist Nichols Singular Value Pole/Zero I/O pole/zero
3-17
Analyzing Models
A sample set of closed-loop transfer function models is included (along with some other models) in the MAT-file ltiexamples.mat. Type
load ltiexamples
to load the provided transfer functions. The three closed-loop transfer function models, Gcl1, Gcl2, and Gcl3, are for a satellite attitude controller. In this example, you analyze the response plots of the Gcl1 and Gcl2 transfer functions.
3-18
LTI Viewer
3-19
Analyzing Models
The minimum stability margins, meaning the smallest magnitude phase and gain margins, are displayed as green and blue markers on the Bode phase diagram. If you want to see all the gain and phase margins of a system, right-click and select Characteristics > Minimum Stability Margins.
3-20
LTI Viewer
This figure shows how to clear the second of the three models using right-click menu options.
The Systems menu lists all the imported models. A system is selected if a check mark is visible to the left of the system name.
3-21
Analyzing Models
3-22
In the LTI Viewer, right-click the plot area and select Plot Types > Linear Simulation. Use the lsim function at the MATLAB prompt:
lsim(modelname)
In the MATLAB Figure window, right-click a response plot and select Input data.
3-23
Analyzing Models
2 In the Timing area, specify the simulation time vector by doing one of
the following: Import the time vector by clicking Import time. Enter the end time and the time interval in seconds. The start time is set to 0 seconds.
3 Specify the input signal by doing one of the following:
Click Import signal to import it from the MATLAB workspace or a file. For more information, see Importing Input Signals on page 3-26. Click Design signal to create your own inputs. For more information, see Designing Input Signals on page 3-33.
4 If you have a state-space model and want to specify initial conditions, click
the Initial states tab. By default, all initial states are set to zero. You can either enter state values in the Initial value column, or import values by clicking Import state vector. For more information about entering initial states, see Specifying Initial Conditions on page 3-35.
3-24
the Interpolation method list to be used by the simulation solver: Zero order hold First order hold (linear interpolation) Automatic (Linear Simulation Tool selects first order hold or zero order hold automatically, based on the smoothness of the input) Note The interpolation method is not used when simulating discrete models.
6 Click Simulate.
3-25
Analyzing Models
displayed.
2 Specify the simulation time in the Timing area. 3 Select one or more rows for the input channels you want to import. The
3-26
4 Click Import signal to open the Data Import dialog box. The following
3-27
Analyzing Models
5 In the Import from list, select the source of the input signals. It can be
one of the following: Workspace MAT file XLS file CSV file ASCII file
6 Select the data you want to import. The Data Import dialog box contains
For an example of importing input signals, see the following: Example: Loading Inputs from a Microsoft Excel Spreadsheet on page 3-28 Example: Importing Inputs from the Workspace on page 3-29
Import dialog box with the data from the Microsoft Excel spreadsheet.
3-28
3-29
Analyzing Models
This opens the Linear Simulation Tool with default input data.
3-30
3 Create an input signal for your system in the MATLAB Command Window,
3-31
Analyzing Models
6 Click Import. This imports the new signal into the Linear Simulation Tool.
3-32
imported signal.
displayed).
3-33
Analyzing Models
2 Specify the simulation time in the Timing area. The time interval (in
seconds) is used to evaluate the input signal you design in later steps of this procedure.
3 Select one or more rows for the signal channels you want to design. The
4 Click Design signal to open the Signal Designer dialog box. The following
3-34
5 In the Signal type list, select the type of signal you want to create. It
can be one of the following: Sine wave Square wave Step function White noise
6 Specify the signal characteristics. The Signal Designer dialog box contains
3-35
Analyzing Models
already displayed).
2 In the Selected system list, select the system for which you want to
values from the MATLAB workspace by clicking Import state vector. The following figure shows an example of the import window:
3-36
3-37
Analyzing Models
response, and general linear simulations. For example, you can simulate the response to white noise inputs using lsim and the MATLAB function randn. In addition to time-domain analysis, you can use the Control System Toolbox functions for frequency-domain analysis using the following standard plots: Bode Nichols Nyquist Singular value This table lists available time and frequency response functions and their use. Functions for Frequency and Time Response Functions
bode evalfr freqresp gensig impulse initial iopzmap lsim margin nichols nyquist pzmap step
Description Bode plot Computes the frequency response at a single complex frequency (not for FRD models) Computes the frequency response for a set of frequencies Input signal generator (for lsim) Impulse response plot Initial condition response plot Pole-zero map for each I/O pair of an LTI model Simulation of response to arbitrary inputs Computes and plots gain and phase margins Nichols plot Nyquist plot Pole-zero map Step response plot
3-38
Description Compute Hankel singular values of LTI model Bode magnitude response of LTI models
These functions can be applied to single linear models or LTI arrays. The functions step, impulse, and initial automatically generate an appropriate simulation horizon for the time response plots. For example,
h = tf([1 0],[1 2 10]) impulse(h)
3-39
Analyzing Models
The simulation horizon is automatically determined based on the model dynamics. You can override this automatic mode by specifying a final time,
step(h,10) % Simulates from 0 to 10 seconds
3-40
Right-Click Menus
All the time and frequency response functions provide right-click menus that allow you to customize your plots. For more information on using the LTI Viewer right-click menus, see Using the Right-Click Menu in the LTI Viewer. This figure shows the plots from Step Responses for a MIMO Model on page 3-40, with the right-click menu open.
3-41
Analyzing Models
Systems Select or clear any models that you included when you created the response plot. Characteristics Add information about the plot. The characteristics available change from plot to plot. For example, Bode plots have stability margins available, but step responses have rise time and steady-state values available. Axes Grouping Change the grouping of your plots. Available options are All, None, Inputs, and Outputs. You can group all the plots together, place each in a separate plot region (none), or group the inputs or outputs together. I/O Selector Open the I/O Selector dialog box.
Use this dialog box to select/clear which inputs and outputs to plot. Normalize Scale responses to fit the view (only available for time-domain plot types). Full View Use automatic limits to make the entire curve visible. Grid Add grids to your plots. Properties Open the Property Editor, which you can use to customize various attributes of your plot. See Customization for a full description of the Property Editor. Alternatively, you can open the Property Editor by double-clicking in an empty region of the response plot.
Data Markers
In addition to right-click menus, you can use plot data markers. These allow you to identify key data points on your plots. This figure, using the same plot as Step Responses for a MIMO Model on page 3-40, shows markers on the plots.
3-42
You can move a data marker by Grabbing the black square located at the corner of the marker Dragging the marker with your mouse The time and amplitude values will change as you move the marker. This does not apply to markers that display plot characteristics (e.g., peak value or rise time). In the case of plot characteristic data markers, you can view them by placing your cursor over the dot that represents the active characteristic. To make the data marker persistent, left-click the marker. Note Data markers do not apply to the SISO Design Tool, which displays data about plot characteristics in the status pane at the bottom of the SISO Design Tool window.
3-43
Analyzing Models
Right-Click Menus
Right-click on any data marker to open a property menu for the marker.
Property options for the marker include Alignment Change the position of the marker. Available options are top-right, top-left, bottom-right, and bottom-left. FontSize Change the font size. Movable By default, you can move data markers by clicking and dragging. Clearing Movable forces the marker to remain at a fixed data point. Delete Remove the selected marker. Alternatively, left-click anywhere in the empty plot region to delete all markers in the plot Interpolation By default, data markers linearly interpolate between points along the plotted curve. Select None to force the markers to snap to nearest points along the plotted curve. Since characteristic data markers are by definition fixed, the right-click menus for them have fewer options.
These options work the same as they do for the full right-click menu.
3-44
so, invoke the corresponding command-line function using the list sys1,..., sysN of models as the inputs.
stepplot(sys1,sys2,...,sysN) impulseplot(sys1,sys2,...,sysN) ... bodeplot(sys1,sys2,...,sysN) nicholsplot(sys1,sys2,...,sysN) ...
All models in the argument lists of any of the response plotting functions (except for sigma) must have the same number of inputs and outputs. To differentiate the plots easily, you can also specify a distinctive color/linestyle/marker for each system just as you would with the plot command. For example,
bodeplot(sys1,'r',sys2,'y--',sys3,'gx')
plots sys1 with solid red lines, sys2 with yellow dashed lines, and sys3 with green x markers. You can plot responses of multiple models on the same plot. These models do not need to be all continuous-time or all discrete-time.
3-45
Analyzing Models
Use this command to compare the Bode plots of the two systems.
bodeplot(sysc,'--',sysd,'-') % Compare Bode responses
3-46
Comparison of Bode Plots for a Continuous Model and Its Discretized Version
A comparison of the continuous and discretized responses reveals a drastic undersampling of the continuous-time system. Specifically, there are hidden oscillations in the discretized time response and aliasing conceals the continuous-time resonance near 30 rad/sec.
3-47
Analyzing Models
bodeplot(h) subplot(222) stepplot(h) subplot(223) pzplot(h) subplot(224) plot(rand(1, 100)) title('Some noise')
For information about plot, subplot, hold, and other options for plotting general data, see Basic Plots and Graphs in the MATLAB Function Reference. These documents are available in the MATLAB online help.
3-48
Note Each of the plots generated by response analysis functions in Example of Creating a Custom Plot on page 3-48 (bodeplot, stepplot, and pzplot) has its own right-click menu (similar to those in the LTI Viewer). To activate the right-click menus, place your mouse in the plot region and right-click. The menu contents depend on what type of plot you have selected.
3-49
Analyzing Models
3-50
4
Designing Compensators
Quick Start for Tuning Compensator Parameters Using the SISO Design Tool on page 4-15 Designing PID Controllers on page 4-2 SISO Design Tool on page 4-15 Bode Diagram Design on page 4-54 Root Locus Design on page 4-80 Nichols Plot Design on page 4-102 Automated Tuning Design on page 4-113 Multi-Loop Compensator Design on page 4-119 Control Design Analysis of Multiple Models on page 4-131 Functions for Compensator Design on page 4-146
Designing Compensators
sys
+ -
sys
4-2
The PID Tuner automatically designs a controller for your plant. You specify the controller type (P, I, PI, PD, PDF, PID, PIDF) and form (parallel or standard). You can analyze the design using a variety of response plots, and interactively adjust the design to meet your performance requirements. To launch the PID Tuner, use the pidtool command:
pidtool(sys,type)
where sys is a linear model of the plant you want to control, and type is a string indicating the controller type to design. Alternatively, enter
pidtool(sys,Cbase)
where Cbase is a baseline controller, allowing you to compare the performance of the designed controller to the performance of Cbase. For more information about sys and Cbase, see the pidtool reference page.
4-3
Designing Compensators
type
input to
pidtool 'p' 'i'
Controller Type
integrator formulas)
P I
Kp
Kp
Ki s
'pi' PI
Ki
Ts z 1 Ts z 1 z 1 Ts
Kp +
Ki s
K p + Ki
'pd'
PD
K p + Kds
K p + Kd
'pdf'
Proportional and derivative with first-order filter on derivative term Proportional, integral, and derivative
Kp +
Kds Tf s + 1
K p + Kd
1 Tf + Ts z 1
'pid'
PID
Kp +
Ki + Kds s
K p + Ki
Ts z 1 + Kd z 1 Ts
'pidf'
PIDF
Kp +
Ki Kds + s Tf s + 1
K p + Ki
Ts + Kd z 1
1 Tf + Ts z 1
If sys is a discrete-time model with sampling time Ts, the PID Tuner designs a discrete-time pid controller using the ForwardEuler discrete integrator formula. To design a controller that has different discrete integrator formulas, use one of the following methods:
4-4
Provide a discrete-time baseline controller Cbase to the launch command pidtool. The PID Tuner designs a controller that has the same discrete integrator formulas as Cbase. After launching the PID Tuner, click the button to open the PID Tuner Settings dialog box. Select discrete integrator formulas from the Integral Formula and Derivative Formula menus. For more information about discrete integrator formulas, see the pid and
pidstd reference pages.
+ -
PID C
d1 u + +
Plant sys
d2 + + y
4-5
Designing Compensators
Response
Reference tracking
Plotted System
Description Shows the closed-loop system response to a change in setpoint. Use when your design specifications include setpoint tracking. Shows the closed-loop controller output response to a change in setpoint. Use when your design is limited by practical constraints, such as controller saturation. Shows the closed-loop system response to load disturbance (a disturbance at the plant input). Use when your design specifications include input disturbance rejection. Shows the closed-loop system response to measurement noise. Shows response of the open-loop controller-plant system. Use for frequency-domain design. Use when your design specifications include robustness criteria such as open-loop gain margin and phase margin. Shows the plant response. Use to examine plant dynamics.
Controller effort
C (from r to u) 1 + C sys
Plant
sys
Choose time-domain (Step) or frequency-domain (Bode) responses from the Plot menu.
4-6
If you provide Cbase, check Show baseline to display the response of the baseline controller.
sys =
1 (s + 1)3
The design requirements are for the closed loop system to track a reference input with a rise time less than 1.5 s, and settling time less than 6 s.
1 Launch the PID Tuner to design a PI controller for a first pass design.
Upon launch, the PID Tuner displays the closed-loop step response of the system with a PI controller designed for a balance between performance (response time) and robustness (stability margins).
4-7
Designing Compensators
Right-click on the plot and select Characteristics > Rise Time to mark the rise time as a blue dot on the plot. Select Characteristics > Settling Time to mark the settling time. To see tool-tips with numerical values, click each of the blue dots.
4-8
The PID Tuner default PI controller provides a rise time of 2.35 s and settling time of 10.7 s. Both results are slower than the design requirements.
4-9
Designing Compensators
Note To display the performance metrics in a table instead of in tool-tips . This action expands on the plot, click the Show parameters button the GUI to show performance and robustness metrics. It also displays the controller gains.
3 Use the Response time slider to try to improve the loop performance.
Slide the slider to the right to make the loop faster. The response plot automatically updates with the new design. Moving the slider far enough to meet the rise time requirement of less than 1.5 s, however, results in unacceptably long settling time. There is also more oscillation. To achieve the faster response speed, the algorithm must sacrifice stability.
4-10
Adding derivative action to the controller gives the PID Tuner more freedom to achieve adequate phase margin with the desired response speed. Select PIDF from the Type menu. The PID Tuner designs a new PIDF controller. (See PID Controller Type on page 4-3 for more information about available controller types.)
4-11
Designing Compensators
The rise time and settling time now meet the design requirements. You can use the Response time slider to make further adjustments to the response. To revert to the default automated tuning result, click the button.
Note To adjust the closed-loop bandwidth and phase margin separately, select Extended from the Design mode menu . The bandwidth is inversely proportional to the response time.
4-12
To analyze other system responses, use the Response menu to choose a response plot and the Plot menu to choose time-domain (Step) or frequency-domain (Bode) responses. For example, to observe the closed-loop system response to disturbance at the plant input, select Input disturbance rejection from the Response menu.
4-13
Designing Compensators
See Analyzing Your Design Using Response Plots on page 4-5 for more information about available response plots.
6 Export your controller design to the MATLAB workspace.
To export your final controller design to the MATLAB workspace, click The PID Tuner GUI exports the controller as a pid controller object, if the Form is Parallel pidstd controller object, if the Form is Standard For more examples of controller design using the PID Tuner, see the Control System Toolbox demo, Designing PID for Disturbance Rejection with PID Tuner
4-14
Quick Start for Tuning Compensator Parameters Using the SISO Design Tool
In this Quick Start, you get an overview of the steps for tuning compensator parameters. Before you begin, you need: A model in the MATLAB workspace representing your plant For information on how to create a model, see Chapter 2, Building Models. Design requirements for your system To tune parameters:
1 Open the control design GUIs by typing the following in the MATLAB
Command Window:
4-15
Designing Compensators
sisotool
This command opens the Control and Estimation Tools Manager and the SISO Design Tool, as shown in the following figure.
4-16
2 Define the control architecture for your system. a In the Architecture tab of the Control and Estimation Tools Manager,
4-17
Designing Compensators
3 Specify the plant model and initial guesses for the compensator elements
workspace.
4-18
4 Design a compensator using automated tuning, for example PID Tuning. a In the Automated Tuning tab of the Control and Estimation Tools
Tune parameters
4-19
Designing Compensators
i In the Analysis Plots tab, select a plot type. ii Select the type of response for each plot.
4-20
values to design requirements. iii Right-click to select performance characteristics. iv Click on the dot that appears to view the characteristic value.
4-21
Designing Compensators
6 Refine compensator design using graphical tuning. a Create plots for graphical tuning.
i In the Graphical Tuning tab, select the loop to tune in each plot. ii Select plot types.
4-22
and lag, for example. To do this, right-click to add dynamic elements in the controller structure.
c Add a new pole, for example, by clicking the pole location on the plot.
4-23
Designing Compensators
d Modify the compensator structure by moving the poles, zeros, and other
4-24
7 Export the compensator to the MATLAB workspace for further analysis. a In the Control and Estimation Tools Manager, select File > Export. b In the SISO Tool Export dialog box, select the compensator. c Click Export to Workspace.
4-25
Designing Compensators
Convert models between discrete and continuous time. Automate compensator design.
at the MATLAB prompt. This loads a collection of linear models, including the DC motor. To open the SISO Design Tool and import the DC motor, type
sisotool(sys_dc)
This command opens: The SISO Design Task node in the Control and Estimation Tools Manager The Graphical Tuning window with the root locus and open-loop Bode diagrams for the DC motor plotted by default
4-26
4-27
Designing Compensators
Using the SISO Design Task Node in the Control and Estimation Tools Manager
The SISO Design Task node in the Control and Estimation Tools Manager contains the following tabs for specifying controller design and behavior: Architecture:
Change the feedback structure and label signals and blocks. Configure loops for multi-loop design by opening signals to remove the effects of other feedback loops. Import LTI models or row or column arrays of LTI models into your system.
4-28
Convert sample time of the system or switch between different sample times to design different compensators. Specify nominal model and frequency grid for multimodel computations. Directly edit compensator poles, zeros, and gains. Add or remove compensator poles and zeros. Configure design plots in the Graphical Tuning window. Use design plots to graphically manipulate system response. Configure analysis plots in the LTI Viewer. Use analysis plots to view the response of open- or closed-loop systems. Automatically generate compensators using optimization-based, PID, internal model control (IMC), linear-quadratic-Gaussian (LQG), or loop shaping methods. Use optimization-based methods that automatically tune the system to satisfy design requirements (available when you have the Simulink Design Optimization product).
Compensator Editor:
Graphical Tuning:
Analysis Plots:
Automated Tuning:
4-29
Designing Compensators
The System Data dialog box opens, as shown in the following figure.
G is a plant modeled as an LTI model or multiple plants modeled as a row or column array of LTI models. If H is also an array, their sizes must match.
4-30
H is the sensor modeled as an LTI model or multiple sensors modeled as a row or column array of LTI models. If G is also an array, their sizes must match. C is a controller and is an LTI model. F is a prefilter and is an LTI model. The default values of G, H, C, and F are 1. See Feedback Structure on page 4-33 for more information. Note If you import an array of LTI models for either G or H or both for control design, you can use the default multimodel options or configure the options by clicking Multimodel Configuration in the Architecture tab. For more information, see Control Design Analysis of Multiple Models on page 4-131. To import the DC motor model:
1 Select G and click Browse. The Model Import dialog box opens, as shown
4-31
Designing Compensators
2 Select sys_dc from the Available Models list. Click Import, and then
click Close. You can now see sys_dc in the System Data dialog box.
3 Click OK.
The Graphical Tuning window updates with the DC motor model, as shown in the following figure.
4-32
Feedback Structure
The SISO Design Tool, by default, assumes that the compensator is in the forward path, i.e., that the feedback structure looks like this figure.
4-33
Designing Compensators
F represents the prefilter C represents the compensator The default values for F, H, and C are all 1. You can see the default values in the System Data dialog box. This means that, by default, the compensator has unity gain. For the DC motor, G contains the DC motor model, sys_dc.
You can use the Signs and Blocks and Signals panes to change the sign of the feedback signal into a summing junction and rename blocks and signals in the diagram respectively. See Block Diagram Structure Modifications for more details. On any tab in the SISO Design Task node, click Show Architecture to see the current architecture and a list of the identifiers and names associated with the components.
4-34
4-35
Designing Compensators
Select the plot types for each plot in the Analysis Plots area. Then select the plots to appear in the Plots list in the Contents of Plots table, as shown in the following figure.
4-36
After you select a plot, the LTI Viewer opens and displays the appropriate response(s) opens. You can also click Show Analysis Plot to open the LTI Viewer. The following figure shows the resulting plot for the closed-loop step response of the DC motor.
4-37
Designing Compensators
The settling time of the DC motor is about 1.5 seconds, which is too slow for many applications. Also, the plot shows a large steady-state error. You can use Bode diagram techniques to improve the response time and steady-state error of the DC motor step response, as described in Bode Diagram Design on page 4-54. For a row or column array of LTI models, the analysis plots show the response of the nominal model only. To view the responses of the remaining models in the array, right-click the plot, and select one of the following options: Multimodel Display > Bounds Displays an envelope encompassing all model responses.
4-38
4-39
Designing Compensators
The plot line in darker shade of blue is the response of the nominal model. When you design a controller for the nominal plant, you can simultaneously analyze the controllers effect on the remaining model responses in the array. For more information on analyzing control design for multiple models, see Control Design Analysis of Multiple Models on page 4-131. As you select different compensator designs, the software computes the responses and updates the response plots in real-time in the LTI Viewer associated with your SISO Design Task. For an array, this computation is expensive. Therefore, real-time updates may cause delay in refreshing the plots for: A large number of responses Responses of a large number of models To deactivate real-time updates, unselect the Real-Time Update option.
4-40
4-41
Designing Compensators
This topic describes some of the methods you can use to navigate in the Graphical Tuning window and manipulate the windows appearance.
4-42
For a row or column arrays of LTI models, the plots show the individual responses and poles and zeros of all models in the array, as shown in the following figure.
4-43
Designing Compensators
The plot line in darker shade of blue represents the response of the nominal model. This plot also displays the response characteristics of the nominal model. You can change the display to view an envelope that encompasses all individual model responses. To do so, right-click the plot, and select Multimodel Display > Bounds. The bounds resemble the following figure.
4-44
As you are designing a controller for the nominal plant, you can simultaneously analyze the controllers effect on the remaining models in the array. The software computes the response for each model and plots them. This computation is expensive and results in a slower refresh of the plots for: Large number of responses Responses for a large number of models Dense frequency grid
4-45
Designing Compensators
To speed up the plot updates, change the display to plot the envelope instead of individual responses. For more information, see Control Design Analysis of Multiple Models on page 4-131.
4-46
Use the options on the Units page to make the change. This unit change persists for the entire session. For more information about property and preference settings, see Customization.
Right-Click Menus
The SISO Design Tool has right-click menus available in any of the plot regions. Open the Bode magnitude menu by right-clicking in the Bode magnitude plot. The following menu appears.
4-47
Designing Compensators
Although the menus for each plot generally contain the same options, there are some options specific to each plot type: The Open-Loop Bode Editor has a Gain Target option, the Closed-Loop Bode Editor has a Select Compensator option instead. For arrays of LTI models, the Multimodel Display option for the Root Locus Editor has an option to show the poles and zeros of the nominal or all models, instead of Bounds and Individual Responses options. The right-click menus contain numerous features. The DC motor example uses many of the available features; for a complete discussion of the right-click menus, see the help for the SISO Design Tool."
4-48
Select models to export area shows a list of models for the components of your designs. For a plant or sensor modeled as row or column array of LTI models, the components are also arrays of LTI models. Export As column displays variables with default names or previously named in the System Data dialog box. Select design drop-down list lets you view the components of other designs. To export your controller to the workspace:
1 Select Compensator C in the Component column. If you want to change
the name, double-click in the cell for Compensator C. To select multiple components, use the Shift key if they are all adjacent and the Ctrl key if they are not.
2 Click Export to Workspace to export the compensator to the MATLAB
workspace.
3 At the MATLAB prompt, type
who
4-49
Designing Compensators
You can save your models as MAT-files in any folder. The default name for the MAT-file is the name of your original model. You can also specify a name for the MAT-file. If you save multiple components, they are stored in a single MAT-file.
4-50
If you have any intermediate designs already stored, they will appear on the Design History page. Click Store Design to save the current design with the default name Design; the suffix increments when you store additional compensators without renaming them. You can rename the design by right-clicking the name under the node and selecting Rename. To retrieve intermediate designs, again click the Design History node or select Store/Retrieve from the Designs menu. From the Design History page, select the design to retrieve, and then click Retrieve Design, as shown next.
4-51
Designing Compensators
The Graphical Tuning window automatically reverts to the selected compensator design. Click any design name in the Design History to view a snapshot summary of the design, as shown in the following figure.
4-52
Return to the compensator list by clicking the Design History node. You can delete an intermediate design by selecting it from the Design History page and clicking Delete.
4-53
Designing Compensators
Example: DC Motor
The following topics use the DC motor example to show how to create a compensator using Bode diagram design techniques. From SISO Example: The DC Motor on page 2-3, the transfer function of the DC motor is
Transfer function: 1.5 -----------------s^2 + 14 s + 40.02
4-54
For this example, the design criteria are as follows: Rise time of less than 0.5 second Steady-state error of less than 5% Overshoot of less than 10% Gain margin greater than 20 dB Phase margin greater than 40 degrees
page.
2 Select C from the compensator selection list. 3 In the text box to the right of the equal sign in the Compensator area,
4-55
Designing Compensators
The SISO Design Tool calculates the compensator gain, and Bode and root locus graphs in the Graphical Tuning window are updated. Alternatively, you can set the gain in the Graphical Tuning window by grabbing the Bode magnitude line and dragging it upward. The gain and poles change as the closed-loop set point is recomputed, and the new compensator value is updated in the Compensator Editor page.
4-56
To make the crossover easier to see, select Grid from the right-click menu. This creates a grid for the Bode magnitude plot. Left-click the Bode magnitude plot and drag the curve until you see the curve crossing over the 0 dB line (on the y axis) at 3 rad/s. This changes both the SISO Design Tool display and the LTI Viewer step response. For a crossover at 3 rad/s, the compensator gain should be about 38. By default, the Graphical Tuning window shows gain and phase margin information in the lower-left corners of the Bode diagrams. In the Bode magnitude plot, it also tells you if your closed-loop system is stable or unstable. This figure shows the Graphical Tuning window.
This plot shows the associated closed-loop step response in the LTI Viewer.
4-57
Designing Compensators
The step response shows that the steady-state error and rise time have improved somewhat, but you must design a more sophisticated controller to meet all the design specifications, in particular, the steady-state error requirement.
Adding an Integrator
One way to eliminate steady-state error is to add an integrator. To add an integrator:
1 Click the Compensator Editor tab to open the Compensator Editor
page.
2 Right-click anywhere in the Dynamics table for the right-click menu, and
then select Add Pole/Zero > Integrator. The following figures show this process.
4-58
4-59
Designing Compensators
Notice adding the integrator changed the crossover frequency of the system. Readjust the compensator gain in the Compensator Editor page to bring the crossover back to 3 rad/s; the gain should be 99. After you have added the integrator and readjusted the compensator gain, the Graphical Tuning window shows a red x at the origin of the root locus plot.
4-60
4-61
Designing Compensators
Use the right-click menu to show the peak response and rise time (listed under the Characteristics). The step response is settling around 1, which satisfies the steady-state error requirement. This is because the integrator forces the system to zero steady-state error. The figure shows, however, that the peak response is 1.3, or about 30% overshoot, and that the rise time is roughly 0.4 second. So a compensator consisting of an integrator and a gain is not enough to satisfy the design requirements, which require that the overshoot be less than 10%.
4-62
the compensator gain to verify this. The only option left is to add dynamics to the compensator. One possible solution is to add a lead network to the compensator. To add the lead network:
1 Click the Compensator Editor tab to open the Compensator Editor
page.
2 In the Dynamics table, right-click and then select Add Pole/Zero > Lead.
The following figures show the process of adding a lead network to your controller.
Adding a Lead Network to the DC Motor Compensator on the Compensator Editor Page
4-63
Designing Compensators
Editable fields are shown in the Edit Selected Dynamics group box (right side of page) when an item in the Dynamics table has been selected, as shown in the following figure.
4-64
For this example, change Real Zero to -7.38 and change Real Pole to -11.1. You can also add a lead network using the Graphical Tuning window. Right-click in the Bode graph, select Add Pole/Zero > Lead, place the x on the plot where you want to add the lead network, and then left-click to place it. The Compensator Editor page is updated to include the new lead network in the Dynamics table. Your Graphical Tuning window and LTI Viewer plots should now look similar to these.
4-65
Designing Compensators
Root Locus, Bode, and Step Response Plots for the DC Motor with a Lead Network
4-66
The Step Response plot shows that the rise time is now about 0.4 second and peak response is 1.24 rad/s (i.e., the overshoot is about 25%). Although the rise time meets the requirement, the overshoot is still too large, and the stability margins are still unacceptable, so you must tune the lead parameters.
the left-most (slowest) pole of the DC motor plant (denoted by a blue x).
2 Change the value of the lead network pole (Real Pole) to move it to the
right. Notice how the gain margin increases (as shown in the Graphical Tuning window) as you do this.
4-67
Designing Compensators
As you tune these parameters, look at the LTI Viewer. You will see the closed-loop step response alter with each parameter change you make. The following figure shows the final values for a design that meets the specifications.
Graphical Tuning Window with Final Design Parameters for the DC Motor Compensator
The values for this final design are as follows: Poles at 0 and -28 Zero at -4.3 Gain = 84
4-68
Enter these values directly in the Edit Selected Dynamics group box in the Compensator Editor page, shown as follows (Integrator is already set to 0).
The following figure shows the step response for the final compensator design.
4-69
Designing Compensators
In the LTI Viewers right-click menu, select Characteristics > Peak Response and Characteristics > Rise Time to show the peak response and rise time, respectively. Hover the mouse over the blue dots to show the data markers. The step response shows that the rise time is 0.45 second, and the peak amplitude is 1.03 rad/s, or an overshoot of 3%. These results meet the design specifications.
4-70
4-71
Designing Compensators
The following figure shows the result in the Graphical Tuning window.
4-72
To see the notch filter parameters in more detail, click the Zoom In
icon on the Graphical Tuning window. In the Open-Loop Bode Editor, press the left mouse button and drag your mouse to draw a box around the notch filter. When you release the mouse, the Graphical Tuning window will zoom in on the selected region. To understand how adjusting the notch filter parameters affects the filter, consider the notch filter transfer function.
2 s2 + 21n s + n 2 s2 + 22n s + n
4-73
Designing Compensators
The three adjustable parameters are 1, 2, and n. The ratio of 2/1 sets the depth of the notch, and n is the natural frequency of the notch. This diagram shows how moving the red and black diamonds changes these parameters, and hence the transfer function of the notch filter.
In the Dynamics table on the Compensator Editor page, select the row containing the newly added notch filter. The editable fields appear in the Edit Selected Dynamics group box, as shown next.
4-74
Modifying a Prefilter
You can use the SISO Design Tool to modify the prefilter in your design. Typical prefilter applications include: Achieving (near) feedforward tracking to reduce load on the feedback loop (when stability margins are poor) Filtering out high frequency content in the command (reference) signal to limit overshoot or to avoid exciting resonant modes of the plant A common prefilter is a simple lowpass filter that reduces noise in the input signal.
4-75
Designing Compensators
Open the Bode diagram for the prefilter by opening the right-click menu in the Closed-Loop Bode Editor in the Graphical Tuning window, and then selecting Select Compensators > F(F).
For clarity, the previous figure does not show the open-loop Bode diagram for the compensator (C). To remove the Bode diagram from the Graphical Tuning window, go to the SISO Design Task node on the Control and Estimation Tools Manager, click the Graphical Tuning tab, and for Plot 2, Open Loop 1, select Plot type None.
4-76
If you havent imported a prefilter, the default is a unity gain. You can add poles and zeros and adjust the gain using the same methods as you did when designing the compensator (C) on the Compensator Editor page. A quick way to create a lowpass roll-off filter is to add a pair of complex poles. To do this, first click the Compensator Editor tab and change the compensator to F. Right-click in the Dynamics table and select Add Pole/Zero > Complex Pole. Select this line to show the editable parameters in the Edit Selected Dynamics group box. For this example, try to place the poles at about 50 rad/s. The following figure shows the poles added to the prefilter Bode diagram.
4-77
Designing Compensators
By default, the damping ratio of the complex pair is 1.0, which means that there are two real-valued poles at about -50 rad/s. The green curve, which represents the prefilter Bode response, shows the -3 dB point for the roll-off is at about 50 rad/s. The magenta curve, which represents the closed-loop response from the prefilter to the plant output, shows that after the -3 dB point, the closed-loop gain rolls off at -40 dB/decade to provide some noise disturbance rejection.
Importing a Prefilter
As an alternative approach, you can design a prefilter using the Control System Toolbox commands like ss or tf and then import the design directly into the prefilter. For example, to create the lowpass filter using zpk, try
prefilt=zpk([],[-35 + 35i, -35 - 35i],1)
4-78
and import prefilt by clicking System Data on the Architecture page. This opens the System Data dialog box. Click Browse to open the Model Import dialog box, as shown next.
Importing a Prefilter
Select prefilt from the Available Models list and click Import to import the prefilter model. Click Close to close the Import Model dialog box. After you have imported the prefilter model, you can modify it using the same methods as described in this chapter for compensator design.
4-79
Designing Compensators
4-80
where P(s) is the plant, H(s) is the sensor dynamics, and k is a scalar gain to be adjusted. The closed-loop poles are the roots of
4-81
Designing Compensators
Electrohydraulic Servomechanism
The force on the spool is proportional to the current in the electromagnet coil. As the spool moves, the valve opens, allowing the high-pressure hydraulic fluid to flow through the chamber. The moving fluid forces the piston to move in the opposite direction of the spool. Control System Dynamics, by R. N. Clark, (Cambridge University Press, 1996) derives linearized models for the electromagnetic amplifier, the valve spool dynamics, and the ram dynamics; it also provides a detailed description of this type of servomechanism. If you want to use this servomechanism for position control, you can use the input voltage to the electromagnet to control the ram position. When measurements of the ram position are available, you can use feedback for the ram position control, as shown in the following figure.
4-82
to load a collection of linear models that include Gservo, which is a linearized plant transfer function for the electrohydraulic position control mechanism. Typing Gservo at the MATLAB prompt opens the servomechanism (plant) transfer function.
Gservo Zero/pole/gain from input "Voltage" to output "Ram position": 40000000 ----------------------------s (s+250) (s^2 + 40s + 9e004)
Design Specifications
For this example, you want to design a controller so that the step response of the closed-loop system meets the following specifications: The 2% settling time is less than 0.05 second. The maximum overshoot is less than 5%. The remainder of this topic discusses how to use the SISO Design Tool to design a controller to meet these specifications.
at the MATLAB prompt. This opens the SISO Design Task node in the Control and Estimation Tools Manager and the Graphical Tuning window with the servomechanism plant imported.
4-83
Designing Compensators
Graphical Tuning Window Showing the Root Locus and Bode Plots for the Electrohydraulic Servomechanism Plant
Zooming
Click the Zoom In
icon in the Graphical Tuning window. Press and hold the mouses left button and drag the mouse to select a region for zooming. For this example, reduce the root locus region to about -500 to 500 in both the x- and y-axes. This figure illustrates the zooming in process.
4-84
As in the DC motor example, click the Analysis Plots tab to set up loop responses. Select Plot Type Step for Plot 1, then select plot 1 for Closed-Loop r to y, shown as follows.
4-85
Designing Compensators
For more information about the Analysis Plots page, see Analysis Plots in "Using the SISO Design Tool and LTI Viewer." Selecting the plot for Closed-Loop r to y opens the associated LTI Viewer. Your LTI Viewer should look like the following figure.
4-86
The step response plot shows that the rise time is on the order of 2 seconds, which is much too slow given the system requirements. The following topics describe how to use frequency design techniques in the SISO Design Tool to design a compensator that meets the requirements specified in Design Specifications on page 4-83.
4-87
Designing Compensators
Changing the Compensator Gain in the Root Locus Plot with the Compensator Editor Page
Enter the compensator gain in the text box to the right of the equal sign as shown in the previous figure. The Graphical Tuning window automatically replots the graphs with the new gain. Experiment with different gains and view the closed-loop response in the associated LTI Viewer. Alternatively, you can change the gain by grabbing the red squares on the root locus plot in the Graphical Tuning window and moving them along the curve.
4-88
Closed-Loop Response
Change the gain to 20 by editing the text box next to the equal sign on the Compensator Editor page. Notice that the locations of the closed-loop poles on the root locus are recalculated for the new gain. This figure shows the associated closed-loop step response for the gain of 20.
In the LTI Viewers right-click menu, select Characteristics > Settling Time to show the settling for this response. This closed-loop response does not meet the desired settling time requirement (0.05 seconds or less) and exhibits unwanted ringing. Adding Poles and Zeros to the Compensator on page 4-90 shows how to design a compensator so that you meet the required specifications.
4-89
Designing Compensators
4-90
Adding a Complex Pair of Poles to the Compensator on the Compensator Editor Page
You can also add a complex pole pair directly on the root locus plot using the Graphical Tuning window. Right-click in the root locus plot and select Add Pole/Zero > Complex Pole. Click in the root locus plot region where you want to add one of the complex poles. Complex poles added in this manner are automatically added to the Dynamics table in the Compensator Editor page. After you have added the complex pair of poles, the LTI Viewer response plots change and both the root locus and Bode plots show the new poles. This figure shows the Graphical Tuning window with the new poles added. For clarity, you may want to zoom out further, as was done here.
4-91
Designing Compensators
4-92
You can also add complex zeros directly on the root locus plot using the Graphical Tuning window by right-clicking in the root locus plot, selecting Add Pole/Zero > Complex Zero, and then clicking in the root locus plot region where you want to add one of the zeros. Complex zeros added in this manner are automatically added to the Dynamics table on the Compensator Editor page. After you have added the complex zeros, the LTI Viewer response plots change and both the root locus and Bode plots show the new zeros.
4-93
Designing Compensators
4-94
If your step response is unstable, lower the gain by grabbing a red box in the right-side plane and moving it into the left-side plane. In this example, the resulting step response is stable, but it still doesnt meet the design criteria since the 2% settling time is greater than 0.05 second. As you can see, the compensator design process can involve some trial and error. You can try dragging the compensator poles, compensator zeros, or the closed-loop poles around the root locus until you meet the design criteria. Editing Compensator Pole and Zero Locations on page 4-95, shows you how to modify the placement of poles and zeros by specifying their numerical values on the Compensator Editor page. It also presents a solution that meets the design specifications for the servomechanism example.
4-95
Designing Compensators
precise numerical values, however, you should use the Compensator Editor page in the SISO Design Task node on the Control and Estimation Tools Manager to change the gain value and the pole and zero locations of your compensator, as shown.
Using the Compensator Editor Page to Add, Delete, and Move Compensator Poles and Zeros
You can use the Compensator Editor page to Add compensator poles and zeros. Delete compensator poles and zeros. Edit the compensator gain. Edit the locations of compensator poles and zeros.
4-96
parameters.
4-97
Designing Compensators
For this example, edit the poles to be at 110 140i and the zeros at 70 270i. Set the compensator gain to 23.3. Your Graphical Tuning window now looks like this.
Graphical Tuning Window with the Final Values for the Electrohydraulic Servomechanism Design Example
To see that this design meets the design requirements, look at the step response of the closed-loop system.
4-98
Closed-Loop Step Response for the Final Design of the Electrohydraulic Servomechanism Example
The step response looks good. The settling time is less than 0.05 second, and the overshoot is less than 5%. You have met the design specifications.
4-99
Designing Compensators
Applying damping ratio requirements to the root locus plot results in a pair of shaded rays at the desired slope, as this figure shows.
4-100
Try moving the complex pair of poles you added to the design so that they are on the 0.707 damping ratio line. You can experiment with different damping ratios to see the effect on the design. If you want to change the damping ratio, select Design Requirements > Edit from the right-click menu. This opens the Edit Design Requirements dialog box.
Specify the new damping ratio requirement in this dialog box. An alternate way to adjust a requirement is to left-click the requirement itself to select it. Two black squares appear on the requirement when it is selected. You can then drag it with your mouse anywhere in the plot region. If you want to add a different set of requirements, for example, a settling time requirement, again select Design Requirements > New from the right-click menu to open the New Requirements dialog box and choose Settling time from the pull-down menu. You can have multiple types of design requirements in one plot, or more than one instance of any type. The types of requirements available depend on which view you use for your design. See Design Requirements for a description of all the design requirement options available in the SISO Design Tool.
4-101
Designing Compensators
overshoot.
DC Motor Example
From SISO Example: The DC Motor on page 2-3, the transfer function of the DC motor is
Transfer function: 1.5 -----------------s^2 + 14 s + 40.02
4-102
This example uses the design criteria specified in Design Specifications on page 4-83: Rise time of less than 0.5 second Steady-state error of less than 5% Overshoot of less than 10% Gain margin greater than 20 dB Phase margin greater than 40 degrees
The SISO Design Task node on the Control and Estimation Tools Manager opens and the Graphical Tuning window with sys_dc opens.
4-103
Designing Compensators
page.
2 Select C from the compensator selection list. 3 In the text box to the right of the equal sign in the Compensator area,
4-104
In this example, the new gain is 112. You can also adjust the compensator gain in the Graphical Tuning window by moving the Nichols curve up and down with your mouse. To do this, place your mouse over the curve. The cursor turns into a hand. Left-click and move the curve up to increase the gain. When you adjust the gain in this manner, the compensator gain is automatically updated in the Compensator Editor page. Click the Analysis Plots tab to set the analysis plots. Select Plot Type
Step for Plot 1, and then select plot 1 for Closed-Loop r to y, as shown in
the following figure, to open a linked LTI Viewer with the closed-loop step response from reference signal r to output signal y.
4-105
Designing Compensators
4-106
The rise time is quite fast, about 0.15 second, but the overshoot is 18.4% and the steady-state is about 0.82.
Adding an Integrator
One approach to eliminating the steady-state error is to add an integrator. To add an integrator:
1 Click the Compensator Editor tab to open the Compensator Editor
page.
2 Right-click in the Dynamics table and select Add Pole/Zero >
4-107
Designing Compensators
You can also add an integrator by selecting Add Pole/Zero > Integrator from the right-click menu in the Graphical Tuning window. When you add the integrator in this manner, it is automatically added to the Dynamics table on the Compensator Editor page. Adding an integrator changes the gain margin from infinity to 10.5 dB. Since the gain and phase margins are now both finite, the Nichols plot shows a vertical line for the gain margin and a horizontal line for the phase margin. The linked LTI Viewer automatically updates to show the new response.
4-108
The steady-state value is now 1, which means the steady-state error has been eliminated, but the overshoot is 34% and the rise time is about 0.7 second. You must do more work to create a good design.
page.
2 Right-click in the Dynamics table and select Add Pole/Zero > Lead.
This figure shows the process of adding a lead network on the Compensator Editor page.
4-109
Designing Compensators
You can also add a lead network in the Graphical Tuning window. To add a lead network, select Add Pole/Zero > Lead from the right-click menu. Your cursor turns into a red x. Left-click along the Nichols curve to add the lead network. To move the lead network along the curve, left-click the pole or zero and drag. You can track the poles movement in the status bar at the bottom of the Graphical Tuning window. The status bar tells you the current location of the pole. Using the Compensator Editor page, move the lead network pole to -28 and the zero to -4.3 for this design. The zero should be almost on top of the right-most pole of the plant (the DC motor model). Adjust the compensator gain to 84. This gives the final design.
4-110
The gain and phase margins are 21.9 dB and 65.7 degrees, respectively. Inspect the closed-loop step response to see if the rise time and overshoot requirements are met.
4-111
Designing Compensators
As this figure shows, the rise time is 0.448 second, and the overshoot is a little over 3%. This satisfies the rest of the design requirements.
4-112
load ltiexamples
4-113
Designing Compensators
2 To open the SISO Design Tool and import the DC motor, type
sisotool(sys_dc)
at the MATLAB prompt. This opens both the SISO Design Task node on the Control and Estimation Tools Manager and the Graphical Tuning window with sys_dc loaded.
3 Click the Analysis Plots tab to set the analysis plots. Select the plot type
as Step for Plot 1. Then, check the box for plot 1 to the left of Closed-Loop r to y, as shown in the following figure, to open a linked LTI Viewer with the closed-loop step response from reference signal r to output signal y.
4 In the LTI Viewer that appears, use the right-click menu to add rise time
4-114
Note that by default, the compensator is 1 and unit negative feedback is used (see Architecture in the Control System Toolbox Users Guide). When a unit step is applied to the setpoint change, the steady state value of the system output is 0.0361, which is far from the setpoint, and its rise time is 0.589.
4-115
Designing Compensators
You can choose from the following controller types: P PI PID PID with derivative filter
1 (1 + s / N )
control (C = Kp).
4-116
application of PID automated tuning with P and the compensator value is now 205.49.
Note that the rise time is arrived at in just 0.0774 seconds, compared with 0.589 when C=1. However, the steady state value of 0.885 can still be improved by setting the automated tuning controller type to PI, as described in Designing a Proportional-Integral Controller on page 4-118.
4-117
Designing Compensators
control ( C = K p +
KI ). s
application of PID automated tuning with PI and the compensator value is now 487.64
(1 + 0.36 s) . s
Although the rise time has increased slightly (0.0876), the steady state value is 1. Applying automated tuning using PID tuning set to PI will guarantee zero offset.
4-118
4-119
Designing Compensators
The design goal for this example is the minimize the closed-loop step response settling time while maintaining an inner loop phase margin of at least 65 with maximum bandwidth. For details on how to derive state-space and transfer function representations of a DC motor, see SISO Example: The DC Motor on page 2-3. Designing a multi-loop compensator for a DC motor involves the following steps: Developing a Mathematical Model of the DC Motor on page 4-120 Selecting the Architecture and Importing the Model on page 4-122 Designing the Inner Loop on page 4-125 Tuning the Outer Loop on page 4-127 Validating the Design with the LTI Viewer for SISO Design on page 4-129
4-120
% Nms % kg.m^2/s^2
First, construct a state-space model of the DC motor with one input, the applied voltage (Va). The output is the angular rate w.
h1 = tf(Km,[L,R]); % Armature h2 = tf(1,[J, Kf]) % Equation of motion dcm = ss(h2) *h1; % w = h2 cascaded with h1 dcm = feedback(dcm, Kb, 1, 1);% Closes back emf loop
Adapting the Model to SISO Tool Architecture One possible choice for your architecture is this multi-loop configuration.
Comparing this architecture to the original Block Diagram of the Position-Controlled DC Motor on page 4-120, it is evident that the two do not match. Using block diagram algebra, you can manipulate the original figure into one that fits this architecture.
4-121
Designing Compensators
To create this representation, add an integrator to get , the angular displacement, and a pure differentiator in the inner loops return path. The channel from Va to w is dcm(1), making it the appropriate channel for adding the integrator.
G = dcm*tf(1,[1,0]) % Motor with integrator; output is theta. C2 = tf('s') % Differentiator
at the MATLAB prompt. Once the Controls & Estimation Tools Manager opens, click Control Architecture on the Architecture page. Select the multi-loop configuration with two compensators, C1 in the forward path and C2 in the inner feedback loop located in the lower-right corner.
Next, import the model parameters by clicking System Data on the Architecture tab. This opens the System Data dialog box. Set G to G from
4-122
the workspace. Assume a perfect sensor and set H to 1. C1 and C2 are the gains you will use to design a compensator. Set C1 to 1 and C2 to C2 from the workspace. Your System Data dialog box should look like this.
4-123
Designing Compensators
Click Show Design Plot to see the SISO Design Graphical editor.
4-124
dialog box.
2 From the pull-down menu, select Open-Loop Output of C2. 3 Click Highlight feedback loop. This opens a figure of the control
4-125
Designing Compensators
Notice how the C1 piece of the compensator and the outer loop are grayed out. This means that they will have no effect on the inner loop at this time. Next, turn to the SISO Design Graphical editor. Use the Bode plot for open loop 2 (the inner loop) and increase the gain to maximize bandwidth subject to a 65 phase margin. This turns out to be a gain of about 16.1 for C2.
4-126
4-127
Designing Compensators
Return to the SISO Design Graphical editor and increase the gain of C1 in the root locus plot. At a gain of about 90.2, you will see the complex pair of poles move toward a slower time constant as the third pole moves toward a faster one. You can view the trade-off in the LTI Viewer for SISO Design. As the gain is changed, the closed-loop step response changes. The 90.2 gain seems to yield a good compromise between rise and settling time.
4-128
Validating the Design with the LTI Viewer for SISO Design
Turning back to the LTI Viewer for SISO Design, it is evident that the settling time is now much lower than the original 78.9 s.
4-129
Designing Compensators
With a settling time of about 0.8 s, and a phase margin of 65 in the inner loop, the design is complete.
4-130
4-131
Designing Compensators
1 Choose a nominal model from the array of LTI models. 2 (Optional) Specify a frequency grid for multimodel computations. 3 Design a controller for the nominal model. 4 Analyze if the controller meets the design requirements for all models in
the array. If the controller design does not meet design requirements on all the models, specify a different nominal model and redesign the controller. For more information, see How to Analyze the Controller Design for Multiple Models on page 4-136.
4-132
Array of LTI Models Both G and H Note The sizes of both arrays must match.
Nominal Model By default, computed using the first element in both arrays. For a different index, computed using the specified index in both arrays.
The same index is also used when you import new arrays in the SISO Design Tool. If the specified index does not exist, the nominal model index reverts to a value you previously specified or the first element.
Only G or H
if G and H are arrays of LTI models of length 3 Nominal model index is 2 the software uses the second element in both the arrays to compute the nominal model:
4-133
Designing Compensators
Nominal Model r 2 y
2
The nominal response from r to y is:
T=
where Gnom = G2, Hnom = H2 and GnomHnom is the open-loop response. The software also computes and plots the responses showing the effect of C on the remaining pairs of plant and sensor combinationsG1H1 and G3H3. If only G is an array of LTI models, and the specified nominal model is 2, then the control architecture for nominal response is:
Nominal Model r 2 y
The software also computes and plots the responses showing the effect of C for the remaining pairs of plant indices and sensorG1H and G3H.
4-134
Represents an average of the multiple models. For example, the open-loop response of the model lies midway among the responses of all models in the array. Represents a worst-case plant. Lies closet to the stability point. You want to work with for control design. Tip You can plot and analyze the open-loop dynamics of the system on a Bode plot to determine which model to choose as nominal. If the controller design for the nominal model does not meet the design requirements on the remaining plants in the array, you can specify a different nominal model and redesign the controller. See How to Analyze the Controller Design for Multiple Models on page 4-136 for more information.
4-135
Designing Compensators
This happens because the grid is not sufficiently dense in a particular frequency range. For example, for an underdamped systems the model response shows sharp and tall peaks. Examine the analysis plots to verify if these dynamics are captured in the response. If the response does not capture these dynamics, specify a denser gridding. The grid computed automatically has more points in the response than you require. You are interested only in a specific frequency range in the response. Tip Specifying a less dense grid reduces the number of computations and is less expensive computationally. For more information, see How to Analyze the Controller Design for Multiple Models on page 4-136.
% Create an array of LTI models to model plant (G) variations. for ct = 1:length(k); G(:,:,ct) = tf(1,[m,b,k(ct)]);
4-136
end % Create an array of LTI models to model sensor (H) variations. for ct = 1:length(T); H(:,:,ct) = tf(1,[1/T(ct), 1]); end
In this case, G and H each contain 3 elements. Create an array of LTI models using the stack command. For example:
% m = 3, b = 0.5, k = 8:1:10. % Create an array of LTI models to model plant (G) variations. G1 = tf(1, [1 1 8]); G2 = tf(1, [1 1 9]); G3 = tf(1, [1 1 10]); % Create an array of LTI models G = stack(1, G1, G2, G3); % Create an array of LTI models to model sensor (H) variations. H1 = tf(1,[1/0.1, 1]); H2 = tf(1,[1/0.15, 1]); H3 = tf(1,[1/0.2, 1]); % Create array of LTI models. H=stack(1,H1,H2,H3);
(Requires Simulink Control Design software) Perform batch linearizations at multiple operating points. Then export the computed LTI models to create an array of LTI models. See the Reference Tracking of a DC Motor with Parameter Variations demo. (Requires Simulink Control Design and Robust Control Toolbox software) Specify a core Simulink block to linearize to an uncertain state-space (uss or ufrd) model. See Working with Models Containing Core Simulink or Custom Blocks. (Requires Robust Control Toolbox software) Compute uncertain state-space (uss) models from Simulink models. hen use usubs or usample to create an array of LTI models. See Working with Models Containing Uncertain State Space Blocks.
1 Open SISO Design Tool.
4-137
Designing Compensators
sisotool(G,1,H)
By default, the combination of the first plant and sensor in the arrays is the nominal model on which you perform the control design. For more information, see How Is a Nominal Model Computed? on page 4-132. The Graphical Tuning window, which opens with the SISO Design Tool, shows the individual responses of all models in the arrays.
4-138
Tip You can view the envelope of the Bode response instead by right-clicking the plot and selecting Multimodel Display > Bounds. See Using the Graphical Tuning Window on page 4-41 for more information. Alternatively, to view the responses of all models in the arrays:
4-139
Designing Compensators
Open an empty SISO Design Tool by typing sisotool and import G and H. See Importing Models into the SISO Design Tool on page 4-29 for more information. Configure SISO Design Tool using sisoinit with the arrays of LTI models and then open the SISO Design Tool.
2 Configure the analysis plots in the Analysis Plots tab in Control and
Estimation Tools Manager. By default, the plots show only the nominal response.
Right-click the plot, and select Multimodel Configuration > Bounds or Multimodel Configuration > Individual Responses to see the individual response or envelope of all models, respectively.
4-140
See Analysis Plots for Loop Responses on page 4-35 for more information.
3 (Optional) If you want to specify a different nominal plant, click
Multimodel Configuration in the Architecture tab. The Multimodel Configuration Dialog window opens.
4-141
Designing Compensators
Specify a different nominal model in Nominal Model Index field. If you specify an index value greater than the maximum index of the arrays, the field reverts back to a value you specified previously or 1. Tip You can keep the Multimodel Configuration Dialog window open as you are following the next steps.
4 (Optional) If the grid computed by Auto select is not dense enough to
For more information, see Frequency Grid for Multimodel Computations on page 4-135.
5 Design the controller for the nominal plant using graphical or automated
tuning.
4-142
For more information on designing a controller, see the following topics: Bode Diagram Design on page 4-54 Root Locus Design on page 4-80 Nichols Plot Design on page 4-102 Automated Tuning Design on page 4-113 As you design the controller, use the design and analysis plots analyze to analyze the controllers effects on the remaining models in the array.
6 (Optional) If the controller design for the nominal model does not meet the
The design and analysis plots update to show the updated nominal model. For example, for a nominal model value of 2, the plots appear as shown in the next figures.
4-143
Designing Compensators
4-144
4-145
Designing Compensators
Description Pole-zero map Evans root locus plot Continuous n , grid for root locus plots
4-146
Function
sisotool zgrid
Description Root Locus Design GUI Discrete n , grid for root locus plots
Pole Placement
The closed-loop pole locations have a direct impact on time response characteristics such as rise time, settling time, and transient oscillations. Root locus uses compensator gains to move closed-loop poles to achieve design specifications for SISO systems. You can, however, use state-space techniques to assign closed-loop poles. This design technique is known as pole placement, which differs from root locus in the following ways: Using pole placement techniques, you can design dynamic compensators. Pole placement techniques are applicable to MIMO systems. Pole placement requires a state-space model of the system (use ss to convert other model formats to state space). In continuous time, such models are of the form
x = Ax + Bu y = Cx + Du
where u is the vector of control inputs, x is the state vector, and y is the vector of measurements.
x = ( A BK ) x
and the closed-loop poles are the eigenvalues of A-BK. Using the place function, you can compute a gain matrix K that assigns these poles to any desired locations in the complex plane (provided that (A,B) is controllable).
4-147
Designing Compensators
For example, for state matrices A and B, and vector p that contains the desired locations of the closed loop poles,
K = place(A,B,p);
= A + Bu + L( y C Du)
The estimator poles are the eigenvalues of A-LC, which can be arbitrarily assigned by proper selection of the estimator gain matrix L, provided that (C, A) is observable. Generally, the estimator dynamics should be faster than the controller dynamics (eigenvalues of A-BK). Use the place function to calculate the L matrix
L = place(A',C',q).'
where A and C are the state and output matrices, and q is the vector containing the desired closed-loop poles for the observer. Replacing x by its estimate in u = Kx yields the dynamic output-feedback compensator
= [ A LC ( B LD) K ] + Ly u = K
Note that the resulting closed-loop dynamics are
4-148
x A BK e = 0
BK x , A LC e
e = x
Hence, you actually assign all closed-loop poles by independently placing the eigenvalues of A-BK and A-LC. Example. Given a continuous-time state-space model
sys_pp = ss(A,B,C,D)
with seven outputs and four inputs, suppose you have designed A state-feedback controller gain K using inputs 1, 2, and 4 of the plant as control inputs A state estimator with gain L using outputs 4, 7, and 1 of the plant as sensors Input 3 of the plant as an additional known input You can then connect the controller and estimator and form the dynamic compensator using this code:
controls = [1,2,4]; sensors = [4,7,1]; known = [3]; regulator = reg(sys_pp,K,L,sensors,known,controls)
4-149
Designing Compensators
Functions
acker estim place reg
Description SISO pole placement Form state estimator given estimator gain MIMO pole placement Form output-feedback compensator given state-feedback and estimator gains
The function acker is limited to SISO systems, and you should use it only for systems with a small number of states. The function place is a more general and numerically robust alternative to acker.
Caution
Pole placement can be badly conditioned if you choose unrealistic pole locations. In particular, you should avoid: Placing multiple poles at the same location. Moving poles that are weakly controllable or observable. This typically requires high gain, which in turn makes the entire closed-loop eigenstructure very sensitive to perturbation.
4-150
3 Form the LQG design by connecting the LQ-optimal gain and the Kalman
filter. For more information about using LQG design to create LQG regulators , see Linear-Quadratic-Gaussian (LQG) Design for Regulation on page 4-151. For more information about using LQG design to create LQG servo controllers, see Linear-Quadratic-Gaussian (LQG) Design of Servo Controller with Integral Action on page 4-156. These topics focus on the continuous-time case. For information about discrete-time LQG design, see the dlqr and kalman reference pages.
u Kalman Filter -K
Plant
LQG Regulator
The plant in this model experiences disturbances (process noise) w and is driven by controls u. The regulator relies on the noisy measurements y to generate these controls. The plant state and measurement equations take the form of
x = Ax + Bu + Gw y = Cx + Du + Hw + v
and both w and v are modeled as white noise.
4-151
Designing Compensators
Note LQG design requires a state-space model of the plant. You can use ss to convert other model formats to state space. To design LQG regulators, you can use the design techniques shown in the following table. To design an LQG regulator using... A quick, one-step design technique when the following is true: G is an identity matrix and H = 0. All known (deterministic) inputs are control inputs and all outputs are measured. Integrator states are weighted independently of states of plants and control inputs. The state estimator of the Kalman Use the following commands:
lqg
filter is based on x [ n| n 1] .
A more flexible, three-step design technique that allows you to specify: Arbitrary G and H. Known (deterministic) inputs that are not controls and/or outputs that are not measured. A flexible weighting scheme for integrator states, plant states, and controls. The state estimator of the Kalman
lqr, kalman, and lqgreg
For more information, see Constructing the Optimal State-Feedback Gain for Regulation on page 4-153 Constructing the Kalman State Estimator on page 4-153 Forming the LQG Regulator on page 4-155
4-152
Constructing the Optimal State-Feedback Gain for Regulation. You construct the LQ-optimal gain from the following elements: State-space system matrices Weighting matrices Q, R, and N, which define the tradeoff between regulation performance (how fast x(t) goes to zero) and control effort. To construct the optimal gain, type the following command:
K= lqr(A,B,Q,R,N)
This command computes the optimal gain matrix K, for which the state feedback law u = Kx minimizes the following quadratic cost function for continuous time:
J (u) =
0 { x
Qx + 2 xT Nu + uT Ru}dt
The software computes the gain matrix K by solving an algebraic Riccati equation. For information about constructing LQ-optimal gain, including the cost function that the software minimizes for discrete time, see the lqr reference page. Constructing the Kalman State Estimator. You need a Kalman state estimator for LQG regulation and servo control because you cannot implement optimal LQ-optimal state feedback without full state measurement.
You construct the state estimate x such that u = Kx remains optimal for the output-feedback problem. You construct the Kalman state estimator gain from the following elements:
State-space plant model sys Noise covariance data, Qn, Rn, and Nn The following figure shows the required dimensions for Qn, Rn, and Nn. If Nn is 0, you can omit it.
4-153
Designing Compensators
Note You construct the Kalman state estimator in the same way for both regulation and servo control. To construct the Kalman state estimator, type the following command:
[kest,L,P] = kalman(sys,Qn,Rn,Nn);
This command computes a Kalman state estimator, kest with the following plant equations:
x = Ax + Bu + Gw y = Cx + Du + Hw + v
where w and v are modeled as white noise. L is the Kalman gain and P the covariance matrix. The software generates this state estimate using the Kalman filter
d x = Ax + Bu + L( y Cx Du) dt
with inputs u (controls) and y (measurements). The noise covariance data
E(wwT ) = Qn ,
E(vvT ) = Rn ,
E(wvT ) = N n
4-154
The Kalman filter is an optimal estimator when dealing with Gaussian white noise. Specifically, it minimizes the asymptotic covariance
lim E ( x x ) ( x x )
)
x
For more information, see the kalman reference page. For a complete example of a Kalman filter implementation, see Kalman Filtering. Forming the LQG Regulator. To form the LQG regulator, connect the Kalman filter kest and LQ-optimal gain K by typing the following command:
regulator = lqgreg(kest, K);
This command forms the LQG regulator shown in the following figure.
u kest -K
LQG Regulator
d x = [ A LC ( B LD) K ]x + Ly dt u = Kx
For more information on forming LQG regulators, see the lqgreg reference page and LQG Regulation: Rolling Mill Example.
4-155
Designing Compensators
v y
kest
r y r-y -
-K
Plant
Integrator x i
LQG Servo Controller
The servo controller you design ensures that the output y tracks the reference command r while rejecting process disturbances w and measurement noise v. The plant in the previous figure is subject to disturbances w and is driven by controls u. The servo controller relies on the noisy measurements y to generate these controls. The plant state and measurement equations are of the form
x = Ax + Bu + Gw y = Cx + Du + Hw + v
and both w and v are modeled as white noise. Note LQG design requires a state-space model of the plant. You can use ss to convert other model formats to state space. To design LQG servo controllers, you can use the design techniques shown in the following table.
4-156
To design an LQG servo controller using... A quick, one-step design technique when the following is true: G is an identity matrix and H = 0. All known (deterministic) inputs are control inputs and all outputs are measured. Integrator states are weighted independently of states of plants and control inputs. The state estimator of the Kalman
filter is based on x [ n| n 1] .
A more flexible, three-step design technique that allows you to specify: Arbitrary G and H. Known (deterministic) inputs that are not controls and/or outputs that are not measured. A flexible weighting scheme for integrator states, plant states, and controls. The state estimator of the Kalman
lqi, kalman, and lqgtrack
For more information, see Constructing the Optimal State-Feedback Gain for Servo Control on page 4-157 Constructing the Kalman State Estimator on page 4-158 Forming the LQG Servo Control on page 4-160
Constructing the Optimal State-Feedback Gain for Servo Control. You construct the LQ-optimal gain from the State-space plant model sys Weighting matrices Q, R, and N, which define the tradeoff between tracker performance and control effort
4-157
Designing Compensators
This command computes the optimal gain matrix K, for which the state feedback law u = Kz = K[ x; xi ] minimizes the following quadratic cost function for continuous time:
J (u) =
0 {z
Qz + uT Ru + 2 zT Nu dt
The software computes the gain matrix K by solving an algebraic Riccati equation. For information about constructing LQ-optimal gain, including the cost function that the software minimizes for discrete time, see the lqi reference page. Constructing the Kalman State Estimator. You need a Kalman state estimator for LQG regulation and servo control because you cannot implement LQ-optimal state feedback without full state measurement.
You construct the state estimate x such that u = Kx remains optimal for the output-feedback problem. You construct the Kalman state estimator gain from the following elements:
State-space plant model sys Noise covariance data, Qn, Rn, and Nn The following figure shows the required dimensions for Qn, Rn, and Nn. If Nn is 0, you can omit it.
4-158
Note You construct the Kalman state estimator in the same way for both regulation and servo control. To construct the Kalman state estimator, type the following command:
[kest,L,P] = kalman(sys,Qn,Rn,Nn);
This command computes a Kalman state estimator, kest with the following plant equations:
x = Ax + Bu + Gw y = Cx + Du + Hw + v
where w and v are modeled as white noise. L is the Kalman gain and P the covariance matrix. The software generates this state estimate using the Kalman filter
d x = Ax + Bu + L( y Cx Du) dt
with inputs u (controls) and y (measurements). The noise covariance data
E(wwT ) = Qn ,
E(vvT ) = Rn ,
E(wvT ) = N n
4-159
Designing Compensators
The Kalman filter is an optimal estimator when dealing with Gaussian white noise. Specifically, it minimizes the asymptotic covariance
lim E ( x x ) ( x x )
)
x
For more information, see the kalman reference page. For a complete example of a Kalman filter implementation, see Kalman Filtering. Forming the LQG Servo Control. To form a two-degree-of-freedom LQG servo controller, connect the Kalman filter kest and LQ-optimal gain K by typing the following command:
servocontroller = lqgtrack(kest, K);
This command forms the LQG servo controller shown in the following figure.
kest
r y r-y -
-K
Integrator x i
LQG Servo Controller
4-160
x A BK x LC + LDK x = 0 xi x u = [ K x Ki ] xi
BK i + LDK i x 0 L r x + I I y 0 i
For more information on forming LQG servo controllers, including how to form a one-degree-of-freedom LQG servo controller, see the lqgtrack reference page.
w
10 s+10
Plant
The goal is to regulate the plant output y around zero. The input disturbance d is low frequency with power spectral density (PSD) concentrated below 10 rad/s. For LQG design purposes, it is modeled as white noise driving a lowpass filter with a cutoff at 10 rad/s, shown in the following figure.
w (white noise)
10 s+10
d (colored noise)
For simplicity, this noise is modeled as Gaussian white noise with variance of 1. The following figure shows the Bode magnitude of the shaping filter.
4-161
Designing Compensators
E(n2 ) = 0.01
Use the cost function
J (u) =
0 (10 y
+ u2 ) dt
to specify the tradeoff between regulation performance and cost of control. The following equations represent an open-loop state-space model:
x = Ax + Bu + Bd y = Cx + n
4-162
The following commands design the optimal LQG regulator F(s) for this problem:
sys = ss(tf(100,[1 1 100])) % State-space plant model % Design LQ-optimal gain K K = lqry(sys,10,1) % u = -Kx minimizes J(u) % Separate control input u and disturbance input d P = sys(:,[1 1]); % input [u;d], output y % Design Kalman state estimator Kest. Kest = kalman(P,1,0.01) % Form LQG regulator = LQ gain + Kalman filter. F = lqgreg(Kest,K)
These commands returns a state-space model F of the LQG regulator F(s). The lqry, kalman, and lqgreg functions perform discrete-time LQG design when you apply them to discrete plants. To validate the design, close the loop with feedback, create and add the lowpass filter in series with the closed-loop system, and compare the openand closed-loop impulse responses by using the impulse function.
% Close loop clsys = feedback(sys,F,+1) % Note positive feedback. % Create the lowpass filter and add it in series with clsys. s = tf('s'); lpf= 10/(s+10) ; clsys_fin = lpf*clsys; % Open- vs. closed-loop impulse responses impulse(sys,'r--',clsys_fin,'b-')
These commands produce the following figure, which compares the open- and closed-loop impulse responses for this example.
4-163
Designing Compensators
w r y
v y
trksys
LQG Servo Controller
Plant
4-164
The plant has two states (x), two control inputs (u), two random inputs (w), one output (y), measurement noise for the output (v), and the following state and measurement equations:
x = Ax + Bu + Gw y = Cx + Du + Hw + v
where
0 1 0 A = 0 0 1 1 0 0 C = [1.9 1.3 1]
J (u) =
0 0.1x
1 0 2 x + xi + uT u dt 0 2
Command Window:
A B G C D = = = = = [0 1 0;0 0 1;1 0 0]; [0.3 1;0 1;-0.3 0.9]; [-0.7 1.12; -1.17 1; .14 1.5]; [1.9 1.3 1]; [0.53 -0.61];
4-165
Designing Compensators
4-166
c = u1 u2 d = u1 u2 r1 0 0 y1 0 0 x1_e -0.5388 -1.492 x2_e -0.4173 -1.388 x3_e -0.2481 -1.131 xi1 0.5578 0.5869
Channels 1 2
Channels 1,2
Continuous-time model.
4-167
Designing Compensators
Key features of this diagram to note are the following: The Linearized Dynamics block contains the linearized airframe. sf_aerodyn is an S-Function block that contains the nonlinear equations for ( , ) = (0, 15 ) . The error signal between and the ref is passed through an integrator. This aids in driving the error to zero.
x = Ax + Bu
where
x = [u, v, w, p, q, r, , ]T
4-168
The variables u, v, and w are the three velocities with respect to the body frame, shown as follows.
The variables and are roll and pitch, and p, q, and r are the roll, pitch, and yaw rates, respectively. The airframe dynamics are nonlinear. The following equation shows the nonlinear components added to the state space equation.
g sin g cos sin g cos cos 0 x = Ax + Bu + 0 0 q cos r sin (q sin + r cos ) tan
Nonlinear Component of the State-Space Equation
4-169
Designing Compensators
Trimming
For LQG design purposes, the nonlinear dynamics are trimmed at = 15 and p, q, r, and set to zero. Since u, v, and w do not enter into the nonlinear term in the preceding figure, this amounts to linearizing around ( , ) = (0, 15 ) with all remaining states set to zero. The resulting state matrix of the linearized model is called A15.
Problem Definition
The goal to perform a steady coordinated turn, as shown in this figure.
To achieve this goal, you must design a controller that commands a steady turn by going through a 60 roll. In addition, assume that , the pitch angle, is required to stay as close to zero as possible.
Results
To calculate the LQG gain matrix, K, type
lqrdes
at the MATLAB prompt. Then, start the lqrpilot model with the nonlinear model, sf_aerodyn, selected. This figure shows the response of to the 60 step command.
4-170
As you can see, the system tracks the commanded 60 roll in about 60 seconds. Another goal was to keep , the pitch angle, relatively small. This figure shows how well the LQG controller did.
4-171
Designing Compensators
Try adjusting the Q and R matrices in lqrdes.m and inspecting the control inputs and the system states, making sure to rerun lqrdes to update the LQG gain matrix K. Through trial and error, you may improve the response time of this design. Also, compare the linear and nonlinear designs to see the effects of the nonlinearities on the system performance.
4-172
Index
A
Index
B
building models MIMO 2-13 SISO 2-6
regulators 4-155 root locus 4-146 state estimator 4-148 state estimator, Kalman 4-153
E
estimator gain 4-148 Kalman 4-153 exporting compensators and models 4-48
C
cell array 2-16 changing units on a plot 4-46 comparing models in plots 3-44 compensator design multi-loop 4-119 compensators editing in SISO Design Tool 4-95 exporting 4-48 feedback (state estimator design) 4-148 concatenation model 2-16 control design analysis of multiple models 4-131 Control System Toolbox product related products 1-4 covariance noise 4-154 4-159
F
final time. See also time response 3-40 frequency response 3-41 customizing plots 3-47 plotting 3-44 functions time and frequency response 3-37
G
gain estimator, Kalman 4-154 4-159 selection 4-81 state-feedback 4-153 Graphical Tuning window 4-25 changing units on a plot 4-46 display 4-42 right-click menus 4-47 using 4-41
D
data markers 3-42 denominator specification 2-16 design Kalman estimator 4-153 LQG Tracker, example of 4-167 LQG, description 4-150 pole placement 4-147
I
input vector 2-2
K
Kalman estimator continuous 4-153
Index-1
Index
gain 4-154 4-159 steady-state 4-153 Kalman filter. See Kalman estimator
L
linear models comparing multiple models in plots 3-44 exporting 4-48 frequency response. 3-41 model order reduction 2-29 time response 3-37 LQG (linear quadratic Gaussian) method continuous LQ regulator 4-153 design. See design, LQG gain, optimal state-feedback 4-153 Kalman state estimator 4-153 LQ-optimal gain 4-153 regulator, designing 4-163 regulator, forming 4-155 weighting matrices 4-153 4-158 LTI Viewer adding plot types 3-16 changing models 3-20 changing plot types 3-14 command line initializing 3-18 comparing multiple models 3-17 importing models 3-9 introduction to 3-8 models, importing 3-9 opening 3-9 plot options rise time 3-11 settling time 3-19 right-click menus 3-10 SISO Design Task 4-25
MIMO 3-40 model order reduction 2-29 models building 2-13 multi-loop design 4-119
N
noise covariance 4-154 4-159 white 3-38 notch filter parameters 4-73 numerator specification 2-16
O
operations on LTI models concatenation 2-16 output vector 2-2 overshoot 3-37
P
plotting changing units 4-46 customizing plots 3-47 multiple systems 3-44 right-click menus 3-41 time responses 3-37 pole placement 4-147 conditioning 4-150
R
reduced-order models 2-29 regulation 4-151 4-162 performance 4-153 Riccati equation 4-153 right-click menus
M
markers, data 3-42
Index-2
Index
LTI Viewer 3-10 plot responses 3-41 rise time 3-37 root locus compensator gain 4-87 designing 4-146 root locus design 4-80 functions for 4-146
S
Servo controller with integral action 4-156 Set point tracking 4-156 settling time 3-37 SISO Design Task in the Control and Estimation Tools Manager 4-25 SISO Design Task pane 4-25 Analysis Plots page 4-35 Automated Tuning page 4-115 Design History page 4-51 using 4-28 SISO Design Tool 4-25 adding a lead network 4-62 adding a lead network to a Nichols plot 4-109 adding a notch filter 4-70 adding an integrator 4-58 adding an integrator to the Nichols plot 4-107 adding poles and zeros 4-90 adjusting compensator gain in a Nichols plot 4-104 adjusting the compensator gain in Bode design 4-55 applying automated PID tuning 4-115 automated tuning design 4-113 Bode Diagram Design 4-54 changing the compensator gain, Bode magnitude 4-55 changing the compensator gain, root locus 4-87
compensators, editing 4-95 editing preferences 4-46 exporting compensator and models 4-48 feedback structures 4-33 importing models into 4-29 loop responses 4-35 Nichols plot design 4-102 opening 4-26 opening a Nichols plot 4-103 root locus design 4-80 storing and retrieving designs 4-50 Using the Graphical Tuning window 4-41 SISO Tool Preferences Editor 4-46 state estimator 4-148 vector 2-2 state estimator design regulators/compensators 4-148 state-space models 2-2 steady state error 3-37
T
time response customizing plots 3-47 final time 3-40 functions 3-37 MIMO 3-40 plotting 3-44 time range 3-40 to white noise 3-38 vector of time samples 3-41 transfer functions MIMO 2-15 transfer functions (TF) 2-2
U
units changing on a plot 4-46
Index-3
Index
W
white noise 3-38 See also noise
Z
zero-pole-gain (ZPK) models 2-3
Index-4