www.gusucode.com > slcontrol 案例源码程序 matlab代码 > slcontrol/TuneControlSystemtoSoftConstraintsExample.m
%% Tune Control System to Soft Constraints % Tune the control system in the |rct_airframe2| model to soft goals for % tracking, roll off, stability margin, and disturbance rejection. %% % Open the Simulink moel. mdl = 'rct_airframe2'; open_system(mdl); %% % Create and configure an |slTuner| interface to the model. st0 = slTuner(mdl,'MIMO Controller'); %% % |st0| is an |slTuner| interface to the |rct_aircraft2| model with the % |MIMO Controller| block specified as the tunable portion of the control % system. %% % The model already has linearization input points on the signals |az ref|, % |delta fin|, |az|, |q|, and |e|. These signals are therefore available % as analysis points for tuning goals and linearization. %% % Specify the tracking requirement, roll-off requirement, stability margins, % and disturbance rejection requirement. req1 = TuningGoal.Tracking('az ref','az',1); req2 = TuningGoal.Gain('delta fin','delta fin',tf(25,[1 0])); req3 = TuningGoal.Margins('delta fin',7,45); max_gain = frd([2 200 200],[0.02 2 200]); req4 = TuningGoal.Gain('delta fin','az',max_gain); %% % |req1| constrains |az| to track |az ref|. The next requirement, |req2|, % imposes a roll-off requirement by specifying a gain profile for the open-loop, % point-to-point transfer function measured at |delta fin|. The next requirement, % |req3|, imposes open-loop gain and phase margins on that same point-to-point % transfer function. Finally, |req4| rejects disturbances to |az| injected % at |delta fin|, by specifying a maximum gain profile between those two % points. %% % Tune the model using these tuning goals. opt = systuneOptions('RandomStart',3); rng(0); [st,fSoft,~,info] = systune(st0,[req1,req2,req3,req4],opt); %% % |st| is a tuned version of |st0|. %% % The |RandomStart| option specifies that |systune| must perform three independent % optimization runs that use different (random) initial values of the tunable % parameters. These three runs are in addition to the default optimization % run that uses the current value of the tunable parameters as the initial % value. The call to |rng| seeds the random number generator to produce % a repeatable sequence of numbers. %% % |systune| displays the final result for each run. The displayed value, % |Soft|, is the maximum of the values achieved for each of the four performance % goals. The software chooses the best run overall, which is the run yielding % the lowest value of |Soft|. The last run fails to achieve closed-loop % stability, which corresponds to |Soft = Inf|. %% % Examine the best achieved values of the soft constraints. fSoft %% % Only |req3|, the stability margin requirement, is met for all frequencies. % The other values are close to, but exceed, 1, indicating violations of % the goals for at least some frequencies. %% % Use |viewSpec| to visualize the tuned control system performance against % the goals and to determine whether the violations are acceptable. To evaluate % specific open-loop or closed-loop transfer functions for the tuned parameter % values, you can use linearization commands such as |getIOTransfer| and % |getLoopTransfer|. After validating the tuned parameter values, if you % want to apply these values to the Simulink(R) model, you can use |writeBlockValue|.