收稿日期:2003-06-03作者简介:刘晓谦(1971)),男,山西翼城人,讲师,从事热工自动化教学与研究工作1S-FunctionPID刘晓谦,王勇,穆顺勇(,710054):介绍了Matlab的S-Function的运行原理功能和实现方法;简要说明了基于S-Function的非线性PID控制器的方案,对于非线性PID控制器参数优化问题,提出了一种先进方法,即采用MATLAB优化工具箱来优化PID控制器参数;介绍了工具箱的主要特点,并给出了在约束条件下的优化算法:S-函数;单纯形法;目标函数;优化;非线性PID控制器:TP13:A:1008-6862(2004)01-0004-(04)Matlab,,,Matlab,,Matlab,,Matlab,MatlabMatlabS-FunctionPID,1S-FunctionMatlab,,SIMULINKSIMULINK,,S-,S-SS-,[1]111S-FunctionS-SIMULINKS-:;M;MEX:,,;MatlabM,,;MEX,SIMULINKS-,SIMULINKM;;,:,,112S-Function[2][3]S:Function[sys,x0]=(t,x,u,flag)t,x,u;flag;flag=0,;flag=1,dx/dt;flag=2,x(n+1);flag=3,y;flag=4,;flag=0,x0,sys:sys(1),;sys(2),;sys(3),;sys(4),;17120043江西电力职业技术学院学报JournalofJiangxiElectricVocationalandTechnicalCollegeVol.17,No.1Mar.2004sys(5),;sys(6),(,1)Simulink,,S-Function,SIMULINKS-Function,S-Functionsys113S-Function[3]SimulinkMS-Function,,()sfuntmp1.m,matlab/toolbox/simulink/blocks/S-Function,,,(2KI),(2KPKI)function[sys,x0,str,ts]=KI(t,x,u,flag,Ki1,Ki2)switchflag,case0,%[sys,x0,str,ts]=md1InitializeSizes;case3,%sys=md1Outputs(t,x,u,Ki1,Ki2);case{1,2,4,9},%flagsys=[];otherwise%error([cUnhandledflag=c,num2str(flag)]);endfunction[sys,x0,str,ts]=mdlInitializeSizessizes=simsizes;%,7sizes.NumContStates=0;%syssizes.NumDiscStates=0;%,:sizes.NumOutputs=-1;%sys=[0,0,-1,-1,1,1]sizes.NumInputs=-1;sizes.DirFeedthrough=1;sizes.NumSampleTimes=1;sys=simsizes(sizes);x0=[];%str=[];%,ts=[-1,0];%functionsys=md1Outputs(t,x,u,Ki1,Ki2)%sys=Ki1+Ki2*exp(-100*u*u)%%(ki1+ki2exp(-100e2))2PIDPID,,,,PID,,,[4]PID(PIDControllerwithVariableArguments,VAPID)PID,,VAPID1:1VAPID1:kp=kp0(1+Kp1(1-exp(-100e2)))ki=ki0(Ki1+Ki2(exp(-100e2)))kd=kd0(1+Kd1(exp(-25e2))):kp0,ki0,kd0PID(Z-N);Kp1Ki1Ki2Kd1;e,Kp1Ki1Ki2Kd1[4],Kp1,Kp11Kp1,,;Ki1,Ki2Ki101,Ki1=0Ki2\1,Ki1=0,Ki2,;Kd1,Kd11Kp1Ki1Ki2Kd151,,:S-FunctionPID3311[6]:n(n+1),(n+1),(),,,,,(),,,,()Kp1Ki1Ki2Kd1,,2:22,(),x0x1x2x3(J=Qt|e(t)|dt)J0J1J2J3,(J3),x3(xh),xhxr,xrJr,Jr\{J0,J1,J2},xh,xrxh,,xhxrxs,J0J1J2,,xhxrxe,xeJeJr,xe,x0x1x2,,E,,,312ITAE,,(I-TAE),J=ITAE=Qt|e(t)|dtyhmb_2.m[7]:functionss=yhmb_2(x)globa1Kp1;globa1Ki1;globa1Ki2;globa1Kd1;globa1i;Kp1=x(1);Ki1=x(2);Ki2=x(3);Kd1=x(4);i=i+1[Kp1Ki1Ki2Kd1][tt,xx,yy]=sim(-nonlinerpid.,1000,[]);%nonlinerpidyylong=length(yy);ss=yy(yylong);313zcx_2.m[7]globa1Kp1;globa1Ki1;globa1Ki2;globa1Kd1;globa1i;i=1;x0=[0.010.72.53];result=fminsearch(-yhmb_2.,x0)x0Kp1Ki1Ki2Kd14411,,,,:W(s)=k/(Ts+1)n:[5]:W01=8/(1+15s)2:W02=1.125/(1+25s)3412SIMULINKMatlab6.5simulink(nonliner-pid.m)3:3,,S-Function4:zcx_2.m:Kp1=0.011215,Ki1=0.41463,Ki2=2.635,Kd1=3.4963413PIDPID,,6173SIMULINK4S-FunctionPID(kp=3.3333,ki=0.0740,kd=37.6666)[5]PID(kp0=313333,ki0=010740,kd0=3716666,Kp1=01011215,Ki1=0141463,Ki2=21635,Kd1=314963),Matlab,500,5[5]5PIDPID55:PID,PIDPID,,kp0ki0kd0PID(PID),Kp1Ki1Ki2Kd1,,MatlabS-Function,:[1]徐静波,邬晓斌1智能控制系统的S-函数仿真[J]1上海工程技术大学学报11999,13(3):163~1691[2]林瑞全,邱公伟1基于S函数的神经元PID控制SIMULINK仿真模型[J]1中国仪器仪表,2001,(2):4~51[3]周英玉,丁淑华,郭晨1利用Matlab的S-Func-tion实现非线性PID控制[J]1自动化与仪器仪表,2001,(2):24~261[4]钟庆昌,谢剑英,李辉1变参数PID控制器[J]1信息与控制,1999,28(4):273~2771[5]吕剑虹,陈来九1模糊控制器及在汽温控制系统中的应用研究[J]1中国电机工程学报,1995,15(1):16~221[6]杨承志1参数寻优智能PID控制[J]1昆明理工大学学报,1998,23(5):95~991[7]李华1基于MATLAB环境下控制系统参数的优化设计[J]1电气传动自动化,2002,24(2):29~301[]TheDesignandOptimizationofNonlinearPIDControllerParametersBasedonS-FunctionLIUXiao-qian,WANGYong,MUShun-yong(XIBEIElectricPowerUniversityforStaff,Xibei710054,China)Abstract:Thepaperintroducestheworkingprinciple,thefunctionandtherealizationwayofMatlab.sS-Function.Withit,nonlinearPIDisrealizedeasily.AsfornonlinearPIDparametersself-optimizing,thepaperputsforwardanadvancedmethodofoptimizingPIDcontrollerbyusingMATLAB.sOptimizationControlToolbox.Thepaperintroducesmainfeaturesaboutthetoolboxandgiveoptimizationalgorithmunderconstraincondition.Keywords:S-Function;simplexmethod;objectfunction;optimization;nonlinearPIDcontroller71,,:S-FunctionPID