www.gusucode.com > control_featured 案例源码程序 matlab代码 > control_featured/OpenLoopSpecExample.m

    %% Loop Shape and Stability Margin Specifications
% This example shows how to specify loop shapes and stability margins
% when tuning control systems with |systune| or |looptune|.

% Copyright 1986-2012 The MathWorks, Inc.

%% Background
% The |systune| and |looptune| commands tune the parameters of
% fixed-structure control systems subject to a variety of time- and 
% frequency-domain requirements. The |TuningGoal| package is the repository
% for such design requirements.

%% Loop Shape
% The |TuningGoal.LoopShape| requirement is used to shape the open-loop response
% gain(s), a design approach known as _loop shaping_. For example,

s = tf('s');
R1 = TuningGoal.LoopShape('u',1/s);

%%
% specifies that the open-loop response measured at the location "u" should 
% look like a pure integrator (as far as its gain is concerned). In MATLAB,
% use an |AnalysisPoint| block to mark the location "u", see the 
% _"Building Tunable Models"_ example for details. In Simulink, use the 
% |addPoint| method of the |slTuner| interface to mark "u"
% as a point of interest.

%%
% As with other gain specifications,
% you can just specify the asymptotes of the desired loop shape using a few
% frequency points. For example, to specify a loop shape with gain crossover at 
% 1 rad/s, -20 dB/decade slope before 1 rad/s, and -40 dB/decade slope after 
% 1 rad/s, just specify that the gain at the frequencies 0.1,1,10 should be 
% 10,1,0.01, respectively.

LS = frd([10,1,0.01],[0.1,1,10]);
R2 = TuningGoal.LoopShape('u',LS);

bodemag(LS,R2.LoopGain)
legend('Specified','Interpolated')

%%
% Loop shape requirements are constraints on the open-loop response $L$.
% For tuning purposes, they are converted into closed-loop gain constraints on the sensitivity
% function $S = 1/(1+L)$ and complementary sensitivity function $T = L/(1+L)$.
% Use |viewSpec| to visualize the target loop shape and corresponding
% gain bounds on $S$ (green) and $T$ (red).

viewSpec(R2)

%% Minimum and Maximum Loop Gain
% Instead of |TuningGoal.LoopShape|, you can use |TuningGoal.MinLoopGain| and
% |TuningGoal.MaxLoopGain| to specify minimum or maximum values for the loop gain
% in a particular frequency band. This is useful when the actual loop 
% shape near crossover is best left to the tuning algorithm to figure out. 
% For example, the following requirements specify the minimum loop gain inside
% the bandwidth and the roll-off characteristics outside the bandwidth, but do
% not specify the actual crossover frequency nor the loop shape near crossover.

MinLG = TuningGoal.MinLoopGain('u',5/s);  % integral action
MinLG.Focus = [0 0.2];

MaxLG = TuningGoal.MaxLoopGain('u',1/s^2);  % -40dB/decade roll off
MaxLG.Focus = [1 Inf];

viewSpec([MinLG MaxLG])

%%
% The |TuningGoal.MaxLoopGain| requirement rests on the fact that the
% open- and closed-loop gains are comparable when the loop gain
% is small ($|L| \ll 1$). As a result, it can be ineffective at keeping 
% the loop gain below some value close to 1. For example, suppose that 
% flexible modes cause gain spikes beyond the crossover frequency and 
% that you need to keep these spikes below 0.5 (-6 dB).
% Instead of using |TuningGoal.MaxLoopGain|, you can directly constrain 
% the gain of $L$ using |TuningGoal.Gain| with a loop opening at "u".

MaxLG = TuningGoal.Gain('u','u',0.5);
MaxLG.Opening = 'u';

%%
% If the open-loop response is unstable, make sure to further disable the implicit 
% stability constraint associated with this requirement.

MaxLG.Stabilize = false;

%%
% Figure 1 shows this requirement evaluated for an open-loop response 
% with flexible modes.
%
% <<../tuningreq2.png>>
%
% *Figure 1: Gain constraint on |L|.*


%% Stability Margins
% The |TuningGoal.Margins| requirement enforces minimum amounts of gain and phase
% margins at the specified loop opening site(s). For MIMO feedback loops, 
% this requirement uses the notion of _disk margins_, which guarantee stability
% for concurrent gain and phase variations of the specified amount in all feedback
% channels (see |loopmargin| for details). For example,

R = TuningGoal.Margins('u',6,45);

%%
% enforces $\pm 6$ dB of gain margin and 45 degrees of phase margin at the location "u".
% In MATLAB, use a |AnalysisPoint| block to mark the location "u", see the 
% _"Building Tunable Models"_ example for details. In Simulink, use the 
% |addPoint| method of the |slTuner| interface to mark "u"
% as a point of interest. Stability margins are typically measured at the plant
% inputs or plant outputs or both. 
%
% The target gain and phase margin values are converted
% into a normalized gain constraint on some appropriate closed-loop transfer function.
% The desired margins are achieved at frequencies where the gain is less than 1.

viewSpec(R)