Home

University of Hertfordshire

image

Contents

1. eee Appendix D Flowchart to Configure Timers eene 26 xq 239 30 Ye Zhang vi Inverted Pendulum with ANFIS Controller Introduction Chapter 1 INTRODUCTION 1 1 Background 1 1 1 Inverted Pendulum Inverted pendulum also called pole on a cart is a classic inherently unstable system Fig 1 An inverted pendulum system consists of four inputs pol anple O pole angle velocity 0 cart position X and cart speed x and single output control force f By applying a sequence of right and left forces to the cart the pendulum can be balanced in upright and the cart works dynamically in the center of the rails Fig 1 1 Inverted pendulum 1 1 2 Control Methods in Inverted Pendulum Traditionally the controller design is based on the simplified linear model of an inverted pendulum system and the control force f is assumed to be a function of the four state variables Classical control theories have been proven successfully in inverted pendulum control such as PID Proportional Integral Derivative control method but most of them require considerable knowledge of the accurate system dynamic model and complicated mathematic analysis Nowadays with the development in Artificial Intelligence it is not necessary to build up any confusing non linear kinematic model A hot research direction is using leaming optimization algorithms like neural network to achieve the sel
2. First printing Chapter 1 amp 2 pp 1 60 2005 Ye Zhang 43 Inverted Pendulum with ANFIS Controller Appendix Appendix Appendix A Mechanical Drawings Fl i ae t 4 H ma E j E Ea E E E EN De d T a Ye Zhang 44 Inverted Pendulum with ANFIS Controller Appendix Unit mm Joint for ACE son UC Q 76 50 s 9 277 pe UU Set crew 10 00 555 01 9 0 2 00 Ye Zhang 45 Inverted Pendulum with ANFIS Controller Appendix Q lt I 2 2 E E e gt Looking e Appendix B Pin Output Code For ACE 128 Bit Pin correlation b7 b6 b5 b4 b3 b2 b1 bO p8 p7 p6 p5 p4 p3 p2 p1 A binary 1 denotes an open switch and a binary 0 denotes a closed switch Positions 0 127 are seen by a clockwise rotation of the shaft OraetHoram ora eer gavo cre ro cr 333835839 3393 5939259 2 o LDIEPIELITI 46 Ye Zhang Inverted Pendulum with ANFIS Controller Appendix C Schematic of Z8 MCU Development Board Appendix DI foras CONSOLE et 8 Ei E g M 4 T4LvC3N tO TMVC3A O 4 TA CONSO 1 T4LVCONSO 1 C fA E a 3 D art 10K Cont Ye Zhang 47 Inverted Pendulum with ANFIS Controller Appendix RE y ERR ill B
3. Installed in a PC with Windows XP OS ZDS II ZSEncore 4 7 0 for Z8 microcontroller configuration and for debugging and compiling the C programs Matlab 6 5 1 amp Simulink for ANFIS c ntroller simulation Fuzzy Logic Toolbox included Microsoft Hy per Terminal for monitoring the input data from sensors Microsoft Office Word PowerPoint Project amp Visio for report documentation 6 4 Chapter Summary This chapter discusses the time management and explains the actual timescales which has been revised according to the original one The main components used in this project and their costs are listed Also the necessary devices and software resource are described Ye Zhang 36 Inverted Pendulum with ANFIS Controller Conclusion amp Further Discussion Chapter 7 CONCLUSION AND FURTHER DISCUSSION 7 1 Conclusion The aim of this project is to implement an ANFIS controller with self learning ability into an inverted pendulum system and this controller should be able to k ep the system in dynamic balance that means the pole is standing upright on the cart and the cart is moving around the center of the track The principle of this control system is using a microcontroller MC to interface the real hardware parts with the software controller jn a host PC The status variables of the inverted pendulum system which are obtained fromthe sensors are sent to the ANFIS controller in MATLAB and simultaneously th
4. Inverted Pendulum with ANFIS Controller Introduction Chapter 7 Conclusion and further discussion Summarize the achievements in this project and comment on the final outcome The future work and improvement have been presented and discussed Ye Zhang 4 Inverted Pendulum with ANFIS Controller ANFIS Controller Design Chapter 2 ANFIS CONTROLLER DESIGN 2 1 What is ANFIS ANFIS Adaptive Network Based Fuzzy Inference System which is a fuzzy inference system implemented in the framework of adaptive network was first introduced by Roger Jang in University of California Berkeley 1993 3 Using a given input output data set ANFIS constructs a fuzzy inference system FIS whose membership function parameters are tuned adjusted using backpropagation training algorithm This learning ability allows the fuzzy systems to be modeled and modified just by these training data 2 1 1 Sugeno Fuzzy Inference System Fuzzy inference is a process of mapping from given input s to an output using the theory of fuzzy sets Fuzzy logic system is based on IF THEN rules Sugeno fuzzy rules are expressed in the following form Rule 1 Rule 2 IF x is A IF xis B AND x is A AND x isB AND x is A AND x isB THEN Jy f5 THEN y f x x X Sessel Rule N IF xis N AND x isN AND x is N THEN y f X X X Ye Zhang 5 Inverted Pendulum with ANFIS Controller ANFIS Controller Design
5. 0 Parity is disabled l Parity is enabled CTS Enable 0 CTS signal has no effect on the tranzmutter transmit enable control signal Receive Enable 0 Receiver disabled 1 Receiver enabled Transmit Enable 0 Transmitter disabled l Transmitter enabled 1 UART recognizes CTS signal as a Fig 4 4 UARTO Control 0 Register 4 4 Chapter Summary In this chapter the configuration of Z8 MCU has been described The GPIO is configured for reading data from the sensors and sending control signals as output Timer is configured as PWM lt signal generator and UART for serial port communication with the host PC After this configuration tlie Z8 MCU is capable to work as the interface between the hard ware system and the ANFIS cohftroller in host PC Ye Zhang 30 Inverted Pendulum with ANFIS Controller Implementation amp Testing Chapter 5 IMPLEMENTATION AND TESTING 5 1 Motion Control Unit The basic motor control circuit using H bridge is shown below Fig 5 1 5V Motor Voltage Q 10k Fig 5 1 Basic motor control cir cuit using H bridge To test this circuit at the first time a signal generator was used as a PWM signal source which provided the square wave signal with changeable duty And the Dir Pin3 was connected to ground GND as 0 input But the motor was not stopped even when I set the duty of the square signal at 5096 More strangely the H bridge was consuming a large a
6. So two flanged bearings are designed to hold the shaft substantially with the cart Furthermore there must b strict no movement between the pendulum and the shaft because the pendulum angle is measured by the optical encoder whose code wheel is fixed on the shaft Accordingly a bolt with nut has been lathed in one end of the shaft to grip the pole in stationary See AppendixA for mechanical dra wing 3 1 3 Driving Set The maindriving device is consisted of a motor an idle pulley and a belt In order to avoid any slippage between the driving wheel and the belt the best choice is a set of timing belt and pulley which have the gear teeth in mesh But unfortunately the timing belt is normally designed for heavy load applications in industry It is not easy to purchase a cheap slim long and flexible timing belt suitable for this inverted pendulum system At last a normal nylon string has been adopted as an alternative and the Ye Zhang 17 Inverted Pendulum with ANFIS Controller Hardware Design pulley is replaced by a small plastic wheel which is glued together with one gear wheel from the gearbox 3 2 Sensors To get all the 4 inputs two sensors are needed one for pendulum arid one for cart The principles of sensor selection are based on capacity feasibility reliability and price 32 1 Optical Encoder For pendulum the angle of the pole with respect to th absolute zero upright is measured A few
7. et 4 l LENS i I PHOTO l DIODES I l l l I l l dr l l wa l I Te E i PROCESSING SIGNAL CIRCUITRY 1 PROCESSING l CIRCUITRY GNO l 0 1 Gestas BOON snsmelsecaenioACoRaurieicupmde Soap ira a EMITTER SECTION CODE DETECTOR SECTION Fig 3 1 Optical encoder Output of optical encoder Fig 3 2 Channel A and B The final outputs are yielded from the IC comparators which process the signals generated by the photodiode The digital output of channel A is in 90 degrees out of phase with that of channel B whichji called as quadrature Channel I Index signal A pulse is generated once for each full rotation of the code wheel c gt j 24V 04v CH A 24V D4v CH B AMPLITUDE ROTATION Fig 3 2 Output waveforms The rotation direction can be derived by checking the signals that which channel is leading the other arid the position of pendulum can be derived by counting the pulses in a certain direction In this method an initial position absolute ZERO needs to be set with all movements being related to this position which is known as Incremental Encoding Ye Zhang 19 Inverted Pendulum with ANFIS Controller Hardware Design 3 2 2 Absolute Contacting Encoder ACE To measure the position of the cart on the track another sensor is required Comparing several possible sensors in the market this Absolute Contacting Encoder ACE has been
8. 100 Divide by 16 101 Divide by 32 110 Divide by 64 111 Divide by 128 Timer Input Output Polarity Operation of this bit is 2 function of the current operating mode of the timer Timer Enable 0 Timer is disabled 1 Timer is enabled Fig 4 2 Tmer1 Control 1 Register The Timer 1 PWM High and Low Byte TIPWMH and TIPWML registers are being defined and these two bytes PWMH 7 0 PWML 7 0 form a 16 bit value that is compared to the current 16 bit timer count When a match occurs the PWM output changes state The PWM output value is set by the TPOL bitin the Timer 1 Control 1 Register TI CTL 1 The PWM period is determined by the following equation Reload Value x Prescale PWM period s 4 1 System Clock Frequency Hz The desired frequency of the PWM signal is 100Hz PWM period 10ms and Prescale is set to 8 The system clock frequency of Z8F642 is 18 432MHz so the Reload Value is calculated to be 0x5A00 Hex The TPOL iS set to 1 so the ratio of the PWM Output High Time to the total period is calculated as follows PWM Value x 100 PWM Output High Time Ratio 96 4 2 Reload Value So changing the PWM Value in Timer PWM Byte Register TIPWMH and TIPWML which decides the duty cycle of the modulated PWM pulse can change the motor speed The flowchart of Z8 Timer configuration is illustrated in Appendix D 13 Ye Zhang 28 Inverted Pendulum with ANFIS Controller Configuration of
9. 2 MF for each inp t vanable in FIS and therefore only 16 2 rules It is evidenced that a 2 MF FIS is competent for the ANFIS controller design Motivated by this another ANFIS with 2 MF FIS is generated by the same training data Follow the same steps as previous Amazingly the result of this ANFIS controller is even better then that one of 3 MF The maximum initial pole angle is 1 1rad 263 which7means the pole can be handled in the range of around 120 degrees Fig 2 9 pole angles lrad 4 6 4 6 ZEN o Angle i 0 NE 4 6 en 2 i Cart Speed Fig 2 9 Simulation result of 2 MF ANFIS controller It is not easy to explain the reasons on the performance of two different ANFIS controllers because the training procedure is invisible The potential reason is that the 3 MF FIS has a more complicated structure which may be more specified for particular circumstance but less robust Ye Zhang 15 Inverted Pendulum with ANFIS Controller ANFIS Controller Design 2 5 Chapter Summary This chapter has introduced the theory of ANFIS also briefly explained the structure and its self learning process Then focusing on this application the ANFIS controller for an inverted pendulum system has been designed and some issues on it have been discussed Finally the ideal model is built up in Matlab Simulink environment and the ANFIS controller is generated from the training data and tested in the demo The results have illu
10. 4 T Configuration of GPIO deret e dort e t e eee NGG 4 2 Configuration of PWM cab mele etes 4 3 Configuration of UART terrier eet cerra ea c Meteo eee 4 4 Chapter Sumtnaty ute pee gie eet ee D e A recte ire tt CHAPTER 5 IMPLEMENTATION AND TESTING eere nennen 5 1 Motion Control Unit ccepit Rn RO reece 5 2 Checking the ACE Output e md eee ene eet erede 3 9 Pole and Cart System eee b HR geteilt a i pepe e t eet SAC hapter Summalty tuit wes tete debris mte d CHAPTER 6 PROJECT MANAGEMENT e eere nente entente no tnn nnn sn atn 6 1 Time Managerment 5 2 ey Re tem e RU i p Hep i e etin 6 2 Project COSTING 2 tritt RR eer OS ene bet temere lat e t nete 6 3 Equipments and Resources N Sws eeeereseseesessessesessessssesesttstereseesesesseeseesesessssesresteree 64 Chapter Summary Re eee eere re oe denter eee iet ke CHAPTER 7 CONCLUSION AND FURTHER DISCUSSION TL Conclusions eee eet eco oce Pee EE E S eu ee RN ETE OE ae 72 F rther DISGUSSIOIES s s e ose a deter eene derer E ere e Ee URL TELE ent REFERENCE 4 orerbbe Perth oae un tes a ia crt ide cua e VERE cost rT aa ESES Ea hid BIelelrs ug hj n f dd PEIN BUX C Appendix A Mechanical Drawings ei esee eene ener eren Appendix B Looking Up Table of ACE cete Appendix C Schematic of Z8 MCU Development Board
11. ANFIS controller design the improvement can be done by modifying the FIS structure and optimizing the training data Instead of the training data from the expert like the demo in Matlab further research is to find out how the ANFIS is capable to learn by its own and which leaming algorithm is the best one Finally even the self initialization can be achieved Some potential methods have been considered which are presented in the literature on this subject like reinforcement learning self adaptive learning etc But each of them needs to be tested and verified in the future Although the hardware system has been nearly completed it still can be improved according to the problems described in Chapter 7 2 1 The research of DC motor is going on and by calculating the maximum speed and torque of the cart and pole system it has been decided the DC motor is at least 15V The further experiments will focus on whether the cart speed is strictly linear to the duty ration of the PWM signal About the driving unit problem with the high speed Ye Zhang 39 Inverted Pendulum with ANFIS Controller Conclusion amp Further Discussion DC motor this simple nylon string is no longer sufficient for a more precisecontrol only the timer belt with gear pulleys is competent Ye Zhang 40 Inverted Pendulum with ANFIS Controller Reference Reference 1 2 3 4 7 8 10 11 12 John Nelson and L Gordon Kr
12. DC Motor Fig 3 8 Complete system circuit connection 3 6 Chapter Summary This chapter has described and illustrated all the important parts of the inverted pendulum hardware system The reasons of each decision of the component selection have been explained Also some problems in assembling and fixing are considered and resolved Finally the whole hardware struct re of at inverted pendulum system has been completed and ready for testing and configuration Ye Zhang 25 Inverted Pendulum with ANFIS Controller Configuration of Z8 Microcontroller Chapter 4 CONFIGURATION OF Z MICROCONTROLLER 4 1 Configuration of GPIO GPIO stands for General Purpose Input Output port In Z8 microcoritroller there are in total seven 8 bit ports Ports A G and one 4 bit port Port H for general purpose input output I O operations In my application 11 pins are needed as input port to get data from the sensors 8 pins for ACE and 3 pins for optical encoder Meanwhile 2 pins re assigned for output signals PWM and Direction Actually most of the pins on board can be configured as input output but Port E pin 7 0 has been selected for ACE Port G pin 1 27 3 for optical encoder and Port C pin 1 for PWM see Chapter 4 2 Port D pin 3 for Direction Refer to Schematic of Z8 MCU development board in Appendix C The Registers for each Port providing access t GPIO control input data and output data
13. May due to the final examinations the progress was going slowly From mid June I dedicated to this project and hurried up in the hard ware design and components selection But it took more then one month to finish the whole hardware system a bit more then expectation One reason was at the beginning it was supposed to use Lego to construct the hardware framework but ten days had been spent before I gave up this attempt and made my own mechanical manufacture Another reason was in assembly Sometimnes just a simple task like joining together two pieces of tiny things can take several hours Also orderings and the reordering H bridge have postponed the schedule 3 In parallel the ANFIS controller was simulated in Matlab It was not so hard in reading the documentations of Matlab and Simulink to find out the correct commends and operations But with the purpose to make the control system simpler the ANFIS controller was tried again with only two inputs This hypothesis was proven untenable later b t 10 days were consumed 4 The biggest problem to accomplish this projectis the coding and programming which is significant in configuring the Z8 microcontroller B t it s a shame that I have no knowledge in C C language Two weeks have been spent in reading the books on C but obviously C is nota two week easy job which needs fully comprehending and a lot of practicing The best solution is finding some pieces of C code from Internet E
14. Where X X X are input variables A A A B B Bo NSN 0 QN n are fuzzy set When y is a constant it is a zero order Sugeno fuzzy model in which the con e quent of a rule is specified by a singleton When y is a first order poly nomial i e y ko t kx k x kx 2 1 It is called first order Sugeno fuzzy model The output of Sugeno fuzzy inference is the weighted average Buy t U V t tH Y 2 2 Hi tH tet M 2 12 ANFIS Architecture ANFIS is normally represented by a six layerfeedforward neural network 1 Layer 1 Layer 2 Layer 3 zw Layer 5 Layer 6 l gt 2 i y gt 3 gt 4 Fig 2 1 Adaptive Neuro Fuzzy Inference System ANFIS Layer 1 Input layer Neurons in this layer just pass external crisp signal to Layer 2 Layer 2 Fuzzification layer Neurons in this layer perform fuzzification Layer 3 Rule layer Each neuron in this layer corres ponds to a single Sugeno type fuzzy rule A rule neuron receives inputs from the respective fuzzification neurons and calculates the firing strength of the rule it represents Layer 4 Normalization layer Each neuron in this layer receives inputs from all neurons in this Ye Zhang 6 Inverted Pendulum with ANFIS Controller ANFIS Controller Design layer receives inputs from all neurons in the mle layer and calculates the rule layer and calculates the normalized firing strength of a given rule The n
15. Z8 Microcontroller 4 3 Configuration of UART 4 3 1 UART UART standing for Universal Asynchronous Receiver Transmitter yis a full duplex communication channel capable of handling asynchronous data transfers UART is configured to build up a connection between the microcontroller and the host PC for the purpose to communicate the system hardware part with the software part in real time The UART always transmits and receives data in an 8 bit data format least significant bit first The data format without parity is shown below Fig 4 3 Data Field y Stop Bit s Idle State MMODOOC CEE Fig 4 3 UART data format without parity Z8 provides two full duplex 9 bit UARTs UARTO amp UARTI with bus transceiver Driver Enable control UARTO has been selected for data transmission Fig 4 4 The data byte is trans mitted to be shifted out through the TXDO pin PA5 TXDO 4 3 2 Configuring UART Steps to configure UART0 to transmit data using the Polled Method modified from 9 1 Write to the UARTO Baud Rate High and Low Byte registers to set the desired baud rate 2 Enable the UARTO pin functions by configuring the associated GPIO Port pins for alternate function operation pin PAS TXDO for data transmission 3 Write to the UARTO Control 0 register to Setthe transmit enable bit T EN to enable the UARTO for data transmission HK parity is desired and multiprocessor mode is not enabled set t
16. are listed below Table 4 1 from manual Port Register Mnemonic Port Register Name Px ADDR Port A H Address Register Selects sub registers PxCTL Port A H Control Register Provides access to sub registers PxIN Port A H Input Data Register PxOUT Port A H Output Data Register Port Sub Register Mnemonic Port Register Name PxDD Data Direction Px AF Alternate Function PxOC Output Control Open Drain PxDE High Drive Enable Px SMRE STOP Mode Recovery Source Enable Table 4 1 GPIO Port Registers and Sub Registers As input the received values from port pins are stored in the corresponding Input Data Registers for further processing And as output data from the MCU is sent into the Output Data Register and then trans mitted thought these pins to the connected devices circuits Ye Zhang 26 Inverted Pendulum with ANFIS Controller Configuration of Z8 Microcontroller 4 2 Configuration of PWM 4 2 1 PWM PWM Pulse Width Modulated is a technique that the digital output from a single GPIO pin sets the pulse width of the signal The pulses have fixed frequency and magnitude but the pulse width is modulated to represent different analogue level The power supplied to the DC motor is switched on and off r pidly according to PWM signal so the motor speed is decided by the average current from the H bridge By changing the register s value of the counter in Z8 the duty cycle ofthe output varies and so the average DC current
17. changes 4 2 2 Configuration of PWM Mode In Z8 the Timers 16 bit up counters Fig 4 can be configured as PWM mode Here Time 1 has been chosen as the PWM generator The PWM signal is output thought GPIO Port C Pinl PC1 TIOUT Timer Block Compare X us Block Control 16 Bit i PR Interrupt Timer Reload Register o PWM and Interrupt 8 Timer Output System 8 Soni deba Clock 16 Bit Counter ne Timer with Prescaler Input tax 16 Bit PWM Compare Capture Input p j Fig 4 1 Architecture of Z8 Encore Timer PWM mode Fig 4 2 shows the Timer 1 Control 1 Register 0 Timer Output is forced Low 0 when the timer is disabled When enabled the Timer Output is forced High 1 upon PWM count match and forced Low 0 upon Reload 1 Timer Output is forced High 1 when the timer is disabled When enabled the Timer Output is forced Low 0 upon PWM count match and forced High 1 upon Reload Ye Zhang zd Inverted Pendulum with ANFIS Controller Configuration of Z8 Microcontroller Timer 1 Control 1 TICTL1 FOF Read Write D D6 D5 D4 D5 D2 D 1 DO L Timer Mode 000 One Shot mode 001 Continuous mode 010 Counter mode 011 PWM mode 100 Capture mode 101 Compare mode 110 Gated mode 111 Capture Compare mode Prescale Value 000 Divide by 1 001 Divide by 2 010 Divide by 4 011 Divide by 8
18. chosen It is adequate in this application but with the lowest price The Absolute Contacting Encoder Fig 3 3 is actually using gray coding m thod which ensures there is only one bit changing at each step A binary 1 denotes an open switch while a binary 0 denotes a close switch The 8 bit digital output gives 128 states of the shaft position and position 0 127 are seen by a clockwise rotation of the shaft Refer to Appendix B for the correlation of the output data to the corresponding actual position ACETAB table ROM Fig 3 3 Absolute Contacting Encoder ACE Remarkably one resistance net RESNET in Fig 3 3 must be added between the ACE and Z8 MCU otherwise the sensormay be damaged To get the accurate position of the cart the movement of this ACE sensor has to be restricted in ONE revolutions Iy order to match the whole distance of the cart moving on the tracks into one revolution of ACE sensor s shaft a gearbox has to be equipped to reduce the rotating velocity The gear downNatio is 16 1 using two gear wheels The gearbox is taken out from the Motor amp Multi Ratio Gearboxes set available in store 3 3 Microcontroller MC In this application the microcontroller works as an interface between the host PC ANFIS controller and the hardware components The require ment of the microcontroller is that it can read the digital signals from the sensors and send them to host PC as input
19. controller one has 2 MF FIS the other has 3 MF FIS have been generated and evaluated in Matlab environment Both of them have satisfactory performance in controlling the simulated system model The training data are collected from the Cart amp Pole system one of the demos in Simulink Fuzzy Logic Toolbox where the Fuzzy Logic Controller is being considered as an expert On the other hand the ANFIS controller with different patterns is tried and tested using 4 inputs of cart and pendulum and using only the 2 inputs of the pendulum It has been proved that in order to make all the control rules accurate all the 4 inputs are necessary and both the states of the pole and cart have Ye Zhang za Inverted Pendulum with ANFIS Controller Conclusion amp Further Discussion to be considered in combination Neglecting the cart position only taking account the pendulum position can never get a successful controller In addition the research on the Z8 microcontroller is going deeper Initially it was just like a puzzle but now some basic theories have been studied and understood The suitable ports and pins have been selected and assigned for each purpose the control registers have been found and studied So it has been known how to configure the Z8 MCU to perform the specialized tasks like GPIO for receiving and transmitting data UART for serial port communication and Timer for PWM signal generation Finally the connection of t
20. types of sensors can provide the motion detection such as potentiometer optical shaft encoder incremental quadrature encoder etc To prevent introducing any extra friction onto the shaft the optical encoder with codewheel is the best choice because these devices make absolutely no mechanical contact After studying and comparing several different types of optical encoder in the market the following selections are made HPHEDS 9140 three channel optical incremental encoder module HPHEDS 5140 three channel code wheel The main features of HP HEDS 9140 are listed below from datas heet Two channel quadrature output with index pulse Resolution up to 2000 CPR Counts Per Revolution Low cost Easy to mount No signal adjustment req ired Small size 40 C to 100 C oper ting temperature TTL compatible Single 5 Visupply The encoder module consists of a lensed LED Light Emitting Diode as the light source and a signal processing IC as the light detector Fig 3 1 We can see from the block diagram above that the parallel light beam is interrupted by the pattem of space and on the codewheel which rotates between the emitter and detector Simultaneously these interruptions detected by photo diodes are arranged in a pattern that corresponds to the radius and design of the codewheel Ye Zhang 18 Inverted Pendulum with ANFIS Controller Hardware Design r F RESISTOR T i Voc J
21. 1 4 Fig 6 1 Original Gantt chart Stage I Studying theories and re ding papers Stage 2 Hardware design and selection Stage 3 Testing the control methods Step 1 Training the neural network using the human help Step 2 Implementing the Self leaming technique in inverted pendulum system Step 3 Implementing the self initialisation ability Stage 4 Project report c mpletion and further discussion But the actual time scale is shown below Fig 6 2 Project Schedule Mar Apr May Jun Jul Aug Sep Read papers amp Study Theories BIEIEI NI Design Hardware amp Select Components Bil EIEIEIENI Ex ES Generate amp Simulat ANFIS Controller Configur Z8 Microcontroller Test amp Improye System mi Write Report amp Prepare Presentation Bill Fig 6 2 Updated Timescale The time arrangement has been revised due to the following reasons 1 Before starting with the practical work a lot of readings are required in order to understand the basic concepts and fundamental theories In April and May without working in the hardware I was struggling in how to implement the self learning ability into the inverted pendulum system But unfortunately even now the complete training algorithm is not clearly understood only a few of brief ideas are conceived but have not been tested and verified Ye Zhang 34 Inverted Pendulum with ANFIS Controller Project Management 2 During
22. 3 5 Motor Power High Side High Side left right Low Side MOTOR Low Side left right Motor Ground Fig 3 5 Basic H bridge Ye Zhang 22 Inverted Pendulum with ANFIS Controller Hardware Design H bridge also called full bridge is a circuit with 4 switches and the current flow which controls the motor forward or reverse is decided by which switches are turned on The 4 states are shown below Table 3 1 High Side High Side Lower Lower Left Right Left Right State Description On Off Off On Motor goes Clockwise Off On On Off Motor goes Counter clockwise On On Off Off Motor brakes and decelerates Off Off On On Motor brakes and decelerates Table 3 1 Four states of H Bridge Initially it was planned to use 2 PNP 2 NPN transistors and 4 diodes to build up my own H bridge But after trying I found it was not so easy to m ake up a reliable full bridge circuit so the LMD18201 H bridge was bought Fig 3 6 OUTPUT 1 BOOTSTRAP 2 THERMAL FLAG OUTPUT BOOTSTRAP 1 Vs OUTPUT 2 9 1 2 6 10 11 THERMAL SENSING UNDERVOLTAGE CHARGE LOCKOUT PUMP DRIVE OVERCURRENT DETECTION SHUTDOWN DIRECTION 3 O BRAKE 4 O PWM 5 8 Power Ground Sense Signal Ground Fig 3 6 Functional block diagram of H bridge The main f atures of LMD18201 are listed below from datasheet Delivers up to 3A continuous output Operates at supply
23. Speed is zero This seems feasible but in the real hard ware system the output Speed from controller cannot act directly onto the cart which still has to be converted into force Their relationship can be described in the following equation dv F m 23 di 2 3 Where v is the Speed and m is the mass of the cart Actually in reality the cart speed can not jump from one value fo another instantaneously otherwise F will be infinite large So this supposition is impossible to be realized and implemented Finally it has been confirmed that all the 4 inputs are compulsory Membership Functions Based on the simpler the better of any neuro network based structure first we set 3 membership functions MFs for each input as well as the output So there are 34 81 mapping rules in total adequate to resolve this control problem The ANFIS structure is illustrated below input inputmt output C2 T CY M A IDIR A D 7 a Logical Operations and 222001 or not Fig 2 2 ANFIS structure Ye Zhang 9 Inverted Pendulum with ANFIS Controller ANFIS Controller Design 2 4 Simulationin Matlab 2 4 1 System Modeling Although using ANFIS we can get rid of the bothersome job in calculating the complicated mathematic equations of the inverted pendulum system even no need to know the cor
24. TRACT ieeedcettete uie ACKNOWLEDGEMENTS LIST OF FIGURES GLOSSARY c cister ar ir tre irri CONTENTS ertet eot or neon eae CHAPTER 1 INTRODUCTION Li Backero nd 2 ette te qe teh dies per Re eR Here 1 2 Project Aims and Objectives d eres eerte eene 13 Overview ot th System yer Rec Deor RE ad eee Ree dte E Pte Pe ele 14 The Formatot Report icici Saag eee Sena tende dd te e dina Contents CHAPTER 2 ANFIS CONTROLLER DESIGN ccscssssssssssesssssssssssssesessesees 5 2 1 What is ANFIS A eere d his ae ee Weenies Raa 2 2 Overview of Control Problems 2 3 Design the ANFIS Controller 2 4 Simulation in Matlab nesnenin i E E E N eene sess nete te ee tete ee enn 2 5 C hapter Summafy idees tede e ett de en Stele ie e e ERE ge CHAPTER 3 7HARDWARE DESIGN e eeeeeee eene terne enata totas n onto asas enn 17 3D Framewotk Des 1gn 2 2 n rti eoe Le tes e E RUE Ge d ioi e oe bos 9 2 S BSOISs ien to eee moe ente AAE teo sud A ego a ee ERE 3 3 M mcrocontroller MG 0 ii eo Ree p dre e e ee etin BA MOO Control Unit eese eeeeeeeee eee tenete ettet stesse as attese asset eat aoo 3 5 Complete Hardware System 5 6 Chapter Su MM ary i store poe er ree tee Ere ree Maa ei ep oxa CHAPTER 4 CONFIGURATION OF Z8 MICROCONTROLLER 26 Ye Zhang Inverted Pendulum with ANFIS Controller Contents
25. UNIVERSITY OF HERTFORDSHIRE Faculty of Engineering amp Information Science MASTER OF ENGINEERING DEGREE WITH HONOURS IN EMBEDED INTELLIGENCE SYSTEM Project Report INVERTED PENDULUM WITH ANFIS CONTROLLER Ye Zhang August 2005 DECLARATION STATEMENT I certify that the work submitted is my own and that any material derived or q oted from the published on unpublished work of other person has been duly acknowledged ref UPR AS C 6 1 Appendix I Section 2 Section on cheating and plagiarism Student Full Name Student Registration Number Signed Date Inverted Pendulum with ANFIS Controller Abstract Abstract This report describes how to generate and implement an ANFIS Adaptive Neuro Fuzzy Inference System controller for an inverted pendulum system ANFIS as a modern artificial intelligence system combines the fuzzy logic and neural network to accomplish self learning ability which is more suitable to deal with the complicated non linear systems This objective has been achieved in Matlab simulation The ANFIS controller which is generated and trained by the data derived from another success ful controller is competent in keeping an inverted pendulum system im dynamic balance Also this report focuses on the real hardware system design All the components are selected and investigated The whole hardware structure has already been built up and partially tested and improved Especially the Z8 microc
26. aft Real Time Control of an Inverted Peridulum System Using Complementary Neural Network and Optimal Techniques Proceedings of the American Control Conference Maryland US pp 2553 2554 June 1994 Wei Ji Chen Lei Fang Sek Un Cheyg Kam Kin Lei and Fei Zhou Zhang Personified Intelligent Control for an Inverted Pendulum System Proceedings of the 3 World Congress on Intelligent Control and Automation Hefei P R China pp 1702 1706 June 28 July 2 2000 Jyh Shing Roger Jang ANFIS Adaptive Network Based Fuzzy Inference System IEEE Trans on Systems Man and Cybernetics vol 23 no 3 pp 665 685 May 1993 Charles W Anderson Learning to Conttol an Inverted Pendulum Using Neural Networks Presented at the 1988 American Control Conference Atlanta Georgia June 15 17 1988 Sigeru Omatu Michifumi Yoshioka Stability of Inverted Pendulum by Neuro PID Control with Genetic Algorithm JEEE 0 78 03 4859 1 98 pp 2142 2145 1998 Andrew James Appleby Dynamic Control of a Helicopter Final Year Report University of Herefords hire April 2004 Ankit Gorwadia Self Working Swing Final Year Report University of Herefordshire April 2005 Perminder Singh Thiara DSP Based Fuzzy Logic Controller for an Inverted Pendulum Final Year Report University of Herefordshire April 2001 ZiLOG Technical Note How to Use ZSL with the Z8 Encore MCU UAR m TN003702 0105 www ZiLOG com ZiLOG Technical N
27. d But amazingly the exceptionis if the pole length is cut to 0 1m the maximum initial pole angel is only 0 18rad 7able 2 shows the simulation result Pole Length 005 01 0 2 0 3 0 4 OF 0 6 0 8 10 meter NM 2 Maximum of 017 048 O18 0 83 0 73 067 060 011 NA Initial Pole Angle Rad gt CY Table 2 1 Result of the maximum initial poleang le of different pole length When the pole is longer then 0 8m the ANFIS controller can never keep the system in stable even the initial pole angle is 0 When the pole length is set to 0 8m system has an ther type of balancing status That is the pole is standing on the cart without falling downy but the cart is vibrating fast in a certain distance on the tracks instead of staying in the center shown in Fig 2 8 TI MI Hit INI ih TM T iM I iM n li Il AMA TT W i Vi II iM it au M M WI Il ii T WM MI MI i d IM lll E T jm i I ll i iM i li 20 40 60 80 100 p Cart Position n TIT IA ll il n ll ill Il Inverted Pendulum with ANFIS Controller ANFIS Controller Design In generally this ANFIS controller has a nice control performance when the pole length is in the range of 0 3m to 0 6m 2 4 4 FIS of Two Membership Functions But checking the demo slcp more carefully in Simulink it was found that the Fuzzy Logic Controller only has two membership functions
28. d converted into decimal data of the absolute position by Z8 MCU And those data displayed in Hyper Terminal stand for the actual position of the shaft But due to the difficulties in compiling the C programs this work has not been finished 5 3 Pole and Cart System Instead of controlling the pole and cart system directly by the ANFIS controller it was decided to test it with manual control The motion control unit was connected as described in Chapter 5 1 and the direction was changed by switching Pin 3 of H bridge from 0 GND to 1 SV But initially the cart was not so swift_and easy to control The main reason was the weight Improvement was made by cutting down four pieces of the cart to reduce its weight show in Fig 5 2 Original Frame Modified Frame N Pole Shaft ae Wheel Axle ET Fig 5 2 Modified Cart Frame Another problem was the slippage between the driving wheel and the nylon string Increasing the tensile force can decrease this slippage but on the other hand the motor power was not enough to deal with the heavy strain So to maintain an amount of tensile force with certain flexibility a spring has been added between one end of the string and the cart chassis Fig 3 7 After all the cart and pole system was tested with manually governing the input signals The Ye Zhang 20 Inverted Pendulum with ANFIS Controller Implementation amp Testing results are displa
29. data and then according to the output data from the PC controller generates the PWM signal for motion control Ye Zhang 20 Inverted Pendulum with ANFIS Controller Hardware Design Various microcontrollers can be used in this application The Z8 Encore d microcontroller has been selected which is integrated onto the development board because t is currently available in the department and also it has been used in a similar final project last year Fig 3 4 Fig 3 4 Z8 Encore 64K serial MCU development board The Z8 Encore Z8F642 MCU which is a member of ZiLOG microcontroller products based on the 8 bit eZ8 core CPU is equipped on this development board The main features of the Z8 Encore Z8F642 are listed below from User Manual 64K of Flash memory with in circuit programming capability AK of register RAM N Either eight or twelve channels 10 bit analog to digital converter ADC Two Full duplex UART Serial Peripheral Interface SPD 3or4 16 bit timers with capture compare and PWM capability Watch Dog Timer WDT with intemal RC oscillator e Up to 60 YOpins Programmable priority interrupts On Chip Debugger Power On Reset POR 2 1 3 6N operating voltage with 5 V tolerant inputs Operating temperature 20 10 C After checking the datasheet of this microcontroller development board it has been confirmed this product meets well all the requirements in this inverted pe
30. e Driven Cart Pole Dynamics idi Fuzzy Logic Controller Fig 2 3 Simulation system in Matlab Training Data 000 40 R o 20 Bs Q o a M _ 0 g 2 o O N Oo 40 50 100 150 200 250 300 350 400 450 data set index Fig 2 4 Training Data Set Index To gen rate FIS the parameters of Train FIS are set as Grid P artition partitioning method Optimize Method hybrid Error Tolerance 0 Training Epochs 20 Ye Zhang 11 Inverted Pendulum with ANFIS Controller ANFIS Controller Design Generate FIS menu is set as follow Fig 2 5 refer to Fig 2 2 for the generated ANFIS structure INPUT Number of MFs 3333 To assign a different number of MFs to each input use spaces to seperate these numbers linear Fig 2 5 Setting of Generate FIS Using these data sets as the training dat the ANFIS controller can be generated from ANFIS Editor GUI But here the m st important factor that decides whether the generated controller is desired or not is how well the training data are To any neuro network b sed system optimizing the training data is always a big problem Only a few data may be not eno gh to train the system properly while too many may cause over training Just kein my simulation the first ANFIS controller which was generated by 1328 data sets worked quite well for all occasions but failed when the initial pole angle was 0 2rad Finally 443 data sets are chos
31. e output signal generated by the controller is sent back to the microcontroller which immediately processes this signal into PWM signal for motion control In this way by handling th desired movement of the cart the pendulum on it is kept upright in dynamic stable 7 1 1 Achievement Due to the practical problems technical difficulties and time limit this project is only partially completed Refer to Chapter 6 1 for detailed time management and updated timescale Even though great efforts have been made to learn the new things and some outcomes have been achieved First of all the frame of the whole hardware system has been built up This work cost me much more time and energy then expected To be honest now I have realized that for any practical work there are much m re complication and difficulties then it looks like In this project all the necessary components are compared studied selected purchased and assembled The pole and cart part is designed and manufactured and most of the requirements have been well satis fied like the cart can move freely and swiftly along the rails the pole can rotate in vertical with little friction and the sensors are easy to be assembled Also all the circuits have been connected and the motion control unit of H bridge and DC motor has been assembled and tested where the motor speed can vary smoothly according to the input PWM signal Furthermore in software part two types of ANFIS
32. e to left and one output F N The force applied on the cart F is positive means the force is drawing the cart to right while negative to left Here questions may arise Do we need all the 4 inputs Is the cart position necessary for keeping the pendulum upright Can we simply control the system only taking account of the pole angle Just imagining when we are trying to keep a chopstick standing upright on you finger it seems that we only focus on the position of the chopstick rather then the position of your finger And the control rules also look like very simple if the chopstick is falling down to the left move your finger to the left if itis falling down to the right move your finger to the right But think about a particular situation both the and the O are zero In this case the pole is exactly upright and no movement on the pivot So definitely the output F should be zero no force applied But without any controlling force the cart will keep in moving due to the inertia and momentum and at the end crash in hitting the edges of the tracks It may be proposed that why not change the output from Force to Speed the speed to cart And revise the rules as follow If the pole is falling to left then Speed is negative to left If the pole is falling to right then Speed is positive to right Ye Zhang 8 Inverted Pendulum with ANFIS Controller ANFIS Controller Design If the pole is upright then
33. eee Fig 3 5 Basic H bridge Fig 3 6 Functional block didum of E H bride Fig 3 7 Photo of complete hardware system esee Fig 3 8 Complete system circuit connection eese ee eese Fig 4 1 Architecture of ZS Encore Timer Fig 4 2 Tmer1 Control 1 Register Fig 4 3 UART data format P n Fig 4 4 UARTO Control 0 Register MU Fig 5 1 Basic motor control circuit using H H bridge Fig 5 2 Modified 5 nte a E N ON Fig 6 1 Original Gafttt ch yt es ee e bien hee e eei tenen Fig 6 2 Updated T mescaJe eee ee eese eee ee teet Taa ene the then nennen nent List of Figures a l 7 2 6 snos esc HH esc HH 12 243 14 14 15 19 19 20 21 22 723 24 25 27 28 29 30 31 32 34 34 Ye Zhang iii Inverted Pendulum with ANFIS Controller Glossary Glossary ACE ANFIS CPU DC Motor FIS GPIO GUI IC LED MCU MF PID PWM RAM UART Absolute Contacting Encoder Adaptive Neural Fuzzy Inference System Central Processing Unit Direct Current Motor Fuzzy Inference System General Purpose Input Output Graphical User Interface Integrated Circuit Light Emitting Diode Micro Controller unit Membership Function Proportional Integral Derivative Pulse Width Modulation Random Access Memory Universal As ynchronous Receiver Transmitter Ye Zhang Inverted Pendulum with ANFIS Controller Contents ABS
34. el E Us N i E r E Hi u Li Ail ue 3 8 i HITT ii 1 E g E 8 o ov our or PAT SCA i PA TOT euf 740 728 eT our cw RESET AESET Wander d a TTT teal oo of ara sf motele ds pluggei cate che ser vlatioce the of Giasdled by pia uz izrar ace is Gas a uu o E o g a a o o for reference only rcc TUN ca a i cw TRI OAMAZ PHIAMAIO PHI AMAN D c e s x Li PRANAS cn Catan cy cx ar PORLANA POS ANA POS AMA PO3T AMAT 5 ES S ene 1 Uwe 3h ri Wonder d B Hesse i Hesse i Header d Hesse d Wonder d Ye Zhang 48 Inverted Pendulum with ANFIS Controller Appendix D Flowchart to Configure Timers START Disable timer Configure the timer in the specified mode Set the prescale value initial logic level Write to the Timer High and Low Byte registers to set the starting count value Write to the timer reload high and low byte registers to set the starting count value Write to the timer PWM high and low byte registers to set the starting count value This is valid in PWM mode only Enable the timer interrupt and set the timer interrupt priority Configure the GPIO port pin for the timer output alternate function Enable the timer and initiate counting Appendix Ye Zhang 49
35. en as the training data In addition the initial condition of the cart and pole dynamics has been experimented several times with different parameter settings so that it benefits the training procedure because the more comprehensive and appropriate training data are collected 2 4 3 Performance of ANFIS Controller The generated ANFIS controller has been tested by applying it into the demo to replace the Fuzzy Logic Controller The controlling result is displayed in Fig 2 6 pole length 0 3 meter and the initial pole angle is set to O 1rad all others are zero Then the value of the initial pole angle is increased by O 1rad each time The biggest initial pole angle this controller can manage is 0 8rad 45 86 with a similar result as above But when Ye Zhang 12 Inverted Pendulum with ANFIS Controller ANFIS Controller Design the initial angle is 0 9rad it fails Fig 2 7 4 5 Si 4 6 Pole Angle i Angle Velocity 4 6 4 6 D Cart Position ime offset 0 Cart Speed Fig 2 6 Control result in simulation pole angle 0 1rad 4 6 4 sii Pole Angle i D Angle Velocity 4 B D 4 B m Cart Position i 0 Cart Speed Ye Zhang f Bi Inverted Pendulum with ANFIS Controller ANFIS Controller Design Fig 2 7 Control result in simulation pole angle 0 8rad Then the pole length is increased by 0 1m each time from 0 3m to 0 8m With the length rising the maximum of the initial pole angle is reduce
36. es the speed and the direction of the DC motor The cart is directly assembled with the DCwmotor With the cart s movement in desirable the pole on it will be in the upright position dynamically stable 1 4 The Format of Report Chapter 1 An introduction to the project and an overview of the overall systems A brief format of the report organiZation is presented Chapter 2 ANFIS controller design Analyze the system and do the simulation in Matlab environment Build up the ANFIS structure and then train it using the data gathered from the existing demo in Matlab The control performance of the generated ANFIS has been displayed Chapter 3 Hardware design Do research in each key component in needed design the framework of the system and assemble them into a whole hardware structure The completed hardware is illustrated in this chapter Chapter 4 Configuration of Z8 microcontroller Assign the GPIO pins for data input from th sensors set up the Timer as the PWM output and program the UART for communicating with host PC Chapter 5 Implementation and testing The motion control unit of DC motor and H bridge has been tested Also the connection has been built up between the ACE the Z8 MCU and the Hyper Terminal in host PC sensor Chapter 6 Project management Describe the time arrangement and explain the schedule alteration The project costing and required resources are listed Ye Zhang 3
37. fadaptive ability ANFIS adaptive neural fuzzy inference system as a hybrid intelligent system can construct an input output mapping based on both human knowledge in the form of fuzzy if then rules and stipulated input output data pairs 1 2 Project Aims and Objectives Ye Zhang 1 Inverted Pendulum with ANFIS Controller Introduction The overall aim of this project is developing a controller using ANFIS algorithm to balance an inverted pendulum system in dynamic stable To accomplish this aim the following objectives have to be achieved Learn the theory of ANFIS as well as the fundamental of Fuzzy Logic and Neural Network Understand the principles of self learning Know where and how to g ther the training data and how to generate the ANFIS controller Do simulation in Matlab and achieve a successful ANFIS controller with optimal performance Do research on Z8 Encore Z8F642x Development Board and study the specification of Z8 Encore MCU and know how to configure it for this particular application Understand PWM together with H Bridge techniques which is a widely used method for motion control DC motor control Also become familiar with the two sensors Optical Encoder and Gray Code Design the whole hardware system and assemble all the components After simulating the controller in Simulink test it in this real system Learn C Language and try to implement the ANFIS controlle
38. he parity enable bit PEN and select either even or odd parity P SEL gt Setor clear the CTSE bit to enable or disable control from the remote receiver using the CTS pin 4 Check the TDRE bit in the UARTO Status O register to determine if the Transmit Data register is empty indicated by a 1 If empty continue to Step 6 If the Transmit Data register is full indicated by a 0 continue to monitor the TDRE bit until the Transmit Data register becomes available to receive new data 5 Write the UARTO Control 1 register to select the outgoing address bit 6 Write the data byte to the UARTO Transmit Data register The transmitter automatically Ye Zhang 29 Inverted Pendulum with ANFIS Controller Configuration of Z8 Microcontroller transfers the data to the Transmit Shift register and transmits the data 7 To transmit additional bytes return to Step 5 But even many efforts have been made in executing all above some problems are still remaining Finally it was decided to use the sample code available from ZibOG documentation UARTO Control 0 UOCTLO F42 Read Write 7Ds D5 432 pd TE Loop Back Enable 0 Normal operation l Transmit data is looped back to the receiver Stop Bit Select 0 Transmitter sends 1 Stop bit l Transmitter sends 2 Stop bits Send Break 0 No break is sent 1 Output of the transmitter 15 zero Parity Select 0 Even parity 1 Odd parity Parity Enable
39. he sensors the Z8 MUC development board and the host PC has been established 7 1 2 Overall Comment Although the ANFIS controller has not been implemented into the real hardware system for testing the simulation results of its controlling performance have confirmed that it is feasible to design and generate a successful controller for th inverted pendulum application using ANFIS training algorithm Also its self learning ability has been demonstrated in the training procedure where the ANFIS controller is trained automatically by only using the training data without any human intervention or pre knowledge So it can be concluded that for a non linear system which the control objective cannot be simply expressed as a set of functions defined over all states ANFIS method is preferable atid desirable in the controller design With the benefit of its self leaming ability if the appropri te training data is available the ANFIS controller is easily to be achieved Even there is no need to understand the inside control principles the fuzzy rules but the only problem which is universal in any neural network based structure and has a great effect on the controller s performance is lying on how and where to gather and choose the optimal training data 7 2 Further Discussion 7 2 1 Problems and Difficulties For the hardware in order to get ideal performance some parts probably need a bit more consideration The first thing is the DC mo
40. mount of current more then 2A and getting very hot in a short time No reason was found after checking the whole circuit and the only suspicion was it s a spoiled product So a new one was bought and has been tested working well 5 2 Checkingthe ACE Output Befor transfer the data read from the ACE into the controller it is necessary to check their accuracy Here Hyper Terminal which is a communication software integrated in Windows has be n used to monitor these data On Z8 MCU development board a serial port has been equipped to support the UART and the connection is established between this serial port and the COMI port in the host PC Meanwhile Hyper Terminal is setup with the same baud rate as the UART in Z8 MCU to display the data received from the microcontroller in arrays But strangely it seems the correlation between the digital output and the corresponding actual Ye Zhang za Inverted Pendulum with ANFIS Controller Implementation amp Testing position is random for example when the output is 1 00000001 it means the actual position is 56 when the output is 127 01111111 the actual position is 0 Therefore looking up table has been created The looking up table of the output codes to the absolute shaft positi n is listed in Appendix B So then it s quite easy to understand the procedure When the ACE Shaft is rotating the binary output data are referred to the Looking Up table an
41. ndulum application Also previous applications have proved Z8 is suitable for motion control Ye Zhang 21 Inverted Pendulum with ANFIS Controller Hardware Design 3 4 Motion Control Unit 3 4 1 DC Motor At the beginning I intended to use a servo motor as the controller of the cart motion But a servo motor can only work in one revolution which is not enough to cover the whole length of the track Also in general the price of a servo motor is a bit higher then a normal DC motor Considering the speed of the DC motor which is much faster thenthe required velocity a normal DC motor with a gearbox is preferred The features of the DC motor with a gearbox are listed below from product specific ation Each pinion to gear ratio is 4 1 Operation voltage 1 5 to 3 0 V Current consumption range 0 2 to 0 8 A By simulating the inverted pendulum system in Matlab we can find that the highest speed needed in controlling the cartis no more then 0 5 m s so 2 gears are assembled together to gear down the motor speed 16 1 approxim te 845 r p m into a reasonable and adequate speed with the maximum torque 3 4 2 H Bridge To use a normal DC motor for motion control the average speed and the running direction of the motor should be able to be changed The direction is decided by the polarity applied to its two terminals The widely applied method to achieve this current change is H bridge The basic H bridge is shown in Fig
42. o go before implementing the ANFIS controller into the real hardware system It has to leam how the controller in Matlab Simulink communicates with the PC serial port COMI and how to distribute the input data into each of the corresponding input port Also the output from the controller Force may need to be converted into a signal which can be recognized and processed by the Z8 microcontroller before being sent out 7 2 2 Future Research and Improvement The complete hardware system can b used as a platform for controllers research and test Different controllers especially designed and generated in Matlab can be easily implemented and tested because the microcontroll r works only as an interface rather then a standalone controller The biggest restriction to complete this project is the C language Due to the deficiency of the essential knowledge of C language the progress of writing programs for microcontroller has got stuck Some efforts haven been made to read some books on C and try to understand them but unfortunately C language is really not an easy subject that can be learned in a short term Many pieces of C code have been found form other sources and modified according to this application But a few errors afise in debugging and compiling which haven t been resolved yet So in the future some mor work is still required to carry on in this aspect in order to make sure that all the programs are correct For the
43. ontroller ts studied and configured for this particular application Ye Zhang i Inverted Pendulum with ANFIS Controller Acknowledgements Ackno wledgements Many thanks to my Project Supervisor Dr David Lee who offered valuable support and suggestions as well as the encouragement at all stages throughout the project I would like to express my gratitude to Mr John Wilmot who helped a great deal during the practical work of this project Also many thanks to my friends and classmates for their support and assistance in particular Johnason Sahil and Praveen As a memory of my one year life in U K Ye Zhang ii Inverted Pendulum with ANFIS Controller List of Figures Fig 1 1 Inverted pendulum Fig 1 2 An overview of the system Fig 2 1 Adaptive Neuro Fuzzy Tnf sence Sum ANEIS cu e eus Fig 2 2 ANFIS structure 2 Fig 2 3 Simulation Gene in Matlab Fig 2 4 Training Data Set Index Fig 2 5 Setting of Generate FIS Fig 2 6 Control result in Em ois anos 0 rali eee beveses cts eed Um ede eR VERE nds Fig 2 7 Control result in simulation pole angle 0 8fad sss Fig 2 6 Balancing status at pole length 0 8m 4 sete Fig 2 9 Simulation result of 2 MF ANFIS controller eee Fig 3 1 Optical encoder Fig 3 2 Output E Fig 3 3 Absolute Contacting ER ACE Ed AAAA elucidate tieu a Fig 3 4 Z8 Encore 64K serial MCU developm nt board
44. ormalized firing strength is the ratio of the firing strength of a given rule to the sum of firing strength of a given rule to the sum of firing strengths of all rules It represents the contribution strengths of all rules It represents the contribution of a given rule to the final result Layer 5 Defuzzification layer Each neuron in this layer issconnected to the respective normalization neuron and also receives initial inputs Layer 6 Summation layer This neuron calculates the sum of outputs of all defuzzification neurons and produces the overall ANFIS output ANFIS uses hybrid learning algorithm Least Square Es timator and Gradient Descent method to leam the rule consequent parameters and rule antecedent parameters and turn the membership functions as well 2 2 Overview of Control Problems The brief control principle of an inyerted pendulum system is by controlling the motion of the cart keeping the pole standing upright and dynamically stable The cart can only move along the tracks forward and backward and the pole is fixed on the pivotshaft on the cart so both the pole and the cart have one dimension motion space The whole system is controlled by the force F which is applied onto the cart The magnitude and the direction of the force are modified in real time based on the combination of the pole angle and the cart position 2 3 Design the ANFIS Controller 2 3 1 Training Data ANFIS has a network
45. ote Using the GPIO Pins of the Z8 Encore MCU TN002401 0304 www ZiLOG com ZiLOG Preliminary Product Specification Z8 Encore Z8F642x Series Microcontrollers with Flash Memory and 10 Bit A D Converter PS019906 1003 www ZiLOG com ZiLOG Application Note A DC Motor Controller Using A ZiLOG MCU AN006001 Z8X0400 www ZiLOG com Ye Zhang A1 Inverted Pendulum with ANFIS Controller Reference 13 14 18 19 ZiLOG Application Note Using the Z8 Encore Timer AN013103 0104 www ZiLOG com Agilent Technologies Inc Technical Data Three Channel Optical Incremental Encoder Modules www semiconductor agilent com Data Sheet LMD18201 3A 55V H Bridge www mational com Data Sheet Bourns Absolute Contacting Encoder ACEM www bourns com http www mc manis com chuck robotics tuto rial h bridge index html H Bridge Theory amp Practice MATLAB Fuzzy Logic toolbox For use with MATLAB 2000 pp 2 1 to 2 47 The MathWorks Inc www mathworks com Ye Zhang 42 Inverted Pendulum with ANFIS Controller Bibliography Bibliography 1 Michael Negnevitsky Artificial Intelligence A Guide to Intelligent Systems First edition Chapter 8 pp 275 284 2002 2 Adrina Biran amp Moshe Breiner Matlab 6 for Engineers Third edition chapter 14 amp 15 pp 547 597 2002 3 Brian Overland C Without Fear A Beginner s Guide That Makes You Feel Smart
46. r by writing the programs in ZDS I software with C compiler provided by ZiLOG 1 3 Overview of the System ZDS II C Compiler Smart Cable Host PC Programs C Code Microcontroller Sensors Encoder Inputs Digtial Data PWM Control Force Hardware System H Bridge Fig 1 2 An overview of the system Ye Zhang 2 Inverted Pendulum with ANFIS Controller Introduction The overall configuration Fig 1 2 Itis a real time controlling s ystem ANFIS controller is running in Matlab in host PC The hardware system is governed by Z8 Encore microcontroll r which is integrated onto the development board All the essential programs in C code are debugged and compiled in tlie software ZiLOG Developer Studio II in host PC and transferred onto the Flash Program Memory on the development board though the Smart Cable Z8 microcontroller interfaces the hardware system withthe software controller The state parameters of both pole and cart are read by the two sensors and transmitted by Z8 into the ANFIS controller Then the desirable output is generated by the controller and sent back to Z8 to be modulated into PWM signal All the communication between Z8 MCU development board and the ANFIS controller is built up by serial port connection UART for Z8 and COM1 for host PC PWM signal controls the H bridge to perform the motion control which chang
47. relation of all the parameters But to do the simulation still we need to understand these equations in order to build up an ideal system model State equations of inverted pendulum zB a e E sint m tm 0 2 4 2 ie mcos 0 3 m m 2 p F mL sinO 0 cos0 m m 2 5 Where g acceleration due to gravity 9 8m sec 0 angle of pole in rad X horizontal position of cart ii m m mass of cart in Kg m mass of polein Kg L the distance from the pivot to the pole s center of mass in m F applied force in Newton In Simulink a detho of an inverted pendulum has existed in Fuzzy Logic Toolbox which is called Cart and Pole In this demo the controller is a Fuzzy Logic Controller using FIS Fuzzy Inference System The block diagram of the whole system in Simulink slcp is shown in Fig 2 3 2 42 Generate ANFIS Controller We can consider the Fuzzy Logic Controller in this demonstration as an expert who has succeeded keeping the cart and pole system in balance In this way using the Jo Workspace function block from Simulink library we can easily obtain the input and output data sets and store them in the Workspace Then we can compose them into a 5 dimensional array where the last column must be the output Fig 2 4 Ye Zhang 10 Inverted Pendulum with ANFIS Controller ANFIS Controller Design Animation L d Im angle Se Target Position I Mous
48. strated that in simulation this ANFIS controller is competent in keeping the cart and pole system stable and balance Ye Zhang 16 Inverted Pendulum with ANFIS Controller Hardware Design Chapter 3 HARDWARE DESIGN 3 1 Framework Design 3 1 1 Cart Cart design is a tradeoff between the agility and the stability A very small and light cart can be easily and quickly steered with less inertia but the stableness is not good enough especially when the pole is s winging At the beginning it was intended to use Lego kit to build up the framework of this cart and pole system Lego toy comes with varied of bits with different sizes and shapes Using these parts almost any required models can be constructed The Lego cart meets some of the requirements very well like light weight and easy_buildy but due to the plastic material the big problem is the weakness in solidity and strength Also it is quite hard to assemble a normal DC motor with the Lego parts unless using Lego DC motor from the kit After trying several different patterns of Lego it was aband ned So designing and manufacturing a mefal cart is the last but best solution See Appendix A for mechanical drawing The 4 wheels and2 axles are selected from Lego modules 3 12 Shaft The shaft which the pendulum is attached to need more special consideration The shaft should be firmly fixed on the cart no_axial movement but able to rotate freely with less friction
49. tor The present one is not so powerful to handle the cart that amp ven a moderate friction can stop it Refer to Chapter 5 3 And this motor goes quite hot after not long time working in full load Another is the driving set The slippery has not been completely eliminated even a spring is added since it is not easy to find out the optimal tensile force that can provide enough strain but not too much To configure the Z8 microcontroller is another big issue Some work has been carried out But still some questions in how to build up the reliable communication from the Z8 MCU to the peripheral equipments are in doubt such as how to configure the UART to transmit TWO signals to the serial port in alternate sequence and how to convert the output signal Force from controller into PWM mode Much more details have to be considered carefully and Ye Zhang 38 Inverted Pendulum with ANFIS Controller Conclusion amp Further Discussion comprehensively For any neural network based learning algorithm the big problem is that the training outcome is always not absolutely predictable Discussed in chapter 2 4 2 The final controller was generated by 443 data sets but it is still not sure whether these are the best training data and whether the ANFIS controller can deal with all the possible situations without any over training or under training phenomena Although the simulation in Matlab has been accomplished there is still a big step t
50. type structure which maps the inputs through input membership functions and associated parameters to the outputs This is quite similar to a neural network So like any eaming algorithm the most important step to get a desirable ANFIS controller is to collect adequate and proper training data sets There are different ways to obtain the training data A straightforward thought is getting help from an expert who can manually handle the cart and manage the whole system in stable Just imagine keeping a pen standing on you finger But in practical it is not easy to find such experts so taking some help from the existing successful controllers can benefit our work much easier and quicker Ye Zhang 7 Inverted Pendulum with ANFIS Controller ANFIS Controller Design 2 3 2 ANFIS Structure Output and Input For an inverted pendulum system there are in total four inputs 0 rad The angle of the pendulum with respect to the absolute zero upright O is positive while the pendulum is leaning to right and negative to left 0 rad s The angle velocity of the pendulum O is positive if the pendulum is swinging clockwise and negative anticlockwise x cm The position of the cart with respect to the lt absolute zero center of the tracks x is positive when the cart is on the right side of the tracks and negative on the left x cm s The moving speed of the cart x is positive when the cart is moving to right and negativ
51. ven now I am still trying my best to understand them and to make some modification according to my application 6 2 Project Costing The main components in the overall system and their costs are listed below Table 5 1 Component Manufacturer Supply CostxQuantity ZiLOG Z8 Encore ZiLOG UH Store 34 99x1 Development Kit Z8F64200100KIT C Multi Ratio Motorgearbox MFA Maplin 8 99x1 Absolute Contacting Encoder BOURNS RS 6 10x1 ACE Three Channel Optical HP Farnell 15 47 1 Incremental Encoder Module Three Channel Codewheel HP Farnell 12 31x1 LMD 18 201 Full Bridge National Farnell 12 73x1 Semiconductor Bearing RS RS 2 42x2 25mm Pulley Rapid Rapid 1 95x1 Total Cost 97 38 Table 5 1 Components and cost Most of the components above are ordered from Project Lab C460 via Internet Some other Ye Zhang 35 Inverted Pendulum with ANFIS Controller Project Management elements are not included such as the thermal cut resistor for motor 2 capacitors for H bridge data cables for communication and the rails for cart as well as the pendulum and the wheels from Lego kit 6 3 Equipments and Resources Equipments and devices provided by laboratory Two power supply one for sensors and one for H bridg A signal generator for emulating PWM signal An oscillograph for wave display A multimeter for testing and examining Two bread board and some wires for circuit connecti n Software
52. voltages up to 55V TTL and CMOS compatible inputs Thermal warning flag output at 145 C Thermal shutdown outputs off at 170 C Internal clamp diodes Shorted load protection But the minimal operation voltage of this H bridge is 12V which is much higher then the working voltage of the DC motor 1 5 3 0V In order to protect the DC motor from buming up Ye Zhang DSK Inverted Pendulum with ANFIS Controller Hardware Design a 50Q thermal cut heat sensitive resistor is added between the H bridge PWM signal pin and one of the DC motor poles We select 50Q resistor because the working resistance of DC motor is around 15Q so the supplied voltage to the DC motor is Macau E 12V x et 2 TTV 3 1 154 50 0 which is perfect in the range of the DC motor working voltage 3 5 Complete Hardware System The overall hardware system is illustrated in the followi Fig 3 7 Photo of complete hardware system Ye Zhang 24 Inverted Pendulum with ANFIS Controller And the complete system circuit connection is shown below Fig 3 8 Hardware Design Power Supply 5V OV Power Supply 12V OV H Bridge Optical Encoder ACE 3 bit O utput 8 bit Output Port F y PWM a a Z8 MCU Dr UART Console Universal j Power Supply Serial Port Host PC Resistor
53. yed below PWM frequency is set at 100Hz and Motor Voltage Vs is 12V PWM Duty Cycle Average Current mA Cart Speed m s Output from H Bridge Approximation 50 0 0 75 362 o 100 667 0 5 The expectative value here should be half of the maximum speed But the friction is too much that overcomes the torque of the DC motor Thought the testing it has demonstrated that changing the duty cycle of the PWM signal can change the speed of the DC motor But the drawback is the friction which prevents the cart speed to be linear with the PWM duty cycle as exp cted in ideal status 5 4 Chapter Summary In this chapter some parts of the whole hardw re system have been tested The problems and difficulties about the interface of ACE sensor have been presented and resolved The cart has been modified to gain the enhancement in control ability Thought the time is not sufficient to test the entire system thought these tests it can be said this inverted pendulum hardware part has been well built up and is ready to be implemented with the controller Ye Zhang 33 Inverted Pendulum with ANFIS Controller Project Management Chapter 6 PROJECT MANAGEMENT 6 1 Time Management The original Gantt charts is shown below Fig 5 1 Project Schedule March April Ju August September stage ee ee ee ee ee stage2 eee ee istage 3 istep 1 step 2 _ E step 3 T stage 4 L Presentation LL I IL I j I

Download Pdf Manuals

image

Related Search

Related Contents

NICE 20.000 - Certificazione Energetica  Kenmore 116.38412 Vacuum Cleaner User Manual    RinNova Cond - schede  Samsung RL56GHGTS Užívateľská príručka  

Copyright © All rights reserved.
Failed to retrieve file