Design and Implementation of a Hybrid Fuzzy Controller Using VHDL

10
Design and Implementation of a Hybrid Fuzzy Controller Using VHDL IsmaelMill´an 1,a , Oscar Montiel 1 , Roberto Sep´ ulveda 1 , and Oscar Castillo 2 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 compari- son with the analog counterpart has impacted the world of controllers by replac- ing 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 con- trollers 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 Proportional- Integral-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. springerlink.com c Springer-Verlag Berlin Heidelberg 2008

Transcript of Design and Implementation of a Hybrid Fuzzy Controller Using VHDL

Design and Implementation of a Hybrid FuzzyController Using VHDL

Ismael Millan1,a, Oscar Montiel1, Roberto Sepulveda1, and Oscar Castillo2

1 Centro de Investigacion y Desarrollo de Tecnologıa Digital (CITEDI- IPN)Av. del Parque No.1310, Mesa de Otay, 22510, Tijuana, BC, Mexico{o.montiel,r.sepulveda}@ieee.org

a M.S. Student of [email protected]

2 Division of Graduate Studies and Research,Calzada Tecnologico S/N, Tijuana, [email protected]

Abstract. It is presented a novel hybrid controller that combines the benefits ofclassical controllers and fuzzy logic to improve the system response in tracking. Thedesign was developed in VHDL for a posterior FPGA implementation. The code wassimulated using Simulink and Xilinx System Generator (XSG) that allows to simulatethe code of the final FPGA target. Several comparative experiments in soft-real timewere conducted using a geared DC motor and the results are commented.

1 Introduction

The rapid development of digital technology and its decreasing cost in compari-son with the analog counterpart has impacted the world of controllers by replac-ing analog solutions with digital proposals because they offer several advantagessuch as a considerable time reduction in the design stage, improvements onsystem reliability and performance, elimination of discrete tuning components,and the possibility of including various performance enhancements. Digital con-trollers can solve problems with enough high complexity to be tackled withanalog technology [1, 2].

Nowadays, no matter how complicated the control of a plant might be, themajority of control loops in industrial control systems are using a Proportional-Integral-Derivative (PID) controller type or subtype. There are several ideasto implement a PID controller to overcome the disadvantages of linear PIDcontrollers based on difference equations. Some of these ideas transform a linearPID 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 discretedigital logic, Digital Signal Processor (DSP) or microcontroller systems, usingdedicated hardware for specific applications like Application-Specific IntegratedCircuit (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.springerlink.com c© Springer-Verlag Berlin Heidelberg 2008

438 I. Millan et al.

At present time, there are several digital techniques to implement a digitalcontroller. Conventional PID controllers are still being a key component in in-dustrial control because they are simple and provide useful solutions to manyimportant industrial processes [5].

Although the extensive use of conventional PID controllers and the imple-mentation 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 afrustrating and time-consuming experience if the nonlinearities of the plantbecomes more accentuated. There are several algorithms to tune or auto-tune PID controllers, but in some situations, when the system becomes toocomplex, where the conventional PID controller would not work, no matterhow 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 Fuzzyimplementation of a PID structure (FPID) has demonstrated to be a successfulidea 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 beused 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 tech-

niques.• 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 solutionsin the sense of mixing conventional controllers with fuzzy, neural or neurofuzzycontrollers [9]. This proposal presents a controller, that is based in an imple-mentation of a PID controller in serial configuration, mixed with fuzzy logic toimprove the system response tracking a signal.

This work is organized as follows: Section 2 presents the formal proposal of thecontroller which is basically an incremental PID with fuzzy adjustment of theproportional 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 maincomponents can be identify: They are the proportional, integral and derivativeterms. The error signal e(k) is defined as (2), it is the difference between theprocess 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 ofrectangular integration. In this equation, Kp, Ki, and Kd are parameters relatedto the gain of each term; Ts, Ti, and Td are the sampling period, the integraltime, and the derivative time, respectively.

u(n) = Kpe(n) +Ki

Ti

n∑j=1

e(j)Ts + KdTde(n) − e(n − 1)

Ts(1)

e(k) = y(k) − r(k) (2)The algorithm given in (1) is seldom used in practical applications since im-provements in the overall performance can be obtained. In this work, a serialrealization of this controller known as incremental controller was used. The firststage consists of a PD controller, hence (1) is transform to (3), the second stageis the integral part that is calculated with (4); in this way, the controller outputcan be rewritten as (5).

upd(n) = Kpe(n) + KdTde(n) − e(n − 1)

Ts(3)

ui(k) =Ki

Ti

n∑j=1

e(j)Ts (4)

u(k) =Ki

Ti

n∑j=1

(Kpe(n) − KdTd

e(n) − e(n − 1Ts

)Ts (5)

In this proposal Kp is a fuzzy input-output mapping, equation (5) can be ex-pressed in fuzzy terms where �Kp(r(k)) is representing a FIS, hence the fuzzyoutput controller u� is (6),

u�(k) =Ki

Ti

n∑j=1

(�Kp(r(k))e(n) − KdTd

e(n) − e(n − 1Ts

)Ts (6)

Since the goal is to carry out the controller to an FPGA implementation, eachstage 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 mainblock labeled PID is the serial implementation of the incremental controllerdescribed by (5). In Figure 1, there is a summing block that produces the errorsignal and it is connected to a display, we used this block to monitor the valuesof this signal for debugging, the same implementation is also into the PID blockto achieve the controller action. The innovative part is in the Kp input of thePID block, where a fuzzy selection of this value is achieved according to theplant characteristic to improve the tracking of a reference signal. The plant is ageared DC motor model GM9236S025-R1 [11].

440 I. Millan et al.

Fig. 1. Controller Simulink Model. The FIS is connected to the input Kp of the PIDincremental controller.

2.2 Fuzzy Adjustment of Kp

The PID implementation based on equation (5) has the characteristic of havingslow response tracking a signal. We are proposing to handle the Kp with afuzzy 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 VSS SM MB B

VB VB

of discourse of the FIS is the domain [0,70] and it is related to the maximalrevolutions per minute (RPM) of the motor. The fuzzy output is the variableKp. Figure 2 shows the membership functions for the input and output of theFIS, and Table 1 shows the fuzzy rules.

3 Experimental Results

To achieve the experiments that we are going to explain next, we implementeda test platform with the next main components:

1. Matlab from Mathworks 7.1 (R14), service pack 3.2. Xilinx ISE pack 8.2.03i3. Xilinx System Generator v8.24. BASIC STAMP editor v2.45. Two PARALLAX Boards with BS2P24 microcontroller.6. H-bridge module based on LMD18200 from National Semiconductor.7. DC Servo Motor GM9236S025-R1 500 CPR.8. Power Supplies.

The control goal of the experiments is to maintain the speed of the DC Motorand to eliminate the control error. In the first experiment, we used the classicalcontroller to illustrate the tracking problem.

3.1 Experiment 1. Classical Controller

Figure 3 shows the system response when the target is to maintain a constantspeed of 50 RPM, Figure 4 shows the response of the same controller trackinga signal, the changes of speed that we used are 50, 40,30,40,50 RPM. Figure 5shows the tracking error when the classical controller was used in the aforemen-tioned serial configuration. Figure 6 shows the effect of using different Kp gainsvalues in a classical controller.

3.2 Experiment 2. Hybrid Fuzzy Controller

The control goals of this experiment are the same of Experiment 1, the differenceis that the proposed hybrid fuzzy controller was used. Hence, Figure 7 shows thesystem response for tracking, Figure 8 presents the error when the controller

442 I. Millan et al.

0 20 40 60 80 100 1200

10

20

30

40

50

60

Time(sec)

Sp

eed

(ra

d/s

ec)

Speed control

Fig. 3. Experiment 1. Constant speed of 50 RPM.

0 20 40 60 80 100 1200

10

20

30

40

50

60

Time(sec)

Sp

eed

(ra

d/s

ec)

Speed control

Fig. 4. Experiment 1. Speed control with changes of speed.

tracks the signal. It is implicit that the controller does not have any problemworking as regulator. Figure 9 shows how the response change when the FIS ismodified, 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 worktracking a signal. Figure 12 shows the corresponding tracking errors. Actually itis straightforward to appreciate which controller has the faster response trackinga signal.

Design and Implementation of a Hybrid Fuzzy Controller Using VHDL 443

0 20 40 60 80 100 120−50

−40

−30

−20

−10

0

10

20

Time(sec)

Err

or

(rad

/sec

)

Tracking error

Fig. 5. Experiment 1. System response error when tracking a signal, using a classicalcontroller.

0 20 40 60 80 100 1200

10

20

30

40

50

60

70

Time (sec)

Spe

ed (

rad/

sec)

Speed Control with differents Kp

Kp=1.1Kp=1.2Kp=1.3Kp=1Kp=0.9Kp=0.8Kp=0.7

Fig. 6. Experiment 1. Effect of using different Kp gain values in a classical controller.

0 50 100 150 2000

10

20

30

40

50

60

70

80

Time(sec)

Sp

eed

(ra

d/s

ec)

Speed control with Fuzzy adjusment of Kp

PID VHDL with Fuzzy KpIdeal Response

Fig. 7. Experiment 2. Control with changes of speed, fuzzy adjustment of Kp.

444 I. Millan et al.

0 50 100 150 200−60

−40

−20

0

20

40

60

Time(sec)

Err

or

(rad

/sec

)

Control Error with Fuzzy adjusment of Kp

Fig. 8. Experiment 2. Control error.

0 50 100 150 2000

10

20

30

40

50

60

70

80

Time(sec)

Sp

eed

(ra

d/s

ec)

Speed control with Fuzzy adjusment of Kp

PID VHDL with Fuzzy KpIdeal Response

Fig. 9. Experiment 2. Control with changes of speed and fuzzy adjustment of Kp anddifferent membership functions.

0 50 100 150 200−60

−40

−20

0

20

40

60

80

Time(sec)

Err

or

(rad

/sec

)

Control Error with Fuzzy adjusment of Kp

Fig. 10. Experiment 2. Control error.

Design and Implementation of a Hybrid Fuzzy Controller Using VHDL 445

0 20 40 60 80 100 1200

10

20

30

40

50

60

70

Time(sec)

Sp

eed

(ra

d/s

ec)

Speed control (PID VHDL vs. Fuzzy PID)

Fuzzy PID with Deffuzification in VHDLIdeal ResponsePID VHDL

Fig. 11. Experiment 3. Tracking a speed signal (Classical controller in VHDL vs.Fuzzy PID in VHDL).

0 20 40 60 80 100 120−40

−30

−20

−10

0

10

20

30

40

50

Time(sec)

Err

or

(rad

/sec

)

Control Error (PID VHDL vs. Fuzzy PID with Defuzzification in VHDL

Fuzzy PID with Defuzzification in VHDLPID VHDL

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 aclassical controller using a FIS to improve the system response when it is trackinga signal. We tested only one kind of classical PID controller to control the speedof a DC motor, and all the comparisons using the hybrid controller proposal weremade against this controller. It was shown how the controller performance wasincrease when we hybridize the classical controller. All methods were tested usingVHDL codification for a posterior FPGA implementation. The test platformworked well to achieve the experiments, the results can be improved by using ahard-real time platform. The use of Simulink and Xilinx System Generator is agood option for a fast prototyping since minors modification have to be done inorder to have a functional controller embedded into an FPGA.

References

1. A Prodic and Dragan Maksimovic, Digital PWM Controller and Current Estimatorfor A Low-Power Switching Converter. In: 7th IEEE Workshop on Computers inPower Electronics, COMPEL 2000, Blacksburg, VA, July 16-18 (2000)

446 I. Millan et al.

2. Wu, A.M., Xiao, J., Markovic, D., Sanders, S.R.: Digital PWM control: applica-tion in voltage regulation modules. In: 30th Annual IEEE on Power ElectronicsSpecialists Conference, 1999. PESC 1999, vol. 1, pp. 77–83 (Auguest 1999)

3. Oldfield, J., Dorf, R.: Field-Programmable Gate Arrays. In: Reconfigurable Logicfor Rapid Prototyping and Implementation of Digital Systems. John Wiley & Son,Chichester (1995)

4. Miguel, A., Rodrıguez, V., Sanchez Perez, J.M., Juan, A., Pulido, G.: Advances inFPGA Tools and Techniques. Microprocessors and Microsystems. Elsevier Science,Amsterdam (2005)

5. Quevedo, J., Escobet, T.: Digital Control 2000: Past, Present and Future of PIDControl. 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, TechnicalUniversity 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., Sepulveda, R., Melin, P., Castillo, O., Porta, M.A., Meza, I.M.: Perfor-mance of a Simple Tuned Fuzzy Controller and a PID Controller on a DC motor.In: Proceedings of the 2007 IEEE Symposium on Foundations of ComputacionalIntelligence (FOCI 2007), Hawaii, U.S.A, pp. 531–537 (2007)

9. Cirstea, M.N., Dinu, A., Khor, J.G., McCormick, M.: Neural and Fuzzy LogicControl of Drives and Power Systems, Newnes, Great Britain (2002)

10. Chu, P.P.: FPGA Prototyping by VHDL Examples: Xilinx Spartan-3. Wiley-Interscience (2008)

11. Pittman, D.C.: Servo Motor, Data Sheet available,http://www.clickautomation.com/PDF/items/GM9236S025.pdf