%% Robust Tuning of Fixed-Structure Controller
% Tune a fixed-structure controller for the control system in Unstructured Robust Controller Synthesis, which shows how to use musyn to design an unstructured full-order centralized controller, and returns a controller of order 11. For this example, use the same control structure, as shown in the diagram, but restrict the structure of K to a fifth-order state-space model.
%
% First, construct the same plant P as in Unstructured Robust Controller Synthesis. The plant is an uncertain plant G augmented by a sensitivity-weighting function Wp.

G0 = tf(1,[1 -1]);
Wu = 0.25*tf([1/2 1],[1/32 1]); 
InputUnc = ultidyn('InputUnc',[1 1]);
G = G0*(1+InputUnc*Wu);
G.InputName = 'u';
G.OutputName = 'y1';

Wp = makeweight(100,[1 0.5],0.25);
Wp.InputName = 'y';
Wp.OutputName = 'e';

SumD = sumblk('y = y1 + d');
inputs = {'d','u'};
outputs = {'e','y'};
P = connect(G,Wp,SumD,inputs,outputs);

%
% Create a tunableSS control design block to represent the fixed controller structure, a fifth-order state-space model.

C0 = tunableSS('K',5,1,1);

%
% Form the closed-loop system, which is a generalized state-space (genss) model that has both a tunable block and a uncertain block.

CL0 = lft(P,C0)

%
% Use musyn to tune the free entries of the controller.

[CL,CLperf,info] = musyn(CL0);

% Even when you specify the structure of K as a fifth-order state-space model, musyn can find tuned parameter values that yield very similar robust performance to the 11th-order controller. You can try still lower controller orders to see whether the robust stability is preserved.
%
% Copyright 2019 The MathWorks, Inc.