Design and Implementation of a Hybrid Fuzzy Controller Using VHDL Ismael Mill´an1,a , Oscar Montiel1 , Roberto Sep´ ulveda1 , and Oscar Castillo2 1
Centro de Investigaci´ on y Desarrollo de Tecnolog´ıa Digital (CITEDI- IPN) Av. del Parque No.1310, Mesa de Otay, 22510, Tijuana, BC, M´exico {o.montiel,r.sepulveda}@ieee.org a M.S. Student of CITEDI-IPN
[email protected] 2 Division of Graduate Studies and Research, Calzada Tecnol´ ogico S/N, Tijuana, M´exico
[email protected]
Abstract. It is presented a novel hybrid controller that combines the benefits of classical controllers and fuzzy logic to improve the system response in tracking. The design was developed in VHDL for a posterior FPGA implementation. The code was simulated using Simulink and Xilinx System Generator (XSG) that allows to simulate the code of the final FPGA target. Several comparative experiments in soft-real time were conducted using a geared DC motor and the results are commented.
1 Introduction The rapid development of digital technology and its decreasing cost in comparison with the analog counterpart has impacted the world of controllers by replacing analog solutions with digital proposals because they offer several advantages such as a considerable time reduction in the design stage, improvements on system reliability and performance, elimination of discrete tuning components, and the possibility of including various performance enhancements. Digital controllers can solve problems with enough high complexity to be tackled with analog technology [1, 2]. Nowadays, no matter how complicated the control of a plant might be, the majority of control loops in industrial control systems are using a ProportionalIntegral-Derivative (PID) controller type or subtype. There are several ideas to implement a PID controller to overcome the disadvantages of linear PID controllers based on difference equations. Some of these ideas transform a linear PID controller into a PID-like structures of fuzzy controllers. Digital controllers can be implemented in different hardware platforms, including personal/industrial computers, industrial boards based on discrete digital logic, Digital Signal Processor (DSP) or microcontroller systems, using dedicated hardware for specific applications like Application-Specific Integrated Circuit (ASIC) or in a Field Programmable Gate Array (FPGA) [3, 4]. O. Castillo et al. (Eds.): Soft Computing for Hybrid Intel. Systems, SCI 154, pp. 437–446, 2008. c Springer-Verlag Berlin Heidelberg 2008 springerlink.com
438
I. Mill´ an et al.
At present time, there are several digital techniques to implement a digital controller. Conventional PID controllers are still being a key component in industrial control because they are simple and provide useful solutions to many important industrial processes [5]. Although the extensive use of conventional PID controllers and the implementation of new techniques to improve them, they have significant limitations, because they work basically for linear processes. Some of the limitations are: • They do not work effectively controlling complex processes that are nonlinear, time-variant, with major disturbances, uncertainties, and large time delays. • They need to be tuned properly when the plant dynamics change. This is a frustrating and time-consuming experience if the nonlinearities of the plant becomes more accentuated. There are several algorithms to tune or autotune PID controllers, but in some situations, when the system becomes too complex, where the conventional PID controller would not work, no matter how it is tuned. • A conventional PID cannot be used as the core of an smart control system. The traditional structure of a PID controller has evolved, and the Fuzzy implementation of a PID structure (FPID) has demonstrated to be a successful idea for several reasons [6, 7], some of them are: • FPID uses every day words to establish the Fuzzy Inference System (FIS). The linguistic variables error, change of error, and integral of error can be used to handle the same signals than the conventional PID controller uses. • They can work as a linear or a non linear PID controller. • They can be smart, working in combination with other soft computing techniques. • The FPID has more parameters to adjust than conventional PID, but there are several effective methods to tune them [8]. Other ideas to implement digital controllers are focused in hybrid solutions in the sense of mixing conventional controllers with fuzzy, neural or neurofuzzy controllers [9]. This proposal presents a controller, that is based in an implementation of a PID controller in serial configuration, mixed with fuzzy logic to improve the system response tracking a signal. This work is organized as follows: Section 2 presents the formal proposal of the controller which is basically an incremental PID with fuzzy adjustment of the proportional gain, Section 3 is devoted to explain the experiments and results, and finally in Section 4 are the conclusions.
2 Controller Design for FPGA Implementation The standard representation of a PID controller is given in (1); where, three main components can be identify: They are the proportional, integral and derivative terms. The error signal e(k) is defined as (2), it is the difference between the process output y(k) and the set point r(k). The derivative term was obtained
Design and Implementation of a Hybrid Fuzzy Controller Using VHDL
439
using the backward difference method, and the integral term using the method of rectangular integration. In this equation, Kp , Ki , and Kd are parameters related to the gain of each term; Ts , Ti , and Td are the sampling period, the integral time, and the derivative time, respectively. u(n) = Kp e(n) +
n e(n) − e(n − 1) Ki e(j)Ts + Kd Td Ti j=1 Ts
e(k) = y(k) − r(k)
(1) (2)
The algorithm given in (1) is seldom used in practical applications since improvements in the overall performance can be obtained. In this work, a serial realization of this controller known as incremental controller was used. The first stage consists of a PD controller, hence (1) is transform to (3), the second stage is the integral part that is calculated with (4); in this way, the controller output can be rewritten as (5). upd (n) = Kp e(n) + Kd Td
ui (k) =
u(k) =
e(n) − e(n − 1) Ts
n Ki e(j)Ts Ti j=1
n Ki e(n) − e(n − 1 Kp e(n) − Kd Td Ts Ti j=1 Ts
(3)
(4)
(5)
In this proposal Kp is a fuzzy input-output mapping, equation (5) can be expressed in fuzzy terms where Kp (r(k)) is representing a FIS, hence the fuzzy output controller u is (6), n e(n) − e(n − 1 Ki u (k) = (6) Kp (r(k))e(n) − Kd Td Ts Ti j=1 Ts Since the goal is to carry out the controller to an FPGA implementation, each stage of the controller was developed using VHDL codification [10]. Five entities (blocks) were identified and implemented: Proportional, Derivative, Incremental, Decimal Substraction, and the Sampling Period block. 2.1
Controller Simulink Model
Figure 1 shows the Simulink model developed to test the controller. The main block labeled PID is the serial implementation of the incremental controller described by (5). In Figure 1, there is a summing block that produces the error signal and it is connected to a display, we used this block to monitor the values of this signal for debugging, the same implementation is also into the PID block to achieve the controller action. The innovative part is in the Kp input of the PID block, where a fuzzy selection of this value is achieved according to the plant characteristic to improve the tracking of a reference signal. The plant is a geared DC motor model GM9236S025-R1 [11].
440
I. Mill´ an et al.
Fig. 1. Controller Simulink Model. The FIS is connected to the input Kp of the PID incremental controller.
2.2
Fuzzy Adjustment of Kp
The PID implementation based on equation (5) has the characteristic of having slow response tracking a signal. We are proposing to handle the Kp with a fuzzy inference system (FIS) to reduce the aforementioned problem. The universe
Fig. 2. Membership functions of Input and Output of the FIS to achieve the Kp adjustment
Design and Implementation of a Hybrid Fuzzy Controller Using VHDL
441
Table 1. Map of Fuzzy Rules Reference r(k) Kp VS VS S S M M B B VB VB
of discourse of the FIS is the domain [0,70] and it is related to the maximal revolutions per minute (RPM) of the motor. The fuzzy output is the variable Kp . Figure 2 shows the membership functions for the input and output of the FIS, and Table 1 shows the fuzzy rules.
3 Experimental Results To achieve the experiments that we are going to explain next, we implemented a test platform with the next main components: 1. 2. 3. 4. 5. 6. 7. 8.
Matlab from Mathworks 7.1 (R14), service pack 3. Xilinx ISE pack 8.2.03i Xilinx System Generator v8.2 BASIC STAMP editor v2.4 Two PARALLAX Boards with BS2P24 microcontroller. H-bridge module based on LMD18200 from National Semiconductor. DC Servo Motor GM9236S025-R1 500 CPR. Power Supplies.
The control goal of the experiments is to maintain the speed of the DC Motor and to eliminate the control error. In the first experiment, we used the classical controller to illustrate the tracking problem. 3.1
Experiment 1. Classical Controller
Figure 3 shows the system response when the target is to maintain a constant speed of 50 RPM, Figure 4 shows the response of the same controller tracking a signal, the changes of speed that we used are 50, 40,30,40,50 RPM. Figure 5 shows the tracking error when the classical controller was used in the aforementioned serial configuration. Figure 6 shows the effect of using different Kp gains values in a classical controller. 3.2
Experiment 2. Hybrid Fuzzy Controller
The control goals of this experiment are the same of Experiment 1, the difference is that the proposed hybrid fuzzy controller was used. Hence, Figure 7 shows the system response for tracking, Figure 8 presents the error when the controller
442
I. Mill´ an et al.
Speed control 60
50
Speed (rad/sec)
40
30
20
10
0
0
20
40
60
80
100
120
Time(sec)
Fig. 3. Experiment 1. Constant speed of 50 RPM.
Speed control 60
50
Speed (rad/sec)
40
30
20
10
0
0
20
40
60
80
100
120
Time(sec)
Fig. 4. Experiment 1. Speed control with changes of speed.
tracks the signal. It is implicit that the controller does not have any problem working as regulator. Figure 9 shows how the response change when the FIS is modified, and Figure 10 shows the control error with fuzzy adjustments of Kp . 3.3
Experiment 3. Comparisons
Figure 11 shows how the classical controller and the Hybrid fuzzy controller work tracking a signal. Figure 12 shows the corresponding tracking errors. Actually it is straightforward to appreciate which controller has the faster response tracking a signal.
Design and Implementation of a Hybrid Fuzzy Controller Using VHDL
443
Tracking error 20
10
Error (rad/sec)
0
−10
−20
−30
−40
−50
0
20
40
60
80
100
120
Time(sec)
Fig. 5. Experiment 1. System response error when tracking a signal, using a classical controller. Speed Control with differents Kp 70
60
Speed (rad/sec)
50
40
30
Kp=1.1 Kp=1.2 Kp=1.3 Kp=1 Kp=0.9 Kp=0.8 Kp=0.7
20
10
0
0
20
40
60 Time (sec)
80
100
120
Fig. 6. Experiment 1. Effect of using different Kp gain values in a classical controller.
Speed control with Fuzzy adjusment of Kp 80 70
Speed (rad/sec)
60 50 40 30 20 10 0
PID VHDL with Fuzzy Kp Ideal Response 0
50
100
150
200
Time(sec)
Fig. 7. Experiment 2. Control with changes of speed, fuzzy adjustment of Kp.
444
I. Mill´ an et al. Control Error with Fuzzy adjusment of Kp 60
40
Error (rad/sec)
20
0
−20
−40
−60
0
50
100
150
200
Time(sec)
Fig. 8. Experiment 2. Control error. Speed control with Fuzzy adjusment of Kp 80 PID VHDL with Fuzzy Kp Ideal Response
70
Speed (rad/sec)
60 50 40 30 20 10 0
0
50
100
150
200
Time(sec)
Fig. 9. Experiment 2. Control with changes of speed and fuzzy adjustment of Kp and different membership functions.
Control Error with Fuzzy adjusment of Kp 80
60
Error (rad/sec)
40
20
0
−20
−40
−60
0
50
100
150
200
Time(sec)
Fig. 10. Experiment 2. Control error.
Design and Implementation of a Hybrid Fuzzy Controller Using VHDL
445
Speed control (PID VHDL vs. Fuzzy PID) 70
60
Speed (rad/sec)
50
40
30
20 Fuzzy PID with Deffuzification in VHDL Ideal Response PID VHDL
10
0
0
20
40
60
80
100
120
Time(sec)
Fig. 11. Experiment 3. Tracking a speed signal (Classical controller in VHDL vs. Fuzzy PID in VHDL). Control Error (PID VHDL vs. Fuzzy PID with Defuzzification in VHDL 50 40
Error (rad/sec)
30 20 10 0 −10 −20 −30 −40
Fuzzy PID with Defuzzification in VHDL PID VHDL 0
20
40
60
80
100
120
Time(sec)
Fig. 12. Experiment 3. Tracking error of Figure 11.
4 Conclusions This proposal showed that it is a good option to handle the proportional gain of a classical controller using a FIS to improve the system response when it is tracking a signal. We tested only one kind of classical PID controller to control the speed of a DC motor, and all the comparisons using the hybrid controller proposal were made against this controller. It was shown how the controller performance was increase when we hybridize the classical controller. All methods were tested using VHDL codification for a posterior FPGA implementation. The test platform worked well to achieve the experiments, the results can be improved by using a hard-real time platform. The use of Simulink and Xilinx System Generator is a good option for a fast prototyping since minors modification have to be done in order to have a functional controller embedded into an FPGA.
References 1. A Prodic and Dragan Maksimovic, Digital PWM Controller and Current Estimator for A Low-Power Switching Converter. In: 7th IEEE Workshop on Computers in Power Electronics, COMPEL 2000, Blacksburg, VA, July 16-18 (2000)
446
I. Mill´ an et al.
2. Wu, A.M., Xiao, J., Markovic, D., Sanders, S.R.: Digital PWM control: application in voltage regulation modules. In: 30th Annual IEEE on Power Electronics Specialists Conference, 1999. PESC 1999, vol. 1, pp. 77–83 (Auguest 1999) 3. Oldfield, J., Dorf, R.: Field-Programmable Gate Arrays. In: Reconfigurable Logic for Rapid Prototyping and Implementation of Digital Systems. John Wiley & Son, Chichester (1995) 4. Miguel, A., Rodr´ıguez, V., S´ anchez P´erez, J.M., Juan, A., Pulido, G.: Advances in FPGA Tools and Techniques. Microprocessors and Microsystems. Elsevier Science, Amsterdam (2005) 5. Quevedo, J., Escobet, T.: Digital Control 2000: Past, Present and Future of PID Control. In: Proceedings of the IFAC Workshop, Terrassa, Spain, 5-7 April (2000) 6. Jantzen, J.: Tuning of Fuzzy PID Controllers, Tech. report no. 98-H 871, Technical University of Dnmark, Department of Automation, (September 30, 1998) 7. Tang, K.S., Man, K.F., Chen, G., Kwong, S.: An optimal fuzzy PID controller. Industrial Electronics. IEEE Transactions 48, 757–765 (2001) 8. Montiel, O., Sep´ ulveda, R., Melin, P., Castillo, O., Porta, M.A., Meza, I.M.: Performance of a Simple Tuned Fuzzy Controller and a PID Controller on a DC motor. In: Proceedings of the 2007 IEEE Symposium on Foundations of Computacional Intelligence (FOCI 2007), Hawaii, U.S.A, pp. 531–537 (2007) 9. Cirstea, M.N., Dinu, A., Khor, J.G., McCormick, M.: Neural and Fuzzy Logic Control of Drives and Power Systems, Newnes, Great Britain (2002) 10. Chu, P.P.: FPGA Prototyping by VHDL Examples: Xilinx Spartan-3. WileyInterscience (2008) 11. Pittman, D.C.: Servo Motor, Data Sheet available, http://www.clickautomation.com/PDF/items/GM9236S025.pdf