SOCIALIST REPUBLIC OF VIETNAM Independence-Freedom-Happiness ****** Ho Chi Minh City, December 29, 2022 EVALUATION SHEET OF DEFENSE COMMITTEE MEMBER Student name: Pham Van Chinh Stude
Trang 1FACULTY FOR HIGH QUALITY TRAINING
CAPSTONE PROJECT AUTOMATION AND CONTROL ENGINEERING
POSITION CONTROL FOR BALL AND BEAM UNDER
Trang 2FACULTY FOR HIGH QUALITY TRAINING
GRADUATION THESIS
Students:
Ho Chi Minh city, December 29, 2022
POSITION CONTROL FOR BALL AND BEAM UNDER
LINEAR ALGORITHMS
PHAM VAN CHINH 18151005
HOANG DUY TAN 18151034
Major: AUTOMATION AND CONTROL ENGINEERING
Advisor: Nguyen Van Dong Hai, PhD
Trang 3SOCIALIST REPUBLIC OF VIETNAM
SUBJECT PROJECT ASSIGNMENT
Student name: Pham Van Chinh Student ID: 18151005
Student name: Hoang Duy Tan Student ID: 18151034
Major: Automation and control engineering Class: 18151CLA
Advisor: PhD Nguyen Van Dong Hai
Date of assignment: 6/9/2022 Date of submission: 30/12/2022
1 Project title:
Position control for Ball and Beam system under linear algorithms
2 Initial materials:
They are provided by the advisor
3 Content of the project:
Calculation of the dynamical equation of the Ball and Beam system
Simulating the ball and beam system on matlab
Calculating the dynamics equation of the engine to apply to the real model
Model building: Select hardware, select motor, H-bridge, 12V DC Power, Ball
Run the PID algorithm: select the appropriate PID parameter
Run the LQR algorithm: calculate the LQR and select the Q, R matrix values
Optimize PID and LQR by GA algorithm Simulation and verification on real models
4 Final product:
Ball and Beam system in real model
Graduation report book
CHAIR OF THE PROGRAM
(Sign with full name)
ADVISOR (Sign with full name)
Trang 4SOCIALIST REPUBLIC OF VIETNAM Independence-Freedom-Happiness
******
Ho Chi Minh City, December 29, 2022
ADVISOR’S EVALUATION SHEET Student name: Pham Van Chinh Student ID: 18151005 Student name: Hoang Duy Tan Student ID: 18151034 Major: Automation and control engineering Class: 18151CLA Advisor: PhD Nguyen Van Dong Hai Project title: Position control for Ball and Beam system under linear algorithms EVALUATION 1 Content of the project:
2 Strengths:
3 Weaknesses:
4 Approval for oral defense? (Approved or denied)
5 Overall evaluation: (Excellent, Good, Fair, Poor)
Trang 5
6 Mark: ……….(in words: )
Ho Chi Minh City, December 29, 2022
ADVISOR
(Sign with full name)
Trang 6SOCIALIST REPUBLIC OF VIETNAM Independence-Freedom-Happiness
******
Ho Chi Minh City, December 29, 2022
EVALUATION SHEET OF DEFENSE COMMITTEE MEMBER Student name: Pham Van Chinh Student ID: 18151005 Student name: Hoang Duy Tan Student ID: 18151034 Major: Automation and control engineering Class: 18151CLA Project title: Position control for Ball and Beam system under linear algorithms Name of Defense Committee Member: EVALUATION 1 Content and workload of the project:
2 Strengths:
3 Weaknesses:
4 Overall evaluation: (Excellent, Good, Fair, Poor):
Trang 7
5 Mark: ……….(in words: )
Ho Chi Minh City, December 29, 2022
COMMITTEE MEMBER
(Sign with full name)
Trang 8Disclaimer
Students hereby declare that this is my own research work and is under the scientific guidance of PhD Nguyen Van Dong Hai The research contents and results in this topic are honest and have not been published in any form before If I find any fault, I will take full responsibility for the content of my graduation thesis Ho Chi Minh City University of Technology and Education is not related to copyright and copyright infringements (if any) caused by me during the implementation
Ho Chi Minh City, December 29, 2022
STUDENTS
Trang 9Acknowledgements
At the beginning, our group would like to express our sincere thanks to the teacher - PhD Nguyen Van Dong Hai for directly guiding us to carry out the graduation project, he enthusiastically guided,encouraged us throughout the process of implementing the topic and creating favorable conditions for us to successfully complete the graduation project Our group would also like to express our sincere thanks and deep gratitude to the teachers
of the University of Technology Education, especially the teachers of the Faculty of High Quality Training for creating conditions for our group have time to do projects
Finally, our team would like to wish the teachers good health, success in their teaching path and bring many values to the next generations
Trang 10Table of Contents
Disclaimer i
Acknowledgements ii
Table of Contents iii
ABBRIVIATION vi
Symbols vi
Meaning vi
B&b system vi
Ball and beam system vi
LQR vi
Linear-Quadratic Regulator vi
PID vi
Proportional Integral Derivative vi
List of Figures vii
List of Tables x
CHAPTER 1 INTRODUCTION 1
1.1 Necessary 1
1.2 Overview 1
1.2.1 Decription about B&b system 1
1.2.2 Model and research completed over the world 2
1.3 Target 2
1.4 Approach 2
1.5.Research Methods 3
1.6 Research subjects 3
CHAPTER 2: THEORETICAL BASIC AND SOLUTION CONTROL 4
2.1.1 Decription 4
2.1.2 Analyze and build mathematical models 4
2.1.3 Analyze and build mathematical models of motor 7
2.2 LQR Algorithm 11
2.2.1 Conception 11
2.2.2 LQR design 12
2.3 PID Controller 13
2.3.4 Integrated Controller 17
2.3.5 Stability 17
Trang 112.3.6 System Calculations 18
2.4 GA Algrithm 18
2.5 Uart communication 20
2.6 Filter 21
CHAPTER 3 HARDWARE AND SOFTWARE DESIGN 24
3.1 Hardware selection 24
3.1.1 Motor 24
3.1.3 Microprocessor 26
3.1.4 H-Bridge 27
3.1.5 CP2102 USB to UART Bridge 30
3.1.6 Power block 30
3.1.7 Modeling The Ball and Beam system with Deviated Axis and mechanical processing 30
3.2 Software 32
3.2.1 Programming STM32F407 by Waijung library on Matlab software 32
3.2.3 Visual studio 33
CHAPTER 4 BUILDING THE CONTROLLERS ON THE SIMULATION 34
4.1 PID 34
4.1.1 Building the PID controller 34
4.1.2 PID rule results and comments 36
4.2 LQR 40
4.2.1 Building LQR controller 40
4.2.2 LQR rule results and comments 41
4.3 GA 48
4.3.1 Building GA algorithm for PID controller 48
4.3.2 GA rule for PID controller results and comments 50
4.3.3 GA rule for LQR controller results and compare GA-PID and GA-LQR 55
4.3.4 Building GA algorithm for LQR controller 56
CHAPTER 5 BUILDING THE CONTROLLERS ON THE REAL MODEL 58
5.1 PID 58
5.1.1 Building the PID controller 58
5.1.2 PID rule results and comments 58
5.2 LQR 66
Trang 125.2.2 LQR rule results and comments 67
5.3 GA rule for PID controller results and comments 71
5.3.1 GA-PID vs GA-LQR in real model 76
5.4 Filter survey 77
5.4.1 Median filter 77
5.4.2 Lowpass filter 80
5.5 Interface 82
5.6 Compare PID with PID-GA 83
CHAPTER 6: CONCLUSION 84
6.1 Conclusion 84
6.2 Improvement 84
REFERENCES 85
APPENDIX 86
Trang 14List of Figures
Fig 1 1 Ball and beam system from Quanser [4] 2
Fig 2 1 B&b system 4
Fig 2 2 DC Motor block 7
Fig 2 3 The transfer function of DC motor 10
Fig 2 4 LQR control system diagram 11
Fig 2 5 PID Controller Block Diagram 13
Fig 2 6 Discrete PID Block Diagram 14
Fig 2 7 Changing proportional term 15
Fig 2 8 Changing integral term 16
Fig 2 9 Changing derivative term 17
Fig 2 10 GA flowchart 20
Fig 2 11 Uart connection 21
Fig 3 1 Nisca NF5475E DC encoder motor 25
Fig 3 2 Operating specifications Nisca Motor 25
Fig 3 3 Mayor bar 26
Fig 3 4 Kit STM32F407 Discovery 27
Fig 3 5 Circuit diagram of H bridge circuit (forward) 28
Fig 3 6 Circuit diagram of H bridge circuit (reverse) 28
Fig 3 7 H-Bridge IR2184 29
Fig 3 8 IR2184 H-bridge pinout 29
Fig 3 9 CP2102 USB (UART communication) 30
Fig 3 10 Power supply 30
Fig 3 11 The actual model of the ball and beam system with Deviated Axis 31
Fig 3 12 Wiring diagram system 31
Fig 3 13 Install the Waijung Blockset library 32
Fig 3 14 Terminal 3 32
Fig 3 15 Code diagram 86
Fig 3.16: Nema 17 stepper motor 86
Fig 3 17 Nema 17 specifications 87
Fig 3 18 Torque holding of nema 17 87
Fig 3 19 DC motor jgb37-520 87
Fig 3 20 Table testing Jgb37-520 88
Fig 3 21 Servo Motor Jgb37-520 wiring diagram 88
Fig 3 22 Ultra sonic sensor HC SR04 88
Fig 4 1 Simulate the PID controller of the ball and beam system 34
Fig 4 2 B&B block 35
Fig 4 3 Result of simulation PD algorithm 36
Fig 4 4 Result of simulation PD algorithm when increase Kp_ball 36
Fig 4 5 Result of simulation PD algorithm when increase Kp_beam 37
Fig 4 6 Result of simulation PD algorithm when increase Kd_ball 38
Fig 4 7 Result of simulation PD algorithm when increase Kd_beam 38
Fig 4 8 Result of simulation PID algorithm 39
Fig 4 9 Result of simulation PID algorithm when increase Ki 39
Trang 15Fig 4 10 Simulate the LQR controller of the ball and beam system 41
Fig 4 11 Result of simulation LQR algorithm 41
Fig 4 12 Voltage response of simulation LQR algorithm 42
Fig 4 13 Result of simulation LQR algorithm when decrease R 42
Fig 4 14 Voltage response of simulation LQR algorithm when decrease R 43
Fig 4 15 Result of simulation LQR algorithm when increase R 43
Fig 4 16 Voltage response of simulation LQR algorithm when increase R 44
Fig 4 17 Result of simulation LQR algorithm when increase Q1 44
Fig 4 18 Voltage response of simulation LQR algorithm when increase Q1 45
Fig 4 19 Result of simulation LQR algorithm when increase Q2 45
Fig 4 20 Voltage response of simulation LQR algorithm when increase Q2 46
Fig 4 21 Result of simulation LQR algorithm when increase Q3 46
Fig 4 22 Voltage response of simulation LQR algorithm when increase Q3 47
Fig 4 23 Result of simulation LQR algorithm when increase Q4 47
Fig 4 24 Voltage response of simulation LQR algorithm when increase Q4 48
Fig 4 25 Simulate the GA-PID controller of the ball and beam system 50
Fig 4 26 PID simulation result of genetic algorithm: The eighth generation 51
Fig 4 27 PID simulation result of genetic algorithm: The ninth generation 52
Fig 4 28 PID simulation result of genetic algorithm: The third generation 53
Fig 4 29 PID simulation result of genetic algorithm: The sixty-fifth generation 54
Fig 5 1 PID controller on the real ball and beam model 58
Fig 5 2 Real model PID standard parameter results 59
Fig 5 3 Result 1 of increase Kp_ball 59
Fig 5 4 Result 2 of increase Kp_ball 60
Fig 5 5 Result 1 of reduce Kp_ball 61
Fig 5 6 Result 2 of reduce Kp_ball 61
Fig 5 7 Result 1 of increase Kd_ball 62
Fig 5 8 Result 2 of increase Kd_ball 63
Fig 5 9 Result 1 of increase Kp_beam 63
Fig 5 10 Result 2 of increase Kp_beam 64
Fig 5 11 Result 1 of increase Kd_beam 65
Fig 5 12 Result 2 of increse Kd_beam 65
Fig 5 13 LQR controller on the real ball and beam model 66
Fig 5 14 Real model LQR standard parameter result 67
Fig 5 15 Result reduce R real model LQR 68
Fig 5 16 Result increase Q1 real model LQR 68
Fig 5 17 Result increase Q2 real model LQR 69
Fig 5 18 Result increase Q3 real model LQR 70
Fig 5 19 Result increase Q4 real model LQR 70
Fig 5 20 Manually calibrated PID result 71
Fig 5 21 The eighth generation result: PID parameter from genetic algorithm applied to the real model 72 Fig 5 22 The ninth generation result: PID parameter from genetic algorithm applied to
Trang 16Fig 5 23 The third generation result: PID parameter from genetic algorithm applied to real
model 73
Fig 5 24 The sixty-fifth generation result: PID parameter from genetic algorithm applied to real model 73
Fig 5 25 Result of changing setpoint: PID parameter from genetic algorithm applied to real model 74
Fig 5 26 Sine Wave 75
Fig 5 27 System response with sine wave setpoint 75
Fig 5 28 Result 1 of median filter (standard median filter) 77
Fig 5 29 Result 2 of median filter (increase median filter) 78
Fig 5 30 Result 3 of median filter (increase median filter) 78
Fig 5 31 Result 4 of median filter (increase median filter) 79
Fig 5 32 Result 5 of median filter (increase median filter) 80
Fig 5 33 Result of changing the pass band lowpass filter 80
Fig 5 34 Result of changing the stop band lowpass filter 81
Fig 5 35 Result of changing the ripple lowpass filter 81
Fig 5 36 Result of changing the atennuation lowpass filter 82
Fig 5 37 The interface to observe the operation of system 82
Trang 17List of Tables
Tab 2 1 System parameters and variables of B&B 5
Tab 2 2 Motor datasheet 8
Tab 4 1 Blocks in simulation program 34
Tab 4 2 Blocks in simulation of B&B block 35
Tab 4 3 The eighth generation: PID parameter from genetic algorithm 50
Tab 4 4 The ninth generation: PID parameter from genetic algorithm 51
Tab 4 5 The third generation: PID parameter from genetic algorithm 52
Tab 4 6 The sixty-fifth generation: PID parameter from genetic algorithm 53
Trang 18
CHAPTER 1 INTRODUCTION
The purpose of this chapter is to provide information about an overview of the topic, the necessity of this project, the goals and approaches to solving problems encountered in the working process In addition, the chapter also suggests the development method of the topic that can be applied in the future to solve remain problems and improve control quality
1.1 Necessary
Nowaday, the country is in the process of transforming labor methods, from manual labor to machine labor and moving to a new level of automation Especially, automatic control systems with the support of robots help to do a series of complex jobs with high accuracy during a short time, bringing a lot of benefits to humans For example: Vinamilk dairy factory in My Phuoc 2 industrial zone, Binh Duong province which was using almost fully automatic robots with high precision or a series of robots developed to perform repetitive tasks such as picking and place, sorting products, drawing or tracking with high speed and accuracy, many times higher than humans such as: scara, delta, magician These robots, to be able to run smoothly and work with incredible speed and accuracy, need to be carefully programmed using complex algorithms Therefore, there is a problem that if you want to control, repair and upgrade these robots, you need not only understanding of the structure of the robot but also basic fundamental of control algorithms and robot control programs However, these robots have a very high cost, so it is not reasonable to buy them and bring them to schools to teach the knowledge of control algorithms to pupils and students, standardized close to actual manufactured models, with low cost, compactness and ease of use, these models are widely used for teaching, doing research about the control rules of old algorithms and developing new algorithms
1.2 Overview
1.2.1 Decription about B&b system
The Ball and Beam system with Deviated Axis(single-input and multi-output system) is commonly used in laboratories to prove the positivity of control algorithms It is a simple and low-cost model that is easily accessible in the teaching environment at universities Some algorithms have been successfully applied on this model such as PID [1], LQR [2], PID and LQR are two simple algorithms, having a simple structure makes the above controllers easy to design, are supported to be embedded in the microprocessor for experimentation Most objects in nature are nonlinear, including B&b system, the stability
of a nonlinear system depends not only on the structure and parameters of the system, but also on the input signal Therefore, linearization of the system will not guarantee complete accuracy at the position of equilibrium, oscillation or stability around the equilibrium point
Trang 191.2.2 Model and research completed over the world
In which, in 2005, Arroyo built a system called “Balanced Ball on Beam” [1] The system uses a wire resistance sensor to determine the position of the ball The signal from the sensor is processed in a DSP and outputs signal transfer to the DC motor control signal with the reducer [2], [3] This system uses PD control law Quanser is one of the most successful developers in researching and manufacturing real models, proving the reality of algorithms
Fig 1 1 Ball and beam system from Quanser [4]
In Vietnam, the objects have been successfully controlled on many different control algorithms such neural network [7], fuzzy, sliding mode control Many articles as well as real models are widely published in newsrooms, journals and universities In this study, the application of control algorithms LQR, PID and GA [8] to control balance at a given stationary point is aimed
1.3 Target
• Survey and verify PID, LQR law
• Ball reachs the equirium state with settling time under 10s
• State steady error lower than 0.1m
• Tracking and follow variable setpoint
• Find the approach to turn the parameter automatically
• Design interface to monitor and control the system
1.4 Approach
First, analyze and calculate the dynamic equation of the B&b system based on Euler-
Trang 20converting refer to voltage, apply different algorithms to perform at simulations on Matlab/Simulink to verify the results Finally, design the real model and check the response
of these strategies and select the optimal parameters Then try appropriate algorithms to search the optimal strategies
1.5.Research Methods
• Applied PID controller and find the Kp, Ki, Kd manually
• Adjust the Q, R matrix to verify the response
• GA method for searching intelligently
• Remove noise by variety of filters
1.6 Research subjects
The object researched in this project is the ball and beam system with Deviated Axis This single-input and multi-output system(SIMO) is commonly used in laboratories to prove the positivity of control algorithms
Trang 21CHAPTER 2: THEORETICAL BASIC AND SOLUTION CONTROL This chapter aims for explain about the working principle and mathematical equation
of B&b system, motor equation, knowledgement about PID, LQR controller and filter for noise removing Moreover, the uart communication is also mentioned
2.1 The ball and beam system with Deviated Axis
2.1.1 Decription
The ball and beam system with Deviated Axis is a simple model in automatic control system theory [9] The system consists of a ball, a beam, a motor, several sensors, lever arm Lever arm is attached to one end of the beam, the other end is fix The lever arm is design connected with the gear box, when the gear moving lead to the lever arm rotate with the same angle and same direction as gear The lever arm move make the angle beam (alpha) change And the gear also connected with the motor so that the motor will be responsible for control the system When the motor rotates an angle W, through the gear (θ), the beam rotates an angle alpha (α) When the beam angle changes over different the positions, under the impact of gravity will cause the ball to roll freely down on the beam The task is to design a controller to balance the ball at particular point on the beam By using sensors, information about the area, velocity of the ball is sent and compared with the reference value in the controller, after run the code the controller will send a signal to control the rotation of the motor so that the ball will reach the desired position on the beam The mathematical model of the system is nonlinear, but we can consider the system to be
a linear system around the horizontal interval This simple linear model is still applicable
to many real systems, such as the system that stabilizes the plane when landing under the influence of turbulent air currents In some studies, the active input is calculated as the torque generated by the motor, but in reality, the voltage or PWM value will be easy to understand and use to drive the motor
In the project, physical laws and linear approximation methods are used to analyze the physical model of B&b system based on Euler-Lagragian
2.1.2 Analyze and build mathematical models
Fig 2 1 B&b system
Trang 22Tab 2 1 System parameters and variables of B&B Symbols Meaning Value Measurement
• The ball's kinetic energy includes:
Translational kinetic energy 1 2
• Kinetic energy of the beam:
The beam has not translational kinetic energy, only rotational kinetic energy:
Trang 23Kinetic energy of the system: 1 2 1 2 1 2 2 1 2
Ball potential: B =m gr B sin (2.1.5)
Beam potential energy: sin
Trang 24r
J m
R
=
2.1.3 Analyze and build mathematical models of motor
The control input here is the force acting on the beam However, in practice, this force will make it difficult for us to adjust the motor Therefore, students will find a way to convert the input to be applied to the motor
According to the real structure, motor include 2 parts: "electric" and "mechanical" as shown below [5]:
Fig 2 2 DC Motor block
The parameters of the motor will be described in the table below:
Trang 25Tab 2 2 Motor datasheet
2
m
K K R
Trang 27Fig 2 3 The transfer function of DC motor Since electrical speed is faster than mechanical speed the hundred times:
Symbols can refer the Tab 2 1 and Tab 2 2
.Causeand are very small, assuming that:
Based on (2.1.30), (2.1.31), (2.1.32) and (2.1.33)
Trang 28The advent of digital computers allows the application of optimal control theory to many complex problems The figure below describes the control process of the LQR algorithm The system (S) with the parameters (x) will be feedback and calculated to give the output signal (u) to control the system
Fig 2 4 LQR control system diagram x: output signal
u: control signal
S: control object
K: optimal coefficient matrix
To form an optimization problem, the first requirement is that the system has a nonlinear characteristic with extremes An essential step in the establishment of an optimal strategy
Trang 29is the determination of the cost function J The cost function J depends on the output signal x(t), the control signal u(t) and the time t The cost function J usually has the following form:
A special form of the LQ problem that arises in many control system problems is the
Linear Quadratic Regulator (LQR), where all the matrices A, B, Q, and R are constant
Trang 30From giving the nonlinear system to linear form:
PID controllers in general are created by using the following block diagram:
Fig 2 5 PID Controller Block Diagram Proportional Integral Derivative (PID) controller is an automatically optimized and
accurate control system used to regulate different parameters like temperature, pressure
and speed at desired values The basic mechanism used in PID controllers is control loop
Trang 31feedback A PID calculates the error by calculating difference between actual value and
desired value and then sets the deciding parameters accordingly This error is continuously
being calculated until the process stops
The above block diagram is in continuous domain The figure below will describe the
The proportional term produces an output value u t( ) that is proportional to the current
error value e t( ) We can easily adjust this proportional response by changing the
proportional gain constant K p
Kinematic description:
( ) p ( )
Where: u t( ): output value of the controller
e t( ): input value – error
K p: proportional gain
Trang 32Fig 2 7 Changing proportional term 2.3.1.2 Integral Term (I)
Integral term is directly proportional to magnitude of error and error duration The integral term calculates the sum of instantaneous error with respect to time The reading is then multiplied by the integral gain and added to system output
Integral term is responsible to speed up the process towards acquiring desired values and eliminates the error due to proportional term However as integral terms acquire sum of past values so it could cause the system to overshoot from the desired values
Where: u t( ): output value of the controller
e t( ): input value – error
Ki: integral gain
Trang 33Fig 2 8 Changing integral term
2.3.1.3 Derivative Term (D)
The derivative term produces an output value u(t) that is proportional to derivative of the current error value e(t) We can easily adjust this derivative response by changing the derivative gain constant Kd
Where: u t( ): output value of the controller
e t( ): input value – error
Kd: derivative gain
Trang 34Fig 2 9 Changing derivative term 2.3.4 Integrated Controller
Control systems often used a combination of the three term mentioned above, depending
on the system’s quality requirements and the complexity of design Designers can use P,
PI, PD, PID controller to control their systems Among them, PID controller tends to be the most effective for control systems
The PID controller is very flexible and can works under different circumstances When
Ti = ∞ and Td = 0, the controller works under Proportional term When Ti = ∞, the controller works under Proportional – Differential term When Td = 0, the controller works under Proportional – Integral term Output signals of the controller will be having a phase shift =
α compared to its input signals, with:
When we choose suitable P, I, D parameters for the PID controller, the system respond will get closer to the setpoint value we wanted, then the controller itself can be used in industrial systems There are two methods of finding parameters for the PID controller, by using theory (Zieger-Nichols method) or by trial and error method In this report, we mostly use trial and error method
2.3.5 Stability
If picked inaccurately, the PID controller can be insecure which means that its output is not precise or accurate Instability is the result of significant unnecessary gain, especially when the system has a high latency, in other words if the system lags, gain amplifies the instability factor
Instability can be observed in the Laplace domain from the following formula:
Trang 35( ) ( )
Hs=Ks G s +Ks G s (2.3.4)
Ks = PID Transfer Function
( )
G s = Plant Transfer Function
The system stability is measured by the result of the product of K(s)*G(s) There are
these conditions, which are:
If Ks G s ( )= <1, then the system is stable
If Ks G s ( )= -1 , then the system is unstable
with T : sampling time
Steady – state error :
E = |peak overshoot – output|
2.4 GA Algrithm
GA was introduced by Holland in 1975 as an algorithm to find the optimal solution on
the principle of imitating the evolutionary process and genetic laws of organisms in nature
[6] The mathematical essence of GA is a probabilistic search algorithm GA as well as
evolutionary algorithms in general is based on the view that the evolutionary process of
nature is the process that is the most perfect, the most reasonable and is itself optimal This
concept can be seen as a true premise that cannot be proved but it is consistent with
objective reality The evolutionary process shows the optimality in that, the next generation
is always better (more developed, more complete) than the previous generation Natural
evolution is sustained by two basic processes: reproduction and natural selection, new
generations are always born to supplement and replace the old generation The individual
that is more developed and adapted to the environment will be more likely to survive and
develop, and the individual that cannot adapt to the environment will be eliminated
Trang 36Environmental change is the driving force of evolution Conversely, evolution also acts back to contribute to environmental change
New individuals are born in the process of evolution by recombination in the parent generation A new individual can have traits from its parents (inherited), or it can also have completely new traits (mutations) Inheritance and mutation are two mechanisms of equal importance in the evolutionary process, although mutation occurs with much less probability than inheritance Although GA in particular and evolutionary algorithms in general have differences, they all simulate three basic processes of natural evolution: natural selection, hybridization (reproduction) and mutation
GA is a general stochastic optimization method used to solve search problems GA has some differences from conventional search and optimization algorithms First, GA works with populations of many chromosomes (sets of solutions), looking for multiple extremes
at the same time By means of genetic operations, GA exchanges information between extreme vertices, thereby limiting the possibility of local extremes In other words, GA is
a method of finding a globally optimal solution Second, GA works with symbol strings (chromosomal strings) but not parameters Third, the GA only needs to evaluate the objective function to guide the search process without any other information (such as derivatives ) Due to the above characteristics, GA has the ability to solve very effectively problems of finding nonlinear, non-differentiable, discontinuous functions extremum The GA diagram used to solve the optimization problem in control is presented To apply
GA to solve the optimal problem, we must first encode (encode) the solution of the problem into a sequence of chromosomes which can be a sequence of binary numbers, a sequence
of decimal numbers, a sequence of natural numbers or a sequence of real numbers Each chromosome represents an individual in the population To evaluate instances, an adaptation function must be defined, is usually the function to find the extreme or an equivalent transformation of the function to find the extreme The first generation of multiple instances (solutions) is randomly started Through the process of natural selection, the individuals that are most adapted to the living environment (with high adaptability) survive and have the opportunity to reproduce to create offspring that tend to adapt to the good living environment than the parent's generation The more adaptive an individual is, the more chances it has to survive and pair up with another individual to produce offspring Base on the process of hybridization, the good characteristics of the previous generation are passed on to the next generation Sometimes due to an error in the genetic process in nature, mutations occur with a very low probability The phenomenon of mutation can create very well-adapted individuals, whose fitness is far superior to the rest of the population Natural selection will eliminate the less well-adapted, resulting in evolution being repeated from generation to generation, The next generation tends to adapt to the living environment better than the previous generation, which means that the solution of the problem is gradually approaching the optimal solution
Trang 37Fig 2 10 GA flowchart 2.5 Uart communication
Uart communication is one of the most common types (also know as rs232 or serial) The data frame start with start (always low): When start bit detect the devices will take the signal every duration then convert to ascii table and print it to the monitor
UART communication components:
+ Baudrate: With asynchronous transmission, the Baudrate must be unified - the number
of bits transmitted in 1s
+ Frame: The frame must be configured to be the same between the receiver and the transmitter The number of transmitted bits is specified by the transmission frame and includes start bit, stop bit, parity bit, in addition, the number of bits specified in a data packet is also specified by the transmission frame
• Idle frame: If it is “1”, no frame is currently transmitted
• Break frame: If it is “0”, there is currently a frame being transmitted
• Start bit: is the first bit to be transmitted to indicate an upcoming frame The start bit is always "1" until it wants to transmit data, it will be pulled down to "0"
• Data: the least significant bit (LSB - right) will be transmitted first and the most influential bit last (MSB - left)
Trang 38• Parity bit: used to check transmitted data There are two types of parity:
‣ Even parity: If the parity bit is 0, then the total number of bits 1 in the data frame must always be an even number
‣ Odd parity: If the parity bit is 1 then the total number of bits 1 in the data frame is an odd number
• Stop bits: used to notify the transmitter/receiver that the data packet has been sent
Fig 2 11 Uart connection 2.6 Filter
When measuring the position of the ball with a sampling time of 0.001, 1000 samples will
be taken in 1s This sampling will increase the ability of the program to react to the position
of the ball, thereby giving reasonable control results, reducing the setup time But at the same time high sampling also results in noise that can occur frequently
Introduction about median filter: Median is a non-linear filter, commonly used to filter out noise in an image or digital signal Median filter is used to filter noise, in the image thereby improving image quality In addition, the median is also used in spike value filtering to improve control quality
History: The original idea of the current median filter comes from the mid-range filter introduced by Al-Biruni It was applied by Biruni to analyze Metals however when he published his work it was not accepted due to suspicion of fraud
Then the idea of the median filter appeared in Edward Wright's 1599 book
It was later recommended by Roger Joseph Boscovich and recommended by Laplace to minimize the expected error level But then it still didn't get much attention due to the appearance of Gauss and Legendre's innovation
Trang 39Antoine Augustin Cournot in 1843 was the first to use the Median concept to divide the probability distribution into two equal halves and was widely used in the fields of astronomy, sociology, psychology, and other fields related area
The median filter is a non-linear digital filtering technique, often used to remove noise from an image or signal Such noise reduction is a typical pre-processing step to improve the results of later processing Median filtering is very widely used in digital image processing because, under certain conditions, it preserves edges while removing noise (but see the discussion below), also having applications in signal processing
Define: In calculating median divide values into two equal halves in a dataset or a population In such a data series the median can be defined as the middle value The median
of a specified data file is the middle value of the file sorted from smallest to largest
In case the data number of a file is odd, the value of median is its middle value for example: median(1, 3, 3, 6, 7, 8, 9) = 6
In the case of an even number of data in a file, the value will be the average of the two middle numbers For example median (1, 2, 3, 4, 5, 6, 8, 9) = (4+5)/2 = 4.5
The median is well-defined for any ordered (one-dimensional) data, and is independent
of any distance metric The median can thus be applied to classes which are ranked but not numerical (e.g working out a median grade when students are graded from A to F) The main idea of the median filter is to run through the signal entry by entry, replacing each entry with the median of neighboring entries The pattern of neighbors is called the
"window", which slides, entry by entry, over the entire signal
Description: The main idea of the median filter is to run through the signal entry by entry, replacing each entry with the median of neighboring entries The pattern of neighbors is called the "window", which slides, entry by entry, over the entire signal For one-dimensional signals, the most obvious window is just the first few preceding and following entries, whereas for two-dimensional (or higher-dimensional) data the window must include all entries within a given radius or ellipsoidal region (i.e the median filter is not a separable filter)
Disadvantages: Median filters can solve the problem of filtering effectively, but require a selection of ranges for the median filter to work best For small ranges, the opposite will allow noise to easily pass through the filter to destroy the system vice versa if the range is too large The output value will be delayed compared to reality, thereby reducing the quality of the system and may cause the system to fluctuate for a long time and not reach the set point
The best way to choose a suitable range is to test on a real model using different median filter numbers to get the best value
Lowpass Filter: A low pass filter is a filter that allows signals with frequencies lower than the cutoff frequency to pass through and removes or attenuates signals with frequencies
Trang 40Low pass filters exist a lot in life: Includes electronic circuits: hiss filter circuit in audio processing, anti-aliasing filters for conditioning signals prior to analog-to-digital conversion smoothing signal for digital, low-pass filters provide a smoother form of a signal, removing the short-term fluctuations and leaving the longer-term trend
The ideal low-pass filter removes all values with frequencies above the cutoff frequency and leaves the frequencies below the cutoff intact
However, an ideal filter is not possible without a signal that is infinite in time, so it is necessary to generate an approximate real-time signal sequence It would therefore require
an infinite delay and support knowledge of the future and the infinite past
Real filter: Real filters for real-time applications approximate the ideal filter by truncating and windowing the infinite impulse response to make a finite impulse response However,
it still requires a moderate delay to calculate and predict the near future Higher accuracy requires higher delay times
Disadvantages of lowpass filter: To use the lowpass filter, you need a deep knowledge about the parameter which affects the system response