%% Specify Different Loop Shapes for Multiple Loops
% Create separate loop shape requirements for the inner and outer loops of the following control system.
%
% For the inner loop, specify a loop shape with integral action, gain crossover at 1, and a roll-off requirement of 40 dB/decade. Additionally, specify that this loop shape requirement should be enforced with the outer loop open.

LS2 = frd([100 1 0.0001],[0.01 1 100]);
Req2 = TuningGoal.LoopShape('X2',LS2);
Req2.Openings = 'X1';

%
% Specifying 'X2' for the location indicates that Req2 applies to the point-to point, open-loop transfer function at the location X2. Setting Req2.Openings indicates that the loop is opened at the analysis point X1 when Req2 is enforced.
% By default, Req2 imposes a stability requirement on the inner loop as well as the loop shape requirement. In some control systems, however, inner-loop stability might not be required, or might be impossible to achieve. In that case, remove the stability requirement from Req2 as follows.

Req2.Stabilize = false;

%
% For the outer loop, specify a loop shape with integral action, gain crossover at 0.1, and a roll-off requirement of 20 dB/decade.

LS1 = frd([10 1 0.01],[0.01 0.1 10]);
Req1 = TuningGoal.LoopShape('X1',LS1);

% Specifying 'X1' for the location indicates that Req1 applies to the point-to point, open-loop transfer function at the location X1. You do not have to set Req1.Openings because this loop shape is enforced with the inner loop closed.
% You might want to tune the control system with both loop shaping requirements Req1 and Req2. To do so, use both requirements as inputs to the tuning command. For example, suppose CL0 is a tunable genss model of the closed-loop control system. In that case, use [CL,fSoft] = systune(CL0,[Req1,Req2]) to tune the control system to both requirements.
% Copyright 2012 The MathWorks, Inc.