主要内容

Usingfminimaxwith a Simulink Model

This example shows how to tune the parameters of a Simulink® model. The model,optsim,包括最佳/演示folder of your MATLAB® installation. The model includes a nonlinear process plant modeled as a Simulink block diagram.

致电饱和的植物

植物是一个机智欠阻尼三阶模型h actuator limits. The actuator limits are a saturation limit and a slew rate limit. The actuator saturation limit cuts off input values greater than 2 units or less than –2 units. The slew rate limit of the actuator is 0.8 units/sec. The closed-loop response of the system to a step input is shown inClosed-Loop Response。您可以通过打开模型来看到此响应(类型optsimat the command line or click the model name), and selectingRun来自模拟菜单。响应图绘制了范围。

Closed-Loop Response

The problem is to design a feedback control loop that tracks a unit step input to the system. The closed-loop plant is entered in terms of the blocks where the plant and actuator are located in a hierarchical Subsystem block. A Scope block displays output trajectories during the design process.

Closed-Loop Model

要优化该系统,请随时最大程度地减少输出的最大值 t 在0到100之间。(相反,示例具有Simulink模型的LSQN金宝appONLIN, the solution involves minimizing the error between the output and the input signal.)

The code for this example is contained in the helper functionruntrackmmat the本示例的结尾。The objective function is simply the outputyoutreturned by thesimcommand. But minimizing the maximum output at all time steps might force the output to be far below unity for some time steps. To keep the output above 0.95 after the first 20 seconds, the constraint functiontrackmmcon包含约束yout >= 0.95t = 20tot = 100。Because constraints must be in the form g 0 , the constraint in the function isg = -yout(20:100) + 0.95

两个都trackmmobjtrackmmconuse the result yout fromsim, calculated from the current PID values. To avoid calling the simulation twice,runtrackmm具有嵌套功能,以便yout在目标和约束功能之间共享。仅当当前点发生变化时,才调用模拟。

Callruntrackmm

[Kp,Ki,Kd] = runtrackmm
Objective Max Line search Directional Iter F-count value constraint steplength derivative Procedure 0 5 0 1.11982 1 11 1.184 0.07978 1 0.482 2 17 1.012 0.04285 1 -0.236 3 23 0.9996 0.00397 1 -0.0195 Hessian modified twice 4 29 0.9996 3.464e-05 1 0.000687 Hessian modified
5 35 0.9996 2.274e-09 1 -0.0175 Hessian modified twice Local minimum possible. Constraints satisfied. fminimax stopped because the predicted change in the objective function is less than the value of the function tolerance and constraints are satisfied to within the value of the constraint tolerance.
Kp = 0.5894
Ki = 0.0605
Kd = 5.5295

The last value in theObjective valuecolumn of the output shows that the maximum value for all the time steps is just under 1. The closed-loop response with this result is shown in the figure使用Fminimax的闭环响应

该溶液与在具有Simulink模型的LSQN金宝appONLINbecause you are solving different problem formulations.

Closed-Loop Response Usingfminimax

Helper Function

The following code creates theruntrackmmhelper function.

功能[KP,KI,KD] = Runtrackmm Optsim% initialize Simulink(R)pid0 = [0.63 0.0504 1.9688];%a1,a2,yout与trackmmobj和trackmmcon共享A1 = 3;A2 = 43;% Initialize plant variables in modelyout = [];% Give yout an initial valuepold = [];%跟踪最后一个pidopt = simset('solver','ode5','SrcWorkspace','当前的'); options = optimset('展示','iter',。。。'TolX',0.001,'TolFun',0.001); pid = fminimax(@trackmmobj,pid0,[],[],[],[],[],[],。。。@trackmmcon,options); Kp = pid(1); Ki = pid(2); Kd = pid(3);功能F = trackmmobj(pid)% Track the output of optsim to a signal of 1.%变量A1和A2与RunTrackMM共享。% Variable yout is shared with RUNTRACKMM and% RUNTRACKMMCON.更新(PID)F = yout;end功能[c,ceq] = trackmmcon(pid)% Track the output of optsim to a signal of 1.% Variable yout is shared with RUNTRACKMM and%trackmmobjupdateifneedeed(pid)c = -yout(20:100)+。95;ceq = [];end功能updateIfNeeded(pid)如果~isequal(pid,pold)% compute only if neededKp = pid(1); Ki = pid(2); Kd = pid(3); [~,~,yout] = sim('optsim',[0 100],选择);pold = pid;endendend

See Also

相关话题