1. Trang chủ
  2. » Luận Văn - Báo Cáo

PID control for a cart and pole system simulation and application: Faculty of high quality training Graduation''s thesis of the Automation and Control Engineering Technology

98 2 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề PID Control For A Cart And Pole System Simulation And Application
Tác giả Đặng Thái Bảo, Nguyễn Tiến Thành
Người hướng dẫn PhD. Nguyễn Văn Đông Hải
Trường học Ho Chi Minh City University of Technology and Education
Chuyên ngành Automation & Control Technology
Thể loại graduation project
Năm xuất bản 2022
Thành phố Ho Chi Minh City
Định dạng
Số trang 98
Dung lượng 5,52 MB

Cấu trúc

  • CHAPTER 1: OVERVIEW (17)
    • 1.1. INTRODUCTION (17)
    • 1.2 RESEARCH OBJECTIVES (19)
    • 1.3 RESEARCH CONTENTS (19)
  • Chapter 1: Overview (17)
  • Chapter 2: Theoretical Basis and Mathematical Model and Controlling Algorithm (21)
  • Chapter 3: Controller Design (28)
  • Chapter 4: Constructing the Model (44)
  • Chapter 5: Results (63)
  • Chapter 6: Conclusion (80)
    • 1.4 LIMITATIONS (20)
  • CHAPTER 2. THEORETICAL BASIS MATHEMATICAL MODEL AND (21)
    • 2.1. CONSTRUCTING THE MATHEMATICAL MODEL (21)
  • CHAPTER 3. CONTROLLER DESIGN (28)
    • 3.1 PID CONTROLLER (28)
      • 3.1.1 PID CONTROLLER BASICS (28)
      • 3.1.2 STRUCTURE OF A PID CONTROLLER (29)
    • 3.2 GENETIC ALGORITHM (GA) (34)
      • 3.2.1 DEFINITION (34)
      • 3.2.2 PROPERTIES (34)
      • 3.2.3 STRUCTURE OF A SIMPLE GA PROGRAM (36)
      • 3.2.4 IMPLEMENTATION IN MATLAB (37)
      • 3.2.5 INVERTED PENDULUM MODEL BLOCK (40)
      • 3.2.6 PID CONTROLLER BLOCKS (41)
      • 3.2.7 USING THE GA TO FIND OPTIMAL PID’S PARAMETERS (42)
  • CHAPTER 4. CONSTRUCTING THE MODEL (44)
    • 4.1.1 EXPERIMENTAL MODEL (44)
    • 4.1.2 EQUIPMENT CHOOSING (45)
    • 4.2 CONNECTION DIAGRAM (55)
    • 4.3 SOFTWARES USED (58)
    • 4.4 CONTROLLING PROGRAM FOR THE MODEL (60)
  • CHAPTER 5. RESULTS (63)
    • 5.1 SIMULATION RESULTS (63)
      • 5.1.1 BALANCED POSITION (63)
      • 5.1.2 SINE WAVE (64)
      • 5.1.3 SQUARE WAVE (64)
    • 5.2 EXPERIMENT RESULTS (66)
      • 5.2.1 EXPERIMENT RESULTS OF THE SET OF FIRST PID PARAMETERS (66)
      • 5.2.2 EXPERIMENT RESULTS OF THE SET OF SECOND PID PARAMETERS (73)
  • CHAPTER 6. CONCLUSION (80)
    • 6.1 CONCLUSION (80)
    • 6.2 FUTURE IMPROVEMENTS (80)

Nội dung

60 Trang 15 LIST OF ACRONYMS Acronyms Meaning GA Genetic Algorithm PID Proportional-Integral-Derivative C&P Cart and Pole Inverted Pendulum on Cart HCMUTE Ho Chi Minh city University o

OVERVIEW

INTRODUCTION

Cart and Pole (C&P, also known as Inverted Pendulum) is a classic mathematic problem, is primarily used in many experiments about controlling theory because of its non-linearity and high instability The system also serves as a foundation for more complex system like orbiting and tracking missiles, machinery axes that needed to be stabilized with high precision, etc

In fact, many similar research on how to control the trajectory of the Inverted Pendulum system have been carried out through the decades, in many countries around the world [1] However, the majority of them are only conducted through simulation [2] Many studies with a functioning model also do not implement orbital control, only do placement control at a fixed point Many researches also use self-made models [3] controlled by the algorithms such as PID, Fuzzy or Sliding Mode Controller

Researchers from many universities around the world, including undergraduates, have done projects related to under-actuated systems (SIMO - single input multiple output) [2][3] In our country, some research such as [4] of the University of Technology have contributed to solving the non-linear control for stabilizing in-place system Ho Chi Minh city University of Technology and Education has also experimentally succeeded in stabilizing the advanced C&P system (with two poles) by linear control algorithms such as LQR [5]

Wanting to learn more about the system, our group has chosen one of the classic controlling algorithms widely applied [3][5] which is the PID Algorithm for this graduation project For optimization purposes, we will also apply Genetic Algorithm (GA) to find the most optimal set of PID parameters Through this project, we also want to test the controllability on unstable models like the Cart and Pole, thereby applying them to larger- scale experimental models

Figure 1.1: Quanser’s Cart and Pole system

RESEARCH OBJECTIVES

Applying the Euler – Larange equation to find the mathematical equation of the Cart and Pole system

Software Implementation: Simulate the system on Matlab Simulink and determine how the system works with orbital control (sine wave, square wave)

Hardware Implementation: Build a PID controller to control the system according to the desired trajectory

Using genetic algorithm to optimize the PID controller through finding its optimal parameters

Test the applicability of the research on our self-made model, using STM32 and Matlab (using Waijung blockset libraries).

Overview

Cart and Pole (C&P, also known as Inverted Pendulum) is a classic mathematic problem, is primarily used in many experiments about controlling theory because of its non-linearity and high instability The system also serves as a foundation for more complex system like orbiting and tracking missiles, machinery axes that needed to be stabilized with high precision, etc

In fact, many similar research on how to control the trajectory of the Inverted Pendulum system have been carried out through the decades, in many countries around the world [1] However, the majority of them are only conducted through simulation [2] Many studies with a functioning model also do not implement orbital control, only do placement control at a fixed point Many researches also use self-made models [3] controlled by the algorithms such as PID, Fuzzy or Sliding Mode Controller

Researchers from many universities around the world, including undergraduates, have done projects related to under-actuated systems (SIMO - single input multiple output) [2][3] In our country, some research such as [4] of the University of Technology have contributed to solving the non-linear control for stabilizing in-place system Ho Chi Minh city University of Technology and Education has also experimentally succeeded in stabilizing the advanced C&P system (with two poles) by linear control algorithms such as LQR [5]

Wanting to learn more about the system, our group has chosen one of the classic controlling algorithms widely applied [3][5] which is the PID Algorithm for this graduation project For optimization purposes, we will also apply Genetic Algorithm (GA) to find the most optimal set of PID parameters Through this project, we also want to test the controllability on unstable models like the Cart and Pole, thereby applying them to larger- scale experimental models

Figure 1.1: Quanser’s Cart and Pole system

Applying the Euler – Larange equation to find the mathematical equation of the Cart and Pole system

Software Implementation: Simulate the system on Matlab Simulink and determine how the system works with orbital control (sine wave, square wave)

Hardware Implementation: Build a PID controller to control the system according to the desired trajectory

Using genetic algorithm to optimize the PID controller through finding its optimal parameters

Test the applicability of the research on our self-made model, using STM32 and Matlab (using Waijung blockset libraries)

Provide an overview of this research, research objectives, contents and limitations

Chapter 2: Theoretical Basis and Mathematical Model and Controlling Algorithm

Presenting basic knowledge on how we built this system’s mathematical model This includes the system’s parameters, theories about Euler-Lagrange equations, dynamic equation and state equation of the system, dynamic structure of the motor…

Provide an overview about PID controllers and GA optimization Based on the system’s parameters and its mathematical model, create a PID controller to control the desired output signal

Constructing an experimental model of cart and pole system, selecting suitable components for the system, develop a connection diagram and provide a brief overview on how the system works

Showing the results of both our simulation and experiment Simulate how the system works with orbital control, meanwhile also try to control it through the self-made experimental model

Present the achieved results, then discuss the advantages and defects as well as future improvements of this project

This project only focused in:

- Developing a suitable mathematical model for the cart and pole system Other inverted pendulum system such as rotary, pendubot, etc are not applicable

- Use simulation to emulate the system and collecting results The controller used is PID, other controllers like Fuzzy, SMC… are also not applicable

- Programming STM32 on Matlab Simulink to control a Cart and Pole self-made system.

Theoretical Basis and Mathematical Model and Controlling Algorithm

The C&P system is described as in figure 2.1 below:

Figure 2.1: Cart and Pole system

In figure 2.1, the pole will be rotating around an axis of the encoder attached directly to the cart We aim to keep the pole stabilized at the balanced position (upward) At the same time, the cart will also be moving along a calculated orbit so that the pole will not be able to fall below and keep swinging at the balanced position A PID controller will be used to achieve this objective

All parameters of this system are listed in Table 2.1 below:

Table 2.1: Parameters of the system

L Length of the pole Meters (m) 0.48 m Weight of the pole Kilograms (kg) 0.23

M Weight of the cart Kilograms (kg) 0.39

Pendulum’s angle rad x Cart’s position m

Force acting on the system N

By using the Euler – Lagrange equation, we have:

L = T − V is the Lagrange’s operator equation, with L is the Lagrange function, V being the system’s potential energy, T is the system’s kinetic energy, Q is the sum of external force acting on it

We have the position of the pole demonstrated under x-axis and y-axis as below:

By taking the derivative of equations (1.2) and (1.3), we can find the velocity of this pole:

Kinetic Energy of the system is demonstrated as: T =T cart +T pole (1.8) With the cart’s kinetic and pole’s kinetic respectively being:

From (1.8), (1.9) and (1.10), we have the final kinetic equation below:

Since the potential energy’s origin is also at the cart’s position, the cart’s potential energy will be zero Therefore, our total potential energy equation will be:

Substitute (1.11) and (1.12) into the Lagrange’s operator:

Finally, we can get the Euler - Lagrange set of equations as following:

( ) cos 2 sin sin sin d L x m M x mL mL dt

L mLx J mL d L mLx mL x J mL dt

The state set of equations’ input is also the force created by the motor:

( ) cos sin cos sin 0 m M x mL mL F mLx J mL mgL

Then, the state set of equations are rewritten in matrix form:

The force acting on the cart will make it difficult for controlling the motor Therefore, to perform the controlling process practically with the real model, we need to transform input signal from force to voltage used to supply the motor To do this, we need to find the kinetic equation as well as parameters of the motor The motor is structurally divided into two following parts in figure 2.1.2 below:

Figure 2.2: Structure of the motor With the default parameters provided below:

• J m : inertia moment of the rotor (kgm 2 )

• : motor’s shaft rotation angel (rad)

• : oil’s frictional coefficient (Nm/(rad/sec))

By applying the Kirchhoff’s circuit laws, we have: m m b

By applying the Newton’s Law for motor’s rotational motion, we also have:

Motor’s power and electrical power is demonstrated respectively as: m m

Due to the principle of energy conservation: P e = P m (1.27) b m

If both Kb and Kt use MKS measuring unit (Kb is V/rad/sec, Kt is Nm/A):

Laplace transforming for both (1.22), (1.23) we get:

K I s − J s C+  = s T s + s (1.30) Presume that and K f are constants, T f = K f sgn(Ω ,

Since the motor’s inductance is rather small, we can ignore L m di dt Equation (1.22)

→ = − , with E = U From this we have:

By the transmission structure of the motor, the cart’s position is:

=  with R is the cart’s wheel radius, while d1 is the gear ratio coefficient

Substitute this result into the (1.32) equation, we have: t t b m m m

Since we ignored T f , we can directly replace (1.33) into (1.24) to get the following equation:

The forces acting on the cart will be calculated as:

F = k U − k x k x − (e = U is the voltage supplying the motor)

The kinetic equation of the whole system became:

( ) cos sin cos sin 0 m M x mL mL k U k x k x mLx J mL mgL

Ultimately, the state variable set of equations of this system is demonstrated as:

Controller Design

A PID controllers in general are created by using the following block diagram:

Figure 3.1: Continuous PID Controller Block Diagram

Controlling process is a closed-loop process Set-point is the initial value that the system must work around depending on its quality Ensuring the stability of the system is based on how close the output signal is compared to the set-point value, with minimum error and highest transient time

The above block diagram is in Continuous domain In Discrete domain, a PID controller will be looking like this:

Figure 3.2: Discrete PID Controller Block Diagram

Each PID controller has 3 components: Proportional Term (P), Integral Term (I) and Derivative Term (D) Each component has different impact on the controlling process Further details about each component and their impact on the overall system will be shown in the following section

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: u(t) = K P e(t) with u(t): output value of the controller e(t): input value – error

By adjusting Kp, we get the result as shown in the figure 3.3 above We can clearly observe the effects of increasing Kp When the proportional gain is too high, the system will become unstable, with high overshoot and high settling time Too low proportional gain also can make the system become less stable, since the control action is too small when responding to the system When Kp is increased by a reasonable value, the output got less settling time, higher rise time and lower overshoot, which also make the system more stable

In Discrete domain, the Proportional term is:

Figure 3.3: Effect of adjusting Kp on the system

The integral term produces an output value u(t) that is proportional to integral of the current error value e(t) We can easily adjust this integral response by changing the integral gain constant K i

Kinematic description: with u(t): output value of the controller e(t): input value – error

Figure 3.4: Effect of adjusting Ki on the system

By adjusting Ki, we get the result as shown in the figure above This term can accelerate movements of the process towards the initial set-point, and also eliminates steady-state error caused when we use the Proportional Term However, it can create high overshoot and high settling time, which means reducing the overall stability, since the Integral Term respond is slow as its nature

In Discrete domain, the Integrator Term can be described as:

It can be estimated in three ways:

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 K d

Kinematic description: with u(t): output value of the controller e(t): input value – error

Figure 3.8: Effect of adjusting Kd on the system

By adjusting Kd, we get the result as shown in figure 3.8 above Derivative term can improves settling time and stability of the system by predicting system behaviors

In Discrete domain, the Derivative Term can be described under three ways:

Genetic Algorithm in computer science is an adaptive search algorithm inspired by Charles Darwin’s theory of nature’s evolution Back in 1975, John Henry Holland a pioneer in what became known as Genetic Algorithms today, has developed this algorithm, applied it to many artificial systems It is now used as an effective solution to combinatorial optimization and classification problems, which utilizes the biologically inspired operators such as inheritance, crossover, mutation and selection GA, like other evolutionary algorithms, are based on a concept that is considered objectively realistic: “The natural evolutionary process is the most perfect, the most rational and is already optimal by itself” This process proves its optimal characteristic through an objective truth: The next generation will always be better than the previous ones

In this research, GA is applied to optimize the system’s PID controller By modifying the attributes in the original dataset, then running through several hundred “generations”, we can gain access to the better optimized results

GA help solving problems by simulating the natural evolution of humans and other creatures (based on the theory of evolution by Charles Darwin), under specified environmental conditions The ultimate goal of GAs is not to give the absolute optimal solution, but to give the relatively optimal solution to a problem

Each individual in GAs will represent a different solution to a problem However, unlike in nature, our limitation in GAs is one individual only has one chromosome

Each chromosome is created by many genes, each of them can have very different values to specify a condition In GAs, a gene is treated as an element of the chromosome chain

A combination of individuals that share certain characteristics is called a population In GAs, a “population” is used to represents a combination of solutions for a problem The population size depends on each problem’s nature, usually it contains several thousands or hundreds of possible solutions The initial population is usually generated randomly, allowing a much bigger range of possible solutions This is the initialization process

During each successive generation, parts of the existing population is selected to breed a new generation A fitness-based process is applied, which allows selecting the fitter (better) solution Then those that are selected will be used to create the second generation population of solutions, through crossover and mutation For each new solution produced, a pair of parent solutions will be selected for breeding from the previously selected pool Through crossover and mutation, a new solution is created which shares many

CHAPTER 3 CONTROLLER DESIGN characteristics of its parents This process will continue until a new population of solutions with appropriate size is generated, which also generates higher quality chromosomes Thus, increasing the average fitness value

3.2.3 STRUCTURE OF A SIMPLE GA PROGRAM

Figure 3.9: A simple GA Program’s Structure

As seen in the figure above, we can see a simple implementation of GAs:

1 Receive parameters for the algorithm

2 Create a random generation with n individuals called Population Zero (with n being the solution for our problem)

3 Evaluate the fitness value of each individual in the current Population

• Create the next Population by going through the genetic operators continuously:

• Selection: Choose 2 parent individuals from the old population depending on their adaptation The higher their adaptation is, the higher chance they are chosen for the breeding process

• Crossover: Combine the genetic information of the previous parents to generate new solutions

• Mutation: Maintain genetic diversity from a population’s generation to the next This is used to avoid local minima by preventing the chromosomes of each population becoming similar to each other and slowing the process down

5 Re-evaluating the new fitness value and check the stop condition If satisfied, return the highest fitness value (best solution) then end the algorithm

Based on the calculation, as well as theoretical methods mentioned in the previous sections, we have implemented a system simulation program through Matlab/Simulink to get an intuitive view of this system’s operation, and its feasibility on applying to real life systems The system is created as following:

Figure 3.10: Simulation model of the C&P system

The following sections have a critical role in this simulation model:

Constructing the Model

4.1 EXPERIMENTAL MODEL AND CHOOSING THE RIGHT EQUIPMENTS 4.1.1 EXPERIMENTAL MODEL

Figure 4.1 is the experimental model which is used in this project

Figure 4.1: Cart & Pole system in experiment (temp) The structure of the actual Cart and Pole system consists of the following parts:

• 1: A hard slider on the base and is pulled back and forth through the head motor base, intermediate via belt Friction is minimized by applying beef grease onto the skid of the cart On the slider is attached an Encoder 600 pulses to calculate the angle of deflection of the pendulum relative to the upward vertical

• 2: Motor controls the system, on the motor shaft is mounted Encoder 600 pulses to calculate the displacement of the Cart

• 3: Base is a 4-legged iron frame Constructed like a low table frame which is light and convenient for moving but also ensures the strengthening when the system is working

• 4: On the encoder shaft, there is an aluminum pendulum bar The pendulum bar is not too light to be able to create an imbalance to show hardware control algorithm However, the pendulum bar cannot be too heavy to protect the encoder shaft on the slider from breaking

• 6: 12VDC power supply to the system

• STM32F4-Discovery is a microcontroller board to learn embedded programming with programming on 32-bit ARM series microcontroller, etc

• The board is integrated with ARM Cortex-M4 chip along with a digital compute unit real (FPU), operating with a very high frequency of 168 MHz, a high DMIPS/MHZ ratio of 1.25 makes the system able to achieve 210 DMIPS performance, the board is very suitable for applications with high computational requirements Fast, for example, DSP, robot control, etc

• With STM32F4Discovery, users will not need to worry and don't need to spend money to buy expensive charging circuits like conventional MCU boards The most outstanding feature of the board is that it has many features while being very cheap

• Core: Arm® 32-bit Cortex®-M4 CPU with FPU, Adaptive real-time accelerator (ART Accelerator) allowing 0-wait state execution from Flash memory, frequency up to 168 MHz, memory protection unit, 210 DMIPS/ 1.25 DMIPS/MHz (Dhrystone 2.1), and DSP instructions

- Up to 1 Mbyte of Flash memory

- Up to 192+4 Kbytes of SRAM including 64- Kbyte of CCM (core coupled memory) data RAM

- Flexible static memory controller supporting Compact Flash, SRAM, PSRAM, NOR and NAND memories

• Clock, reset and supply management

- 1.8 V to 3.6 V application supply and I/Os

- POR, PDR, PVD and BOR

- Internal 16 MHz factory-trimmed RC (1% accuracy)

- 32 kHz oscillator for RTC with calibration – Internal 32 kHz RC with calibration

- Sleep, Stop and Standby modes

- VBAT supply for RTC, 20×32 bit backup registers + optional 4 KB backup SRAM

• 3×12-bit, 2.4 MSPS A/D converters: up to 24 channels and 7.2 MSPS in triple interleaved mode

• General-purpose DMA: 16-stream DMA controller with FIFOs and burst support

• Up to 17 timers: up to twelve 16-bit and two 32- bit timers up to 168 MHz, each with up to 4 IC/OC/PWM or pulse counter and quadrature (incremental) encoder input

- Serial wire debug (SWD) & JTAG interfaces

• Up to 140 I/O ports with interrupt capability

- Up to 136 fast I/Os up to 84 MHz

- Up to 3 × I2C interfaces (SMBus/PMBus)

- Up to 4 USARTs/2 UARTs (10.5 Mbit/s, ISO 7816 interface, LIN, IrDA, modem control) – Up to 3 SPIs (42 Mbits/s), 2 with muxed full-duplex I2S to achieve audio class accuracy via internal audio PLL or external clock

- USB 2.0 full-speed device/host/OTG controller with on-chip PHY

- USB 2.0 high-speed/full-speed device/host/OTG controller with dedicated DMA, on-chip full-speed PHY and ULPI

- 10/100 Ethernet MAC with dedicated DMA: supports IEEE 1588v2 hardware, MII/RMII

• 8- to 14-bit parallel camera interface up to 54 Mbytes/s

• RTC: sub-second accuracy, hardware calendar

Figure 4.3: STM32F4 Discovery Board – Pin Diagram

Figure 4.5: Omron encoder E6B2-CWZ6C pinout

• Encoder 1000 pulses E6B2-CWZ6C is produced by genuine Omron for accuracy, stability and durability, note that currently on the market there are many types of Fake with cheap price, very unstable and quickly damaged

• Encoder 1000 pulses Omron E6B2-CWZ6C is used to connect to motors or other structures that need to determine coordinates, positions, etc Encoder has high accuracy up to 1000 pulses/ 1 round (1000 p/ r) with 3 separate output pulse channels A, B, Z

• Number of pulses: 1000 pulses / 1 cycle (1000 p/r)

• Number of pulse channels: 3 separate pulse channels A, B, Z

• Pulse output type: NPN open collector (need to connect a resistor to VCC to make high (High))

• Pins configuration of this encoder is shown in the table below:

Table 4.1: Pins of Omron encoder

4.1.2.3 JGB37-545 DC GEARED MOTOR DC SERVO MOTOR

Figure 4.6: JGB37-545 DC Geared Motor DC Servo Motor

Vcc GND Channel A Channel B Speed

JGA25-370 DC Geared Motor has a metal structure for durability and high stability, used in models of robots, vehicles, boats, , the motor's reducer has Many gear ratios make it easy to choose between traction and speed (the greater the traction, the slower the speed and vice versa), the engine uses high-quality materials (pure copper wire core, 407 steel foil) , nickel contact ring, strong magnetic magnet, ) for strength and durability superior to cheap ones on the market today (using aluminum wire core, weak magnetic magnet)

• Gear ratio 9:1 (motor turns 9 revolutions main shaft, reducer rotates 1 revolution)

• Maximum withstand current under load: 1.3A

• No-load speed: 800RPM (800 rpm)

• Maximum endurance speed under load: 550RPM (550 rpm)

• Rated Torque Moment: 0.18KG.CM

• Maximum Torque Moment: 0.65KG.CM

• Attached to the end of this motor is another unamed rotary encoder to read the cart’s position which has the following pins configuration:

Table 4.2: Pins of DC Motor’s encoder

4.1.2.4 SWITCHING MODE POWER SUPPLY (SMPS) 12V 5A S-60-12

Figure 4.7: Switching Mode Power Supply S-60-12

Vcc GND Channel A Channel B Speed

• The Switching Mode Power Supply is used for rectification from the AC grid into

DC power for electronic equipment

• Uses: power supply for led lights, motors, electronic devices,

• Input voltage: AC 220V or 110VAC

• Switching Mode Power Supply, led source 12V 5A S-60-12

• The L298 DC motor driver circuit is capable of controlling 2 DC motors, maximum current 2A each, integrated circuit protection diode and power IC 7805 to supply 5VDC power to other modules (only use this 5V if power supply

Ngày đăng: 25/02/2024, 14:39

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN