#*------------------------------------------------------------------- * EMSO Model Library (EML) Copyright (C) 2004 - 2007 ALSOC. * * This LIBRARY is free software; you can distribute it and/or modify * it under the therms of the ALSOC FREE LICENSE as available at * http://www.enq.ufrgs.br/alsoc. * * EMSO is distributed under the terms of the ALSOC LICENSE as * available at http://www.enq.ufrgs.br/alsoc. *----------------------------------------------------------------------- * Author: Jonathan Ospino P. * $Id: PID_id.mso 2012$ *---------------------------------------------------------------------*# using "types"; Model PID_id ATTRIBUTES Pallete=true; Icon="icon/PID"; Info="== PID Controller block =="; PARAMETERS #Controller Options Controller_Mode as Switcher(Valid=["P","I","D","PI","PD","PID"],Default="PID"); # PID Parameters Kc as Real(Brief="Proportional controller gain"); TauI as Real(Brief="Integral or reset time",Unit='s'); TauD as Real(Brief="Derivative time",Unit='s'); N as Real(Brief="Filter parameter",Unit='1/s', Default=200); VARIABLES in e as Real(Brief="Deviation error",Protected=true,PosX=0,PosY=0.5); Inte as Real(Brief="Integral of the error",Hidden=true,Unit='s'); ef as Real(Brief="Derivative error filter",Hidden=true); P as Real(Brief="Proportional action",Hidden=true); I as Real(Brief="Integral or reset action",Hidden=true); D as Real(Brief="Final Derivative or anticipative action",Hidden=true); out m as Real(Brief="Controller Output",PosX=1, PosY=0.5,Protected=true); EQUATIONS "Integral of the error" diff(Inte)=e; "Proportional action" P=Kc*e; "Integral or reset action" I=Kc*(Inte/TauI); "Derivative or anticipative action" D=Kc*TauD*diff(ef); "Error filter" (1/N)*diff(ef)=e-ef; #PID Controller equation switch Controller_Mode case "P": m=P; case "I": m=I; case "D": m=D; case "PI": m=P+I; case "PID": m=P+I+D; case "PD": m=P+D; end INITIAL Inte=0*'s'; diff(ef)*'s'=0; # ef=0; end #* Notes: (1) A simple derivative-filtered approach as in Simulink was implemented. (2) The controller modes I and D were added for analysis purposes. Revision Date: 02.09.2013 *#