10th Portuguese Conference on Automatic Control 16-18 July 2012 CONTROLO’2012 Funchal, Portugal Gains Tuning of Fuzzy Controllers Based on a Cost Function Optimization C. Lucena ∗ ∗ L. Palma A. Cardoso ∗∗ P. Gil ∗,∗∗ ∗ Departamento de Engenharia Electrotécnica, Faculdade de Ciências e Tecnologia, Universidade Nova de Lisboa (e-mail: c.lucena@fct.unl.pt, psg@fct.unl.pt, lbp@fct.unl.pt). ∗∗ CISUC, Department of Informatics Engineering, University of Coimbra, Portugal (pgil@dei.uc.pt, alberto@dei.uc.pt) Abstract: This paper presents a methodology for tuning the gains of fuzzy proportionalintegral controllers where the concept of closed loop control system performance is explicitly taken into account. The fuzzy controller gains are found by solving a nonlinear constrained optimization problem considering the system’s dynamics described by a nonlinear model and a set of constraints on the controller gains, control actions and outputs. Experimental results from a testbed show the pertinence of using the proposed tuning technique. Copyright Controlo 2012. Keywords: Fuzzy Control, Gains Tuning, Nonlinear Optimization, Constrained admissible Solution. 1. INTRODUCTION Standard Proportional-Integral-Derivative (PID) control techniques are still largely used in the process industry, mainly due to its recognized simplicity. However, in the case of nonlinear systems it is difficult to get satisfied closed loop control performance over extended operating regimes by using classical PID controllers. Fuzzy Logic Control (FLC) techniques are inherently nonlinear approaches since they incorporate three sources of nonlinearity, namely, the rule base, the inference engine and fuzzification and defuzzification modules. This control paradigm has proven to be successful in controlling many nonlinear systems and it has been suggested as an alternative approach to conventional control techniques Feng (2006). FLCs are more robust and their performance are less sensitive to parametric variations of systems than conventional controllers Wang et al. (1996). Furthermore, recent applications of FLC methodologies have shown great potential in the context of complex illdefined systems, which can effectively be controlled by a skilled operator without the knowledge of the underlying systems dynamics Lee (1990). Nevertheless the great potential of fuzzy control systems applications, finding a good setting, by choosing appropriate linguistic variables, membership functions, rules and scaling factors, and subsequently tune it, is still a challenge issue due to the lack of a systematic framework. Control of MIMO (Multi-Input/Multi-Output) systems is even more challenging because one or more manipulated variables might be affecting the other controlled variables due coupling effects. Ultimately, this interaction might affect the closed loop system performance. 105 In literature there are multiple approaches to select FLC parameters. They include heuristics based approaches (see e.g. Misir et al. (1996)), methodologies relying on pseudoequivalence between digital fuzzy PID controllers and linear PID controllers Boubertakh et al. (2010); Pivonka (2002) or those based on evolutionary computation Herrera and Lozano (2009). The present paper proposes a new conceptual methodology for tuning PI-fuzzy scaling factors or gains, although not exclusively restricted to this topology, by solving a nonlinear optimization problem subject to a set of explicit constraints on scaling factors, control actions and outputs, and assuming the systems dynamics described by a nonlinear model. Because the gains are found by solving an offline constrained optimization problem the closed loop system response might be considered, to some extent, for the reference signal adopted in the optimization problem, as an optimal trajectory provided the certainty equivalence principle holds. In order to assess the effectiveness of the proposed approach, it will be compared with a heuristics based controller and a pseudo-equivalence based controller. 2. FUZZY LOGIC CONTROL SYSTEMS Fuzzy Logic can be defined as a theory of vagueness and uncertainties. This theory provides an approximate yet effective mean of describing the behavior of systems, which could be too complex and ill-defined to permit a precise mathematical analysis. The basic structure of FLC (Fig. 1) consists of four conceptual components: knowledge base, fuzzification module, inference engine and defuzzification module. Fig. 1. General structure of a Mamdani-type Fuzzy Logic System. The knowledge base contains all the knowledge of the fuzzy control system. It comprises a fuzzy control rule base (procedural part of the knowledge) and a data base (facts, terms, concepts). The inference engine, regarded as the kernel of all fuzzy systems, is a reasoning mechanism that performs inference procedures upon the fuzzy control rules and given conditions to derive appropriate control actions. The fuzzification module defines a mapping from a real-value space to a fuzzy space, while the defuzzification module implements a mapping from a fuzzy space defined over an output universe of discourse to a real-valued space Feng (2006). One of the major issues regarding fuzzy control design refers to how to reflect in the tuning stage the concept of closed loop performance. This would lead to better fuzzy control systems behavior over extended operation regimes, while enabling a balance between the tracking error, energy consumption and actuators wearing. In this context, the present work proposes an effective structured automatic framework to deal with the problem of PIfuzzy controller gains tuning based on the minimization of a user defined explicit metric. This approach not only makes easier the tuning stage, avoiding cumbersome trialand-error heuristics, but also promotes a more efficient and rational usage of resources, including energy, which ultimately contributes to sounding improvements in terms of overall efficiency and final product quality. 2.1 PI-Fuzzy Controller Structure With no loss of generality let us consider a two-dimension PI-fuzzy controller structure, in which error e (1) and change in error ∆e (2) are selected as input words, while the output from the fuzzy system is the increment of control action. e(k) = r(k) − y(k) ∆e = e(k) − e(k − 1) (1) (2) In the previous equations k is the current discrete time, y is the system output and r the reference signal. Fig. 2 shows the PI-Fuzzy control structure where the scaling factors Ke , K∆e and K∆u , are explicitly represented. The normalized error ẽ, ∆ẽ and the denormalized increment of control action ∆u are given as: ẽ(k) = Ke × e(k) (3) 106 Fig. 2. PI-Fuzzy Logic Control system. ∆ẽ = K∆e × ∆e(k) (4) ∆u = K∆u × ∆ũ (5) After choosing a given setting for the FLC structure the subsequent step involves the controller tuning. The next section focuses on the proposed methodology for tuning the FLC scaling factors based on constrained nonlinear optimization. 2.2 Optimal Tuning of Scaling Factors Optimization methods are classified according to the type of the search space A ⊆ Rn and objective functions. The simplest method is the linear programming, which concerns the case where the objective function L(·) to be minimized is linear and the restriction space A is specified using only linear equality and inequality constraints Schrijver (1986). However, in general, the cost function and/or the constraints contain nonlinearities, leading to a nonlinear programming problem where multiple minima may exist in virtue of the nonconvexity of the optimization problem. This work considers the case in which the performance index is described by a single objective function subject to a set of constraints. The underlying optimization problem can be formulated as follows: minV ≡ min K subject to: K Np X k=1 Lk (e(k), u(k − 1), K) (6) y(k) − g(k) = 0 φ(y(k), u(k), K) = 0 (7) ψ(y(k), u(k), K) ≤ 0 where V ∈ R+ is the objective function, Np ∈ N + the prediction horizon, y ∈ Rp the output vector, u ∈ Rm the control trajectory, K ∈ Rq the vector of scaling factors, g(·) the nonlinear system dynamics model, φ(·) and ψ(·) functions defining equality and inequality constraints. Concerning the underlying system dynamics it is considered a nonlinear model. The main reason is due to the fact that this kind of models allows a properly approximation of the system dynamics in a broad range of operating regimes. In what the optimization of PI-Fuzzy controller gains is concerned it is here carried out using the MATLAB function fmincon() available in the Optimization Toolbox. The algorithm relies on the Hessian of the Lagrangian (8) and uses a merit function in the search for the optimal gains. In each iteration the Hessian matrix is calculated based on a quasi-Newton approximation. X X 52xx L(x, λ) = 52 f (x) + λi 52 ci (x) + λi 52 ceqi (x) (8) with f the objective function, c the nonlinear inequality constraint vector, ceq the nonlinear equality constraint vector and λi the Lagrange multipliers. 3. EXPERIMENTS ON A TESTBED The testbed used in the experiments consisted of a R Feedback Process Trainer PCT 37-100 (Figure 3). This system comprises a variable-speed axial fan, regulated via a potentiometer that circulates an airstream along a polypropylene tube. The airflow rate is heated by means of a heating element controlled by a thyristor circuit. A thermistor detector is incorporated to sensing the temperature at the insertion point. Table 1. Format of the rule base. e ∆e NB NM NS ZE PS PM PB NB NB NB NB NB NM NP ZE NM NB NB NB NM NS ZE PS NS NB NB NM NS ZE PS PM ZE NB NM NS ZE PS PM PB PS NM NS ZE PS PM PB PB PM NS ZE PS PM PB PB PB PB ZE PS PM PB PB PB PB Medium; N S, Negative Small; ZE, Zero; P S, Positive Small; P M , Positive Medium; P B, Positive Big). For the fuzzy controller output, ∆ũ, the corresponding universe of discourse was defined in the range [−1.0 , 1.0], and assuming a partition similar to those assumed for ẽ and ∆ẽ. The fuzzy inference considered in this work is the Mamdani-type inference (9), while the controller output is generated by the Centroid Defuzzification technique. The membership functions for ẽ and ∆ẽ are presented in Fig. 4 and the membership functions for ∆ũ are shown in Fig. 5 µe/∆e (e, ∆e) = min(µA (e), µB (∆e)) with µ the membership value. (9) Concerning the rule base it comprises forty-nine rules, as shown in Table 1. The design of the rule base was made according to Li and Gatland (1996). Fig. 4. Membership functions of ẽ and ∆ẽ. Fig. 5. Membership functions of ∆ũ. R Fig. 3. Feedback Process Trainer PCT 37-100. 3.2 Experimental Results 3.1 PI-Fuzzy Controller Design The PI-fuzzy controller comprises two inputs, namely, the control error and the change in error, and one output, under the form of control action increment (see Fig. 2). Regarding the normalized universe of discourse for ẽ and ∆ẽ they were chosen as [−1.5 , 1.5] and partitioned into seven fuzzy sets, namely, {N B, N M, N S, ZE, P S, P M, P B} (N B, Negative Big; N M , Negative 107 The experiments included in this section aim to compare the optimal gains PI-fuzzy controller performance against a gains tuning approach based on a trial-and-error heuristic and on the pseudo-equivalence between digital fuzzy PID controllers and linear PID controllers. In these experiments the airstream temperature should follow a given user defined reference temperature by manipulating the input voltage to the heater grid. The default fan speed was adjusted to position 5 and the sampling time set to 0.1 second. The first experiment was carried out using a PI-fuzzy controller with the corresponding gains tuned by means of a trial-and-error heuristic. As can be observed from Fig. 6 the closed loop system response is fairly acceptable, showing a short settling time and no overshoot. However, this closed loop response was achieved at an expense of a time consuming and rather tedious tuning process. The output of the PI-FLC is given by: ∆u(k) = K∆uP I D{F{K∆eP I ∆e(k)+KeP I e(k)}}+u(k−1) (13) As can be inferred from this figure, the closed loop system response is rather oscillatory as a result of an aggressive controller, whose behavior is reflected in the control signal variance. 40 45 35 Temperature [Cº] Temperature [Cº] 45 with T the sampling time, Ti the PI controller time constant, K the PI controller gain and M the universe range. Output Reference 30 0 10 20 30 40 50 60 70 40 35 Time [s] Output Reference 30 5 0 10 20 30 40 50 60 70 50 60 70 Time [s] 4.5 4 Input [V] 3.5 5 3 4.5 2.5 4 2 3.5 Input [V] 1.5 1 0.5 0 0 10 20 30 40 50 60 70 3 2.5 2 1.5 Time [s] 1 Fig. 6. PI-FLC with trial-and-error tuning heuristic. 0.5 Fig. 7 shows the closed loop response and input signals for the pseudo-equivalence between digital fuzzy PID controllers and linear PID controllers approachPivonka (2002). According to this approach, the scaling factors of a PI-Fuzzy controller are given by: K∆uP I = KT M ; Ti 1 KeP I = ; M Ti K∆eP I = ; M 0 0 10 20 30 40 Time [s] Fig. 7. PI-FLC with a pseudo-equivalence between digital fuzzy PID controllers and linear PID controllers tuning approach. (10) (11) (12) 108 The last experiment concerns a context where the PIFuzzy gains are found by solving the following nonlinear constrained optimization problem, where the cost function was chosen as a quadratic performance index involving the penalized control error and the control action, and assuming the system dynamics described by a nonlinear model. K k=0 2 2 [ y(k) − r(k)] + [0.8u(k − 1)] ) subject to the system dynamics and 0 ≤ y(k) ≤ 60, k = 1, ..., NP (14) (15) 0 ≤ u(k) ≤ 5, k = 0, ..., NP − 1 (16) 0 ≤ Ke (17) 0 ≤ K∆e (18) K∆u ≥ 0 (19) Temperature [Cº] min (N P X 45 40 35 Output Reference 30 10 20 30 40 50 60 70 50 60 70 Time [s] 5 4.5 4 3.5 Input [V] with u(k) given by: u(k) = u(k − 1) + K∆u × ∆u(k) (20) The nonlinear model of the system is described by a three-layered feedforward neural network with sigmoidal activation functions in the hidden layer, and linear activation functions for the output layer. In order to capture the underlying system’s dynamics the neural network was trained offline using the Levenberg-Marquardt algorithm, available in the MATLAB Neural Network Toolbox, and subsequently validated on a different data set. Equation (21) describes the system dynamics embedded in the training data set. 0 3 2.5 2 1.5 1 T 6.25 −7.74 −1.16 −1.81 15.45 −13.38 −2.54 −0.05 y(k) = 25.39 × tangh 7.50 15.35 −5.26 −11.50 2.20 6.53 25.15 −5.92 −0.30 0.13 −0.01 −2.28 " # 1.67 y(k − 1) × y(k − 2) + 13.74 −14.52 u(k − 1) 0.35 (21) Fig. 8 shows the closed loop system response for the offline gains optimization. As can be observed, the closed system response is quite satisfactory, exhibiting short settling time and lacking of any overshoot. To enable a comparative assessment in terms of performance for the PI-Fuzzy controllers considered in this work the root mean squared of error (RMSE) given according to (22) and the root mean squared of control action increment (RMSI) given according to (23) for each controller are presented in Table 2 . v u PN T u k=1 [y(k) − r(k)] [y(k) − r(k)] t RM SE = PN T k=1 r(k) r(k) (22) 109 0.5 0 0 10 20 30 40 Time [s] Fig. 8. PI-FLC with offline gains optimization. RM SI = q T [u(k) − u(k − 1)] [u(k) − u(k − 1)] N (23) As can be inferred from Table 2 the performance of all the PI-Fuzzy controllers are of the same order of magnitude, with a slight outperformance for the optimal gains PIfuzzy controller. Although the corresponding closed loop performances are somehow similar, the ability to automate the tuning process taking into account the closed performance is invaluable, easing the underlying process of tuning. Table 2. Performance metrics. Tuning Approach Trial-and-Error Conventional based PI-Fuzzy controller Offline Optimization RMSE 0.0902 0.0937 Variance 0.0047 0.0095 0.0861 0.0044 4. CONCLUSIONS This paper addressed the problem of tuning the gains of Proportional plus Integral fuzzy controllers. The proposed approach takes into account the closed loop control system performance and is formulated in terms of a constrained nonlinear optimization problem. Results collected in a testbed demonstrated the effectiveness and pertinence of the proposed methodology, not only in terms of easing and automating the tuning task, but also in what the closed loop system performance and longevity of the system is concerned. REFERENCES Hamid Boubertakh, Mohamed Tadjine, Pierre-Yves Glorennec, and Salim Labiod. Tuning fuzzy pd and pi controllers using reinforcement learning. ISA Transactions, 49(4):543–551, 2010. URL http://dx.doi.org/ 10.1016/j.isatra.2010.05.005. Gang Feng. A survey on analysis and design of modelbased fuzzy control systems. 14(5):676–697, 2006. doi: 10.1109/TFUZZ.2006.883415. F. Herrera and M. Lozano. Fuzzy Evolutionary Algorithms and Genetic Fuzzy Systems: A Positive Collaboration between Evolutionary Algorithms and Fuzzy Systems, volume 1 of Intelligent Systems Reference Library. Springer Berlin Heidelberg, 2009. ISBN 978-3-642-01799-5. URL http://dx.doi.org/10.1007/978-3-642-01799-5_4. C. C. Lee. Fuzzy logic in control systems: fuzzy logic controller. i. 20:404–418, 1990. doi: 10.1109/21.52551. Han-Xiong Li and H. B. Gatland. Conventional fuzzy control and its enhancement. 26(5):791–797, 1996. doi: 10.1109/3477.537321. Dave Misir, Heidar A. Malki, and Guanrong Chen. A heuristic approach to determine the gains of a fuzzy pid controller. In Proceedings of the 1996 ACM symposium on Applied Computing, SAC ’96, pages 609–613, New York, NY, USA, 1996. ACM. ISBN 0-89791-820-7. doi: http://doi.acm.org/10.1145/331119.331468. URL http://doi.acm.org/10.1145/331119.331468. P. Pivonka. Comparative analysis of fuzzy pi/pd/pid controller based on classical pid controller approach. In Fuzzy Systems, 2002. FUZZ-IEEE’02. Proceedings of the 2002 IEEE International Conference on, volume 1, pages 541 –546, 2002. doi: 10.1109/FUZZ.2002.1005048. Alexander Schrijver. Theory of linear and integer programming. John Wiley & Sons, Inc., New York, NY, USA, 1986. ISBN 0-471-90854-1. H. O. Wang, K. Tanaka, and M. F. Griffin. An approach to fuzzy control of nonlinear systems: stability and design issues. 4(1):14–23, 1996. doi: 10.1109/91.481841. 110