USING A PLC TECOMAT TC600 AS A FUZZY REGULATOR IN THE PROBLEM OF AN INVERTED PENDULUM SYSTEM REGULATION Petr Želasko, Martin MoštČk, Miroslav Pokorný Faculty of Electrical Engineering and Computer Science VSB Technical University of Ostrava Department of Measurement and Control 17. listopadu 15, 708 33 Ostrava - Poruba, CZECH REPUBLIC
[email protected],
[email protected],
[email protected]
Abstract: This work solves a problem of the inverted pendulum system regulation using a fuzzy regulator. As this regulator has been used the programmable logic controller (PLC) Tecomat TC600, type 607. The PLC is connected to the personal computer (PC) by the use of a voltage converter and an industrial PC card PCI 1751. The PC works as a simulation device of the inverted pendulum system, where the simulation is performed by a program created in the Delphi programming language version 5. The fuzzy model used in the fuzzy regulator is designed directly for the inverted pendulum system. The whole application has been successfully tested and also very good results have been reached. Copyright ©2004 IFAC Keywords: Fuzzy control, Programmable logic controller, Regulation, Inverted pendulum, System model, Simulation, Tests
1. INTRODUCTION This paper solves a problem of the inverted pendulum regulation. The inverted pendulum system is very difficult to regulate, because it is unstable. Closely said, it has only one stable point, but if it is forced to leave this point, it will never return to it by itself again. So a regulator can’t be designed using traditional methods here and the regulation must be solved in some other way. A very good approach how to solve the problem is lying in the use of a fuzzy model as a regulation mechanism (Rojek, et al., 2000). So at the first step a fuzzy model was designed and implemented to the programmable logic controller (PLC) Tecomat TC600 type 607 (or TC607). Then a simulation program, which simulates the inverted pendulum system, has been created in a personal computer (PC)
using the Delphi 5 programming language. Next, the connection between the PLC fuzzy regulator and the simulated system in the PC has been made using an industrial PC card PCI 1751 and a voltage converter. And as the last step the parameters of the fuzzy regulator were experimentally set (these parameters are gain coefficients of the inputs and output) so that the system is able to function properly. After the fuzzy regulator was designed, it has been tested with many different settings of the inverted pendulum parameters (these parameters are friction coefficient, acceleration of gravity, weight of a bob at the end of a pole, length of the pole from the attachment point on a wagon to the bob’s centre of gravity) and also with various starting conditions (values of heeling angle and angular velocity).
In the next paragraphs are described single components of the whole system. 2. THE INVERTED PENDULUM SYSTEM The inverted pendulum system is shown in the following figure.
Fig. 2. The inputs definition of the designed fuzzy model Type of fuzzy model used: Takagi-Sugeno Rule base:
Fig. 1. The inverted pendulum system The system is consisting of a wagon with four wheels, which are moving by the force of an engine situated inside the wagon. The moment of the wagon is labeled by the letter M. The wagon can’t turn so it is moving only forward and back. On the wagon there is situated a pole of the inverted pendulum, which is moveably attached to the body of the wagon and can move only in the plane perpendicular to the wheels axles. Length of the pole is labeled by the letter l. At the end of the pole there is a bob, whose weight is labeled by the letter m. Behavior of the inverted pendulum system is described by the following differential equation (simplified description).
M k t M
g l
sin M
M 2 ml
IF IF IF IF IF IF IF IF IF IF IF IF IF
(M IS NH) (M IS NS) (M IS NS) (M IS NS) (M IS ZR) (M IS ZR) (M IS ZR) (M IS ZR) (M IS ZR) (M IS PS) (M IS PS) (M IS PS) (M IS PH)
AND AND AND AND AND AND AND AND AND AND AND AND AND
(dM IS ZR) (dM IS NS) (dM IS ZR) (dM IS PS) (dM IS NH) (dM IS NS) (dM IS ZR) (dM IS PS) (dM IS PH) (dM IS NS) (dM IS ZR) (dM IS PS) (dM IS ZR)
THEN THEN THEN THEN THEN THEN THEN THEN THEN THEN THEN THEN THEN
M1 = -0.8 M2 = -0.4 M2 = -0.4 M3 = 0 M1 = -0.8 M2 = -0.4 M3 = 0 M4 = 0.4 M5 = 0.8 M3 = 0 M4 = 0.4 M4 = 0.4 M5 = 0.8
Defuzzyfication: 5
¦c M i
M
i
i 1 5
¦c
i
i 1
Mi are values of individual regressive functions from M1 to M5 and ci are values of their cutting coefficients coming out from antecedents of the rules.
(1)
Meaning of symbols in the equation (1): kt g [m/s2] m [kg] l [m]
- friction coefficient, - acceleration of gravity, - weight of a bob at the end of a pole, - length of the pole from the attachment point on a wagon to the bob’s centre of gravity, M [Nm] - wagon’s moment affecting the pendulum’s movement, M [rad] - heeling angle of the inverted pendulum,
4. REGULATION OF THE INVERTED PENDULUM SYSTEM Because of lack of money, which were available for solving this project, a real hardware model of the inverted pendulum system couldn’t be built. So the system has been simulated using a PC and a simulation program specially created for this project and the inverted pendulum system. The block diagram of the regulation loop is shown in the next figure.
The heeling angle M = 0 rad means the upstanding position of the pendulum. 3. THE DESIGNED FUZZY MODEL USED IN THE FUZZY REGULATOR Inputs definition:
(2)
Fig. 3. The block diagram of the regulation loop
In the figure above there is a PC which provides the simulation of the inverted pendulum system and communicates with the PLC TC607 using an industrial card Advantech PCI 1751 interface located directly in the PC. Data composed from two variables M (heeling angle) and dM (angular velocity) are sent to the industrial card PCI 1751 and then are sent by a digital line to the voltage modifier to adjust digital voltage levels from 0V (low level) and +5V (high level) to 0V (low level) and 24V (high level) and then to the PLC Tecomat TC607. According to the data received the PLC sets the value of the action variable (moment of the wagon’s motor) and sends it by the digital line to another voltage modifier, which adjusts the digital voltage levels back from 0 to 24V to 0 to 5V and sends the value to the PC using the PCI 1751 card’s support. The PC modifies parameters of the inverted pendulum system and the whole loop continues again. Simple parts of the block diagram are more closely described in the following subparagraphs. 4.1 The PLC Tecomat TC600 The PLC Tecomat TC600 is a programmable logic controller, which has been used in various applications in many industrial processes (PLC Handbook, 2002). As requested by these processes, the Tecomat TC600 (as well as all the other PLCs) is characterized by its reliability and speed in controlling applications in industrial zones. In this application the type 607 of the Tecomat TC600 series is used. This type contains 20 fast transistor digital inputs and 20 fast transistor digital outputs as a communication interface with other devices. To program the PLC Tecomat TC600 with the fuzzy model from the paragraph 3 to create a fuzzy regulator were used the special programming software MOSAIC and additional instructions (FZ, DFZ, ANF and ORF) supporting the creation of simple fuzzy applications from another special programming software XPRO. 4.2 The PLC program code #usi #usi #usi #usi #def #def #def #def
ufuz = fz udfz = dfz uanf = anf uorf = orf FUZ usi ufuz DFZ usi udfz ANF usi uanf ORF usi uorf
#table word FuzzySets = -32767, -32767, -26214,-13107, -26214, -13107, -13107, 0, -13107, 0, 0, 13107, 0, 13107, 13107, 26214, 13107, 26214, 32767, 32767
#table word Singletons = -26214, -13107, 0, #reg #reg #def #reg #reg #reg
word word Motor word word word
P 60 GetAngle: LD WR RET
Angle Speed YW0 AngleF[5] SpeedF[5] MotorF[5]
XW0 Angle
GetSpeed: LD WR RET
XW0 Speed
NullMotor: LD WR RET
0 YW0
Regulate: ;Fuzzyfication LD indx FuzzySets LD indx AngleF LD Angle FUZ LD indx FuzzySets LD indx SpeedF LD Speed FUZ ;Rules for M1 LD AngleF[0] LD SpeedF[2] ANF LD AngleF[2] LD SpeedF[0] ANF ORF WR MotorF[0] ;Rules for M2 LD AngleF[1] LD SpeedF[1] ANF LD AngleF[1] LD SpeedF[2] ANF ORF LD AngleF[2] LD SpeedF[1] ANF ORF WR MotorF[1] ;Rules for M3 LD AngleF[1] LD SpeedF[3] ANF LD AngleF[2] LD SpeedF[2] ANF ORF LD AngleF[3] LD SpeedF[1] ANF ORF WR MotorF[2] ;Rules for M4 LD AngleF[2] LD SpeedF[3] ANF
13107, 26214
LD LD ANF ORF LD LD ANF ORF WR
AngleF[3] SpeedF[2] AngleF[3] SpeedF[3] MotorF[3]
;Rules for M5 LD AngleF[2] LD SpeedF[4] ANF LD AngleF[4] LD SpeedF[2] ANF ORF WR MotorF[4] ;Defuzzyfication LD indx LD indx DFZ WR Motor RET E 60
Singletons MotorF
P 0 ;Inputs reading LD X2.0 CAD GetAngle LD WR
X2.0 Y2.0
LD CAD
X2.1 GetSpeed
LD WR
X2.1 Y2.1
LD CAD
X2.2 NullMotor
LD WR
X2.2 Y2.2
;Fuzzy regulation LD X2.3 CAD Regulate LD WR
X2.3 Y2.3
E 0
The above shown PLC TC600 program code is very short and simple but fully functional in the process of fuzzy regulation of the inverted pendulum system. It can’t be fully understood without knowledge of the communication protocol used to communicate with the connected PC, but it is shown here mainly because of understanding the fuzzy model implementation using the special instructions FZ (fuzzyfication), DFZ (defuzzyfication), ANF (fuzzy AND) and ORF (fuzzy OR) from the XPRO programming software. Any Takagi-Sugeno fuzzy model consisted of input fuzzy variables, which are using trapezoidal (or triangular) membership functions to formulate its linguistic values, and regressive functions constructed only from absolute parts (constants) in consequents of the rules can be very simply implemented by the use of these instructions, like shown in the program above.
4.3 The Industrial PC Card Advantech PCI 1751 The PCI 1751 is an industrial PC interface card developed by the Advantech Co., Ltd. (User’s manual, 1998). It creates an interface between a PC and other industrial devices, which use many digital TTL inputs and outputs to communicate with the PC. The PCI 1751 allows the PC to use 48 TTL digital I/O lines. Each of these lines can be easy configured as input or output and software coupled into singlebit, 8-bit or 16-bit ports. Other features of the card are for example interrupts handling, triggering external devices with the interrupt, two 16-bit timers or one 16-bit counter. But these features are not used in the inverted pendulum regulation process. While communicating with the PLC, 20 digital TTL lines as inputs and 20 digital TTL lines as outputs are used. So 8 lines are not used and are reserved for various possibilities of application’s upgrades. The PCI 1751 card also includes software libraries written in various programming languages to easy support procedures of sending and receiving single bits, bytes (in 8-bit ports configuration) or words (in 16-bit ports configuration). 4.4 The Voltage Level Modifier
Fig. 4. One channel of the voltage level modifier (schematic diagram) The voltage level modifier, which is divided into two blocks in the block diagram in the figure 3, is in fact integrated into one part. This modifier is composed from twenty same parts, showed in the figure 4. Each part supports one bi-directional data line between the PLC and the PC. PLC IN and PLC OUT are inputs and outputs of the PLC and similarly PC IN and PC OUT are inputs and outputs of the PC. 4.5 The Simulation and Visualization Software of the Inverted Pendulum As was written above, a real hardware model of the inverted pendulum system wasn’t available, so that’s why an alternative solution of the problem had to be used and this solution is a simulation of the inverted pendulum system. The mathematical model of the inverted pendulum is described above in the paragraph 2. Very important is the fact, that the simulator simulates only the inverted pendulum
system, not the regulator, which is represented by the real PLC in this application. Delphi version 5 has been used here as a programming language. This programming environment is very good because of its easy creation of projects, graphical interface of the program also easy to create and possibility to use many predefined objects, API procedures and other extensions, which are doing from this programming environment a very good and user friendly programming tool. Because of its object approach to the project creation, the program code is very well readable and simple methods of used objects are creating themselves automatically, so most of the programming lies only in filling empty methods of various graphical objects placed in the program form. It also gives you a possibility to use threads and to build a parallel project in this way with many in parallel executed threads. The inverted pendulum system simulator has been also built using threads. There is a main thread, which controls a main program form (as buttons pressing or filling the text fields), and there is also a second thread, which is doing all the numerical calculations of the differential equation describing the model of the pendulum in each simulation time step, supports the whole communication protocol between the PC and the PLC and is also displaying values of the heeling angle, the angular velocity and the wagon’s moment using text fields and the graphical representation in each simulation time step, so the program is not only the simulator of the inverted pendulum, but also the graphical interface between the user and devices and also the visualization tool to watch progress and results of the simulation. The main window of the program is shown in the figure below (figure 5). This window contains text fields, buttons and graphics windows to support the simulation control and the visualization process. The section Multipliers contains three text fields for setting gains of inputs and output of the PLC, because it uses normalized ranges of input and output variables to one interval to cover the whole range of numeric types used. By changing these gains, the regulator can be tuned to receive better results of the regulation. The gains were experimentally set to the values shown in the figure 5 to obtain very good regulation results. Using the Motor active check field the regulator can be turned on or off. In the section Parameters the parameters of the inverted pendulum and starting values (placed in text fields at the bottom of the program’s window) of the heeling angle (Angle), the angular velocity (Speed) and also the duration of the simulation (Time) can be set. The program can be easily started, stopped or exited using buttons at the bottom of the program’s window. Three graphics windows show the heeling angle, the angular velocity and the moment of the wagon
(Motor) during the whole simulation process. Also the fields at the bottom of the program’s window are showing the same values as graphic windows during the simulation run.
Fig. 5. The simulation and visualization program 5. TESTING THE APPLICATION During the application testing many tests were done for various settings of the inverted pendulum parameters (length of the pole, weight of the bob, friction coefficient, acceleration of gravity) and starting values (heeling angle, angular velocity) and all of them showed that the simulation of the inverted pendulum’s behavior is very realistic and the regulation process always moved the pendulum back to its stable position in very short time. There are some tests showed in the figures below. They are done for different settings of pendulum parameters and also different starting values. Settings 1: Parameters: kt = 1, g = 9.81 [m/s2], m = 1 [kg], l = 1 [m] Starting values: M = 0.5 [rad], dM = 0.5 [rad/s]
Fig. 6. Simulation for settings 1 without regulation
Fig. 7. Simulation for settings 1 with regulation Settings 2: Parameters: kt = 1, g = 9.81 [m/s2], m = 5 [kg], l = 0.5 [m] Starting values: M = 0.5 [rad], dM = 0.5 [rad/s]
Fig. 10. Simulation for modified settings 2 with regulation 6. CONCLUSION It is clear, that a simulation of the inverted pendulum system doesn’t match the real character of its behavior. But one of the characteristics of a fuzzy regulator is its robustness and that’s why the fuzzy regulator set to regulate a simulated system shouldn’t have any problems with regulating the real one. Simulated systems are also good for robustness testing of regulators, because of their easy parameters changing. The fuzzy regulator we used in this application has been tested with various modifications of the inverted pendulum parameters and every time it reached very good results (some tests were already shown in the paragraph 5). In the future this application will be available for students of the applied artificial intelligence and the system control using expert systems.
Fig. 8. Simulation for settings 2 without regulation ACKNOWLEDGEMENT The support for this research work has been provided by the GACR project 106/02/1128 “Rationalization in control of melt in steelworks with usage of the expert system”. REFERENCES
Fig. 9. Simulation for settings 2 with regulation Modified settings 2: Parameters: kt = 1, g = 9.81 [m/s2], m = 5 [kg], l = 0.5 [m] Starting values: M = 0.8 [rad], dM = 1.2 [rad/s]
Rojek, R., K. Bartecki and J. Korniak (2000). Zastosowanie sztucnych sieci neuronowych i logiki rozmytej w automatyce (The application of neural networks and fuzzy logic in automation), ISSN 1427-9932, Politechnika Opolska PLC Handbook (2002). Technical Equipment of TC600 Programmable Logic Controllers, Teco a.s. User’s manual (1998). PCI-1751 48-bit Digital Input/Output Card for PCI Bus, Advantech Co., Ltd., Taiwan