Patent ID: 12235638

BEST MODE FOR CARRYING OUT THE INVENTION

The following detailed description with accompanying drawings refers to the best mode for carrying out the invention, which should not be considered as a stripped-down form of the invention object. All amendments and supplements contained in the claims are disclosed in the relevant claims.

The best mode for carrying out the invention is described below.

The proposed invention relates to the adaptive tuning of a PID controller described by a standard equation as follows [3]:

yt=Kp·et+Ki·∫et⁢dt+Kd·detdt,(1)
in which:ytis a control variable at time t;etis a control error between a setpoint w and an actual value xtat time t, which is calculated as et=w−xt;Kpis a proportional coefficient;Kiis an integral action coefficient;Kdis a derivative action coefficient.

The PID controller (1) is a basis for reverse engineering to derive the tuning equations for parameters Kp, Ki, and Kd. This derivation method is characterized by the following sequence of steps:Step 01: Eliminate an integrator represented explicitly in a PID controller. This is achieved by differentiating both sides of equation (1) according to the time t[3]:

dyt=Kp·det+Ki·et·dt+Kd·d2⁢etdt(2)Step 02: Fixing two of the three PID controller parameters at any time point t. To maximally simplify the derivation method of tuning equations, two of the three PID controller parameters Kp, Ki, and Kdare used as fixed values in succession. That is, Kiand Kdare used as fixed values in tuning equations for Kpat time t. Kpand Kdare used as fixed values in tuning equations for Kiat time t+1. And Kpand Kiare used as fixed values in tuning equations for Kdat time t+2. Thus, the adaptive tuning of all three PID controller parameters Kp, Ki, and Kdis performed separately in time, i.e. only one PID parameter is modified at any time point t. To separate the parameter modifications in the tuning method over time and determine the iteration steps, three additional indices k for Kp, m for Ki, and n for Kdare used (seeFIG.1). With these indices the PID controller (2) takes its final form:

dyt=Kpk·det+Kim·et·dt+Kdn·d2⁢etdt(3)Step 03: Derive an equation to calculate an adjustment step value dKp kfor the proportional coefficient Kp. For this purpose, the parameter Kp kis expressed from (3), and the derived equation is differentiated according to the time t:

dKpk=(d2⁢yt-Kim-1·det·dt-Kdn-1·d3⁢etdt)·det(det)2-(dyt-Kim-1·et·dt-Kdn-1·d2⁢etdt)·d2⁢et(det)2,(4)
in which:dytis a control variable change at time t, which is determined as dyt=yt−yt−1;d2ytis a 2ndorder differential of the control variable ytat time t, which is calculated as d2yt=dyt−dyt−1;detis a 1storder differential of the control error etat time t, which is calculated as det=et−et−1;d2etis a 2ndorder differential of the control error etat time t, which is calculated as d2et=et−2·et−1+et−2;d3etis a 3rdorder differential of the control error etat time t, which is calculated as d3et=et−3·et−1·et−2−et−3;Ki m−1is the actual integral action coefficient Kiat time t, which was modified in iteration step m−1;Kd n−1is the actual derivative action coefficient Kdat time t, which was modified in iteration step n−1.Step 04: Determine a rule to adjust the proportional coefficient Kpin iteration step k as follows:
Kpk=Kpk−1−αpk·dKpk,
αpk·dKpk∈[−0.5,+0.5],  (5)
in which:Kp k−1is the actual proportional coefficient Kpat time t, which was modified in iteration step k−1;αp kis an adjustment speed for the proportional coefficient Kpin iteration step k.

Equation (5) limits the maximum modification of the parameter Kpup to ±0.5 to prevent uncontrollability of the tuning method.Step 05: Derive an equation to calculate an adjustment speed αp kfor the proportional coefficient Kp. For this purpose, equation (5) is substituted into (3), and the control error etis expressed from the derived equation. Considering that a limit of etas t→+∞ equals zero, αp kis expressed from the derived equation:

αpk=Kpk-1·det+Kdn-1·d2⁢etdt-dytdKpk·det·dt,(6)αpk∈[0.001,et42.718282∈[0.0001,1]]

This equation is characterized by an additional limitation of the parameter αp kin the range from 0.0001 to 1 depending on the control error et. This ensures a smooth attenuation of the adaptive tuning method in the final phase. In addition, this prevents an abrupt modification of the proportional coefficient Kpwhen the control error etapproaches zero.Step 06: Derive an equation to calculate an adjustment step value dKi mfor the integral action coefficient Ki. For this purpose, the parameter Ki mis expressed from (3), and the derived equation is differentiated according to the time t:

dKim=(d2⁢yt-Kpk·d2⁢et·dt-Kdn-1·d3⁢etdt)·etet2·dt-(dyt-Kpk·det-Kdn-1·d2⁢etdt)·detet2·dt(7)Step 07: Determine a rule to adjust the integral action coefficient Kiin iteration step m as follows:
Kim=Kim−1+αim·dKim,
αim·dKim∈[−0.5,+0.5],  (8)
in which:αi mis an adjustment speed for the integral action coefficient Kiin iteration step m.

Equation (8) limits the maximum modification of the parameter Kiup to ±0.5 to prevent uncontrollability of the tuning method.Step 08: Derive an equation to calculate an adjustment speed αi mfor the integral action coefficient Ki. For this purpose, equation (8) is substituted into (3), and the 1storder differential of the control error detis expressed from the derived equation. Considering that a limit of detas t→+∞ equals zero, αi mis expressed from the derived equation:

αim=dyt-Kim-1·et·dt-Kdn-1·d2⁢etdtdKim·et·dt,(9)αim∈[0.001,4·❘"\[LeftBracketingBar]"et3❘"\[RightBracketingBar]"2.71828∈[0.0001,1]]

This equation is characterized by an additional limitation of the parameter αi min the range from 0.0001 to 1 depending on the control error et. This ensures a smooth attenuation of the adaptive tuning method in the final phase. In addition, this prevents an abrupt modification of the integral action coefficient Kiwhen the control error etapproaches zero.Step 09: Derive an equation to calculate an adjustment step value dKd nfor the derivative action coefficient Kd. For this purpose, the parameter Kd nis expressed from (3), and the derived equation is differentiated according to the time t:

dKdn=((d2⁢yt-Kpk·d2⁢et-Kim·det·dt)·d2⁢et(d2⁢et)2-(dyt-Kpk·det-Kim·et·dt)·d3⁢et(d2⁢et)2)·dt(10)Step 10: Determine a rule to adjust the derivative action coefficient Kdin iteration step n as follows:
Kdn=Kdn−1−αdn·dKdn,
αdn·dKdn∈[−0.5,+0.5],  11)
in which:αd nis an adjustment speed for the derivative action coefficient Kdin iteration step n.

Equation (11) limits the maximum modification of the parameter Kdup to ±0.5 to prevent uncontrollability of the tuning method.Step 11: Derive an equation to calculate an adjustment speed αd nfor the derivative action coefficient Kd. For this purpose, equation (11) is substituted into (3), and the control error etis expressed from the derived equation. Considering that a limit of etas t→+∞ equals zero, αd nis expressed from the derived equation:

αdn=Kpk·det+Kdn-1·d2⁢etdt-dytdKdn·d2⁢et·dt2,(12)αdn∈[0.001,❘"\[LeftBracketingBar]"et5❘"\[RightBracketingBar]"13.5914∈[0.0001,1]]

This equation is characterized by an additional limitation of the parameter αd nin the range from 0.0001 to 1 depending on the control error et. This ensures a smooth attenuation of the adaptive tuning method in the final phase. In addition, this prevents an abrupt modification of the derivative action coefficient Kdwhen the control error etapproaches zero.Step 12: Select a digital PID controller. The PID velocity algorithm is the most suitable variant for this adaptive tuning method (see [4], p. 1085):

yt=yt-1+dyt+1=yt-1+(Kp+Ki·dt+Kddt)·et-(Kp+2·Kddt)·et-1+Kddt·et-2,⁢yt∈[0,100⁢%],yt≤0=dyt≤0=0,(13)
in which:dyt+1is a control variable change for the time t+1;dt is a sampling time of a digital PID controller.

In this equation the actual values of the PID controller parameters Kp, Ki, and Kdare always used at time t.

A choice of the PID velocity algorithm is caused by the following criterion:Direct integration of control errors etinto the control variable yt. In practice, this allows the control variable ytto be forcibly modified as needed without explicitly correcting an integrator for seamless functionality (as distinct from the PID position algorithm).

Finally, a flowchart shown in drawingsFIG.2AandFIG.2Bintegrates and arranges the equations for automatic tuning of a digital PID controller as a sequence of steps to illustrate the entirety and completeness of the proposed invention description.

Demonstration of the Invention

To illustrate the description, the invention is demonstrated on some mathematical models of controlled systems.

FIG.3shows a closed control loop with negative feedback that consists of a PID controller and a controlled system.

To demonstrate the invention, the adaptive digital PID controller developed for a PLC in the programming language SCL (Structured Control Language [5], see Appendix A) was used with some transfer functions as controlled systems (see Table I).

TABLE ITransfer functions G(s) of controlled systems in the Laplace s-domainNo.Transfer functions G(s)Reference1G⁡(s)=5⁢0⁢0⁢0(s+1)⁢(s+5)⁢(s+1⁢0⁢0)[6]2G⁡(s)=1⁢6⁢0⁢0⁢0⁢07.2⁢2⁢⁢s3+8.2⁢65⁢⁢s2+3⁢81600⁢⁢s+1600⁢0⁢0[7]3G⁡(s)=1s2+s+1[8]4G⁡(s)=0.1⁢⁢s+100.0⁢004⁢⁢s4+0.0⁢45⁢⁢s3+0.5⁢55⁢⁢s2+1.4⁢1⁢⁢s+1[9]5G⁡(s)=0.0⁢5⁢1⁢8⁢7⁢9⁢3⁢6-3.5⁢9⁢4×1⁢0-6⁢⁢s0.0⁢0⁢02979⁢⁢s2+0.0⁢1⁢0⁢11916⁢⁢s+0.00⁢9⁢2[10]

Since the transfer functions G(s) in the Laplace s-domain cannot be used explicitly in a PLC, they are to be converted beforehand into equivalent equations of the time domain. For this purpose, the transfer functions G(s) are first converted by the MATLAB function c2d from the Laplace s-domain into similar discrete transfer functions in the Z-domain with a sampling time dt=0.1 s (see Table II).

TABLE IIEquivalent transfer functions in the z-domain with asampling time dt = 0.1 sNo.Discrete transfer functions in the z-domain G(z)1G⁡(z)=0.0⁢5⁢4⁢8⁢8+0.2462⁢⁢z-1+0.0⁢7307⁢⁢z-2+0.0⁢0⁢02884⁢⁢z-31-1.5⁢11⁢⁢z-1+0.5⁢489⁢⁢z-2-2.4⁢9⁢2×1⁢0-5⁢⁢z-32G⁡(z)=0.0⁢2⁢0⁢55+0.0421⁢⁢z-1+0.0⁢4063⁢⁢z-2+0.0⁢1885⁢⁢z-31+0⁢08548⁢⁢z-1-0.0⁢7151⁢⁢z-2-0.8⁢918⁢⁢z-33G⁡(z)=0.0⁢0⁢1⁢6⁢2⁢5+0.0⁢06338⁢⁢z-1+0.0⁢01546⁢⁢z-21-1.8⁢95⁢⁢z-1+0.9⁢048⁢⁢z-24G⁡(z)=0008⁢0⁢9+0⁢06928⁢⁢z-1+0⁢05295⁢⁢z-2+00036⁢⁢z-3-9.1⁢8⁢2×1⁢0-8⁢⁢z-41-2059⁢⁢z-1+1327⁢⁢z-2-02546⁢⁢z-3+1⁢3⁢0⁢1×1⁢0-5⁢⁢z-45G⁡(z)=0.1⁢4⁢6⁢4+0.3⁢096⁢⁢z-1+0.0⁢2883⁢⁢z-21-0.9⁢475⁢⁢z-1+0.0⁢3348⁢⁢z-2

The transfer functions in the z-domain are then converted into recurrent equations of the time domain as polynomials as follows (for details, see [4], pp. 443-444):
xt=b1·xt−1+b2·xt−2+b3·xt−3+b4·xt−4+α0·yt+α1·yt−1+
+α2·yt−2+α3·yt−3+α4·yt−4,  (14)
in which:ytis a control variable of a PID controller at time t;xtis a controlled system response on the control variable as a simulated sensor value at time t.

All polynomial parameters (14) for the simulated controlled systems are given in Table III.

TABLE IIIPolynomial parameters (14) for transfer functions of the controlled systemsNo.b1b2b3b4a0a1a2a3a411.511−0.54892.492 ×05.488 ×0.24627.307 ×2.884 ×010−510−210−210−42−8.548 ×7.151 ×0.891802.055 ×4.21 ×4.063 ×1.885 ×010−210−210−210−210−210−231.895−0.9048001.625 ×6.338 ×1.546 ×0010−310−310−342.059−1.3270.2546−1.301 ×8.09 ×6.928 ×5.295 ×3.6 ×−9.182 ×10−510−310−210−210−310−850.9475−3.348 ×000.14640.30962.883 ×0010−210−2

The simulation was performed on a computer-aided PLC simulator as a closed control loop (seeFIG.3). The results shown in Table IV were obtained for all mathematical models of the controlled systems from Table I. Here Tiis a reset time, which is determined as Ti=Kp/Ki, and Tdis a derivative time, which is determined as Td=Kd/Kp. All experiments were performed with initial parameters Kp=1, Ki=1, Kd=1, and a sampling time dt=0.1 s. A step function 0→1 was used as an activation trigger.

TABLE IVParameters of a digital PID controller foundusing the adaptive tuning methodParameters of a PID controller for controlled systemsNo.KpTi[s]Td[S]FIG.10.1675429593330631.2748233690.381714789420.9989364895200220.7914338960.945415624531.165648613597310.9994561940.999827146640.3306033728510951.0258249960.260850227750.1289460213729361.2750315500.3907028128

REFERENCES

[1] Vladimir Bobal et. al., “AUTO-TUNING OF DIGITAL PID CONTROLLERS USING RECURSIVE IDENTIFICATION”,Adaptive systems in Control and Signal Processing, Jun. 16, 1995 (1995-06-16), pp. 359-364, XP055754038, Great Britain, ISBN: 978-0-08-042375-3.[2] Sukede Abhijeet Kishorsingh et al., “Auto tuning of PID controller”, 2015International Conference on Industrial Instrumentation and Control(ICIC), IEEE, May 28-30, 2015, pp. 1459-1462, XP033170865.[3] “Three Types of PID Equations”, http://bestune.50megs.com/typeABC.htm[4] Lutz H., Wendt W., “Taschenbuch der Regelungstechnik mit MATLAB and Simulink”, 10., ergänzte Auflage, Verlag Europa-Lehrmittel, Haan-Gruiten, 2014.[5] International standard IEC 61131-3:2013. Programmable controllers—Part 3: Programming languages.[6] Lin Feng, Brandt Robert D., Saikalis George, “Self-tuning of PID Controllers by Adaptive Interaction”,Proceedings of the2000American Control Conference, pp. 3676-3681.[7] Y. Chen et al., “Design of PID Controller of Feed Servo-System Based on Intelligent Fuzzy Control”,Key Engineering Materials, Vol.693, pp. 1728-1733, 2016.[8] X. Wang et al., “Simulation Research of CNC Machine Servo System Based on Adaptive Fuzzy Control”,Advanced Materials Research, Vol.819, pp. 181-185, 2013.[9] T. Boone et al., “PID Controller Tuning Based on the Guardian Map Technique”,International Journal of Systems Applications, Engineering&Development, Vol.9, pp. 192-196, 2015.[10] Dipraj, Dr. A. K. Pandey, “Speed Control of D.C. Servo Motor By Fuzzy Controller”,International Journal of Scientific&Technology Research, Vol.1, Issue 8, pp. 139-142, 2012.

INDUSTRIAL APPLICABILITY

This invention is preferably used in automation systems of industrial facilities with programmable logic controllers, where the individual tuning of PID controller parameters is required to regulate the technological processes in production.

APPENDIX AA source code of the adaptive digital PID controller001FUNCTION_BLOCK ″A-PID_CONTROL″002TITLE= A-PID controller003AUTHOR: Valentin_Dimakov004FAMILY: PID_CONTROL005NAME: ′A-PID_CONTROL′006VERSION: 13.44007// FUNCTION008// Digital PID controller with automatic tuning of parameters009//010// Called blocks: none011012VAR_INPUT013MAN_ON: Bool:= FALSE;// Switch-over between manual & automatic mode (0=A/1=M)014AUTO_ON: Bool:= FALSE;// Activate automatic mode for the A-PID controller015INV_CONTROL: Bool:= FALSE;// Control direction (0 = SP > PV, 1 = PV > SP)016CYCLE: Time:= T#100MS;// Sampling time dt for the controller [10 ms. .10 s]017SP: LReal:= 0.0;// Setpoint w <temperature, pressure, etc.>018PV: LReal:= 0.0;// Actual value xt<temperature, pressure, etc.>019LMN_LLM: LReal:= 0.0;// Lower limit for the control variable yt[0..99 %]020LMN_HLM: LReal:= 100.0;// Upper limit for control variable yt[LMN_LLM..100 %]021END_VAR022023VAR_OUTPUT024CTRL_ERR: LReal:= 0.0;// Actual control error et025LMN: LReal:= 0.0;// Control variable yt[0..100 %]026ERR_CODE: USInt:= 0;// Error code of the A-PID controller < > 0, 0 = no error027END_VAR028029VAR_IN_OUT030SELF_TUN_ON: Bool:= FALSE;// Activate auto-tuning for the A-PID controller031GAIN: LReal:= 1.0;// Proportional coefficient Kp[0.01..30]032TI: LTime:= LT#1S;// Reset time Ti[CYCLE. .100 m]033TD: LTime:= LT#1S;// Derivative time Td[0..60 s]034TUN_ERR_TOLER: LReal:= 0.01;// Threshold value to stop auto-tuning [0..100]035TUN_COMPL_TM: Time:= T#3S;// Delay to stop auto-tuning [1 s..1 m]036LMN_MAN: LReal:= 0.0;// Control variable for the manual mode [0..100 %]037END_VAR038039VAR040Kp: LReal:= 1.0;// Proportional coefficient Kp041Ki: LReal:= 1.0;// Integral action coefficient Ki042Kd: LReal:= 1.0;// Derivative action coefficient Kd043PASS_NO: USInt:= 0;// Pass counter for auto-tuning [0..2]044045e: STRUCT // Control errors at different times046t: LReal;// Control error etat time t047t1: LReal;// Control error et−1at time t−1048t2: LReal;// Control error et−2at time t−2049t3: LReal;// Control error et−3at time t−3050t4: LReal;// Control error et−4at time t−4051sqr: LReal;// Control error squared e2tat time t052END_STRUCT;053054y: STRUCT // Control variables055out: LReal; // Internal control variable yt[0..100 %]056END_STRUCT;057058d: STRUCT // Calculated 1storder differentials059e: LReal;// 1storder differential detof the control error et060Kp: LReal;// Adjustment step value dKpfor the proportional coefficient Kp061Ki: LReal;// Adjustment step value dKifor the integral action coefficient Ki062Kd: LReal;// Adjustment step value dKdfor the derivative action coefficient Kd063y: LReal;// Control variable change dyt+1for the time t+1064y_t1: LReal;// Control variable change dytin previous cycle065END_STRUCT;066067d2: STRUCT // Calculated 2ndorder differentials068e:LReal;// 2ndorder differential d2etof the control error et069y:LReal;// 2ndorder differential d2ytof the control variable yt070END_STRUCT;071072d3: STRUCT // Calculated 3rdorder differentials073e: LReal; // 3rdorder differential d3etof the control error et074END_STRUCT;075076a: STRUCT // Adjustment speeds for parameters of the A-PID controller077Kp:LReal:= 1.0;// Adjustment speed apfor the proportional coefficient Kp078Ki:LReal:= 1.0;// Adjustment speed aifor the integral action coefficient Ki079Kd:LReal:= 1.0;// Adjustment speed adfor the derivative action coefficient Kd080END_STRUCT;081082T_TUN_MON: TON_TIME; // Timer to stop auto-tuning for the A-PID controller083END_VAR084085VAR_TEMP086LT_CYCLE: LTime;// Sampling time dt for the A-PID controller087Ts: LReal;// Sampling time dt for the A-PID controller [sec]088dKp: LReal;// Adjustment value for the proportional coefficient Kp089dKi: LReal;// Adjustment value for the integral action coefficient Ki090dKd: LReal;// Adjustment value for the derivative action coefficient Kd091a_mx_Kp: LReal;// Upper limit of the adjustment speed apfor parameter Kp092a_mx_Ki: LReal;// Upper limit of the adjustment speed aifor parameter Ki093a_mx_Kd: LReal;// Upper limit of the adjustment speed adfor parameter Kd094fact_1: LReal;// 1stfactor in an equation095fact_2: LReal;// 2ndfactor in an equation096divisor: LReal;// Divisor in an equation097098r: STRUCT // Time parameters converted to seconds099TI:LReal;// Reset time Ti[sec]100TD:LReal;// Derivative time Td[sec]101END_STRUCT;102END_VAR103104VAR CONSTANT105GAIN_MN: LReal:= 0.01;// Lower limit for the proportional coefficient Kp106GAIN_MX: LReal:= 30.0;// Upper limit for the proportional coefficient Kp107TI_MK: LTime:= LT#100M;// Upper limit for the reset time Ti108TD_MK: LTime:= LT#1M;// Upper limit for the derivative time Td109LMN_MN: LReal:= 0.0;// Lower limit for the control variable yt[%]110LMN_MK: LReal:= 100.0;// Upper limit for the control variable yt[%]111TUN_ACCURACY: LReal:= 1.0E−07;// Computational accuracy for auto-tuning112TUN_ERR_TOLER_MN: LReal:= 0.0;// Minimum control error etto stop auto-tuning113TUN_ERR_TOLER_MK: LReal:= 100.0;// Maximum control error etto stop auto-tuning114TUN_COMPL_TM_MN: Time:= T#1S;// Minimum delay to stop auto-tuning115TUN_COMPL_TM_MK: Time:= T#1M;// Maximum delay to stop auto-tuning116CF_MN: LReal:= 0.0001;// Lower limit for an adjustment speed117CF_MK: LReal:= 1.0;// Upper limit for an adjustment speed118END_VAR119120BEGIN121// Reset an error code of the A-PID controller122#ERR_CODE := 0;123124IF #CYCLE < T#10MS OR #CYCLE > T#10S THEN125// E01 = Sampling time CYCLE is out of the range [10 ms. .10 s]126#ERR_CODE:= 1;127#y.out:= 0.0;128ELSIF #LMN_LLM > #LMN_HLM THEN129// E02 = Lower limit for the control variable LMN_LLM > upper limit LMN_HLM130#ERR_CODE:= 2;131#y.out:= 0.0;132ELSIF #LMN_LLM < #LMN_MN THEN133// E03 = Lower limit for the control variable LMN_LLM < 0 %134#ERR_CODE:= 3;135#y.out:= 0.0;136ELSIF #LMN_HLM > #LMN_MK THEN137// E04 = Upper limit for the control variable LMN_HLM > 100 %138#ERR_CODE:= 4;139#y.out:= 0.0;140ELSE141// Convert the sampling time dt to seconds142#Ts := DINT_TO_LREAL(TIME_TO_DINT(#CYCLE)) / 1000.0;143144// Convert the sampling time dt to IEC high resolution time145#LT_CYCLE := TIME_TO_LTIME(#CYCLE);146147// Check the permissible values of the A-PID controller parameters148#GAIN:= LIMIT(IN:= #GAIN,MN := #GAIN_MN,MX := #GAIN_MK);149#TI:= LIMIT(IN:= #TI,MN := #LT_CYCLE,MX := #TI_MK);150#TD:= LIMIT(IN:= #TD,MN := LT#0NS,MX := #TD_ME);151#TUN_ERR_TOLER:= LIMIT(IN := #TUN_ERR_TOLER,MN := #TUN_ERR_TOLER_MN,152MX := #TUN_ERR_TOLER_MX);153#TUN_COMPL_TM:= LIMIT(IN := #TUN_COMPL_TM,MN := #TUN_COMPL_TM_MN,154MX := #TUN_COMPL_TM_MX);155#LMN_MAN:= LIMIT(IN := #LMN_MAN,MN := #LMN_MN, MX := #LMN_MX) ;156157// Save the previous control errors158#e.t4 := #e.t3;159#e.t3 := #e.t2;160#e.t2 := #e.t1;161#e.t1 := #e.t;162163// Calculate a control error etaccording to the specified control direction164IF #INV_CONTROL THEN165#e.t := #PV − #SP;166ELSE167#e.t := #SP − #PV;168END_IF;169170// Output an actual control error et171IF #INV_CONTROL THEN172#CTRL_ERR := −#e.t;173ELSE174#CTRL_ERR := #e.t;175END_IF;176177// Activate the A-PID controller in automatic mode178IF #AUTO_ON AND NOT #MAN_ON THEN179// Stop condition for auto-tuning of the A-PID controller180#T_TUN_MON(IN:= #SELF_TUN_ON AND ABS(#e.t) <= #TUN_ERR_TOLER, PT: =#TUN_COMPL_TM);181IF #T_TUN_MON.Q THEN182#SELF_TUN_ON:= FALSE;183#PASS_NO:= 0;184END_IF;185186// Convert a reset time Tito seconds187#r.TI := LINT_TO_LREAL(LTIME_TO_LINT(#TI)) / 1.0E+9;188189// Calculate an integral action coefficient Ki190#Ki := #GAIN / #r.TI;191192// Convert a derivative time Tdto seconds193#r.TD := LINT_TO_LREAL(LTIME_TO_LINT(#TD)) / 1.0E+9;194195// Calculate a derivative action coefficient Kd196#Kd := #GAIN * #r.TD;197198// Save a proportional coefficient Kp199#Kp := #GAIN;200201(************************************************************************202*     AUTO-TUNING OF THE A-PID CONTROLLER PARAMETERS     *203************************************************************************)204IF #SELF_TUN_ON AND ABS (#e.t4) > 0.0 AND ABS (#d.y_t1) > 0.0 THEN205// Calculate a 2ndorder differential d2ytfor the control variable yt206#d2.y := #d.y - #d.y_t1;207208// Calculate a 1storder differential detfor a control error et209#d.e := #e.t − #e.t1;210211// Calculate a 2ndorder differential d2etfor a control error et212#d2.e := #e.t − 2.0 * #e.t1 + #e.t2;213214// Calculate a 3rdorder differential d2etfor a control error et215#d3.e := #e.t − 3.0 * #e.t1 + 3.0 * #e.t2 − #e.t3;216217// Calculate upper limits for the adjustment speeds of controller parameters218#e.sgr:= #e.t * #e.t;219#a_mx_Kp:= LIMIT(IN := #e.sgr * #e.sgr / 2.71828,MN := #CF_MN, MX := #CF_ME);220#a_mx_Ki:= LIMIT(IN := 4.0 * ABS(#e.sgr * #e.t) / 2.71828,221MN := #CF_MN, MX := #CF_ME);222#a_mx_Kd:= LIMIT(IN := ABS(#e.t * #e.sgr * #e.sgr) / 13.5914,223MN := #CF_MN, MX := #CF_ME);224(************************************************************************225*        AUTO-TUNING OF THE PROPORTIONAL PART        *226************************************************************************)227// Perform auto-tuning for the proportional coefficient Kp228IF #PASS_NO = 0 THEN229// Calculate an adjustment step value dKpfor the proportional coefficient Kp230IF ABS(#d.e) > #TUN_ACCURACY THEN231#fact_1:= #d2.y − #Ki * #d.e * #Ts − #Kd * #d3.e / #Ts;232#fact_2:= #d.y − #Ki * #e.t * #Ts − #Kd * #d2.e / #Ts;233#d.Kp:= (#fact_1 * #d.e − #fact_2 * #d2.e) / (#d.e * #d.e);234ELSE235#d.Kp := 0.0;236END_IF;237238// Calculate an adjustment speed apfor the proportional coefficient Kp239#divisor := #d.Kp * #d.e;240IF ABS(#divisor) > #TUN_ACCURACY THEN241#a.Kp := (#Kp * #d.e + #Kd * #d2.e / #Ts − #d.y) * #Ts / #divisor;242#a.Kp := LIMIT(IN := #a.Kp, MN := #CF_MN, MX := #a_mx_Kp);243ELSE244#a.Kp := #CF_MN;245END_IF;246247// Adjust the proportional coefficient Kp248#dKp:= LIMIT(IN := #a.Kp * #d.Kp,MN := −0.5,MX := 0.5);249#GAIN:= LIMIT(IN := #GAIN − #dKp ,MN := #GAIN_MN,MX := #GAIN_MX);250#Kp:= #GAIN;251END_IF;252253(************************************************************************254*        AUTO-TUNING OF THE INTEGRAL PART         *255************************************************************************)256// Perform auto-tuning for the integral action coefficient Ki257IF #PASS_NO = 1 THEN258// Calculate an adjustment step value dKifor integral action coefficient Ki259IF ABS(#e.t) > #TUN_ACCURACY THEN260#fact_1:= #d2.y − #Kp * #d2.e − #Kd * #d3.e / #Ts;261#fact_2:= #d.y − #Kp * #d.e − #Kd * #d2.e / #Ts;262#d.Ki:= (#fact_1 * #e.t − #fact_2 * #d.e) / (#e.t * #e.t * #Ts);263ELSE264#d.Ki:= 0.0;265END_IF;266267// Calculate an adjustment speed aifor the integral action coefficient Ki268#divisor := #d.Ki * #e.t;269IF ABS(#divisor) > #TUN_ACCURACY THEN270#a.Ki := (#d.y − #Ki * #e.t * #Ts − #Kd * #d2.e / #Ts) * #Ts / #divisor;271#a.Ki := LIMIT(IN := #a.Ki, MN := #CF_MN, MX := #a_mx_Ki);272ELSE273#a.Ki := #CF_MN;274END_IF;275276// Adjust the integral action coefficient Ki277#dKi:= LIMIT(IN:= #a.Ki * #d.Ki, MN := −0.5, MX := 0.5);278#Ki:= LIMIT(IN:= #Ki + #dKi,279MN:= #GAIN * 1.0E+9 / LINT_TO_LREAL(LTIME_TO_LINT(#TI_MX)),280MX:= #GAIN / #Ts);281282// Convert Kito a reset time Ti[sec]283#r.TI := #GAIN / #Ki;284285// Convert a reset time Ti[sec] to IEC high resolution time286#TI := LINT_TO_LTIME(LREAL_TO_LINT(#r.TI * 1.0E+9));287END_IF;288289(************************************************************************290*        AUTO-TUNING OF THE DERIVATIVE PART         *291************************************************************************)292// Perform auto-tuning for the derivative action coefficient Kd293IF #PASS_NO = 2 THEN294// Calculate an adjustment step value dKdfor the derivative action coeff. Kd295IF ABS(#d2.e) > #TUN_ACCURACY THEN296#fact_1 := #d2.y − #Kp * #d2.e − #Ki * #d.e * #Ts;297#fact_2 := #d.y − #Kp * #d.e − #Ki * #e.t * #Ts;298#d.Kd := (#fact_1 * #d2.e − #fact_2 * #d3.e) * #Ts / (#d2.e * #d2.e);299ELSE300#d.Kd := 0.0;301END_IF;302303// Calculate an adjustment speed adfor the derivative action coefficient Kd304#divisor := #d.Kd * #d2.e;305IF ABS(#divisor) >#TUN_ACCURACY THEN306#a.Kd := (#Kp * #d.e + #Kd * #d2.e / #Ts − #d.y) * #Ts * #Ts / #divisor;307#a.Kd := LIMIT(IN := #a.Kd, MN := #CF_MN, MX := #a_mx_Kd);308ELSE309#a.Kd := #CF_MN;310END_IF;311312// Adjust the derivative action coefficient Kd313#dKd:= LIMIT(IN:= #a.Kd * #d.Kd,MN := −0.5,MX := 0.5);314#Kd:= LIMIT(IN:= #Kd − #dKd,MN := 0.0,315MX:= #GAIN * LINT_TO_LREAL(LTIME_TO_LINT(#TD_MX))/ 1.0E+9);316317// Convert Kdto a derivative time Td[sec]318#r.TD := #Kd / #GAIN;319320// Convert a derivative time Td[sec] to IEC high resolution time321#TD := LINT_TO_LTIME(LREAL_TO_LINT(#r.TD * 1.0E+9));322END_IF;323324// Increase a pass counter by one for auto-tuning325#PASS_NO := #PASS_NO + 1;326327// Reset a pass counter if it is greater than 2328IF #PASS_NO > 2 THEN329#PASS_NO := 0;330END_IF;331ELSE332#PASS_NO := 0;333END_IF;334335(****************************************************336*         DRIVE CONTROL         *337****************************************************)338// Save a control variable change dyt339#d.y_t1 := #d.y;340341// Calculate a control variable change dyt+ifor the time t+1342#d.y := (#Kp + #Ki * #Ts + #Kd / #Ts) * #e.t − (#Kp + 2.0 * #Kd / #Ts) * #e.t1 +343#Kd / #Ts * #e.t2;344345// Modify the control variable ytat time t346#y.out := LIMIT(IN := #y.out + #d.y, MN := #LMN_LLM, MX := #LMN_HLM);347ELSE348IF #MAN_ON THEN349// Use the control variable for manual mode350#y.out := LIMIT(IN := #LMN_MAN, MN := #LMN_MN, MX := #LMN_MX);351ELSE352// Reset a control variable ytat standstill353#y.out := #LMN_MN;354END_IF;355// Reset the internal controller variables356#d.y:= #d.y_t1:= 0.0;357#e.t:= #e.t1:= #e.t2 := #e.t3 := 0.0;358#PASS_NO:= 0;359END_IF;360END_IF;361362// Move the actual control variable ytto the control variable for manual mode363#LMN_MAN := #y.out;364365// Output a control variable yt366#LMN := #y.out;367368END_FUNCTION_BLOCK