IP Experiment Manual V2.00

184
©Googol 2006 1 INVERTED PENDULUM EXPERIMENTAL MANUAL Suitable for GLIP Series GOOGOL TECHNOLOGY Second Edition, July, 2006 Be sure to give this instruction manual to customers! Thank you very much for purchasing INVERTED PENDULUM (GIP Series) of Googol Tech. Be sure to read this manual carefully before operation. For any technical trouble, call us or visit http://www.googoltech.com on the World Wide Web for consultation. After reading this manual, keep it handy so that it can be referred to at anytime.

Transcript of IP Experiment Manual V2.00

Page 1: IP Experiment Manual V2.00

©Googol 2006 1

INVERTED PENDULUM

EXPERIMENTAL MANUAL Suitable for GLIP Series

GOOGOL TECHNOLOGY

Second Edition, July, 2006

Be sure to give this instruction manual to customers!

Thank you very much for purchasing INVERTED PENDULUM (GIP Series) of Googol Tech.

Be sure to read this manual carefully before operation. For any technical trouble, call us or visit http://www.googoltech.com on the World

Wide Web for consultation. After reading this manual, keep it handy so that it can be referred to at anytime.

Page 2: IP Experiment Manual V2.00

GOOGOL TECHNOLOGY

©Googol 2005 I

Copyright Statement

Googol Technology (HK) Limited

All rights reserved

Googol Technology owns the patent, copyright or any other intellectual property right of this product and its software:

Linear inverted pendulum GLIP series including 《GLIP Series Installation and User Manual》and《Inverted Pendulum and Automatic Control Theory Experiment》

Under the copyright laws, no one shall directly or indirectly duplicate, produce,

process or use this product and its relevant parts in any form without the prior written permission of Googol Technology.

Disclaimer

Googol Technology reserves the right of modifying the products and product specifications described in this manual without notification in advance. Googol Technology is not responsible for any direct, indirect, special, incidental or consequential loss or liability caused by using this manual or product incorrectly.

Trademarks

Windows and Microsoft are registered trademarks of Microsoft Corporation.

Mathematica is registered trademark of Wolfram Research Inc.

Matlab is trademark of Mathworks Inc.

Page 3: IP Experiment Manual V2.00

©Googol 2006 II

CAUTIONS ON SAFETY

Linear inverted pendulum systems are mainly used for education and research purpose. Before installation, operation and maintenance, please read this manual carefully. After reading this manual, keep it handy so that it can be referred to at anytime.

CAUTIONS ON USING

Before use (installation, operation, maintenance, examine and repair), please make sure to comprehend this manual and other related materials. Do not use the equipment until user get familiar with the machine property, safety caution and instructions.

The safety instructions are classified to “Danger”, “Caution”, “Compulsion” and “Prohibition”.

Table 1-1 Warning Signs

Incorrect operation may result in such a dangerous situation as death or serious injury.

Incorrect operation may result in such a dangerous situation as medium or slight injury.

Operations must be done.

Prohibited operations.

Moreover, even the content in “Caution” may result in serious accident in certain situations. Please strictly comply all the instruction in operating the equipment.

Although not in “Danger” or “Caution”, user should still comply the rules strictly.

Page 4: IP Experiment Manual V2.00

©Googol 2006 III

This manual describes general safety precautions only. It doesn't include every

precaution measure for laboratory personnel in actual experimental environment. Sorry for any inconvenience caused.

For safety reason, please make sure all the operation and maintenance staff be trained according to this manual. The operator should read carefully all the manuals of linear inverted pendulum system.

The figure or photo in this manual are demo examples, the real product might

be slightly different in appearance; Please contact our sale department if the manual is lost or damaged; Please note that warranty will be voided if any modification is made on the

product.

Machinery in motion can be dangerous. Please be careful to the possible

dangerous situations.

Page 5: IP Experiment Manual V2.00

Table of Content

©Googol 2006 IV

Foreword

This is an experimental instruction for undergraduate and postgraduate students major in the area of industrial automation and mechatronics. The book can be used in control courses as the experimental instruction. The main content of this book includes experiments of classical control and modern control theories. The classical control theory includes system modeling, root locus analysis and controller design, frequency response, PID control, etc. The modern control theory includes state space pole placement and linear quadratic regulator (LQR) method. All experiments are based on Googol inverted pendulum platform.

Inverted pendulum is the typical experiment platform for the study of control

theories. Since the control strategies of the inverted pendulum system is similar to the balance performance of the acrobats, and a lot of the abstract control concepts such as system stabilities, controllability, system anti-interference property etc can be displayed via the inverted pendulum system experiments, it becomes the essential control theory educational experiment facility in a lot of US and European institutes and colleges. Students can verify the control theories and algorithms of the automatic control theories via the inverted pendulum system experiments easily and directly.

Not only is the inverted pendulum an excellent educational experiment apparatus, it is also an ideal experiment platform for carrying out researches on control theories. Since the inverted pendulum system possesses the characteristics of high order, instability, multiple-variables, non-linear and coupled, it is considered as a typical research target by many modern control theory researchers. New control strategies and control methods are discovered, and the related results are widely applied in the fields of aerospace technology and robotics. More complicated and different formats of inverted pendulum systems become the focal point in the fields of control theory research, and lot of outstanding papers appears in professional journals every year since the 90s.

Googol Technology LTD(Googol for short here after) provides experimental solutions for automatic control study in institutes and colleges base on inverted pendulum systems, including varies pendulum systems development and production, experiment set up and recommendation of textbooks and references related to automatic control theories. The inverted pendulum system developed by Googol includes linear series, circular series and configurable series. The main features are:

Open architecture: Bu using 4 axes motion control card, the mechanical and

electrical part can be easily extended according to the user requirement. Software interface is also open to the user. User may either use the provided experimental

Page 6: IP Experiment Manual V2.00

Table of Content

©Googol 2006 V

software or add user define function. Modularization: the mechanical part can be based on linear or rotary platform,

and then configured to 1-stage, 2-stage or 3-stage inverted pendulum. 3-stage inverted pendulum can be easily disassembled to 2-stage inverted pendulum and 2-stage inverted pendulum can be disassembled to 1-stage inverted pendulum. Software is also modularized, customer may add or modify related function module conveniently.

Easy and safety: the experimental system includes motion controller, electric box (integrated to mechanical body in rotary platform systems), mechanical body and PC, easy for maintenance and update. Moreover, there are protection designs on the mechanical part, motion controller and software, to ensure the safety of operator and equipments.

Convenience:Inverted pendulum systems are easy to install, update and the software interface is user friendly.

Advance:The system use industrial 4 axes motion control card as the core control system, advanced AC servo motor driver and high precision photoelectric coded compass. The design matches the direction of advanced motion control development.

Experimental software diversity: the experimental software includes BorlandC++, VC++ and Matlab,providing complete hardware and software interface, convenient for experiment and development.

Complete experimental manuals: There are <<Operation Manual>> and <<Experimental Manual>>, user may set up experiments as instructed in the manual or design experiment by themselves.

Googol inverted pendulum systems are suitable for experiment of the following courses: automation control principle, modern control theory, modern control engineering, optimal control, nonlinear system control, intelligent control, fuzzy control and neural network control, etc. In this book, a series of experiments are introduced based on Googol linear inverted pendulum systems. When setting up the related experiments, user should both have <<GT Series Motion Controller User Manual>>, <<GT Series Motion Controller Programming Manual>>, <<Panasonic AC Servo Motor Driver Operating Manual>> and manuals of other related equipment.

Page 7: IP Experiment Manual V2.00

Table of Content

©Googol 2006 VI

Table of Content

COPYRIGHT STATEMENT ............................................................................................. I DISCLAIMER................................................................................................................ I TRADEMARKS ............................................................................................................. I CAUTIONS ON SAFETY........................................................................................ II CAUTIONS ON USING........................................................................................... II FOREWORD ...............................................................................................................IV TABLE OF CONTENT ..................................................................................................VI

CHAPTER 1 OVERVIEW.........................................................................................1

1.1 INTRODUCTION ...................................................................................................1 1.2 INVERTED PENDULUM CLASSIFICATION ..............................................................1 1.3 INVERTED PENDULUM PROPERTIES .....................................................................3 1.4 CONTROLLER DESIGN METHOD..........................................................................4 1.5 INVERTED PENDULUM EXPERIMENTS..................................................................4

CHAPTER 2 MOTION CONTROL BASIC EXPERIMENT ................................6

2.1 ENCODER PRINCIPLE AND APPLICATION..............................................................6 2.1.1 Encoder Principle.........................................................................................6 2.1.2 Angle Conversion ........................................................................................7 2.1.3 Encoder Experiment.....................................................................................7

2.2 MOTOR CONTROL IN MATLAB SIMULINK..........................................................16

CHAPTER 3 LINEAR INVERTED PENDULUM MODELING, SIMULATION AND EXPERIMENT.................................................................................................25

3.1 1-STAGE LINEAR INVERTED PENDULUM SYSTEM MODEL .................................25 3.1.1 Differential Equations Methods.................................................................25

3.1.1.1 Newton’s Mechanics............................................................................25 3.1.1.2 Lagrange Method.................................................................................29

3.1.2 System Parameters .....................................................................................33 3.1.3 Real System Model ....................................................................................33 3.1.4 System Controllability Analysis ................................................................34 3.1.5 System Step Response Analysis.................................................................36

3.2 1-STAGE LINEAR IP ROOT LOCUS CONTROL EXPERIMENT ................................38 3.2.1 Root Locus Analysis ..................................................................................38 3.2.2 Root Locus Method and Simulation ..........................................................40

3.2.2.1 Root Locus Method..............................................................................40 3.2.2.2 MATLAB Simulation...........................................................................43 3.2.2.3 MATLAB Simulink .............................................................................48

3.2.3 Root Locus Real Time Control Experiment...............................................54 3.2.4 Experiment Result and Report ...................................................................57

3.3 1-STAGE LINEAR INVERTED PENDULUM FREQUENCY RESPONSE ......................59

Page 8: IP Experiment Manual V2.00

Table of Content

©Googol 2006 VII

3.3.1 Frequency Response Analysis....................................................................59 3.3.2 Frequency Response Design and Simulation.............................................61 3.3.3 1-stage Linear IP Frequency Response Experiment ..................................70 3.3.4 Experiment Result and Report ...................................................................73

3.4 1-STAGE LINEAR IP PID CONTROL EXPERIMENT ..............................................74 3.4.1 PID Control Analysis .................................................................................74 3.4.2 PID Control parameters and Simulation ....................................................75 3.4.3 PID Control Experiment ............................................................................80

3.4.3.1 Experiment steps in MATLAB experimental software........................80 3.4.4 Experimental Result and Report ................................................................83

3.5 STATE SPACE POLE PLACEMENT CONTROL EXPERIMENT ..................................84 3.5.1 State Space Analysis ..................................................................................84 3.5.2 Pole Placement and Simulation .................................................................85 3.5.3 Pole Placement Control Experiment..........................................................97 3.5.4 Experiment Result and Report .................................................................100

3.6 LINEAR QUADRATIC LQR OPTIMAL CONTROL EXPERIMENT ..........................101 3.6.1 Linear Quadratic LQR Optimal Control Principle and Analysis .............101 3.6.2 LQR Control Parameters and Simulation ................................................102 3.6.3 1-stage Linear IP LQR Control Experiment ............................................106 3.6.4 Experiment Result and Report .................................................................109

CHAPTER 4 1-STAGE LINEAR PENDULUM MODELING AND EXPERIMENT ........................................................................................................ 110

4.1 1-STAGE LINEAR PENDULUM MODELING AND ANALYSIS ................................110 4.1.1 1-stage Linear Pendulum Modeling.........................................................110 4.1.2 Real System Model ..................................................................................114 4.1.3 System Controllability Analysis ..............................................................115

4.2 1-STAGE LINEAR PENDULUM ROOT LOCUS ANALYSIS ....................................116 4.3 1-STAGE LINEAR PENDULUM FREQUENCY RESPONSE ANALYSIS.....................117 4.4 1-STAGE LINEAR PENDULUM STEP RESPONSE ANALYSIS ................................118 4.5 1-STAGE LINEAR PENDULUM PID CONTROL SIMULATION AND EXPERIMENT..119

4.5.1 1-stage Linear Pendulum PID Control Analysis and Simulation.............119 4.5.2 1-stage Linear Pendulum PID Real Time Control ...................................123

4.6 1-STAGE LINEAR PENDULUM LQR CONTROL SIMULATION AND EXPERIMENT 126 4.6.1 1-stage Linear Pendulum LQR Control Analysis and Simulation ...........126 4.6.2 1-stage Linear Pendulum LQR Control Experiment ...............................130

CHAPTER 5 1-STAGE LINEAR IP SWING UP EXPERIMENT.....................134

5.1 ENERGY CONTROL IN IP SWING UP.................................................................134 5.2 1-STAGE LINEAR IP SWING UP EXPERIMENT...................................................135 5.3 SWING UP EXPERIMENT BY OTHER ALGORITHMS ...........................................137

CHAPTER 6 2-STAGE LINEAR INVERTED PENDULUM ............................140

6.1 SYSTEM PHYSICAL MODEL .............................................................................140 6.2 SYSTEM CONTROLLABILITY ANALYSIS ...........................................................146

Page 9: IP Experiment Manual V2.00

Table of Content

©Googol 2006 VIII

6.3 2-STAGE LINEAR IP MATLAB SIMULATION ...................................................148 6.4 LQR CONTROLLER DESIGN AND SIMULATION ................................................150 6.5 2-STAGE LINEAR IP LQR CONTROL EXPERIMENT...........................................155 6.6 EXPERIMENT RESULT AND REPORT .................................................................159 6.7 CONTROL EXPERIMENT BY OTHER ALGORITHMS............................................159

CHAPTER 7 3-STAGE LINEAR INVERTED PENDULUM ............................161

7.1 SYSTEM PHYSICAL MODEL .............................................................................161

CHAPTER 8 APPENDIX.......................................................................................172

8.1 LIST OF FIGURES .............................................................................................172 8.2 LIST OF PROGRAM...........................................................................................175

Page 10: IP Experiment Manual V2.00

Chapter 1 Overview

©Googol 2006 1

Chapter 1 OVERVIEW

1.1 Introduction

Inverted pendulum (IP) problem is the combination of research area like robotics, control theory, computer control, etc. The IP system has the property of unstable, higher order, multi-variable and highly coupled, which can be treated as a typical nonlinear control problem. The research started from 50th, 20 century, control scientist in MIT developed the first 1-stage IP system based on the theory of rocket propeller. There are lots of new control algorithms appear in recent years. People apply them to IP systems to examine their ability to control multi-variable, nonlinear and unstable systems. As a relatively ideal experimental means for the teaching, experimentation and scientific research of control theories, IP system provides an excellent experimental platform for examining specific control theories or typical solutions and thus promoting the development of the new theories. Since they are widely applied in different fields such as semiconductors, delicate devices processing, robot control technology, artificial intelligence, missiles interception control systems, aviation docking control technology, perpendicularity control in rocket launching, gesture control in satellite circling and general industrial applications, they will have a broad prospects for development and utilization. Inverted pendulum can vividly simulate the flight control of rockets and the stabling control in walking robots etc.

1.2 Inverted Pendulum Classification

There are many series of IP systems extended from linear 1-stage IP, such as linear IP, circular IP, planar IP and configurable IP. IP is the system with pendulum plants placed on motion modules. Diverse pendulum plants and motion modules constitute different IP series. The following IP systems are classified by structure:

1) Linear Inverted Pendulum

Linear IP has pendulum plant on a linear motion module with one degree of freedom. The cart moves on the sliding shaft horizontally. There are different kinds of linear IP systems based on different pendulum plant structure such as the flexible IP, which has two carts on the sliding shaft with a spring connected. The linear IP series are shown in Figure 1-1.

2) Circular Inverted Pendulum

Circular IP system has the pendulum plant on a circular motion module with one degree of freedom. The pendulum is on the arm end are rotates around the center of the circle. Different IP system can be set up by varying the stage number

Page 11: IP Experiment Manual V2.00

Chapter 1 Overview

©Googol 2006 2

in series or parallel as shown in Figure 1-2.

3) Planar Inverted Pendulum

Planar IP system has the pendulum plant on the planar motion module with two degrees of freedom. There are two classes of planar motion module: XY table and SCARA robotic arm. The pendulum can also be divided by stage like 1-stage or 2-stage as depicted in Figure 1-3.

4) Configurable Inverted Pendulum

Configurable IP is a new class of IP systems whose pendulum plant is composed of pendulum rod and connection rod. The connection rod can be configured to 3 modes: level, vertical upper and vertical down.

Classified by pendulum stages, there are 1-stage, 2-stage, 3-stage and 4-stage IP systems. 1-stage IP is used for basic experiment of control theory while others are mostly used for development of advanced control algorithms. Control complexity increase dramatically as the pendulum stage increase. The feasible maximal stage for IP system is 4 currently.

Figure 1-1 Linear IP Series

Figure 1-2 Circular IP Series

Page 12: IP Experiment Manual V2.00

Chapter 1 Overview

©Googol 2006 3

Figure 1-3 Planar IP Series

Figure 1-4 Configurable IP

1.3 Inverted Pendulum Properties

Despite the different size and structure, all IP systems have the following properties in common:

1) Nonlinearity IP is a typical nonlinear system. In real control, the system model is usually

linearized. There are also nonlinear control methods applied to IP which is becoming a hot topic recently.

2) Uncertainty Most uncertainties come from model uncertainty, mechanical transmission error

and other resistances. In real control, uncertainties are reduced by controlling errors like, tighten the belt or screw to reduce the transmission error, or use ball bearing to reduce the friction.

3) Coupling There are coupling between each stage of IP and the motion module. We will

Page 13: IP Experiment Manual V2.00

Chapter 1 Overview

©Googol 2006 4

decouple the IP near the equilibrium point and ignore some less important coupling variables.

4) Open loop instability There are two equilibrium states for IP systems: vertical upper and vertical down,

in which vertical upper is the unstable equilibrium point and vertical down is the stable equilibrium point.

5) Limitations The IP system performance is limited by mechanisms like motion module travel

distance, motor torque, etc. To make it convenient and reduce the cost, the structure size and the motor power of IP are required to be small. The effect of travel distance to IP swing up is especially evident: short travel distance easily gets the cart exceed the limit switch.

1.4 Controller Design Method

Controller design is the key content of IP systems. Controllers are used to stabilize the unstable system and make it robust to disturbances. The widely used control methods recently are: PID control, root locus and frequency response, state space, optimal control, fuzzy control, neural network, humanoid artificial intelligent, robust control, adaptive control and some more power algorithms which combine the above ones.

1.5 Inverted Pendulum Experiments

The experiments can be accomplished by IP platform in this book are as follows:

Table 1-1 Inverted Pendulum Experiments

Type No. Experiment Name Experiment Equipment

1. Encoder Principle and Application All IP Series Basic Experiment 2. Motor Control in Motor Control in

Matlab Simulink All IP Series

3. Linear Inverted Pendulum Modeling, Simulation and Experiment

1-stage IP

4. 1-stage Linear Pendulum Modeling and Analysis

1-stage IP

5. 2-stage Linear Inverted Pendulum 2-stage IP

Modeling Experiment

6. 3-stage Linear Inverted Pendulum 3-stage IP 7. 1-stage Linear IP Root Locus Control

Experiment 1-stage IP Control

Experiment 8.

1-stage IP

Page 14: IP Experiment Manual V2.00

Chapter 1 Overview

©Googol 2006 5

9. 1-stage Linear IP PID Control Experiment

1-stage IP

10. 1-stage Linear Pendulum PID Control Simulation and Experiment

1-stage IP

11. 1-stage Linear Pendulum LQR Control Simulation and Experiment

1-stage IP

12. State Space Pole Placement Control Experiment

1-stage IP

13. Linear Quadratic LQR Optimal Control 1-stage IP 14. 2-stage Linear IP LQR Control

Experiment 2-stage IP

Linear 3-stage IP can be taken apart to 2-stage IP and 1-stage IP.

Page 15: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 6

Chapter 2 Motion Control Basic Experiment

The objective of this experiment is let users understand the basic principle of angle encoder; master the skill to collect data from encoder by computer and motion control card for computer control. Two important contents in mechatronics will be comprehended in IP system experiments: sensors and motion control techniques.

2.1 Encoder Principle and Application

2.1.1 Encoder Principle

Rotary encoder is a class of angle position sensor which can be classified as photoelectric, contact and electromagnetism. The photoelectric pulse encoder is the most widely used position sensor in close loop systems currently.

Figure 2-1 Photoelectric Encoder Component and Structure

There are two kinds of rotary encoders: incremental encoder and absolute encoder. Figure 2-1 is the illustration of incremental photoelectric encoder, which is composed of irradiance device, photoelectric coded compass, photosensitive device and signal processing circuits. When the coded compass is rotating with the working axis simultaneously, light source will transmit the light signals through the light-blocking board of the photoelectric coded compass with alternative bright and dark in light intensity, the photosensitive device will convert the light signal into electrical signals, it will be outputted after rectifying, magnifying, frequency division, and number recording via the signal processing circuit. In order to measure the direction of rotation, make sure that the distance of the two slits of the light-blocking board is less than ¼ of the intervals of the coded compass, the output signals of the two light sensitive devices will be π/2 out of phase, the direction of the rotation of the coded compass can be found by feeding the output signal into the phase-detector circuit.

Output Input

Lamp Photosensitive element

Page 16: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 7

The resolution of photoelectric incremental encoder depends on its minimal distinguishable angle, which is related to the number of intervals (line number) on the compass:

=360α

In which n denotes compass line number. Each time the photoelectric pulse encoder rotates a minimal distinguishable

angle it outputs a pulse signal. The rotation angle of the current axis can be obtained from the pulse number, thus the linear distance can be calculated by transmission rate. The rotation speed of current axis can be calculated by pulse frequency and the rotation direction can be estimated by the sequence of consecutive signals.

The absolute encoder detects the rotation angle by the output of light emitting diode (LED) and photo diode which correspond to each bit of output binary code. The sensor for measuring linear distance is grating bar which has the same principle with incremental encoder.

The photoelectric encoder becomes more and more popular nowadays for its convenience as it outputs digital signal, which can be directly processed by computer without any operation like magnification or transformation.

2.1.2 Angle Conversion

For n-line encoder, if the frequency ratio is m , the angle conversion relationship will be:

Nnm

14.32×=φ (radian) or N

nm

o360=φ (degree)

In which φ——rotation angle of encoder

N ——encoder reading For IP motor encoder, the encoder reading is required to be converted to the

position of the cart by the following equation:

Nnm

l Φ×=

14.3

In which l——cart displacement Φ——diameter of the synchronization belt

2.1.3 Encoder Experiment

The object of this experiment is the photoelectric rotary encoder. The following experiments can be implemented based on the above principle.

Experiment 1 Pendulum rod angle measurement Please follow the instructions to finish the angle measurement experiment in

Page 17: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 8

MATLAB. Note: Please read carefully of IP user manual and get familiar with MATLAB environment, make sure that MATLAB real time control toolbox and VisualC are installed. (Please refer to 《Googol MATLAB real time control software user manual》).

1) Open MATLAB Simulink:

Figure 2-2 MATLAB Simulink Environment

2) Press “ ” on the window to create a new window:

Page 18: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 9

3) Open “Googol Education Products\GT-400-SV Block Library” in Simulink as depicted in the figure below:

4) Select“Get Current Axis’s Position” module and pull it to the new window“untitled”:

5) Double click“GetPos” to open the following window, set axis number to 2, which is the encoder of the first stage fixed on the cart.

Page 19: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 10

6) Pull “Scope” from “Simulink\Sinks” to “untitled”:

7) Connect the two modules(move mouse to“<“,when the arrowhead icon become“+”,left press the mouse and move to“>”, then release the mouse):

Select Axis No.

Page 20: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 11

8) Pull “ GT400-SV Initialization ” in “ Googol Education Products\GT-400-SV Block Library” to the window:

9) Select“External” as depicted in the above figure:

10) Save file as “EncoderTest”, set parameters in“Simulation\Simulation Parameters”:

Here

Page 21: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 12

Set “Simulation time” and “Solver options”as shown in the above figure,the stop time“inf”denotes infinity and the step size is set to 0.005s。

Click“Real-Time Workshop” to open the following window:

11) Press “Browse” to change the setting to”Real-Time Windows Target”

1

2

3

Page 22: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 13

12) Then press “OK” as shown below:

13) Press“ ”to build the file,the compiling information will be displayed in Command window:

Page 23: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 14

14) Power on the electric box;

15) Press“ ” to connect the program;

16) Press“ ” to run;

17) Double click“Scope” to watch the data:

18) Rotate the stage counterclockwise by hand for about 360 degree and see the result. When data exceed the display range, click“ ”to resize the scale。

Page 24: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 15

We can see from the above figure, the encoder reading is 2400, which is 4 times of encoder line number (600). Manually rotate the pendulum rod clockwise or counterclockwise and observe the reading and actual pendulum rod angle.

19) Record the experiment result, analyze the data and finish the report. Note:Detailed model please refer to EncoderTest.mdl in the following path:“matlabroot\toolbox\GoogolTech\InvertedPendulum\”, which can also be opened in Simulink:

Enter MATLAB Simulink“Googol Education Products”, open “Encoder Test Experiment” from“Inverted Pendulum\Basic Experiments”as depicted below:

System model is as follow:

Page 25: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 16

2.2 Motor Control in Matlab Simulink

The object of this experiment is the AC servo motor of IP system. Set the motion controller current axis to operate in speed control mode and also users are required to set maximum velocity and acceleration. In speed control mode, the initial velocity will keep increase in fixed acceleration until it reaches the maximum velocity. The motion direction is decided by velocity sign. These two parameters can be changed in motion.

Experiment procedures are as follow: 1) Open MATLAB/Simulink;

Page 26: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 17

2) Click “ ”on the window to create a“Model”window:

3) Open “ Googol Education Products\GT-400-SV Block Library ” in

“Simulink Library Browse”window as depicted below:

Page 27: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 18

4) Pull “Set Current Axis’s Acc and Vel”module to the new window

“untitled” :

5) Double click“SetAccVel”module to open the following window, set

parameters as in the following figure:

Page 28: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 19

“Axis number”: select axis number“1”, the axis of cart motor “Back velocity”: define the cart velocity after the limit switch is on (the cart

will move towards the inverse direction when reach the limit), unit in m/s. “Back position”:define the cart target position after the limit switch is on (the

cart will move towards the inverse direction when reach the limit), unit in pulse number.

6) Pull two“Constant”from“Simulink\Souces” to“untitled” window:

Page 29: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 20

7) Connect the following 3 modules as the following figure:

8) Set the 2“Constant”modules parameter as follow:

Page 30: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 21

Set cart speed be 0.2m/s, acceleration be 0.1m/s2。 9) Pull “ GT400-SV Initialization ” module in “ Googol Education

Products\GT-400-SV Block Library”to the window:

10) Select“External” as depicted in the above figure: 11) Save file as“MoterTest”, Select“Simulation\Simulation Parameters” to

set parameters:

Here

Page 31: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 22

Set “Simulation time” and “Solver options” as depicted in the above figure, in which the simulation time“inf”means infinity and step size is 0.005s.

Click“Real-Time Workshop” to open the following window:

1

2

3

Page 32: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 23

12) Click“Browse”to change the setting as ”Real-Time Windows Target”

13) Click“OK”in the following figure:

14) Click“ ” to build the file,the compiling information will be displayed in

“Command” window:

Page 33: IP Experiment Manual V2.00

Chapter 2 Motion Control Basic Experiment

©Googol 2006 24

15) Power on the electric box; 16) Click“ ”to connect the program; 17) Click“ ”to run the program; 18) Observe the cart locus and record the experiment result.

Change the maximum velocity and acceleration, observe and record the cart locus and finish experiment report.

Reference model: Open“Googol Education Products”in MATLAB Simulink toolbox, Select

“Servo Motor Control Experiment” in “Inverted Pendulum\Basic Experiments”, System diagram is as follow:

Page 34: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 25

Chapter 3 Linear Inverted Pendulum

Modeling, Simulation and Experiment

The objective of this experiment is to allow users master the method of modeling to real system, get familiar with system modeling using matlab simulink, applied control theories to design controller and experiment on real systems. Observe and analyze the experiment result and thus have the personal impression on the applications of controllers.

1-stage linear IP is the most frequently seen IP system which is composed of linear motion module and 1-stage pendulum plant, as shown in Figure 1-1。

3.1 1-stage Linear Inverted Pendulum System Model

There are two classes of system modeling method: mechanism modeling and experimental modeling. The experimental modeling is established through the feeding of a series of predetermined input signals by the users, the study target is stimulated and the visible output is examined after it passes the sensor, the input/output relationship of the system is established by applying mathematical formulae. It includes the design selection of the input signals, precise detection of the output signals, and the study of mathematical calculations. Mechanism modeling is based on the foundation of understanding the motion patterns through physical, chemical and mathematical means to set up the internal input/output relationship in the system.

There are difficulties in IP system modeling because of its instability. But after ignoring some less important factors, the IP system becomes a typical rigid body in motion. The dynamic equation will be obtained in the inertial frame by classical mechanics theory. Next we are going to use Newton-Euler and Lagrange methods to develop the 1-stage linear IP model respectively.

3.1.1 Differential Equations Methods

3.1.1.1 Newton’s Mechanics

After ignoring the air resistance and other frictions, 1-stage linear IP can be simplified as a system of cart and even quality rod, as shown in Figure 3-1.

Let’s define: M cart mass m rod mass

Page 35: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 26

b friction coefficient of the cart l distance from the rod axis rotation center to the rod mass center I rod inertia F force acting on the cart x cart position

Figure 3-11-stage Linear Inverted Pendulum Model

φ angle between the rod and vertically upward direction θ angle between the rod and vertically downward direction(consider that the initial position of the rod is vertically downward) Figure 3-2 is the force analysis of cart and rod system. N and P denote the

interactive force of cart and rod in the horizontal and vertical direction respectively. Note: In real system the detection and implementation direction is fixed, the

predefined positive vector is shown as the arrow in the following figure.

Figure 3-2 Cart and Rod Force Analysis

From the forces in the horizontal direction, we obtain:

NxbFxM −−= &&& (3-1)

From the force acting on the rod in horizontal direction we get:

Pendulum Rod

x

φ

F

Cart

Sliding shaft

l

Page 36: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 27

)sin(2

2

θlxdtdmN += (3-2)

That is θθθθ sincos 2&&&&& mlmlxmN −+= (3-3)

Combining with equation (3-1),the first dynamic equation is obtained:

FmlmlxbxmM =−+++ θθθθ sincos)( 2&&&&&& (3-4)

To get the second dynamic equation, analyze the force in the vertical direction then we have:

)cos(2

2

θldtdmmgP =− (3-5)

θθθθ cossin 2&&& mlmlmgP −−=− (3-6)

By moment conservation: θθθ &&INlPl =−− cossin (3-7)

Note: the direction of moment is negative because θφθφφπθ sinsin,coscos, −=−=+= .

Combining two, we get the second dynamic equation:

θθθ cossin)( 2 xmlmglmlI &&&& −=++ (3-8)

Let φπθ += ( φ is the angle between the rod and vertically upward

direction),assume φ is relatively small to 1(unit in radian), which meansφ <<1,

then following approximation can be obtained: 1cos −=θ , φθ −=sin , 0)( 2 =dtdθ .

Let u denotes the input force of the object, linearize the two dynamics equations:

( )⎪⎩

⎪⎨⎧

=−++

=−+

umlxbxmMxmlmglmlI

φ

φφ&&&&&

&&&&

)(

2

(3-9)

The Laplace transformation of equation (3-9) are as follow:

( )⎪⎩

⎪⎨⎧

=Φ−++

=Φ−Φ+

)()()()()()()()(22

222

sUssmlssbXssXmMssmlXsmglssmlI

(3-10)

Note: the initial condition is assumed to be 1 when deducing the transfer function. The output angle isφ , solving the first equation:

)(])([)( 2

2

ssg

mlmlIsX Φ−

+= (3-11)

Page 37: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 28

or mglsmlI

mlssXs

−+=

Φ22

2

)()()( (3-12)

Let ..xv = , then:

mglsmlIml

sVs

−+=

Φ22 )()(

)( (3-13)

Substituting the above equation to the second on in equation (3-10):

)()()()()()()( 22

22

2

sUssmlsssg

mlmlIbss

sg

mlmlImM =Φ−Φ⎥

⎤⎢⎣

⎡+

++Φ⎥

⎤⎢⎣

⎡−

++ (3-14)

The transfer function is obtained after simplification:

sq

bmglsq

mglmMsqmlIbs

sq

ml

sUs

−+

−+

+=

Φ

232

4

2

)()()()( (3-15)

In which ])())([( 22 mlmlImMq −++=

Assume the system state space equations are:

DuCXyBuAXX

+=+=&

(3-16)

Solve the algebraic equation of φ&&&& ,x , the solutions are as follow:

⎪⎪⎪⎪

⎪⎪⎪⎪

+++

+++

+++

−=

=

+++

+++

+++

+−=

=

uMmlmMI

mlMmlmMImMmglx

MmlmMImlb

uMmlmMI

mlIMmlmMI

glmxMmlmMI

bmlIx

xx

222

2

2

2

22

2

2

)()()(

)(

)()(

)()()(

φφ

φφ

φ

&&&

&&

&&&

&&

(3-17)

The state space equation can then be written as:

u

MmlmMIml

MmlmMImlI

xx

MmlmMImMmgl

MmlmMImlb

MmlmMIglm

MmlmMIbmlI

xx

⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢

++

+++

+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢

+++

++−

+++++−

=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

2

2

2

22

2

22

2

2

)(

0)(

0

0)(

)()(

01000

0)()(

)(0

0010

φ

φ

φ

φ&

&

&&

&

&&

&

Page 38: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 29

uxx

xy ⎥

⎤⎢⎣

⎡+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

⎡=

00

01000001

φ

φφ&

& (3-18)

The first equation of (3-9) is:

( ) xmlmglmlI &&&& =−+ φφ2

To rod of even quality there is: 2

31 mlI =

So we have:

xmlmglmlml &&&& =−⎟⎠⎞

⎜⎝⎛ + φφ22

31

After simplification:

xll

g&&&&

43

43

+= φφ (3-19)

Let },,,{..φφxxX = ,

..' xu = then we have:

'

43010

04300

100000000010

u

l

xx

lg

xx

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

φ

φ

φ

φ&

&

&&

&

&&

&

'

00

01000001

uxx

xy ⎥

⎤⎢⎣

⎡+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

⎡=

φ

φφ&

& (3-20)

The above state space equation can also be derived by applying the tf2ss command to equation (3-13) in MATLAB.

3.1.1.2 Lagrange Method

Next we are going to derive the system model by Lagrange equation. The Lagrange equation is:

),(),(),(...qqVqqTqqL −= (3-21)

In which L is the Lagrange operator, q is the generalized coordinates, T denotes the kinetic energy and V denotes potential energy of the system.

Page 39: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 30

ii

i

fqL

q

Ldtd

=∂∂

−∂

∂. (3-22)

In which i=1,2,3……n, if is the acting force of system in the its generalized

coordinate. In 1-stage IP system, there are 2 generalized coordinates: 1θandx .

The system kinetic energy is:

mM TTT +=

In which mM TT , denotes the kinetic energy of cart and rod 1 respectively.

The kinetic energy of the cart is: 2.

21 xMTM =

The kinetic energy of the rod is: '''

mmm TTT +=

In which ''' , mm TT denote the translational and rotational kinetic energy of the

pendulum rod respectively. Let’s assume: xpend ——x axis coordinate of the rod mass center; ypend ——y axis coordinate of the rod mass center; There is:

φφ

lCosypendlSinxxpend

=−=

The kinetic energy of the rod is:

⎟⎠⎞

⎜⎝⎛ += 22' ))(())((

21

dtypendd

dtxpenddmTm

2.2

2.

2''

61

21 φθ mlJT pm ==

Then we obtained the system kinetic energy: 2.

222'''

61))(())((

21 φml

dtypendd

dtxpenddmTTT mmm +⎟

⎠⎞

⎜⎝⎛ +=+=

The system potential energy is:

φmglCosypendgmVV m =××==

Page 40: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 31

As there is only friction in the φ coordinates, we obtain: .

. xbLLdtd

=∂∂

−∂

∂φφ

For 1-stage linear IP system, system state variables are:

⎭⎬⎫

⎩⎨⎧ ..

,,, φφ xx

To solve the following state space equation:

⎪⎩

⎪⎨⎧

=+=

CXYBuAXX '

.

We need to solve ..φ first.

Assume:

),,,,(......xxxf φφφ =

Take Taylor expansion in the equilibrium point and linearize, we obtain: ..

15

.

14

.

131211

..xkkxkkxk ++++= φφφ

In which 0,0,0,0,0

11 ....|=====∂

∂=

xxxxfk

φφ

0,0,0,0,012 ....|

=====∂∂

=xxx

fkφφφ

0,0,0,0,0.13 ....|=====∂

∂=

xxxx

fkφφ

0,0,0,0,0.14 ....|

=====∂

∂=

xxx

fkφφφ

0,0,0,0,0..15 ....|=====∂

∂=

xxxx

fkφφ

Before calculation, let’s introduce Mathematica first(More detail please refer to the website: www.wolfram.com)

Mathematica is a kind of new machine language that is able to calculate in various areas. It has wide influence in the area of computer calculation since its release in 1988. In this book, we mainly use the symbol calculation and equation solving function of Mathematica.

Next we are going to use Mathematica to develop the 1-stage linear IP model: (program file please refer to “L1DIP.nb” in “\GLIP2001\ModelFiles\MathematicaFile”)

Page 41: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 32

PRO 3-1 1-stage Linear Inverted Pendulum Modeling Program

xpend= x@tD− l∗Sin@φ@tDD;ypend= l∗Cos@φ@tDD;

tpend= 1ê2∗ m∗HH∂t xpendL^2+H∂t ypendL^2L + 1ê6∗ m∗ l^2∗ Hφ'@tDL^2;Simplify@tpendD;v= m∗g∗ypend;

lang= tpend− v;Simplify@langD;

ldad= ∂φ'@tD lang;Simplify@ldadD;fa= ∂t ldad− ∂φ@tD lang;Simplify@faD;

Solve@8fa 0< , 8φ''@tD<D;add= φ''@tD ê. %;

k11= ∂x@tD add ê.x@tD → 0 ê. φ@tD → 0 ê. x'@tD→ 0 ê. φ'@tD → 0 ê. x''@tD→ 0k12= ∂φ@tD add ê.x@tD → 0 ê. φ@tD → 0 ê. x'@tD→ 0 ê. φ'@tD → 0 ê. x''@tD→ 0k13= ∂x'@tD add ê.x@tD → 0 ê. φ@tD → 0 ê. x'@tD→ 0 ê. φ'@tD → 0 ê. x''@tD→ 0k14= ∂φ'@tD add ê.x@tD → 0 ê. φ@tD → 0 ê. x'@tD→ 0 ê. φ'@tD → 0 ê. x''@tD→ 0k15= ∂x''@tD add ê.x@tD → 0 ê. φ@tD → 0 ê. x'@tD→ 0 ê. φ'@tD → 0 ê. x''@tD→ 0

g= 9.8;l= 0.25;

Simplify@k12DSimplify@k15D Run program(Press Shift+Enter)to obtain:

lk

kk

lgk

k

4315

0140134312

011

=

==

=

=

Let },,,{..φφxxX = ,system state space equation become:

'

'

DuCXyBuAXX

+=

+=&

Page 42: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 33

Then:

'

43010

04300

100000000010

u

l

xx

lg

xx

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

φ

φ

φ

φ&

&

&&

&

&&

&

(3-23)

'

00

01000001

uxx

xy ⎥

⎤⎢⎣

⎡+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

⎡=

φ

φφ&

&

The state space equations derived from Lagrange method can be transformed to the same form with the one by Newton’s mechanics. To different input there is different system state space equation. For simple 1-stage linear IP, Newton’s mechanics is more convenient and simple, but for multi-stage IP, the programming of Lagrange method is more convenient.

3.1.2 System Parameters

The real system model parameters are as follows: M cart mass 1.096 Kg m rod mass 0.109 Kg b friction coefficient of the cart 0 .1N/m/sec l distance from rod rotation axis center to rod mass center 0.2 5m I rod inertia 0.0034 kg*m*m

Please check if the system parameters match with the real system in

MATLAB Smiulink. If not, please use the real system data for calculation.

3.1.3 Real System Model

With the above parameters actual system model will be obtained. The transfer function of pendulum rod angle and cart displacement will be:

26705.00102125.002725.0

)()(

2

2

−=

Φs

ssXs (3-24)

The transfer function of pendulum rod and cart acceleration is:

Page 43: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 34

26705.00102125.002725.0

)()(

2 −=

ΦssV

s (3-25)

The transfer function of pendulum angle and external force acting on the cart is:

30942.29169.270883167.035655.2

)()(

23 −−+=

Φsss

ssUs (3-26)

The system state space equations with external force as input will be:

uxx

xx

⎥⎥⎥⎥

⎢⎢⎢⎢

+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

−=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

35655.20

883167.00

08285.27235655.0010000629317.00883167.000010

φ

φ

φ

φ&

&

&&

&

&&

&

uxx

xy ⎥

⎤⎢⎣

⎡+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

⎡=

00

01000001

φ

φφ&

& (3-27)

The system state space equations with cart acceleration as input will be:

'

3010

04.2900100000000010

uxx

xx

⎥⎥⎥⎥

⎢⎢⎢⎢

+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

φ

φ

φ

φ&

&

&&

&

&&

&

'

00

01000001

uxx

xy ⎥

⎤⎢⎣

⎡+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

⎡=

φ

φφ&

& (3-28)

Please note that, all controller design and program provided by Googol use the cart acceleration as the system input. In case of torque control mode, users may also use the external force as the input.

3.1.4 System Controllability Analysis

The principle of system controllability analysis is introduced in many books concerning modern control theory so we don’t give the detail here.

For continuous time system, there is:

DuCXyBuAXX

+=+=&

The system is controllable if and only if vectors BAABB n 1,...,, − are linear

Page 44: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 35

independent, or the n×n matrix ][ 1BAABB n−⋅⋅⋅ MMM is full rank.

The system output controllable condition: if and only if the rank of matrix

][ 12 DBCABCACABCB n MMMMM −⋅⋅⋅ equal to the dimension of vector y .

Apply the above principle to estimate the system controllability,

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥

⎢⎢⎢⎢

=

3010

04.2900100000000010

B

A

⎥⎦

⎤⎢⎣

⎡=

⎥⎦

⎤⎢⎣

⎡=

00

01000001

D

C

Put them in the state space equation and calculate in MATLAB:

Or we may use the command ctrb for the controllability and obsv for the

observability.

clear; A=[ 0 1 0 0; 0 0 0 0; 0 0 0 1; 0 0 29.4 0]; B=[ 0 1 0 3]'; C=[ 1 0 0 0; 0 1 0 0]; D=[ 0 0 ]'; cona=[B A*B A^2*B A^3*B]; cona2=[C*B C*A*B C*A^2*B C*A^3*B D];rank(cona) rank(cona2)

Page 45: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 36

Then there is:

We can see that, the system state controllability matrix is full rank and the rank

of output controllability matrix equal to the dimension of vector y , so the system is controllable and controller can be designed to stabilized the system.

For controllability analysis of state space equations with external force as the input, readers may also follow the above calculations.

3.1.5 System Step Response Analysis

From above state space equations, we could conduct the step response analysis first, type the following command in MATLAB:

The following result is obtained:

Uc=ctrb(A,B); Vo=obsv(A,C); rank(Uc) rank(Vo)

clear; A=[ 0 1 0 0; 0 0 0 0; 0 0 0 1; 0 0 29.4 0]; B=[ 0 1 0 3]'; C=[ 1 0 0 0; 0 1 0 0]; D=[ 0 0 ]'; step(A, B ,C ,D)

ans = 4

ans = 2

Page 46: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 37

Figure 3-3 1-stage Linear Inverted Pendulum Step Response Simulation

We can see that, the step responses of both cart position and pendulum angle diverge.

Page 47: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 38

3.2 1-stage Linear IP Root Locus Control Experiment

The close loop system transient response property is closely related with the system close loop poles. If system gain is adjustable, the place of close loop pole will depends on the selected system gain. From design point of view, some system could easily change the pole place to the required one by varying the system gain. However, when simply changing the system gain cannot reach the system performance requirement, controller design become critical. Some recently most popular used controller design methods are phase-lead, phase-lag and lead-lag compensator.

3.2.1 Root Locus Analysis

We already get IP system open loop transfer function from previous section, let the input be cart acceleration, and output be IP system pendulum rod angle, the transfer function become:

mglsmlIml

sVs

−+=

Φ22 )()(

)(

Adding disturbance to the system, output pendulum rod angle, the system diagram is as follow:

Figure 3-41-stage Linear IP Close Loop Diagram(with disturbance)

Considering input 0)( =sr , the diagram structure becomes:

Figure 3-5 1-stage Linear IP Simplified Close Loop Diagram(with disturbance)

The system output is:

Page 48: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 39

In which num ——numerator of plant transfer function;

den——denominator of plant transfer function;

numlead 、 denlead ——numerator and denominator of phase-lead block

transfer function;

numlag 、denlag ——numerator and denominator of phase-lag block transfer

function;

k ——controller gain

The close loop transfer function can be obtained by MATLAB command. The real system open loop transfer function is:

26705.00102125.002725.0

)()(

2 −=

ΦssV

s

Create a new file in MATLAB, type in the following commands:

The following results are obtained:

The system has 2 zeros and 2 poles. One of the poles is positive. Plot the system close loop transfer function root locus as depicted in Figure 3-6.

z = 0 0 p = 5.1136 -5.1136

clear; num=[0.02725 ]; den=[0.0102125 0 -0.26705]; rlocus(num,den) z=roots(num); p=roots(den);

Page 49: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 40

There is a close loop pole on the right half plane. One root locus starts from this point towards left along the real axis and ends at zero. That means however the systems gain change; the locus will stay on the right half plane. The system is always unstable.

Figure 3-6 1-stage Linear IP Open Loop Root Locus

3.2.2 Root Locus Method and Simulation

3.2.2.1 Root Locus Method

1-stage linear IP root locus method can be formulated as the following problem: For system with transfer function:

26705.00102125.002725.0)( 2 −

=s

sG

Design a controller to make the system satisfy the following performance criteria:

Response time %)2(5.0 sts = ;

Maximal overshot %10≤pM

Root locus design steps are as follows:

1) Calculate the expecting close loop pole ds from maximal overshot

%10)1/( 2

≤= −− πζζeM p

There is: 591155.0=ζ ,approximately let 6.0=ζ 。

From )(θζ Cos= we have: )radian(938306.0=θ

In whichθ is the angle between the real axis negative direction and the line connecting the origin and the pole in the second quadrant.

Page 50: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 41

Figure 3-7 Performance Index and Root Locus

By

stn

s 5.04≤=

ζω

There is: 5328.13=nω . The expected close loop pole is:

)(5328.13 θθ jSinCos ±− 2) The uncompensated system root locus is based on the real and imaginary axes,

which don’t pass the expected close loop pole. The phase-lead compensation is needed, design controller:

)1(1

1)( ≤++

=++

= apszs

aTsTsasK

c

c

3) Calculate the phase angle should be provided by phase-lead controller. The sum of phase angle of expected close loop poles and the system original poles is:

27676.4

28.61136.55328.13

5328.13tan1136.55328.13

5328.13tan)( 11

−≈

⎟⎟⎠

⎞⎜⎜⎝

⎛+⎟

⎠⎞

⎜⎝⎛

+−⎟

⎠⎞

⎜⎝⎛

−−= −−

θθ

θθ

CosSin

CosSinsG d

So the phase angle should be provided by phase-lead controller is: 13517.1)27676.4(14.3 =−−−=φ

4) Design the phase-lead compensator, we know that: 938306.0=θ The γ corresponding to maximal a can be calculated by the following equation:

)(21 φθπγ −−=

There is: 534059.0)(21

=−−= φθπγ

dwnw

0

×

×

σ

jw

θ

Page 51: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 42

Figure 3-8 1-stage Linear IP Root Locus Calculation

Plot corresponding straight line by optimal principle, the zero and pole of phase-lead compensator are:

4568.26;92214.6 −=−= pc zz

The open loop transfer function after compensation is:

26705.00102125.002725.0

)4568.26()92214.6()()( 2 −+

+==

sssKsKsGQ

5) By gain condition 1)()( =dd sHsG ,assume unit feedback, there is 137.141=k ;

6) The system controller is obtained as:

4568.26)92214.6(137.141)(

++

=s

ssG

7) The previous calculation might be complex manually, users are suggested to do the calculation by computer programming:

Write program as follows in Mathematica for the above calculation: The program file please refer to “ L1DIPRLocusCompute.nb ” in“\GLIP2001\ModelFiles\MathematicaFile”.

Page 52: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 43

PRO 3-2 1-stage Linear IP Root Locus Calculation Mathematica Program

3.2.2.2 MATLAB Simulation

Write the following m file in MATLAB to run system simulation:

Page 53: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 44

PRO 3-3 1-stage Linear IP Root Locus Calculation MATLAB Program

Run above program to get the result. The root locus after compensation is shown in the following figure:

Figure 3-9 Root Locus after Compensation

We can see from the figure, all root locus are on the left half plane. The system can be stabilized by properly choice of K.

The system step response is as follow:

clear; num=[0.02725]; % Transfer function of the Linear 1 stage den=[0.0102125 0 -0.26705]; % inverted penulum numlead=-6.92214; % Controller Zeros denlead=-26.4568; % Controller Poles [Z,P,K]=tf2zp(num,den); Za=[Z;numlead]; % Add Zeros to the LIP system Pa=[P;denlead]; % Add Poles to the LIP system [num2,den2]=zp2tf(Za,Pa,K); sys=tf(num2,den2); rlocus(sys); KK=141.137 % compensated system sys2=zpk(Za,Pa,KK*K); sysc=sys2/(1+sys2); t=0:0.005:5; step(sysc,t) % Response of the Close-loop system

Page 54: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 45

Figure 3-10 Step Response after Compensation

Though the system has good stability but there is certain steady state error and large overshoot. To satisfy the system transient response requirements, users may use the following methods:

The first one: increase damping ratioς , follow the previous steps (the above program can be easily modified) to redesign until the system performance is satisfied. Users may design by themselves; details won’t be described here.

The second one: left move the zero of compensator while keeping φ unchanged, thus to reduce the influence of close loop zeros and poles. Users may use this method to redesign controller.

Experienced users may directly adding zeros or poles to the system to control. To pull the root locus from right half plane to the left half plane, adding a zero on

the left half plane,assume it’s -7, the system root locus becomes:

Figure 3-11 Root Locus after Adding Zero

We see that, the system root locus are on the left half plane so the system is stabilizable. But for real system, the order of the transfer function molecular should be smaller than the denominator. We need to add a pole far away from the zero. After the

Page 55: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 46

pole is added (for example -30), the system root locus will be like:

Figure 3-12 Root Locus after Adding Pole

System root locus are all on the left half plane. By selecting proper system gain(result: 236.1682) the close loop system will be stable.

Close loop system step response will be as follow:

Figure 3-13 Close Loop System Step Response

The system can be stabilized in 1 second. The response time is short and overshot is small.

The MATLAB program of the previous root locus design method is as follow: (Enter MATLAB Simulink toolbox “Googol Education Products” Open

“ Root Locus Control M Files ” in “ Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ Root Locus Experiments”)

Page 56: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 47

PRO 3-4 1-stage Linear IP Root Locus Control MATLAB Program

Different control effect will be obtained by varying the controller poles and zeros.

User may design and analysis by themselves.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Googol Linear 1 stage Inverted Pendulum Transfer Function % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear; num=[0.02725]; % Transfer function of the Linear 1 stage den=[0.0102125 0 -0.26705]; % inverted penulum numlead=-7; % Controller Zeros denlead=-30; % Controller Poles subplot(2,2,1) rlocus(num,den) [Z,P,K]=tf2zp(num,den); Za=[Z;numlead]; % Add Zeros to the LIP system sysaddzero=zpk(Za,P,K); subplot(2,2,2) rlocus(sysaddzero) Pa=[P;denlead]; % Add Poles to the LIP system [num2,den2]=zp2tf(Za,Pa,K); sys=tf(num2,den2); subplot(2,2,3) rlocus(sys); [KK,poles]=rlocfind(sys) % Find the K and Poles of the %KK=141.137 % compensated system sys2=zpk(Za,Pa,KK*K); % Open loop transfer function % of the compensated system subplot(2,2,3) axis([-60 10 -10 10]) rlocus(sys2) % Draw the root locus of the % compensated system sysc=sys2/(1+sys2); % Close-loop transfer function t=0:0.005:5; subplot(2,2,4); step(sysc,t) % Response of the Close-loop system

Page 57: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 48

3.2.2.3 MATLAB Simulink

MATLAB provides a power graphic simulation tool Simulink,Next we are going to model the 1-stage linear IP in Simulink, (For first user of MATLAB Simulink, please get familiar with Simulink environment before experiment). Following we will introduce the steps of modeling in detail:

1) Open MATLAB Simulink Click“ ” in MATLAB to open the Simulink, Simulink window is as follow:

2) Click“ ”to create a new file, named“L1IPModelRLocus”。 Pull“Transfer Fcn” block in“Continuous” to new window,

Page 58: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 49

3) Rename the above transfer function block as“L1IP Transfer Fcn”, right click

mouse, set“BackGround Color”as“Cyan” and double click the block, open block parameters window:

4) Pull“Zero-Pole”block from Simulink to the window as the controller.

Double click the block, set zeros, poles and controller gain KK by above program.

Page 59: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 50

5) Connet“Controller”block and“L1IP L1IP Transfer Fcn”block.

6) Pull “ Sum ” block from “ Math Operations” block in Simulink to

“L1IPModelRLocus”window and double click the block to change it as follow(set“++”as“+-”):

7) Pull “ Step ” block from “ Sourses ” block in Simulink to the

“L1IPModelRLocus”window and double click the block to set step signal parameter:

Page 60: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 51

8) Pull“Scope” from“Sinks”in Simulink to“L1IPModelRLocus”window

as follow:

9) Connect each block as follow which constitutes a close loop control system.

10) Click“Simulation”menu and select“Simulation Parameters”,

Open the following window:

Page 61: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 52

Set options like“Simulation time”and“Solver options”in the above window. Set

simulation step size as 0.005s. 11) Click to run simulation, double click“Scope”block to view the simulation

result:

Figure 3-14 1-stage Linear IP Root Locus Method Simulation Result (First Order Controller)

If the result exceed the visible range, click “ ”to resize. 12) The system track step signal well but there is still certain steady state error. Varying the controller poles and zeros can get different control effect. Users may select the best one after varying the parameters several times. For example, adding a pole and a zero to second order lead-lag controller. Details may refer to related text books. 13) Pull“Manual Switch”in“Simlulink\Signal Routing”to the window:

Page 62: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 53

14) Copy a controller block to the window and reset parameters:

15) The final root locus simulation block will be as the following figure: (Reference model: enter MATLAB Simulink tool box“Googol Education Products”, open“Root Locus Control Simulink”in“Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ Root Locus Experiments”)

Figure 3-15 1-stage Linear IP Root Locus Simulation Model

Double click“Manual Switch”to select the lower path, click“ ”to run and get the following result:

Page 63: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 54

Figure 3-16 1-stage Linear IP Root Locus Control Simulation Result(Second Order Controller)

We can see, the steady state error decrease but overshoot increase. Users may

analyze the reason and improve controller by themselves.

3.2.3 Root Locus Real Time Control Experiment

Please install Googol MATLAB real control software before experiment. Details please refer to software user manual.

1) Open MATLAB and Simulink as follow:

2) Open“Googol Educational Products” in Simulink and select“Linear Inverted Pendulum” in“Inverted Pendulum” block, choose“Linear 1 Stage Inverted Pendulum Root Locus Control”on the right window.

3) Open 1-stage linear IP root locus control window:

(Enter MATLAB Simulink tool box“Googol Education Products”, open“Root Locus Control Demo”in“Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ Root Locus Experiments”)

Page 64: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 55

Figure 3-17 1-stage Linear IP Root Locus Real Control Block

4) Click“ ”to build, after successful build there will be information notice in MATLAB command window as follow(If the control interface structure is not changed, not further build is needed after run once):

If not successful, please refer to Googol Technology MATLAB Real Time Control Software User Manual to find out the reason.

5) Click“ ”to connect;

6) Click“ ”to run;

7) When program is running, the sound of motor servo on will be heard,

After motor servo on, no one is allowed to stand within the IP reachable

area. Shut down the electrical box when there is any thing abnormal and check the status of IP before experiment each time.

8) Put the pendulum rod to vertical upward manually, the program will automatically run stabilizing control.

9) Double click“Scope”to view the experiment data:

Page 65: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 56

Figure 3-18 1-stage Linear IP Root Locus Control Result(equilibrium)

10) Double click“Manual Switch”to switch controller, observe the experiment data and record. The IP system response under certain disturbances can be observed:

Figure 3-191-stage Linear IP Root Locus Control Result(with disturbance)

11) Users can also save the experiment data as file or output to MATLAB“Workspace”as follow. Details please refer to MATLAB references.

Page 66: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 57

12) Compare the experiment data with simulation result.

13) Users may also use other root locus means for controller design.

3.2.4 Experiment Result and Report

Please record the calculation steps, simulation and experiment results and finish the experiment report.

The sample experiment report is as follow:

Page 67: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 58

Table 3-1 Linear IP Root Locus Realtime Control Experiment Report

Linear IP Root Locus Realtime Control Experiment Report

Student Name: Student Number:

Department: Date:

Class Name:

Objective

Equipment

Theory

Simulation and Results

Experiment Results

Experiment Results

Analysis

Comments

Page 68: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 59

3.3 1-stage Linear Inverted Pendulum Frequency

Response

The System response to sinusoidal signal is called frequency response. In frequency response method, we change the input signal frequency in certain range to study the system response.

Frequency response can be analyzed in the following 2 convenient way: One is bode plot, which use two separate figure: one plots the relation between magnitude and frequency and another plots the relation between phase and frequency; the other is

polar coordinates plot which gives the locus of vector )()( ωω jGjG when ω

varies from 0 to infinity. The polar coordinates plot is also called Nyquist plot. The Nyquist stability criterion helps us decide the close loop system absolute stability and relative stability according to the open loop frequency response property information.

3.3.1 Frequency Response Analysis

We already have 1-stage linear IP physical model previously, the real system open loop transfer function is:

26705.00102125.002725.0

)()(

2 −=

ΦssV

s

In which the input is cart acceleration )(sV and output is the pendulum rod angle )(sΦ .

Draw system Bode plot and Nyquist plot in MATLAB. The command for Bode plot is: Bode(sys) The command for Nyquist plot is: Nyquist(sys) Type the following command in MATLAB:

Page 69: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 60

The following result is obtained:

Figure 3-20 1-stage Linear IP Bode Plot

z = Empty matrix: 0-by-1 p = 5.1136 -5.1136

clear; num=[0.02725]; den=[0.0102125 0 -0.26705]; z=roots(num); p=roots(den); subplot(2,1,1) bode(num,den) subplot(2,1,2) nyquist(num,den)

Page 70: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 61

Figure 3-21 1-stage Linear IP Nyquist Plot

We could see that the system has no zero but 2 poles, one of which is on the right

half s plane. According to Nyquist stability criterion, the sufficient and necessary condition of close loop system be stable is: whenω change from ∞+∞− to , the open loop transfer function )( ωjG encircle the point -1 p times, in which p is the number of poles of open loop transfer function on the right half plane. For 1-stage linear IP, From Figure 3-21 the open loop transfer function has a pole on the right half S plane, so )( ωjG needs to encircle the point -1 once. We could see the system Nyquist plot does not encircle the point -1 once, so the system is unstable. Further controller design is required to stabilize the system.

3.3.2 Frequency Response Design and Simulation

1-stage linear IP frequency response design can be formulated as the following problem:

Consider a unit negative feedback system with open loop transfer function:

26705.00102125.002725.0

)()()( 2 −=

Φ=

ssVssG

Design controller )(sGc , let system static position constant be 10, phase margin

be o50 ,gain margin larger or equal to 10dB。

By above requirements, the controller design steps are as follow:

1) Select controller. We already get the system Bold plot previously. It can be observed that the design criterion could be satisfied by adding a phase-lead controller. Assume it be:

Page 71: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 62

Ts

Ts

KTs

TsKsG ccc

αα

α1

1

11)(

+

+=

++

=

The controlled system has open loop transfer function )()( sGsGc

Assume

26705.00102125.002725.0)()( 21 −

×==

sKsKGsG

In which αcKK = 。

2) Calculate control gain K according to steady state error requirement:

1026705.00102125.0

02725.0

)1(

)1()()( 200

=−

×+

+==

→→ sT

s

Ts

KimlsGsGimlK cscsp

α

There is:

KKc == 98α

Then we have:

26705.00102125.09802725.0)( 21 −

×=

ssG

3) Bode plot of )(1 sG in MATLAB:

Page 72: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 63

Figure 3-22 1-stage Linear IP Bode Plot and Nyquist Plot after Adding Control Gain

4) We can see that the system phase margin is o0 . According to design criterion, system phase margin should be o50 which means o50 more is needed. Adding phase-lead controller will also change the gain curve of Bode plot. The gain crossover frequency will move rightward. Thus we have to compensate for the

phase lag increment of )(1 ωjG as a result of increasing gain crossover frequency.

Assume the maximal required phase lead mφ is approximately o55 .

Since

ααφ

+−

=11

mSin

We will get: 0994.0=α

5) After determining the damping system, the lead controller corner frequency

Page 73: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 64

will also be determined: T/1=ω )/(1= and Tαω . It can be observed that the

maximal phase lead angle mφ is on the geometric center of the corner frequency,

which means )/(1 Tαω = . At point )/(1 Tαω = , as it contains the term of

)1/()1( ++ TsTs α , the gain increment will be:

ααα

ωαω

αω

11

11

11

)/(1

=+

+=

++

= j

j

TjTj

T

And 0261.100994.011

==α

dB

As 0261.10)(1 −=ωjG dB corresponds to 5.28=ω rad/s , we select this

frequency as new gain crossover frequency cω ,this frequency corresponds to

)/(1 Tαω = , that is )/(1 Tc αω = , then

3965.901

9854.81

==

==

αω

α

ωα

c

c

T

T

6) The controller is established:

3965.909854.8

11)(

++

=++

=ssK

TsTsKsG ccc α

α

9155.985==αKKc

7) The root locus and Nyquist plot after control are as follow:

(Enter MATLAB Simulink tool box“Googol Education Products”. Open“Frequency Response Control M Files” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ Frequency Response Experiments”)

Page 74: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 65

PRO 3-5 1-stage Linear IP Frequency Response Control MATLAB Program

We can see from Bode plot that system has satisfactory phase and gain margin. From Nyquist plot, the curve encircle -1 once, thus compensated system is stable.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Googol Linear 1 stage Inverted Pendulum Frequence Response % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear; num=[0.02725]; num2=98*[0.02725]; den=[0.0102125 0 -0.26705]; [z,p,k]=tf2zp(num,den); subplot(2,1,1); bode(num2,den) subplot(2,1,2);nyquist(num2,den)

za=[z;-8.9854]; pa=[p;-90.3965]; kk=985.9155; sys=zpk(za,pa,k*kk); % za=[z;-8.9854;-2]; pa=[p;-90.3965;-0.1988]; k=985.9155; % sys=zpk(za,pa,k); figure subplot(2,1,1) bode(sys) subplot(2,1,2) nyquist(sys); figure sysc=feedback(sys,1); t=0:0.005:5; impulse(sysc,t)

Page 75: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 66

Figure 3-23 1-stage Linear IP Bode Plot and Nyquist Plot after Control(First Order Controller)

System step response will be obtained as follow:

Figure 3-24 Step Response after Frequency Response Control(First Order Controller)

Page 76: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 67

The system can be stabilized in 1 second after disturbed. However, the overshoot is large.

8) Open“L1dofFreq.mdl”to run simulation in MATLAB Simulink(We ignore the steps of all examples from now on, details user may refer to previous chapter ).

(Enter MATLAB Simulink tool box“Googol Education Products”, open“Frequency Response Control Simulink” in “ Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ Frequency Response Experiments”)

Figure 3-25 1-stage Linear IP Frequency Response Control Simulation

Double click“Controller1” to set controller parameter:

Click“ ”to obtain the following simulation result:

Page 77: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 68

9) It can be observed that there is certain steady state error. To achieve fast response as well as small steady state error, we use lag-lead controller (by applying lag-lead controller, low frequency gain increase, steady state error decrease and the system bandwidth as well as stability margins will both increase). Let the lag-lead controller be:

)1)((

)1)(1()(

21

21

Ts

Ts

Ts

Ts

KsG cc

ββ

++

++=

10) The detailed lag-lead controller design steps user may refer to related textbooks. The controller is:

1988.02

3965.909854.8980

)1)((

)1)(1()(

21

21

++

×++

×=++

++=

ss

ss

Ts

Ts

Ts

Ts

KsG cc

ββ

The position error constant is obtained:

6.10026705.00102125.0

02725.01988.02

3965.909854.8980

)()(

20

0

=−

×+

++

×=

=

sss

ssiml

sGsGimlK

s

csp

This increased a lot than the one of phase-lead control. As zero -2 is close to pole -0.1988, the effect on phase margin is relative small. System Bode and Nyquist plot after lag-lead will be:

Page 78: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 69

Figure 3-26 Bode and Nyquist Plot after Frequency Response Control(Second Order)

Set“Controller2”as:

Page 79: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 70

Run simulation and obtain:

Figure 3-27 Step Response after Frequency Response Control Simulation(Second Order)

It can be observed that system steady state error is small.

3.3.3 1-stage Linear IP Frequency Response Experiment

1) Ener MATLAB Simulink tool box“Googol Education Products”, open“Frequency Response Control Demo” in“Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ Frequency Response Experiments”(Steps please refer to previous root locus control experiment):

Page 80: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 71

Figure 3-28 1-stage Linear IP Frequency Response Real Time Control Diagram

2) Click“Manual Switch”to select controllers like“Contrller1”or“Controller2”

3) Double click Controller2, set parameters.

4) Click“ ”to build and click“ ”to connect after build.

5) Power on electrical box.

6) Click“ ”to run program.

7) When the motor servo on, pull the pendulum rod to vertically upward by hand. Release the rod when program started to control. Note that, the frequency response method only control the rod angle but not cart position, the cart may

Page 81: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 72

reach the limit switch and stop control. Users are suggested to control the position of the cart by hand to avoid reaching the limit switch.

8) Double click“Scope”to observe the result:

Figure 3-29 Frequency Response Real Time Control Result(First Order Controller)

Please analyze in detail the relationship between the system actual stabilization time (about 0.25s as shown above) and design index.

9) Different performance index will get different controller parameters. Observe control effect with different parameters.

10) Click“Manual Switch”to switch controller, the system control performance is as follow:

Page 82: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 73

Figure 3-30 Frequency Response Real Time Control Result(Second Order Controller)

Please analysis the difference of control effect between this controller and the previous mentioned one.(Stabilization time is about 0.5 second).

3.3.4 Experiment Result and Report

Record the experiment result and finish report.

Page 83: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 74

3.4 1-stage Linear IP PID Control Experiment

The objective of this experiment is to let users comprehend and master the PID control principle and apply to 1-stage linear IP control. PID control does not require precise analysis of system model so we can set control parameters according to experimental experience.

3.4.1 PID Control Analysis

Classical control theory mainly focused on the research of single input single output (SISIO) systems. The precise control plant model is often required in controller design. Thus PID controller is widely used in control applications for its simple structure, easy tuning and independence from system model.

First of all, for IP system outputs pendulum rod angle whose equilibrium point is vertically upward. System control diagram will be as follow:

Figure 3-31 1-stage Linear IP Close Loop System Diagram

In which )(sKD is controller transfer function, )(sG is control plant transfer function

Considering input 0)( =sr , the structure diagram can be easily transformed to:

Figure 3-32 1-stage Linear IP Close Loop System Simplified Diagram

The system output is:

Page 84: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 75

)())(())((

)(

)(

))(())((1

)()()(1

)()(

sFnumnumPIDdendenPID

denPIDnum

sF

dendenPIDnumnumPID

dennum

sFsGsKD

sGsy

+=

+=

+=

In which num ——numerator of control plant transfer function

den——denominator of control plant transfer function

numPID ——numerator of PID controller transfer function

denPID——denominator of PID controller transfer function

The system performance can be obtained by analyzing previous equations. The transfer function of pendulum rod and cart acceleration can be obtained from equation (3-13):

mglsmlIml

sVs

−+=

Φ22 )()(

)(

PID controller transfer function will be:

denPIDnumPID

sKsKsK

sK

KsKsKD IpDIpD =

++=++=

2

)(

The PID parameters should be carefully tuned to achieve satisfactory control effect. We only discussed the pendulum rod angle previously, then how will the cart position vary in control process?

Cart position output is: 2)()( ssVsX =

The cart position can be calculated by double integrate the control variable v .

3.4.2 PID Control parameters and Simulation

PID parameter set could refer to 《Modern Control Theory》 Chapter 10 PID Control and Robust Control. We use the following method to decide PID control parameters. By actual system physical model:

26705.00102125.002725.0

)()(

2 −=

ΦssV

s

Page 85: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 76

Setup the following 1-stage linear IP model in Simulink: (Enter MATLAB Simulink real time control tool box“Googol Education

Products”, open“PID Control Simulink”in“Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ PID Experiments”).

Figure 3-33 1-stage Linear IP PID Control MATLAB Simulation Model

In which PID Controller is the masked PID controller, double click the module to open parameters window,

Figure 3-34 PID Set Parameter Window

First set PID controller be P controller, let 0,0,9 === Dip KKK , the following

simulation result is obtained:

Figure 3-35 1-stage Linear IP P Control Simulation Result(Kp=9)

We can see from the figure that the system output diverges. Increase control gain,

Page 86: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 77

0,0,40 === Dip KKK , the simulation result is as follow:

Figure 3-36 1-stage Linear IP Proportional Control Simulation Result Kp=40)

From the figure, close loop system keeps vibrating and the period is about 0.7s.

To eliminate system vibration, increase differential control gain DK ,

Let 4,0,40 === Dip KKK , the simulation result is:

Figure 3-37 1-stage Linear IP PD Control Simulation Result(Kp=40,Kd=4)

From the figure, system stabilization time is long, about 4 second which is two

vibration periods. So we increase differential control gain DK ,

Let: 10,0,40 === Dip KKK

Simulation result will be:

Page 87: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 78

Figure 3-38 1-stage Linear IP PD Control Simulation Result(Kp=40,Kd=10)

From the figure, system is stabilized in about 1.5 second, but there is certain

steady state error.

To eliminate the steady state error, let’s increase the integral gain iK ,

Let: 10,20,40 === Dip KKK

The following simulation result will be obtained:

Figure 3-39 1-stage Linear IP PID Control Simulation Result(Kp=40,Ki=20,Kd=4)

From the simulation result, system can be well stabilized. But because of the

integral factor, it is evident that the stabilization time increased. Double click“Scope1”, the cart position output is:

Figure 3-40 1-stage Linear IP PD Control Simulation Result(cart position curve)

Page 88: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 79

We can see that, PID controller is SISO system. It only controls the pendulum rod but not the cart position. The cart might move towards one direction only.

We can also simulate by programming M file. (Enter MATLAB Simulink tool box“Googol Education Products”, open“PID

Control M Files” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ PID Experiments”)

PRO 3-6 1-stage Linear IP PID Control MATLAB Simulation

The simulation result is as follow:

Figure 3-41 1-stage Linear IP PID Control MATLAB Simulation Result(impulse disturbance)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Googol Linear 1 stage Inverted Pendulum PID Control % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear; num=[0.02725]; den=[0.0102125 0 -0.26705]; kd=10 %pid close loop system pendant response for impluse signal k=40 ki=10 numPID= [ kd k ki ]; denPID= [ 1 0 ]; numc= conv ( num, denPID ) denc= polyadd ( conv(denPID, den ), conv( numPID, num ) ) t = 0 : 0.005 : 5; figure(1); impulse ( numc , denc , t )

Page 89: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 80

3.4.3 PID Control Experiment

Real time control experiment is done in MATALB Simulink. Please read carefully the user manual before conducting experiment.

Before conducting MATLAB real time control experiment, please

check IP system mechanical structure and electrical wiring to ensure the safety.

3.4.3.1 Experiment steps in MATLAB experimental software

1) Open 1-stage linear IP PID Control diagram as shown below: (Enter MATLAB Simulink tool box“Googol Education Products”, open“PID Control Demo” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ PID Experiments”)

Figure 3-42 1-stage Linear IP MATLAB Real Time Control Diagram

2) Double click“PID”block to set PID parameters, as shown below:

Page 90: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 81

Set PID parameters as the simulation results, double click“OK”to save parameters. 3) Click to build, click to connect computer and IP system after successful

built. 4) Click to run. If motor is not servo on, users may refer to related chapter in IP

user manual to solve the problem. Pull the pendulum rod vertically upward slowly by hand and release when the program started to control. When the cart is getting reach the limit switch, touch the rod to make it move backward.

5) Experiment result is as follow:

Figure 3-43 1-stage Linear IP PID Control Experiment Result 1

Page 91: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 82

From the figure, IP system is well stabilized. The pendulum rod angle is about 3.14 (rad). The same with simulation result, PID controller is not able to control the cart position, cart will move slightly along the sliding shaft. Under fixed disturbance, the cart position and pendulum rod angle will be as in the figure below:

Figure 3-44 1-stage Linear IP PID Control Experiment Result 2(with disturbance)

We can see, system balance well under disturbance and will back to the

equilibrium point soon when disturbance stopped. Change the PID parameters, like:

Page 92: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 83

Observe the control result. We can see that system settling time decrease but small vibration occasionally appear during equilibrium time.

Figure 3-45 1-stage Linear IP PID Control Experiment Result 3(change PID parameters)

3.4.4 Experimental Result and Report

Record the calculation steps, simulation and experiment result and finish the report.

Page 93: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 84

3.5 State Space Pole Placement Control Experiment

Classical control theory mainly focused on the research of SISIO systems. The precise control plant model is often required in controller design. Modern control theory mainly uses modern mathematical tools to expand the control object of classical control theory to multi-input multi-output (MIMO) systems. Pole placement method places the close loop pole of MIMO system to the expected place by designing state feed back controller, thus to satisfy system transient and steady state performance requirement. We already have IP systems dynamic model previously. Next we are going to design controller by pole placement method and apply to 1-stage linear IP system.

3.5.1 State Space Analysis

For control system

BuAXX +=⋅

In which X State vector(n dimension)

u Control vector A nn× constant matrix B 1×n constant matrix Select control signal be:

KXu −=

Figure 3-46 State Feedback Close Loop Control Diagram

Solve the equation, we get

)()()( txBKAtx −=•

The solution is:

)0()( )( xetx tBKA−=

Page 94: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 85

We can see, if system state is controllable, for arbitrary initial state, )(tx will go

to 0 when time goes to infinity as long as K is properly chosen. Pole placement design steps:

1) Verify system controllability condition.

2) By characteristic polynomial of matrix A :

nnnn asasasAsI ++⋅⋅⋅++=− −−

11

1

Decide values of naaa ⋅⋅⋅,, 21 .

3) Determine matrix T that transform the state space equations to controllable canonical form:

MWT =

In which M is the controllability matrix,

[ ]BAABBM n 1−⋅⋅⋅= MMM

⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢

=−−

−−

0001001

0011

1

32

121

L

L

MMMMM

L

a

aaaaa

Wnn

nn

4) Formulate expected polynomial by expected eigenvalues:

nnnn

n ssssss αααµµµ ++⋅⋅⋅++=−−− −−

11

121 )())(( L

And decide the value of nααα ⋅⋅⋅,, 21 .

5) State feed back gain matrix K is decided by following equation:

[ ] 1112211

−−− −−−−= TaaaaK nnnn αααα MMLMM

3.5.2 Pole Placement and Simulation

We already have 1-stage linear IP state space model. The state space equations using cart acceleration as input are:

Page 95: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 86

'

3010

04.2900100000000010

uxx

xx

⎥⎥⎥⎥

⎢⎢⎢⎢

+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

φ

φ

φ

φ&

&

&&

&

&&

&

'

00

01000001

uxx

xy ⎥

⎤⎢⎣

⎡+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

⎡=

φ

φφ&

&

There are:

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥

⎢⎢⎢⎢

=

3010

04.2900100000000010

B

A

⎥⎦

⎤⎢⎣

⎡=

⎥⎦

⎤⎢⎣

⎡=

00

01000001

D

C

1-stage linear IP pole placement problem becomes: Design controller for above system. The system settling time is required to be

short (about 3s) and the required damping ratio is about 5.0=ς .

Next we are going to use 4 methods to calculate feed back gain matrix K. Method 1: By previous pole placement steps.

1) Checking system controllability. From section 3.1.4 System Controllability Analysis, the system state controllability matrix rank equal to system state dimension(4), the system output controllability matrix rank equal to the dimension of system output vector(2), so the system is controllable.

Page 96: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 87

IP/Cart System

BuAxx +=.

.x

Variables State

u Force Control

1k

2k

3k

4k

x

θ.θ

-

-

-

-

Figure 3-47 Inverted Pendulum Pole Placement Principle Diagram

2) Compute eigenvalues. According to the performance requirement with certain margin(assume the

settling time is 2s), we select the expected close loop poles as )4,3,2,1( == is iµ , in

which:

322,322,10,10 4321 jj −−=+−=−=−= µµµµ

In which 43 ,µµ are a pair of dominant poles with 4,5.0 == nως ; 21 ,µµ

locate on the left of dominant close loop poles thus have less impact. The expected characteristic polynomial is:

160072019624

)322)(322)(10)(10())()()((234

4321

++++=

++−+++=−−−−

ssss

jsjsssssss µµµµ

There is:

1600,720,196,24 4321 ==== αααα

From system characteristic polynomial:

24 4.29

4.2900100

000001

ss

ss

ss

AsI

−=

⎥⎥⎥⎥

⎢⎢⎢⎢

−−

=−

So we have:

0,0,4.29,0 4321 ==−== aaaa

Page 97: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 88

System feed back gain matrix is:

[ ] 111223344

−−−−−= TaaaaK αααα MMM

3) Determine matrix T that transform the state equation to controllable canonical form:

MWT =

In which:

[ ]

⎥⎥⎥⎥

⎢⎢⎢⎢

=

=

02.88032.88030

00010010

32 BABAABBM MMM

⎥⎥⎥⎥

⎢⎢⎢⎢

⎡−

=

⎥⎥⎥⎥

⎢⎢⎢⎢

=

000100100104.29104.290

0001001011

1

12

123

aaa

aaa

W

So we have:

⎥⎥⎥⎥

⎢⎢⎢⎢

⎡−

==

30000300104.2900104.29

MWT

⎥⎥⎥⎥

⎢⎢⎢⎢

⎡−

=−

3333.000003333.000

0113.00034.0000113.00034.0

1T

4) The state feed back gain matrix K is:

[ ]

[ ]

[ ]16.1633 93.2739 24.4898- 54.4218- 3333.000003333.000

0113.00034.0000113.00034.0

0244.29196072001600

111223344

=

⎥⎥⎥⎥

⎢⎢⎢⎢

⎡−

−+−−=

−−−−= −

MMM

MMM TaaaaK αααα

The control variable becomes: ⋅⋅

+=−= φφµ 16.1633 - 93.2739- 24.4898 54.4218 xxKX

Above calculation can be conducted by MATLAB programming.

Page 98: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 89

Run and obtain the following result:

Figure 3-48 Pole Placement Simulation Result

We could see, IP system can be stabilized in 2s after fixed disturbance to satisfy the design criterion.

PRO 3-7 1-stage Linear IP State Space Pole Placement MATLAB Program 1

Page 99: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 90

(Enter MATLAB Simulink tool box“Googol Education Products”, open“Poles Control M File1” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Googol Linear 1 stage Inverted Pendulum Poles Placement Method1 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear; A=[ 0 1 0 0; 0 0 0 0; 0 0 0 1; 0 0 29.4 0]; B=[ 0 1 0 3]'; C=[ 1 0 0 0; 0 0 1 0]; D=[ 0 0 ]'; J=[ -10 0 0 0; 0 -10 0 0; 0 0 -2-2*sqrt(3)*i 0; 0 0 0 -2+2*sqrt(3)*i]; pa=poly(A);pj=poly(J); M=[B A*B A^2*B A^3*B]; W=[ pa(4) pa(3) pa(2) 1; pa(3) pa(2) 1 0; pa(2) 1 0 0; 1 0 0 0]; T=M*W; K=[pj(5)-pa(5) pj(4)-pa(4) pj(3)-pa(3) pj(2)-pa(2)]*inv(T) Ac = [(A-B*K)]; Bc = [B]; Cc = [C]; Dc = [D]; T=0:0.005:5; U=0.2*ones(size(T)); Cn=[1 0 0 0]; Nbar=rscale(A,B,Cn,0,K); Bcn=[Nbar*B]; [Y,X]=lsim(Ac,Bcn,Cc,Dc,U,T); plot(T,X(:,1),'-'); hold on; plot(T,X(:,2),'-.'); hold on; plot(T,X(:,3),'.'); hold on; plot(T,X(:,4),'-') legend('CartPos','CartSpd','PendAng','PendSpd')

Page 100: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 91

IP Experiment\ Poles Experiments”) Method 2: Users may also use the following method for pole placement calculation:

Eigenvalues of matrix (A-BK)is the solution of equation 0)( =−− BKAIs :

[ ] 0010

000100000000010

000000000000

4321 =×

⎥⎥⎥⎥

⎢⎢⎢⎢

+

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

kkkk

bass

ss

The above equation can be rewritten as:

0)()( 122

313

424 =−−++−+++ aksaksbkkasbkks

The expected system eigenvalue can be achieved by selecting proper feed

back gain coefficient 4321 ,,, kkkk .

Let the 4 engenvalues 4321 ,,, λλλλ be roots of the algebraic equation, there

are:

0)(

)(

)(

4321

214431432321

2423114433221

34321

4

=++++−

++++++

+++−

λλλλλλλλλλλλλλλλ

λλλλλλλλλλλλ

λλλλ

ss

ss

Compare two equations and we get

43211

2144314323212

42311443322131

432142

)(

)(

λλλλλλλλλλλλλλλλ

λλλλλλλλλλλλλλλλ

=−+++−=−

+++++=++−+++−=+

akak

bkkabkk

If the given 4321 ,,, λλλλ are real numbers or conjugate complex numbers,

then the right hand side of the equation is real number which can be used to solve

real numbers 4321 ,,, kkkk .

Assign eigenvalues as following

1λ , 2λ , 3λ , 4λ = j322 ±− ,-10, -10

And 3,4.29 == ba

Page 101: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 92

The equations of 4321 ,,, kkkk can then be written as:

16004.297204.29

19634.29243

1

2

31

42

=−=−

=++−=+

kk

kkkk

The solutions are

1633.162739.934898.244218.54 4321 ==−=−= kkkk

The control force acting horizontally on the cart is:

⋅⋅

+=−= φφµ 16.1633 - 93.2739- 24.4898 54.4218 xxKX

We could see, the result is the same from the one in method 1. PRO 3-8 1-stage Linear IP State Space Pole Placement MATLAB Program 2

Page 102: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 93

(Enter MATLAB Simulink tool box“Googol Education Products”, open“Poles Control M File2” in“Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ Poles Experiments”) Method 3: By Ackermann formula Feed back gain matrix determined by Ackermann formula:

[ ][ ] )(1000 11 ABAABBK n φ−−⋅⋅⋅= MMML

In which IAAAA 322

13)( αααφ +++=

This can be easily calculated by MATLAB, program as follow:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Googol Linear 1 stage Inverted Pendulum Poles Placement Method2 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear; syms a s b k1 k2 k3 k4; A=[ 0 1 0 0; 0 0 0 0; 0 0 0 1; 0 0 a 0]; B=[ 0 1 0 b]'; SS=[ s 0 0 0; 0 s 0 0; 0 0 s 0; 0 0 0 s]; K=[k1 k2 k3 k4]; J=[ -10 0 0 0; 0 -10 0 0; 0 0 -2-2*sqrt(3)*i 0; 0 0 0 -2+2*sqrt(3)*i]; ans=A-B*K; P=poly(ans) PJ=poly(J)

Page 103: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 94

PRO 3-9 1-stage Linear IP Pole Placement MATLAB Program 3(Ackermann formula)

(Enter MATLAB Simulink tool box“Googol Education Products”, open“Poles Control M File3” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ Poles Experiments”) Run and get

We could see, the result is the same with those from the previous two. Method 4:

Directly use MATLAB pole placement function for calculation. [K,PREC,MESSAGE] = PLACE(A,B,P)

(Enter MATLAB Simulink tool box“Googol Education Products”, open“Poles Control M File4” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ Poles Experiments”)

K = -54.4218 -24.4898 93.2739 16.1633

clear; A=[ 0 1 0 0; 0 0 0 0; 0 0 0 1; 0 0 29.4 0]; B=[ 0 1 0 3]'; M=[B A*B A^2*B A^3*B]; J=[ -10 0 0 0; 0 -10 0 0; 0 0 -2-2*sqrt(3)*i 0; 0 0 0 -2+2*sqrt(3)*i]; phi=polyvalm(poly(J),A); K=[ 0 0 0 1]*inv(M)*phi

Page 104: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 95

PRO 3-10 1-stage Linear IP Pole Placement MATLAB Program 4(Ackermann formula)

To match the format of function place(), change poles -10,-10 to

0.0001j10-0.0001j,-10- + , the additional imaginary number is small thus can be

ignored. Run and get the following result:

Both 4 methods obtain the same result.

Use the previous result for simulation in MATLAB Simulink. Open 1-stage linear IP simulation model:

(Enter MATLAB Simulink real time control tool box“Googol Education Products”,open“Poles Control Simulink” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ Poles Experiments”)

Figure 3-49 1-stage Linear IP State Space Pole Placement MATLAB Simulink Simulation

In which“GL1IP State-Space”is the state space model of 1-stage linear IP, double

click to open the following window:

K = -54.4218 -24.4898 93.2739 16.1633

clear; A=[ 0 1 0 0; 0 0 0 0; 0 0 0 1; 0 0 29.4 0]; B=[ 0 1 0 3]'; P=[-10-0.0001*j,-10+0.0001*j,-2-2*sqrt(3)*j,-2+2*sqrt(3)*j]; K=place(A,B,P);

Page 105: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 96

Double click“Controller1”block to set parameters of state feed back matrix K:

Input the calculated K value to the above window. Run simulation and get the following result:

Page 106: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 97

Figure 3-50 1-stage Linear IP State Space Pole Placement MATLAB Simulation Result

It can be observed that with the existence of certain disturbance, system can be

stabilized again in 3 seconds. Users may revise the expected performance criterion for new pole placement. Set

new control parameters in“Controller2”block and click“Manual Switch”to switch control signal to“Controller2”

3.5.3 Pole Placement Control Experiment

Experimental steps: 1) Enter MATLAB Simulink“\\matlab6p5\toolbox\GoogolTech\ InvertedPendulum \

Linear Inverted Pendulum, ”catalog, open 1-stage linear IP state space pole placement control program as follow: (Enter MATLAB Simulink tool box“Googol Education Products”, open“Poles

Control Demo” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ Poles Experiments”)

Page 107: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 98

Figure 3-51 1-stage Linear IP State Space Pole Placement Real Control Diagram

2) Click“Controller”block to set controller parameters, input the parameters that

obtain better simulation results to the block:

Click“OK”to finish. 3) Click to build and click to connect computer and IP system after build finish. 4) Click to run. If motor is not servo on, users may refer to related chapter in IP

user manual to solve the problem. Pull the pendulum rod vertically upward slowly by hand and release when the program started to control.

5) Double click “ Scope ” to observe experimental results as below:

Page 108: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 99

Figure 3-52 1-stage Linear IP State Space Pole Placement Real Control Result (equilibrium)

System is in equilibrium within small range of vibration. The cart vibration range

is about 3104 −× m, the pendulum vibration range is about 0.05rad. Note: different

control parameters will have different result. System response under certain disturbance is depicted in below figure:

Figure 3-53 1-stage Linear IP State Space Pole Placement Real Control Result(in disturbance)

Page 109: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 100

From the figure, system settling time is about 3 seconds. The design criterion is satisfied.

3.5.4 Experiment Result and Report

Record the calculation steps, simulation and experiment result and finish the report. Note: Users may add state observer in pole placement experiment for further design, simulation and experiment.

Page 110: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 101

3.6 Linear Quadratic LQR Optimal Control Experiment

The content of this experiment is to allow users comprehend and master linear quadratic LQR optimal control principle and method, and apply to 1-stage linear IP system.

3.6.1 Linear Quadratic LQR Optimal Control Principle

and Analysis

The linear quadratic LQR optimal control principle is, by system equations:

BuAXX.

+= (4-1)

Determine matrix K that gives the optimal control vector:

u(t)=-K*x(t) (4-2) Such that the performance index is minimized:

dtJ )(0

*RuuQXX *∫∞

+= (4-3)

In which Q——positive definite (or semi-positive definite) hermitian or real symmetric matrix.

R——positive definite hermitian or real symmetric matrix.

Figure 3-54 Optimal LQR Control Diagram

The second term on the right of the equation is introduced in concern of energy

loss. Matrix Q and R determine the relative importance of error and energy loss. Assume that the control vector u(t) is unbounded.

For linear systems:

⎪⎩

⎪⎨⎧

=+=

CXYBuAXX

.

Select Q and R according to expected performance criterion, the matrix K can be easily obtained by MATLAB command lqr.

K=lqr(A,B,Q,R) Change Q value will get different system response. The system will be more robust to disturbance and the settling time will be shorter if Q is larger (in certain range). The influence of Q will be described in experiment result analysis.

Detailed theory of optimal LQR control please refer to related textbooks about

Page 111: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 102

modern control theory.

3.6.2 LQR Control Parameters and Simulation

We already have 1-stage linear IP system dynamic model previously. Next we are going to design LQR controller which not only stabilize the pendulum rod vertically upward but also control the cart position.

The 1-stage linear IP system state space equations are:

'

3010

04.2900100000000010

uxx

xx

⎥⎥⎥⎥

⎢⎢⎢⎢

+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

φ

φ

φ

φ&

&

&&

&

&&

&

'

00

01000001

uxx

xy ⎥

⎤⎢⎣

⎡+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

⎡=

φ

φφ&

&

Applying linear feed back controller, suppose R is step input acting on the cart

and the 4 state variables⋅

φφ,,, xx & represents cart position, cart velocity, pendulum rod

angle and pendulum rod velocity respectively. The output ],[ ′= φxy includes cart

position and pendulum angle. Design controller such that, when acting step signal to the system, pendulum rod will be back to vertically upward after oscillation. The cart will reach new given position.

Assume all state feed back can be realizable (4 state variable are observable), find out the vector K that determine the feed back control rule. Obtain the K that corresponds to optimal controller in MATLAB. There are 2 parameters for functions Lqr——R and Q, which are weightening coefficients of input and state variables. The

most simple case is assume 1=R , CCQ *′= . The expected response could also be

achieved through adjusting the controller by changing nonzero element in matrix Q.

⎥⎥⎥⎥

⎢⎢⎢⎢

=′=

0000010000000001

*CCQ

In which, 1,1Q is the cart position coefficient, 3,3Q is the pendulum rod angle

coefficient, and the input coefficient R is 1.

Next we are going to calculate matrix K, use Matlab command ),,,( RQBAlqrK = .

The MATLAB programming is as follow:

Page 112: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 103

( Enter MATLAB Simulink real time control tool box “ Googol Education Products”,open“LQR Control MFiles” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ LQR Experiments”)

PRO 3-11 1-stage Linear IP LQR Control MATLAB Program

Let 11,1 =Q , 13,3 =Q , there is

[=K -1 -1.7855 25.422 4.6849]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Googol Linear 1 stage Inverted Pendulum LQR Control % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear; A=[ 0 1 0 0; 0 0 0 0; 0 0 0 1; 0 0 29.4 0]; B=[ 0 1 0 3]'; C=[ 1 0 0 0; 0 0 1 0]; D=[ 0 0 ]'; Q11=1000; Q33=200; Q=[Q11 0 0 0; 0 0 0 0; 0 0 Q33 0; 0 0 0 0]; R = 1; K = lqr(A,B,Q,R) Ac = [(A-B*K)]; Bc = [B]; Cc = [C]; Dc = [D]; T=0:0.005:5; U=0.2*ones(size(T)); Cn=[1 0 0 0]; Nbar=rscale(A,B,Cn,0,K); Bcn=[Nbar*B]; [Y,X]=lsim(Ac,Bcn,Cc,Dc,U,T); plot(T,X(:,1),'-');hold on; plot(T,X(:,2),'-.');hold on; plot(T,X(:,3),'.');hold on; plot(T,X(:,4),'-') legend('CartPos','CartSpd','PendAng','PendSpd')

Page 113: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 104

Set up 1-stage linear IP model in Simulink as shown in below figure: (Enter MATLAB Simulink real time control tool box“Googol Education Products”, open “ LQR Control Simulink ” in “ Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ LQR Experiments”)

Figure 3-55 1-stage Linear IP LQR Control Simulation Model

“LQR Controller”block is encapsulated. Right click on the block and select“Look under mask”to open the block:

Double click“Matrix gain K” to set control parameters:

Click to run simulation and get the following result:

Page 114: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 105

Figure 3-56 1-stage Linear IP LQR Control Simulation Result 1

LQR control step response is depicted as above figure. CartPos is the cart

position curve, CartSpd is the cart velocity curve, PendAng is the pendulum angle curve and PendSpd is the pendulum rod angular velocity curve. It can be observed from the figure, close loop system response overshoot is small, but the settling time is long. We could increase control gain to decrease the settling time.

It can also be observed that in Q matrix, both the settling time and pendulum rod

angle movement will decrease as 11Q increase. Let 1,1Q =1000, 3,3Q =200,

Then [=K -31.623 -20.151 72.718 13.155]

Set parameters and run, the system response is as follow:

Figure 3-57 1-stage Linear IP LQR Control Simulation Result 2

From the figure, system response time improved dramatically. The response can

even be faster by increasing 1,1Q and 3,3Q . But for real discrete time control system,

Page 115: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 106

large control may result in oscillation

3.6.3 1-stage Linear IP LQR Control Experiment

Real time control experiment is implemented in MATALB Simulink environment. Please read carefully the user manual before operating.

Before conducting MATLAB real time control experiment, please

check IP system mechanical structure and electrical wiring to ensure the safety.

Operation steps:

1) Open 1-stage linear IP LQR real time control block. ( Enter MATLAB Simulink real time control tool box “ Googol Education Products”,open“LQR Control Demo” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Experiment\ LQR Experiments”)

Figure 3-58 1-stage Linear IP LQR Real Time Control Diagram

In which“LQR Controller”is LQR controller block, “Real Control”is real time

control block. Double click“LQR Controller”to set control parameters as follow:

Page 116: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 107

Right click mouse on“LQR Controller”block and select“Look under mask”to

open the following block:

Double click“Real Control”block to open real time control window as follow:

In which“Pendulum”block is the IP system input output module, which inputs

cart velocity“Vel”and acceleration“Acc” and outputs cart position“Pos”and pendulum rod angle“Angle”.

Double click“Pendulum”block to open:

Page 117: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 108

In which“Set Cart’s Acc and Vel”module sets cart velocity and acceleration, “Get Cart’s Position” module reads cart current position and“Get Pend’s Angle”module reads pendulum rod current angle. More detailed description please refer to linear IP user manual.

2) Click to build, “ ”to connect and “ ”to run. Make sure the motor is servo

on. Pull the pendulum rod vertically upward slowly by hand and release when the program started to control.

3) The experiment result will be like the figure below:

Figure 3-59 1-stage Linear IP LQR Real Time Control Experiment Result

The top of the figure is the cart position plot and the bottom part is the pendulum

rod angle plot. From the figure, the cart can be stabilized in 1.5 second after being disturbed. The control effect is satisfactory.

4) Change the matrix Q value 3311 QandQ , set real control LQR parameters as those

get from simulation. Run real control program and observe the response.

When implementing MATLAB real control experiment, please don’t

change controller parameters excessively. The system may get out of control with too large parameters. Please ensure safety in the experiment.

Page 118: IP Experiment Manual V2.00

Chapter 3 Linear Inverted Pendulum Modeling, Simulation and Experiment

©Googol 2006 109

3.6.4 Experiment Result and Report

Record the calculation steps, simulation and experiment result and finish the report.

Page 119: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 110

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

1-stage linear IP will be in free down static state without external force. When the pendulum is disturbed by external force, the rod will swing freely for a long time if the friction is small. In many situations such long time oscillation is not expected. For example, when a crane is hoisting up an object, we wish the object could stop still quickly to the appointed position. Next we are going to model the 1-stage linear pendulum and do simulation and experiment.

4.1 1-stage Linear Pendulum Modeling and Analysis

4.1.1 1-stage Linear Pendulum Modeling

Similar with 1-stage linear IP modeling, both Newton’s mechanics and Lagrange method can be used in the modeling process. The Newton’s mechanics method modeling could refer to 1-stage Linear Inverted Pendulum System Model and we skip here. Next we will model the 1-stage pendulum system by Lagrange method.

Figure 4-1 1-stage Linear Pendulum Physical Model

The Lagrange equation is:

),(),(),(...qqVqqTqqL −= (4-1)

In which L is Lagrange operator, q is system generalized coordinate, T is system

Pendulum Rod

x

φ

F

Cart Trank

Page 120: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 111

kinetic energy and V is system potential energy.

ii

i

fqL

q

Ldtd

=∂∂

−∂

∂. (4-2)

i=1,2,3……n, if 为 is the external force acting on the thi generalized coordinate.

In 1-stage pendulum system, there are 2 generalized coordinates: φandx .

First calculate the kinetic energy:

mM TTT +=

In which mM TT , are kinetic energy of cart and pendulum rod 1 respectively.

Cart kinetic energy: 2.

21 xMTM =

The pendulum rod kinetic energy is: '''

mmm TTT += , in which '' , mm TT denote the translational and rotational kinetic

energy of the pendulum rod respectively. Assume: xpend ——x axis coordinate of the rod mass center; ypend ——y axis coordinate of the rod mass center; There are:

φφ

lCosypendlSinxxpend

−=+=

The rod kinetic energy is:

⎟⎠⎞

⎜⎝⎛ += 22' ))(())((

21

dtypendd

dtxpenddmTm

2.2

2.''

61

21 φφ mlJT pm ==

Over all system kinetic energy is: 2.

222'''

61))(())((

21 φml

dtypendd

dtxpenddmTTT mmm +⎟

⎠⎞

⎜⎝⎛ +=+=

The system potential energy is:

φmglCosypendgmVV m −=××==

As there is only friction force acting on the system in the generalized coordinateφ , so:

Page 121: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 112

.

. xbLLdtd

=∂∂

−∂

∂φφ

To a 1-stage linear IP system, system state variables are:

⎭⎬⎫

⎩⎨⎧ ..

,,, φφ xx

Solve for the equation:

⎪⎩

⎪⎨⎧

=+=

CXYBuAXX '

.

We need to solve for..φ ,

Assume

),,,,(......xxxf φφφ =

Take Taylor expansion in the equilibrium point and linearize, there is: ..

15

.

14

.

131211

..xkkxkkxk ++++= φφφ

In which 0,0,0,0,0

11 ....|=====∂

∂=

xxxxfk

φφ

0,0,0,0,012 ....|

=====∂∂

=xxx

fkφφφ

0,0,0,0,0.13 ....|=====∂

∂=

xxxx

fkφφ

0,0,0,0,0.14 ....|

=====∂

∂=

xxx

fkφφφ

0,0,0,0,0..15 ....|=====∂

∂=

xxxx

fkφφ

Calculate the above in Mathematica. ( Program file please refer to “ L1DP.nb ” in “ \GLIP2001\Modelfiles\ MathematicaFile”)

Page 122: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 113

PRO 4-1 1-stage Linear Pendulum Modeling Program

xpend= x@tD+ l∗Sin@φ@tDD;ypend= −l∗Cos@φ@tDD;

tpend= 1ê2∗ m∗HH∂t xpendL^2+ H∂t ypendL^2L + 1ê6∗ m∗ l^2∗ Hφ'@tDL^2;Simplify@tpendD;v= m∗g∗ypend;

lang= tpend− v;Simplify@langD;

ldad= ∂φ'@tD lang;Simplify@ldadD;fa= ∂t ldad− ∂φ@tD lang;Simplify@faD;

Solve@8fa 0< , 8φ''@tD<D;add= φ''@tD ê. %;

k11= ∂x@tD add ê.x@tD → 0 ê. φ@tD → 0 ê. x'@tD→ 0 ê. φ'@tD → 0 ê. x''@tD→ 0k12= ∂φ@tD add ê.x@tD → 0 ê. φ@tD → 0 ê. x'@tD→ 0 ê. φ'@tD → 0 ê. x''@tD→ 0k13= ∂x'@tD add ê.x@tD → 0 ê. φ@tD → 0 ê. x'@tD→ 0 ê. φ'@tD → 0 ê. x''@tD→ 0k14= ∂φ'@tD add ê.x@tD → 0 ê. φ@tD → 0 ê. x'@tD→ 0 ê. φ'@tD → 0 ê. x''@tD→ 0k15= ∂x''@tD add ê.x@tD → 0 ê. φ@tD → 0 ê. x'@tD→ 0 ê. φ'@tD → 0 ê. x''@tD→ 0

g= 9.8;l= 0.25;

Simplify@k12DSimplify@k15D Run program:

lk

kk

lgk

k

4315

014013

4312

011

−=

==

−=

=

Assume },,,{..φφxxX = , system state space equations are:

DuCXyBuAXX

+=+=&

Page 123: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 114

There are:

u

l

xx

lg

xx

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

43

010

04300

100000000010

φ

φ

φ

φ&

&

&&

&

&&

&

(4-3)

uxx

xy ⎥

⎤⎢⎣

⎡+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

⎡=

00

01000001

φ

φφ&

&

By transformation:

xll

g&&&&

43

43

−−= φφ

The transfer function of pendulum rod and cart position is:

lgs

sl

sXs

43

43

)()(

2

2

+

The transfer function of pendulum rod angle and cart acceleration is:

lgs

lsVs

43

43

)()(

2 +

4.1.2 Real System Model

Real system physical parameters could refer to related content in chapter System Parameters. 把 Input parameters and system physical model is obtained. The transfer function of pendulum rod angle and cart position is:

4.293

)()(

2

2

+−

ss

sXs (4-4)

The transfer function of pendulum rod angle and cart acceleration is:

4.293

)()(

2 +−

ssVs (4-5)

The system state equations using cart acceleration as the input has the following form:

'

3010

04.2900100000000010

uxx

xx

⎥⎥⎥⎥

⎢⎢⎢⎢

+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

φ

φ

φ

φ&

&

&&

&

&&

&

Page 124: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 115

'

00

01000001

uxx

xy ⎥

⎤⎢⎣

⎡+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

⎡=

φ

φφ&

& (4-6)

4.1.3 System Controllability Analysis

According to 3.1.4 System Controllability Analysis, there is:

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥

⎢⎢⎢⎢

=

3010

04.2900100000000010

B

A

⎥⎦

⎤⎢⎣

⎡=

⎥⎦

⎤⎢⎣

⎡=

00

01000001

D

C

Calculate in MATLAB:

Or directly use command ctrb and obsv to calculate.

clear; A=[ 0 1 0 0; 0 0 0 0; 0 0 0 1; 0 0 -29.4 0]; B=[ 0 1 0 -3]'; C=[ 1 0 0 0; 0 1 0 0]; D=[ 0 0 ]'; cona=[B A*B A^2*B A^3*B]; cona2=[C*B C*A*B C*A^2*B C*A^3*B D];rank(cona) rank(cona2)

Page 125: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 116

There are:

It can be observed that, the rank of system state controllable matrix equal to state

dimension and the rank of output controllability matrix equation to dimension of

output vector y . So the system is controllable and will be stabilized by proper

controller design.

4.2 1-stage Linear Pendulum Root Locus Analysis

After obtaining system transfer function, the root locus analysis can be conducted. Similar with 3.2 1-stage Linear IP Root Locus Control Experiment, create a new file in MATLAB, type the following commands:

The result is as follow, system poles and zeros are:

System root locus:

z = 0 0 p = 0 + 5.4222i 0 - 5.4222i

clear; num=[-3 ]; den=[1 0 29.4]; rlocus(num,den) z=roots(num); p=roots(den);

Uc=ctrb(A,B); Vo=obsv(A,C); rank(Uc) rank(Vo)

ans = 4

ans = 2

Page 126: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 117

Figure 4-2 1-stage Linear Pendulum Root Locus Plot

It can be observed from the figure, system zero is infinity and there are two poles

on imaginary axis.

4.3 1-stage Linear Pendulum Frequency Response

Analysis

Based on control principle in 0 , analyze frequency response of 1-stage linear pendulum; type the following

commands in MATLAB:

The result will be like following:

clear; num=[-3]; den=[1 0 29.4]; subplot(2,1,1) bode(num,den) subplot(2,1,2) nyquist(num,den)

Page 127: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 118

Figure 4-3 1-stage Linear Pendulum Bode Plot

Figure 4-4 1-stage Linear Pendulum Nyquist Plot

It can be observed that, system Nyquist plot encircle point -1 once, system is not

stable.

4.4 1-stage Linear Pendulum Step Response

Analysis

Analyze the 1-stage pendulum step response as in 3.1.5 System Step Response Analysis.

clear; num=[-3]; den=[1 0 29.4]; step(num,den)

Page 128: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 119

Run and get the following result:

Figure 4-5 1-stage Linear Pendulum Step Response Result

It can be observed from the figure, this is a typical undamped second order

system. The system step response will not converge.

4.5 1-stage Linear Pendulum PID Control Simulation

and Experiment

Similar with 1-stage linear IP, 1-stage linear pendulum can also be controlled by root locus, frequency response or state space method. The experiments mentioned above could refer to 1-stage linear IP experiments and 1-stage linear pendulum PID control experiment. For 1-stage linear pendulum, we only introduce PID and LQR control experiment here.

4.5.1 1-stage Linear Pendulum PID Control Analysis and

Simulation

Modeling 1-stage linear pendulum in MTALAB Simulink:

Page 129: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 120

The result will be as follow:

We could see, the result is the same with the previous section. Next we will add the PID controller: (Enter MATLAB Simulink real time control tool box“Googol Education Products”, open “ PID Control Simulink ” in “ Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage Pendulum Experiment\ PID Experiments”)

Figure 4-6 1-stage Linear Pendulum PID Control Simulation

Double click PID block to set PID parameters:

Note: As there is already a “-” in system model, the PID parameter should be set a minus value.

Run simulation and the result should be:

Page 130: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 121

Figure 4-7 1-stage Linear Pendulum P Control Result

It can be observed that, with P controller, the system will vibrate without any attenuation. The differential gain should be added to control. Reset PID parameters as:

Run simulation and the result will be as follow:

The system vibrates excessively and the settling time is too long. The problem

can be solved by adding differential gain:

Adding step signal of magnitude 0.01 to the system, the simulation result will be:

Page 131: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 122

Figure 4-8 1-stage Linear Pendulum PD Control Result

From the figure, the system can be stabilized in a short time though there exist certain steady state error. Adding integral gain, the steady state error will be further decreased.

Assume that the system is required to be stabilized in 1 second and the overshot

be less than 20%. Change the control parameters and observe the result. Let:

Figure 4-9 1-stage Linear Pendulum PID Controller

Page 132: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 123

The simulation result will be as follow:

Figure 4-10 1-stage Linear Pendulum PID Control Result

It can be observed that the simulation result is satisfactory.

4.5.2 1-stage Linear Pendulum PID Real Time Control

The real time control experiment is implemented in MATALB Simulink. Please read carefully the user manual before experiment.

Before conducting MATLAB real time control experiment, please

check IP system mechanical structure and electrical wiring to ensure the safety.

Experiment steps:

1) Open 1-stage linear pendulum real time control program in MATLAB Simulink.

(Enter MATLAB Simulink real time control tool box“Googol Education Products”, open “PID Control Demo”in“Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage Pendulum Experiment\ PID Experiments”).

Page 133: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 124

Figure 4-11 1-stage Linear Pendulum PID Real Time Control Diagram

2) Double click“PID Controller”block to open PID parameters window:

Input the parameters obtained from the simulation:

3) Click“ ”to build. There will be instruction in MATLAB command window to inform if build is success or not. If yes, continue to the next step.

4) Switch on the electric box power.

5) Click“ ”to connect and click“ ”to run after connecting succeed. Adding disturbance to the system when it is stabilized.

The following real control result will be obtained:

Page 134: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 125

Figure 4-12 1-stage Linear Pendulum PID Real Time Control Result

It can be observed that, after adding disturbance, system will be stabilized within 1 second and the overshoot is also small.

Note: PID control is signal output control so we won’t be able to control the cart position. In general, the cart will move towards one direction slowly and when the cart is near the limit switch of one side users should touch the pendulum rod slightly to avoid the cart reach the limit.

6) Change PID parameters and redo the experiment. Observe the different result.

7) Record the result and finish the report.

When implementing MATLAB real control experiment, please don’t

change controller parameters excessively. The system may get out of control with too large parameters. Please ensure safety in the experiment.

Page 135: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 126

4.6 1-stage Linear Pendulum LQR Control

Simulation and Experiment

PID control as described in previous section can only control the pendulum rod angle but not the cart position. In order to control cart position and rod angle, a single-input (cart acceleration), multi-output (cart position and pendulum rod angle) controller is required. By the system state equation obtained previously, state space pole placement and LQR optimal control method can be applied to system control. Next we will control the system by LQR method; other algorithm design and experiment are left to users.

Related LQR control algorithm principle please refer to 3.6.1 Linear Quadratic LQR Optimal Control Principle and Analysis or textbooks about modern control theory.

4.6.1 1-stage Linear Pendulum LQR Control Analysis

and Simulation

We already have the system state equation using cart acceleration as the input:

'

3010

04.2900100000000010

uxx

xx

⎥⎥⎥⎥

⎢⎢⎢⎢

+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

φ

φ

φ

φ&

&

&&

&

&&

&

'

00

01000001

uxx

xy ⎥

⎤⎢⎣

⎡+

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎦

⎤⎢⎣

⎡=⎥

⎤⎢⎣

⎡=

φ

φφ&

&

The 4 state variables ⋅

φφ,,, xx & represent cart position, cart velocity, pendulum

rod angle and pendulum rod angular velocity respectively. The output ],[ ′= φxy

include cart position and pendulum rod angle. Next we are going to use LQR control algorithm to calculate: Assume optimal control gain matrix K:

u(t)=-K*x(t) K=lqr(A,B,Q,R)

Create the following m file in MATLAB: Set cart position gain be 1000, pendulum rod angle gain be 500. In general we

set R=1, simulation time be 5 second and simulation steps be 0.005 seond.

Page 136: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 127

1-stage linear pendulum LQR simulation file is as follow: (Enter MATLAB Simulink real time control tool box “Googol Education

Products”, Open “LQR Control M Files” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage Pendulum Experiment\ LQR Control Experiments”)

PRO 4-2 1-stage Linear Pendulum LQR Control MATLAB Program

Run program and obtain the following result: Feedback gain matrix is: K = 31.6228 14.4046 -22.3514 0.1188 It can be observed that, system will be stabilized in 3 seconds after being

clear; A=[ 0 1 0 0; 0 0 0 0; 0 0 0 1; 0 0 -29.4 0]; B=[ 0 1 0 -3]'; C=[ 1 0 0 0; 0 0 1 0]; D=[ 0 0 ]'; Q11=1000; Q33=500; Q=[Q11 0 0 0; 0 0 0 0; 0 0 Q33 0; 0 0 0 0]; R = 1; K = lqr(A,B,Q,R) Ac = [(A-B*K)]; Bc = [B]; Cc = [C]; Dc = [D]; T=0:0.005:5; U=0.2*ones(size(T)); Cn=[1 0 0 0]; Nbar=rscale(A,B,Cn,0,K); Bcn=[Nbar*B]; [Y,X]=lsim(Ac,Bcn,Cc,Dc,U,T); plot(T,X(:,1),'-');hold on; plot(T,X(:,2),'-.');hold on; plot(T,X(:,3),'.');hold on; plot(T,X(:,4),'-') legend('CartPos','CartSpd','PendAng','PendSpd')

Page 137: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 128

disturbed. The cart will be back to the original position and the pendulum rod will be in static free down state.

Figure 4-13 1-stage Linear Pendulum Simulation Result (with disturbance)

Similar with 1-stage linear IP, model 1-stage linear pendulum in MATLAB Simulink:

(Enter MATLAB Simulink real time control tool box “Googol Education Products” Open “LQR Control Simulink” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage Pendulum Experiment\ LQR Control Experiments”).

Figure 4-14 1-stage Linear Pendulum Simulink Diagram

Double click “LP1D” block to open 1-stage linear pendulum model parameter

window:

Page 138: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 129

Set matrix A,B,C,D as the real system model value. Double click “LQR Controller” to open LQR control parameter window:

Input the calculated feedback control gain K to the window respectively. Double click “Disturbance” block to set disturbance signal. Set disturbance

signal magnitude as 0.1 rad, the diagram is as follow. System will be stabilized again with disturbance adding to f(s).

Page 139: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 130

After setting parameters, click“ ”to run simulation and the result will be as

follow:

Figure 4-15 1-stage Linear Pendulum LQR Control Simulation Result

Users may modify the value of weighting matrix Q to obtain different feedback control parameter K and input to simulation model to observe the different results.

4.6.2 1-stage Linear Pendulum LQR Control Experiment

Real time control experiment is implemented in MATALB Simulink. Please read carefully the user manual before experiment.

Before conducting MATLAB real time control experiment, please

check IP system mechanical structure and electrical wiring to ensure the safety.

Page 140: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 131

Operation procedures: 1) Open 1-stage linear pendulum LQR real time control block: (Enter MATLAB Simulink real time control tool box “Googol Education Products”. Open “LQR Control Demo” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage Pendulum Experiment\ LQR Control Experiments”).

Figure 4-16 1-stage Linear Pendulum LQR Real Time Control Diagram

In which“LQR Controller” is LQR control block, “Real Control” is real time

control block. Double click“LQR Controller”block to set LQR controller parameters as follow:

Right click on“LQR Controller” block, select“Look under mask” to open the

following diagram:

Page 141: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 132

Double click“Real Control”block to open real time control block as follow:

In which“Pendulum”block is the IP system I/O module. The input is cart

velocity“Vel”&acceleration“Acc” and the output is cart position“Pos”&pendulum angle“Angle”.

Double click “Pendulum” block to open:

In which“Set Cart’s Acc and Vel”block sets cart velocity and acceleration. “Get

Cart’s Position” block reads the cart actual position. “Get Pend’s Angle” block reads pendulum current angle. More details please refer to IP instruction manual. 2) Click to build and click “ ” to connect. Click “ ” to run program. When

the program is running, the cart should be in the middle of the shaft and keep static downward.

3) The experiment result should be as in below figure:

Page 142: IP Experiment Manual V2.00

Chapter 4 1-stage Linear Pendulum Modeling and Experiment

©Googol 2006 133

Figure 4-17 1-stage Linear Pendulum LQR Control Result

The first chart is the cart position curve and the second one is the pendulum

angle curve. It can be observed from the figure that, the cart can be stabilized again in 2 seconds with external disturbance. The control performance is satisfactory.

4) Change the value 3311 Q and Q of matrix Q, input the simulation result of LQR

parameters to real time control program, run and observe the different control performance.

5) Record and analyze the experiment result. Finish the report.

When implementing MATLAB real control experiment, please don’t

change controller parameters excessively. The system may get out of control with too large parameters. Please ensure safety in the experiment.

Page 143: IP Experiment Manual V2.00

Chapter 5 1-stage Linear IP Swing Up Experiment

©Googol 2006 134

Chapter 5 1-stage Linear IP Swing Up Experiment

For 1-stage linear IP, the initial status is static down. To transform the status to vertically upward, external force is required to be applied to pendulum rod. In previous experiments, we pull the pendulum rod up by hand. Next we are going to control the IP to swing up automatically.

5.1 Energy Control in IP Swing Up

The energy of a single unconstrained IP system is:

)1(cos21 2

−+=⋅

φφ mglJE

There is:

φφφφφφ CosmulSinmglJdtdE ...

−=−=⋅⋅

In which u ——control vector in horizontally right direction Applying Lyapunov method, let:

2)(21

refEEV −=

Then:

φφ CosmulEEdtdV

ref

.)( −−=

Let: φφ CosEEku ref

.)( −=

Notice that when 0=or 0=.

φφ Cos , 0=u .

Besides, the control variable can not be too large as a result of the physical limitations, there is:

⎪⎩

⎪⎨⎧ ≤⋅−=

02

])[(. πθφφ ngCosEEsignv ref

In which, ()sign is sign function, gvn /max= is a constant.

Page 144: IP Experiment Manual V2.00

Chapter 5 1-stage Linear IP Swing Up Experiment

©Googol 2006 135

5.2 1-stage Linear IP Swing Up Experiment

Real time control experiment is implemented in MATALB Simulink environment, please read carefully the instruction manual before experiment.

Before conducting MATLAB real time control experiment, please

check IP system mechanical structure and electrical wiring to ensure the safety.

Experiment procedures:

1) Open 1-stage linear IP swing up program in MATLAB Simulink:

(Enter MATLAB Simulink real time control toolbox“Googol Education Products”, open “Swing-Up Control Demo” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 1-Stage IP Swing-Up Control”)

Figure 5-1 1-stage Linear IP Swing Up Real Time Control Diagram

2) In which“Swing-up Controller” is the swing up control mudule.

Page 145: IP Experiment Manual V2.00

Chapter 5 1-stage Linear IP Swing Up Experiment

©Googol 2006 136

Double click“Swing-up Controller” block to open the following diagram:

In which“Swing-up” is the programmed swing up function.

Double click“Swing-up”block to set the energy coefficient:

3) After confirming parameters, click“ ” to build program.

4) Click“ ” to connect after built successfully.

5) Click“ ” to run program, the experimental result will be as follow:

Page 146: IP Experiment Manual V2.00

Chapter 5 1-stage Linear IP Swing Up Experiment

©Googol 2006 137

Figure 5-2 1-stage Linear IP Swing Up Control Result (cart position)

Figure 5-3 1-stage Linear IP Swing Up Control Result (pendulum rod angle)

It can be observed that the maximum value of pendulum rod angle increase gradually. When the value is large enough in certain range, the system starts stabilization control. At this stage, the cart will be stabilized near the initial position (0) and pendulum rod will be vertically upward (the pendulum rod angle is –pi relative to the static down angle which is 0 )

5.3 Swing Up Experiment by Other Algorithms

In MATLAB real time control software, users may apply their own algorithms conveniently. For SISO algorithm in classic control theory, users may substitute the controller in 3.41-stage Linear IP PID Control Experiment with their own controller:

Page 147: IP Experiment Manual V2.00

Chapter 5 1-stage Linear IP Swing Up Experiment

©Googol 2006 138

Figure 5-4 Apply user define controller(SISO)

Data acquisition module like pendulum angle and cart position, and other signal

converting module are not suggested to be modified except for some special case. By applying single-input(cart acceleration) multi-output(pendulum rod angle

and cart position) algorithms of modern control theory, users may substitute controller like the LQR in 3.6Linear Quadratic LQR Optimal Control with their own.

Figure 5-5 Apply user define controller(MIMO)

After changing controller, rebuild program and connect after built successful.

Ensure the safety and run the program.

Apply user define controller

Apply user define controller

Page 148: IP Experiment Manual V2.00

Chapter 5 1-stage Linear IP Swing Up Experiment

©Googol 2006 139

User may also use their own swing up algorithm as shown in following figure:

Figure 5-6 Apply user define swing up controller

When implementing the user define controller, please ensure the

safety. Users should not start real control without good simulation result. If the system can not be controlled, please cut off the power of electric

box immediately.

Apply user define swing up controller

Page 149: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 140

Chapter 6 2-stage Linear Inverted Pendulum

2-stage linear IP is composed of linear motion module and 2-stage IP main body.

6.1 System Physical Model

For simplicity, we ignore the air resistance and other frictions and assume the pendulum rod be rigid body. The 2-stage IP configuration is shown as in Figure 6-1:

Figure 6-1 2-stage Linear IP Physical Model

IP parameters are defined as follow: M cart mass

1m rod 1 mass

2m rod 2 mass

3m Joint mass

1l distance from the rod1 axis rotation center to the rod mass center

2l distance from the rod2 axis rotation center to the rod mass center

1θ angle between the rod1 and vertically upward direction

Pendulum rod 2

Joint

Pendulum rod1

x

F

cart Sliding shaft

Page 150: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 141

2θ angle between the rod2 and vertically upward direction

F external force acting on the system Next we are going to derive the system kinematic equations by Lagrange method. The Lagrange equation is:

),(),(),(...qqVqqTqqL −=

In which L is the Lagrange operator, q is the generalized coordinates, T denotes the kinetic energy and V denotes potential energy of the system.

ii

i

fqL

q

Ldtd

=∂∂

−∂

∂.

In which i=1,2,3……n, if is the force acting on the system in the ith generalized

coordinate. In 2-stage IP system, there are 3 generalized coordinates: 21 ,, θθx 。

The system kinetic energy is:

321 mmmM TTTTT +++=

In which 321 ,,, mmmM TTTT denotes the kinetic energy of cart, rod 1, rod 2 and Jiont

respectively. The kinetic energy of the cart is:

2.

21 xMTM =

''2

'11 mmm TTT += In which '

2'

1 , mm TT denote the translational and rotational kinetic

energy of the pendulum rod 1 respectively. ''

2'

22 mmm TTT += In which '2

'2 , mm TT denote the translational and rotational kinetic

energy of the pendulum rod 2 respectively. Let’s assume: xpend1--- x axis coordinate of rod 1 mass center; yangle1 --- y axis coordinate of the rod 1 mass center; xpend2 --- x axis coordinate of rod 2 mass center; yangle2 --- y axis coordinate of the rod 2 mass center; xmass --- x axis coordinate of the joint mass center; ymass--- y axis coordinate of the joint mass center; There are:

Page 151: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 142

⎩⎨⎧

=−=

⎩⎨⎧

+=−−=

⎩⎨⎧

=−=

11

11

2211

2211

11

11

22

22)(22

11

θθ

θθθθ

θθ

CoslymassSinlxxmass

CoslCoslypendSinlSinlxxpend

CoslypendSinlxxpend

Then:

⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛=

22

1'

1)1()1(

21

dtypendd

dtxpenddmTm

2.

12

11

2.

1''

1 61

21 θθ lmJT pm ==

Same as above:

⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛=

22

2'

2)2()2(

21

dtypendd

dtxpenddmTm

2.

22

22

2.

22''

2 61

21 θθ lmJT pm ==

⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛=

22

33)()(

21

dtymassd

dtxmassdmTm

The overall system kinetic energy will be:

⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛+

+⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛+

+⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛+=

+++=

22

3

2.

22

22

22

2

2.

12

11

22

1

2.

321

)()(21

61)2()2(

21

61)1()1(

21

21

dtymassd

dtxmassdm

lmdt

ypendddt

xpenddm

lmdt

ypendddt

xpenddmxM

TTTTT mmmM

θ

θ

The system potential energy become:

11322112111

321321

2)2(21

θθθθ CoslmCoslCoslmCoslmymassmypendmypendmVVVV mmm

+++=++=++=

There are no external force acting on the system under 21,θθ generalized coordinates,

there are:

Page 152: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 143

⎪⎪

⎪⎪

=∂∂

−∂

=∂∂

−∂

0

0

2.

2

1.

1

θθ

θθLL

dtd

LLdtd

For 2-stage IP system, the state variables are:

⎭⎬⎫

⎩⎨⎧ .

2

.

1

.

21 ,,,,, θθθθ xx

To solve the state equations:

⎪⎩

⎪⎨⎧

=+=

CXYBuAXX

.

The solution of ..

2

..

1 and θθ should be solved first.

Assume:

⎪⎩

⎪⎨⎧

=

=

),,,,,,(

),,,,,,(...

2

.

1

.

212

..

2

...

2

.

1

.

211

..

1

xxxf

xxxf

θθθθθ

θθθθθ

Take Tyler expansion around the equilibrium point and linearize, there are:

⎪⎩

⎪⎨⎧

++++++=

++++++=..

27

.

226

.

125

.

2422312221

..

2

..

17

.

216

.

115

.

1421311211

..

1

xkkkxkkkxk

xkkkxkkkxk

θθθθθ

θθθθθ

In which:

0,0,0,0,0,0,0

111 ...

2

.

1

.

21

|=======∂

∂=

xxxxf

kθθθθ

0,0,0,0,0,0,01

112 ...

2

.

1

.

21

|=======∂

∂=

xxx

fk

θθθθθ

0,0,0,0,0,0,02

113 ...

2

.

1

.

21

|=======∂

∂=

xxx

fk

θθθθθ

0,0,0,0,0,0,0.1

14 ...

2

.

1

.

21

|=======∂

∂=

xxxx

fk

θθθθ

0,0,0,0,0,0,0.

1

115 ...

2

.

1

.

21

|=======∂

∂=

xxx

fk

θθθθθ

0,0,0,0,0,0,0.

2

116 ...

2

.

1

.

21

|=======∂

∂=

xxx

fk

θθθθθ

0,0,0,0,0,0,0..1

17 ...

2

.

1

.

21

|=======∂

∂=

xxxx

fk

θθθθ

0,0,0,0,0,0,0

221 ...

2

.

1

.

21

|=======∂

∂=

xxxxf

kθθθθ

0,0,0,0,0,0,01

222 ...

2

.

1

.

21

|=======∂

∂=

xxx

fk

θθθθθ

0,0,0,0,0,0,02

223 ...

2

.

1

.

21

|=======∂

∂=

xxx

fk

θθθθθ

Page 153: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 144

0,0,0,0,0,0,0.2

24 ...

2

.

1

.

21

|=======∂

∂=

xxxx

fk

θθθθ

0,0,0,0,0,0,0.

1

225 ...

2

.

1

.

21

|=======∂

∂=

xxx

fk

θθθθθ

0,0,0,0,0,0,0.

2

226 ...

2

.

1

.

21

|=======∂

∂=

xxx

fk

θθθθθ

0,0,0,0,0,0,0..2

27 ...

2

.

1

.

21

|=======∂

∂=

xxxx

fk

θθθθ

The above equations can be solved in Mathematica: (Calculation file please refer to “L2DIP.nb” in “\GLIP2002\Modelfiles\ MathematicaFile”.)

PRO 6-1 2-stage Linear IP Modeling Mathematica Program

TM=12

Mcar∗ x @tD2 ;

xpend1= x@tD− l1 ∗Sin@θ1@tDD;ypend1= l1∗Cos@θ1@tDD;tpend1= 1ê2∗ m1∗HH∂t xpend1L^2+H∂t ypend1L^2L+ 1ê2∗H1ê3∗ m1∗l1^2L∗ θ1'@tD^2;

xpend2= x@tD− 2∗l1 ∗Sin@θ1@tDD− l2∗Sin@θ2@tDD;ypend2= 2∗l1∗ Cos@θ1@tDD+ l2∗Cos@θ2@tDD;tpend2= 1ê2∗ m2∗HH∂t xpend2L^2+H∂t ypend2L^2L+ 1ê2∗H1ê3∗ m2∗l2^2L∗Hθ2'@tDL^2;

xmass= x@tD− 2∗l1 ∗Sin@θ1@tDD;ymass= 2∗l1∗ Cos@θ1@tDD;tmass= 1ê2∗ m3∗HH∂t xmassL^2+H∂t ymassL^2L;

v= m1∗g∗ypend1+ m2∗g∗ypend2+ m3∗g∗ymass;Simplify@vD;

lang= TM+ tpend1+ tpend2+tmass− v;Simplify@langD;

ldad= ∂θ1'@tD lang;

Simplify@ldadD;f1= ∂t ldad− ∂θ1@tD lang;

Simplify@f1D;

ldbd= ∂θ2'@tD lang;

Simplify@ldbdD;f2= ∂t ldbd− ∂θ2@tD lang;

Simplify@f2D;

Solve@8f1 0, f2== 0< , 8θ1''@tD, θ2''@tD<D;add= θ1''@tD ê.%;bdd= θ2''@tD ê.%;

Page 154: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 145

k11= ∂x@tD a dd ê.x@tD → 0 ê. θ1@tD→ 0 ê. θ2@tD → 0 ê. x'@tD→ 0 ê. θ1'@tD→ 0 ê.θ2'@tD → 0 ê. x''@tD→ 0;

k12= ∂θ1@tD add ê. x@tD→ 0 ê. θ1@tD → 0 ê.θ2@tD→ 0 ê. x'@tD → 0 ê. θ1'@tD → 0 ê.

θ2'@tD → 0 ê. x''@tD→ 0;k13= ∂θ2@tD add ê. x@tD→ 0 ê. θ1@tD → 0 ê.θ2@tD→ 0 ê. x'@tD → 0 ê. θ1'@tD → 0 ê.

θ2'@tD → 0 ê. x''@tD→ 0;k14= ∂x'@tD add ê.x@tD → 0 ê.θ1@tD→ 0 ê. θ2@tD → 0 ê. x'@tD→ 0 ê. a'@tD → 0 ê.

θ2'@tD → 0 ê. x''@tD→ 0;k15= ∂θ1'@tD add ê. x@tD→ 0 ê. θ1@tD → 0 ê.θ2@tD→ 0 ê. x'@tD → 0 ê. θ1'@tD → 0 ê.

θ2'@tD → 0 ê. x''@tD→ 0;k16= ∂θ2'@tD add ê. x@tD→ 0 ê. θ1@tD → 0 ê.θ2@tD→ 0 ê. x'@tD → 0 ê. θ1'@tD → 0 ê.

θ2'@tD → 0 ê. x''@tD→ 0;k17= ∂x''@tD add ê.x@tD → 0 ê. θ1@tD→ 0 ê. θ2@tD → 0 ê. x'@tD→ 0 ê. θ1'@tD→ 0 ê.

θ2'@tD → 0 ê. x''@tD→ 0;

k21= ∂x@tD bdd ê.x@tD → 0 ê. θ1@tD→ 0 ê. θ2@tD → 0 ê. x'@tD→ 0 ê. θ1'@tD→ 0 ê.θ2'@tD → 0 ê. x''@tD→ 0;

k22= ∂θ1@tDbdd ê. x@tD→ 0 ê. θ1@tD → 0 ê.θ2@tD→ 0 ê. x'@tD → 0 ê. θ1'@tD → 0 ê.

θ2'@tD → 0 ê. x''@tD→ 0;k23= ∂θ2@tD bdd ê. x@tD→ 0 ê. θ1@tD → 0 ê.θ2@tD→ 0 ê. x'@tD → 0 ê. θ1'@tD → 0 ê.

θ2'@tD → 0 ê. x''@tD→ 0;k24= ∂x'@tD bdd ê.x@tD → 0 ê. θ1@tD→ 0 ê. θ2@tD → 0 ê. x'@tD→ 0 ê. θ1'@tD→ 0 ê.

θ2'@tD → 0 ê. x''@tD→ 0;k25= ∂θ1'@tD bdd ê. x@tD→ 0 ê. θ1@tD → 0 ê.θ2@tD→ 0 ê. x'@tD → 0 ê. θ1'@tD → 0 ê.

θ2'@tD → 0 ê. x''@tD→ 0;k26= ∂θ2'@tD bdd ê. x@tD→ 0 ê. θ1@tD → 0 ê.θ2@tD→ 0 ê. x'@tD → 0 ê. θ1'@tD → 0 ê.

θ2'@tD → 0 ê. x''@tD→ 0;k27= ∂x''@tD bdd ê.x@tD → 0 ê. θ1@tD→ 0 ê. θ2@tD → 0 ê. x'@tD→ 0 ê. θ1'@tD→ 0 ê.

θ2'@tD → 0 ê. x''@tD→ 0;

Simplify@k12DSimplify@k13DSimplify@k17DSimplify@k22DSimplify@k23DSimplify@k27D

m1= 0.05; m2 = 0.13; m3= 0.236; l1 = 0.0775; l2 = 0.25; g = 9.8;

k12k13k17k22k23k27

Page 155: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 146

Because the result of other terms are all 0, we only list 7 terms k12、k13、k17、k22、k23、k27 and the results are as follow:

69.86))342(314())32(21(312

1

=++++

=lmmm

mmmgk

62.21))342(314(2

29131

−=++

−=

lmmmgmk

6.64))342(314(2)34212(317

1

=++−+

=lmmm

mmmk

31.40))342(314(2

))32(21(9222

−=++++−

=lmmm

mmmgk

45.39))342(314())32(31(323

2

=++++

=lmmm

mmmgk

-0.088))342(314(2

)321(3272

=++

−=

lmmmmlmk

Finally, the system state equations are:

ux

x

x

x

⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢

+

⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢

−−

=

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

088.064.61000

00045.3931.40000062.2169.860000000100000010000001000

.

2

.

1

2

1

..

2

..

1

..

.

2

.

1

θ

θ

θθ

θ

θ

θ

θ

&

&

6.2 System Controllability Analysis

System state matrices DCBA ,,, are as follow:

ux

x

xy

⎥⎥⎥

⎢⎢⎢

⎡+

⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

⎡=

⎥⎥⎥

⎢⎢⎢

⎡=

000

000100000010000001

.

2

.

1

2

1

2

1

θ

θ

θθ

θθ

&

Page 156: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 147

⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢

−−

=

00045.3931.40000062.2169.860000000100000010000001000

A

⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢

=

088.064.61000

B

⎥⎥⎥

⎢⎢⎢

⎡=

⎥⎥⎥

⎢⎢⎢

⎡=

000

000100000010000001

D

C

The rank of system state controllability and observability matrices can be solved by MATLAB:

The results are as follow:

clear; A=[ 0 0 0 1 0 0; 0 0 0 0 1 0; 0 0 0 0 0 1; 0 0 0 0 0 0; 0 86.69 -21.62 0 0 0; 0 -40.31 39.45 0 0 0]; B=[ 0 0 0 1 6.64 -0.088]'; C=[ 1 0 0 0 0 0 ; 0 1 0 0 0 0 ; 0 0 1 0 0 0]; D=[ 0 0 0 ]'; cona=[B A*B A^2*B A^3*B A^4*B A^5*B]; cona2=[C*B C*A*B C*A^2*B C*A^3*B C*A^4*B C*A^5*B D]; rank(cona) rank(cona2)

Page 157: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 148

The controllability and observability could also be obtained by commands ctrb and obsv in MATLAB.

Run to get the result:

Therefore, both the system state and output are controllable and the system is

observable.

6.3 2-stage Linear IP MATLAB Simulation

Setup 2-stage linear IP model in MATLAB Simulink:

Figure 6-2 2-stage Linear IP Open Loop Simulation

In which “State-Space” module is the 2-stage linear IP state space equations. Double click to open the module:

ans = 6 ans = 6

Uc=ctrb(A,B); Vo=obsv(A,C); rank(Uc) rank(Vo)

ans = 6 ans = 3

Page 158: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 149

“Controller” module is the controller plant. Right click on block “Controller” and select “Look under mask” to see the model structure:

In which “Matrix Gain K” is the feedback matrix. Double click “Controller” block to set parameters:

Page 159: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 150

First set all parameters be “1”. “Disturbance” block stands for the external disturbance, which is used for adding a step signal to the system. Click “ ” to run the open loop system simulation. The result will be as follow:

Figure 6-3 2-stage Linear IP Open Loop Simulation Result

It can be observed from the result that the system will diverge. Controller should be added to stabilize the system.

6.4 LQR Controller Design and Simulation

Adding LQR controller to the system and the close loop system will be shown as

Page 160: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 151

in the following figure: ( Enter MATLAB Simulink real time control tool box “Googol Education Products”, open “LQR Control Simulink” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 2-Stage IP Experiments”)

Figure 6-4 2-stage Linear IP LQR Control Simulation Next we are going to design controller by linear quadratic optimal control (LQR) method. The principle of LQR method please refer to chapter of 1-stage linear IP “Linear Quadratic LQR Optimal Control Experiment” and other related textbooks. (Enter MATLAB Simulink real time control tool box “Googol Education Products”. Open “LQR Control M Files” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 2-Stage IP Experiments”).

Page 161: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 152

PRO 6-2 2-stage Linear IP LQR Control MATLAB Program

clear all; format long; k12=86.69;k13=-21.62;k17=6.64; k22=-40.31;k23=39.45;k27=-0.088; A=[0 0 0 1 0 0; 0 0 0 0 1 0; 0 0 0 0 0 1; 0 0 0 0 0 0; 0 k12 k13 0 0 0; 0 k22 k23 0 0 0] B=[ 0 0 0 1 k17 k27]'; C=[1 0 0 0 0 0; 0 1 0 0 0 0; 0 0 1 0 0 0]; D=[0; 0; 0]; Q11=1;Q22=1;Q33=1;

Page 162: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 153

Set the LQR parameters as: K=[ 1 73.818 -83.941 2.0162 4.2791 -13.036] The simulation result will be as following:

Q=[Q11 0 0 0 0 0; 0 Q22 0 0 0 0; 0 0 Q33 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0]; R=1; K=lqr(A,B,Q,R) Ac=[(A-B*K)]; Bc=[B]; Cc=[C]; Dc=[D]; Cn=[1 0 0 0 0 0]; s=size(A,1); Z=[zeros([1,s]) 1]; N=inv([A,B;Cn,0])*Z'; Nx=N(1:s); Nu=N(1+s); Nbar=Nu+K*Nx; Bcn=[Nbar*B]; x0=[0 0 0.05 0 0 0]; [Y,X]=lsim(Ac,Bcn,Cc,Dc,U,T,x0); xpos=Y(:,1); xangle=Y(:,2); xangle2=Y(:,3); plot(T,xpos,':') hold on; plot(T,xangle,'--') hold on; plot(T,xangle2,'-')

Page 163: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 154

It can be observed that the system stabilization time is too long. Therefore increase the weighting factor Q. Assume Q11=300;Q22=500;Q33=500; Run and obtain the simulation result: The LQR controller parameters are: K=[ 17.321 110.87 -197.57 18.468 2.7061 -32.142]

Figure 6-5 2-stage Linear IP LQR Control Simulation Result 1

It can be observed from the picture that the system can be well stabilized. After

adding disturbance signal, the system will be back to the equilibrium point within 2.5 seconds.

Input above simulation parameters to Simulink model,

Page 164: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 155

Run and the result will be as follow:

Figure 6-6 2-stage Linear IP LQR Control Simulation Result 2

Adjust the LQR parameters in simulation and observe the result. Select proper control parameters.

6.5 2-stage Linear IP LQR Control Experiment

Real time control is implemented in MATALB Simulink. Users are suggested to read the manual carefully before experiment.

Page 165: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 156

When implementing MATLAB real time control experiment, please

check the mechanical structure and electrical wiring of the IP system to ensure safety.

Experimental steps:

6) Open 2-stage linear IP control diagram as in the following figure:

(Enter MATLAB Simulink real time control tool box “Googol Education Products”, open “LQR Control Demo” in “Inverted Pendulum\Linear Inverted Pendulum\Linear 2-Stage IP Experiments”).

Figure 6-7 2-stage Linear IP LQR Real Time Control Diagram

The left part consists of cart position module and angle processing module for pendulum rod 1 and 2:

Page 166: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 157

The output signals are cart position, cart velocity, pendulum rod 1 angle, pendulum rod 1 angular velocity, pendulum rod 2 angle and pendulum rod 2 angular velocity respectively.

7) “LQR Controller” is the LQR controller block, double click to set parameters:

Figure 6-8 2-sage Linear IP LQR Control Parameters

Input the control parameters to LQR controller. Please pay attention to the correspondency.

8) “Real Control” is the real time control block. The input is control cart acceleration and the output is cart position, pendulum rod 1 angle and pendulum rod 2 angle.

Page 167: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 158

9) After confirming parameters, click “ ” to build.

10) When build successful, click “ ” to connect.

11) Click “ ” to run. When motor is servo on, gradually pull up the pendulum rod to the equilibrium position and release when the program start control. The experiment result will be as follow:

Figure 6-9 2-stage Linear IP LQR Control Result (cart position)

Figure 6-10 2-stage Linear IP LQR Control Result (pendulum rod 1 angle)

Figure 6-11 2-stage Linear IP LQR Control Result (pendulum rod 1 angle)

12) Adding disturbance to the pendulum and the system response will be as follow:

Page 168: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 159

Figure 6-12 2-stage Linear IP LQR Control Result (with disturbance)

13) It can be observed that, without disturbance, the system can be well stabilized. Though there are small oscillations, the cart oscillate scale is about 15mm, pendulum rod 1 oscillate scale is about 0.02 radian and that of pendulum rod 2 is about 0.01 radian.

14) The system can be restabilized in 1 second after adding disturbance. The overshoot is also acceptable.

15) Change the control parameters and simulate again. Run experiment after simulation to observe the different control effect.

6.6 Experiment Result and Report

The report will include the experimental result. The result should be analyzed in the lab report.

6.7 Control Experiment by Other Algorithms

Many control algorithms can be applied to 2-stage IP system such like: fuzzy control, robust control, adaptive control, etc. User could use other controller by

Page 169: IP Experiment Manual V2.00

Chapter 6 2-stage Linear Inverted Pendulum

©Googol 2006 160

simply replacing the “LQR Controller” block in real time control diagram with their own.

Figure 6-13 2-stage Linear IP Controller Replacement

Apply other algorithms by replacing the controller

Page 170: IP Experiment Manual V2.00

Chapter 7 3-stage Linear Inverted Pendulum

©Googol 2006 161

Chapter 7 3-stage Linear Inverted Pendulum

7.1 System Physical Model

For simplicity, we ignore the air resistance and other frictions. Assume the pendulum rod be rigid body. The structure of 3-stage linear IP is shown in the following figure:

Figure 7-1 3-stage Linear IP Physical Model

Pendulum parameters are defined as follow:

M cart mass

1m pendulum rod 1 mass

2m pendulum rod 2 mass

3m pendulum rod 3 mass

4m Joint1 mass

5m Joint2 mass

Pendulum rod 2

Joint1

Pendulum rod 1

x

F

Cart Sliding shaft

Pendulum rod3

Joint2

Page 171: IP Experiment Manual V2.00

Chapter 7 3-stage Linear Inverted Pendulum

©Googol 2006 162

1l distance from rod 1 axis rotation center to rod 1 mass center

2l distance from rod 2 axis rotation center to rod 2 mass center

3l distance from rod 3 axis rotation center to rod 3 mass center

1θ angle between rod 1 and vertically upward direction

2θ angle between rod 2 and vertically upward direction

3θ angle between rod 3 and vertically upward direction

F external force acting on the system Deduce the kinematics equations by Lagrangian equation: The Lagrangian equation is:

),(),(),(...qqVqqTqqL −=

In which L is the Lagrangian operator, q is the system generalized coordinate. T is the system kinetic energy and V denotes the potential energy.

ii

i

fqL

q

Ldtd

=∂∂

−∂

∂.

In which i=1,2,3……n, if is the external force acting on the ith generalized

coordinate. In 3-stage IP system, there are 4 generalized coordinates: 321 ,,, θθθx .

The system kinetic energy is:

54321 mmmmmM TTTTTTT +++++=

In which 54321 ,,,,, mmmmmM TTTTTT are kinetic energy of cart, pendulum rod 1,

pendulum rod 2, pendulum rod 3, Joint1 and Joint2. The cart kinetic energy:

2.

21 xMTM =

''1

'11 mmm TTT += In which ''

1'

1 , mm TT denote the translational and rotational kinetic

energy of the pendulum rod 1 respectively. ''

2'

22 mmm TTT += In which ''2

'2 , mm TT denote the translational and rotational kinetic

energy of the pendulum rod 2 respectively. ''

3'

33 mmm TTT += In which ''3

'3 , mm TT denote the translational and rotational kinetic

Page 172: IP Experiment Manual V2.00

Chapter 7 3-stage Linear Inverted Pendulum

©Googol 2006 163

energy of the pendulum rod 3 respectively. For system, assume: xpend1: x axis coordinate of rod 1 mass center; ypend1: y axis coordinate of rod 1 mass center; xpend2: x axis coordinate of rod 2 mass center; ypend2: y axis coordinate of rod 2 mass center; xpend3: x axis coordinate of rod 3 mass center; ypend3: y axis coordinate of rod 3 mass center; xmass1: x axis coordinate of Joint1 mass center; ymass1: y axis coordinate of Joint1 mass center; xmass2: x axis coordinate of Joint2 mass center; ymass2: y axis coordinate of Joint2 mass center; There are:

⎩⎨⎧

+=−=

⎩⎨⎧

+=−=

⎩⎨⎧

+=−=

⎩⎨⎧

=−=

⎩⎨⎧

=−=

33

33

22

22

22

22

11

11

11

11

2323

212212

1212

2121

11

θθ

θθ

θθ

θθ

θθ

CoslymassypendSinlxmassxpend

CoslymassymassSinlxmassxmass

CoslymassypendSinlxmassxpend

CoslymassSinlxxmass

CoslypendSinlxxpend

Then:

⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛=

22

1'

1)1()1(

21

dtypendd

dtxpenddmTm

2.

12

11

2.

11''

1 61

21 θθ lmJT pm ==

The same are:

⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛=

22

2'

2)2()2(

21

dtypendd

dtxpenddmTm

2.

22

22

2.

22''

2 61

21 θθ lmJT pm ==

⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛=

22

3'

3)3()3(

21

dtypendd

dtxpenddmTm

Page 173: IP Experiment Manual V2.00

Chapter 7 3-stage Linear Inverted Pendulum

©Googol 2006 164

2.

32

33

2.

33''

3 61

21 θθ lmJT pm ==

⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛=

22

44)1()1(

21

dtymassd

dtxmassdmTm

⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛=

22

55)2()2(

21

dtymassd

dtxmassdmTm

The system overall kinetic energy is:

⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛+

⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛+

+⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛+

+⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛+

+⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+⎟

⎠⎞

⎜⎝⎛+=

+++++=

22

5

22

4

2.

32

33

22

3

2.

22

22

22

2

2.

12

11

22

1

2.

54321

)2()2(21

)1()1(21

61)3()3(

21

61)2()2(

21

61)1()1(

21

21

dtymassd

dtxmassdm

dtymassd

dtxmassdm

lmdt

ypendddt

xpenddm

lmdt

ypendddt

xpenddm

lmdt

ypendddt

xpenddmxM

TTTTTTT mmmmmM

θ

θ

θ

System potential energy is:

21321 5432154321 ymassmymassmypendmypendmypendmVVVVVV mmmmm ++++=++++=

The system has no external force under 321 ,, θθθ generalized coordinate, so there

are:

⎪⎪⎪⎪

⎪⎪⎪⎪

=∂∂

−∂

=∂∂

−∂

=∂∂

−∂

0

0

0

3.

3

2.

2

1.

1

θθ

θθ

θθ

LLdtd

LLdtd

LLdtd

For 3-stage IP system, system variables are selected as:

⎭⎬⎫

⎩⎨⎧ .

3

.

2

.

1

.

321 ,,,,,,, θθθθθθ xx

To solve the state equations:

Page 174: IP Experiment Manual V2.00

Chapter 7 3-stage Linear Inverted Pendulum

©Googol 2006 165

⎪⎩

⎪⎨⎧

=+=

CXYBuAXX

.

..

3

..

2

..

1 and , θθθ should be solved first, therefore assume:

⎪⎪

⎪⎪

=

=

=

),,,,,,,,(

),,,,,,,,(

),,,,,,,,(

...

3

.

2

.

1

.

3213

..

3

...

3

.

2

.

1

.

3212

..

2

...

3

.

2

.

1

.

3211

..

1

xxxf

xxxf

xxxf

θθθθθθθ

θθθθθθθ

θθθθθθθ

Taking Taylor expansion around the equilibrium point and linearize, the variables will have the following form:

⎪⎪

⎪⎪

++++++++=

++++++++=

++++++++=

..

39

.

338

.

237

.

136

.

3533423313231

..

3

..

29

.

328

.

227

.

126

.

2532422312221

..

2

..

19

.

318

.

217

.

116

.

1531421311211

..

1

xkkkkxkkkkxk

xkkkkxkkkkxk

xkkkkxkkkkxk

θθθθθθθ

θθθθθθθ

θθθθθθθ

In which ijk is the partial derivative of if to its j th variable, for example:

00,,0,0,0,0,0,0,0

111 ...

3

.

2

.

1

.

321

|=========∂

∂=

xxxxf

kθθθθθθ

Do above calculation in Mathematica:

Page 175: IP Experiment Manual V2.00

Chapter 7 3-stage Linear Inverted Pendulum

©Googol 2006 166

PRO 7-1 3-stage Linear IP Modeling Mathematica Program

Page 176: IP Experiment Manual V2.00

Chapter 7 3-stage Linear Inverted Pendulum

©Googol 2006 167

Page 177: IP Experiment Manual V2.00

Chapter 7 3-stage Linear Inverted Pendulum

©Googol 2006 168

Page 178: IP Experiment Manual V2.00

Chapter 7 3-stage Linear Inverted Pendulum

©Googol 2006 169

Page 179: IP Experiment Manual V2.00

Chapter 7 3-stage Linear Inverted Pendulum

©Googol 2006 170

(The program file please refer to “L3DIP.nb” in “\GLIP2003\ModelFiles\MathematicaFile” )

Run the program and the following result will be obtained:

Page 180: IP Experiment Manual V2.00

Chapter 7 3-stage Linear Inverted Pendulum

©Googol 2006 171

00318211.03485.39

9245.1657086.2

15831.0189.17

9951.579.127

64904.6784646.0

4356.38504.159

39

34

33

32

29

24

23

22

19

14

13

12

==

−==

−=−=

=−=

==

−==

kkkkkkkkkkkk

The system state equations are as follow:

ux

x

x

x

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

+

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

−−−

=

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

⋅00318211.0

15831.064904.6

10000

00003485.399245.1657086.200000189.179951.579.12700000784646.04356.38504.15900000000010000000010000000010000000010000

.

3

2

.

1

3

2

1

..

3

..

2

..

1

..

.

3

.

2

.

1

θ

θ

θ

θθθ

θ

θ

θ

θ

θ

θ

&

&

ux

x

x

y

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

+

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥

⎢⎢⎢⎢

=

0000

00001000000001000000001000000001

.

3

2

.

1

3

2

1

3

2

1

θ

θ

θ

θθθ

θθθ

&

Note: The real system model might be different with this one. This model is not verified by experiment yet. User may check its validity when using the system.

Page 181: IP Experiment Manual V2.00

Appendix

©Googol 2006 172

Chapter 8 Appendix

8.1 List of Figures

Figure 1-1 Linear IP Series ....................................................................................2 Figure 1-2 Circular IP Series .................................................................................2 Figure 1-3 Planar IP Series ....................................................................................3 Figure 1-4 Configurable IP ....................................................................................3 Figure 2-1 Photoelectric Encoder Component and Structure ................................6 Figure 2-2 MATLAB Simulink Environment........................................................8 Figure 3-11-stage Linear Inverted Pendulum Model ...........................................26 Figure 3-2 Cart and Rod Force Analysis..............................................................26 Figure 3-3 1-stage Linear Inverted Pendulum Step Response Simulation ..........37 Figure 3-41-stage Linear IP Close Loop Diagram(with disturbance) ............38 Figure 3-5 1-stage Linear IP Simplified Close Loop Diagram(with disturbance)

......................................................................................................................38 Figure 3-6 1-stage Linear IP Open Loop Root Locus..........................................40 Figure 3-7 Performance Index and Root Locus...................................................41 Figure 3-8 1-stage Linear IP Root Locus Calculation .........................................42 Figure 3-9 Root Locus after Compensation.........................................................44 Figure 3-10 Step Response after Compensation..................................................45 Figure 3-11 Root Locus after Adding Zero..........................................................45 Figure 3-12 Root Locus after Adding Pole ..........................................................46 Figure 3-13 Close Loop System Step Response ..................................................46 Figure 3-14 1-stage Linear IP Root Locus Method Simulation Result (First Order

Controller)....................................................................................................52 Figure 3-15 1-stage Linear IP Root Locus Simulation Model.............................53 Figure 3-16 1-stage Linear IP Root Locus Control Simulation Result(Second

Order Controller).......................................................................................54 Figure 3-17 1-stage Linear IP Root Locus Real Control Block...........................55 Figure 3-18 1-stage Linear IP Root Locus Control Result(equilibrium)........56 Figure 3-191-stage Linear IP Root Locus Control Result(with disturbance) ...56 Figure 3-20 1-stage Linear IP Bode Plot .............................................................60 Figure 3-21 1-stage Linear IP Nyquist Plot .........................................................61 Figure 3-22 1-stage Linear IP Bode Plot and Nyquist Plot after Adding Control

Gain..............................................................................................................63 Figure 3-23 1-stage Linear IP Bode Plot and Nyquist Plot after Control(First

Order Controller).......................................................................................66 Figure 3-24 Step Response after Frequency Response Control(First Order

Controller) .................................................................................................66 Figure 3-25 1-stage Linear IP Frequency Response Control Simulation ............67

Page 182: IP Experiment Manual V2.00

Appendix

©Googol 2006 173

Figure 3-26 Bode and Nyquist Plot after Frequency Response Control(Second Order) ........................................................................................................69

Figure 3-27 Step Response after Frequency Response Control Simulation(Second Order) .......................................................................................70

Figure 3-28 1-stage Linear IP Frequency Response Real Time Control Diagram......................................................................................................................71

Figure 3-29 Frequency Response Real Time Control Result(First Order Controller) .................................................................................................72

Figure 3-30 Frequency Response Real Time Control Result(Second Order Controller) .................................................................................................73

Figure 3-31 1-stage Linear IP Close Loop System Diagram...............................74 Figure 3-32 1-stage Linear IP Close Loop System Simplified Diagram .............74 Figure 3-33 1-stage Linear IP PID Control MATLAB Simulation Model ..........76 Figure 3-34 PID Set Parameter Window .............................................................76 Figure 3-35 1-stage Linear IP P Control Simulation Result(Kp=9) .............76 Figure 3-36 1-stage Linear IP Proportional Control Simulation Result Kp=40)

......................................................................................................................77 Figure 3-37 1-stage Linear IP PD Control Simulation Result(Kp=40,Kd=4)

......................................................................................................................77 Figure 3-38 1-stage Linear IP PD Control Simulation Result(Kp=40,Kd=10)

......................................................................................................................78 Figure 3-39 1-stage Linear IP PID Control Simulation Result(Kp=40,Ki=20,

Kd=4).......................................................................................................78 Figure 3-40 1-stage Linear IP PD Control Simulation Result(cart position curve)

......................................................................................................................78 Figure 3-41 1-stage Linear IP PID Control MATLAB Simulation Result(impulse

disturbance) ...............................................................................................79 Figure 3-42 1-stage Linear IP MATLAB Real Time Control Diagram ...............80 Figure 3-43 1-stage Linear IP PID Control Experiment Result 1........................81 Figure 3-44 1-stage Linear IP PID Control Experiment Result 2 ( with

disturbance) ...............................................................................................82 Figure 3-45 1-stage Linear IP PID Control Experiment Result 3(change PID

parameters) ................................................................................................83 Figure 3-46 State Feedback Close Loop Control Diagram..................................84 Figure 3-47 Inverted Pendulum Pole Placement Principle Diagram...................87 Figure 3-48 Pole Placement Simulation Result ...................................................89 Figure 3-49 1-stage Linear IP State Space Pole Placement MATLAB Simulink

Simulation ....................................................................................................95 Figure 3-50 1-stage Linear IP State Space Pole Placement MATLAB Simulation

Result ...........................................................................................................97 Figure 3-51 1-stage Linear IP State Space Pole Placement Real Control Diagram

......................................................................................................................98 Figure 3-52 1-stage Linear IP State Space Pole Placement Real Control Result

(equilibrium) ................................................................................................99

Page 183: IP Experiment Manual V2.00

Appendix

©Googol 2006 174

Figure 3-53 1-stage Linear IP State Space Pole Placement Real Control Result(in disturbance)..................................................................................................99

Figure 3-54 Optimal LQR Control Diagram .....................................................101 Figure 3-55 1-stage Linear IP LQR Control Simulation Model ........................104 Figure 3-56 1-stage Linear IP LQR Control Simulation Result 1 .....................105 Figure 3-57 1-stage Linear IP LQR Control Simulation Result 2 .....................105 Figure 3-58 1-stage Linear IP LQR Real Time Control Diagram......................106 Figure 3-59 1-stage Linear IP LQR Real Time Control Experiment Result......108 Figure 4-1 1-stage Linear Pendulum Physical Model........................................110 Figure 4-2 1-stage Linear Pendulum Root Locus Plot.......................................117 Figure 4-3 1-stage Linear Pendulum Bode Plot.................................................118 Figure 4-4 1-stage Linear Pendulum Nyquist Plot ............................................118 Figure 4-5 1-stage Linear Pendulum Step Response Result ..............................119 Figure 4-6 1-stage Linear Pendulum PID Control Simulation ..........................120 Figure 4-7 1-stage Linear Pendulum P Control Result ......................................121 Figure 4-8 1-stage Linear Pendulum PD Control Result ...................................122 Figure 4-9 1-stage Linear Pendulum PID Controller.........................................122 Figure 4-10 1-stage Linear Pendulum PID Control Result................................123 Figure 4-11 1-stage Linear Pendulum PID Real Time Control Diagram ..........124 Figure 4-12 1-stage Linear Pendulum PID Real Time Control Result ..............125 Figure 4-13 1-stage Linear Pendulum Simulation Result (with disturbance)....128 Figure 4-14 1-stage Linear Pendulum Simulink Diagram.................................128 Figure 4-15 1-stage Linear Pendulum LQR Control Simulation Result............130 Figure 4-16 1-stage Linear Pendulum LQR Real Time Control Diagram.........131 Figure 4-17 1-stage Linear Pendulum LQR Control Result ..............................133 Figure 5-1 1-stage Linear IP Swing Up Real Time Control Diagram ...............135 Figure 5-2 1-stage Linear IP Swing Up Control Result (cart position) .............137 Figure 5-3 1-stage Linear IP Swing Up Control Result (pendulum rod angle) .137 Figure 5-4 Apply user define controller(SISO) ............................................138 Figure 5-5 Apply user define controller(MIMO) .........................................138 Figure 5-6 Apply user define swing up controller .............................................139 Figure 6-1 2-stage Linear IP Physical Model ....................................................140 Figure 6-2 2-stage Linear IP Open Loop Simulation.........................................148 Figure 6-3 2-stage Linear IP Open Loop Simulation Result .............................150 Figure 6-4 2-stage Linear IP LQR Control Simulation......................................151 Figure 6-5 2-stage Linear IP LQR Control Simulation Result 1 .......................154 Figure 6-6 2-stage Linear IP LQR Control Simulation Result 2 .......................155 Figure 6-7 2-stage Linear IP LQR Real Time Control Diagram........................156 Figure 6-8 2-sage Linear IP LQR Control Parameters ......................................157 Figure 6-9 2-stage Linear IP LQR Control Result (cart position) .....................158 Figure 6-10 2-stage Linear IP LQR Control Result (pendulum rod 1 angle) ....158 Figure 6-11 2-stage Linear IP LQR Control Result (pendulum rod 1 angle) ....158 Figure 6-12 2-stage Linear IP LQR Control Result (with disturbance).............159 Figure 6-13 2-stage Linear IP Controller Replacement .....................................160

Page 184: IP Experiment Manual V2.00

Appendix

©Googol 2006 175

Figure 7-1 3-stage Linear IP Physical Model ....................................................161

Table 1-1 Warning Signs....................................................................................... II Table 1-1 Inverted Pendulum Experiments............................................................4 Table 3-1 Linear IP Root Locus Realtime Control Experiment Report...............58

8.2 List of Program

PRO 3-1 1-stage Linear Inverted Pendulum Modeling Program.........................32 PRO 3-2 1-stage Linear IP Root Locus Calculation Mathematics Program........43 PRO 3-3 1-stage Linear IP Root Locus Calculation MATLAB Program............44 PRO 3-4 1-stage Linear IP Root Locus Control MATLAB Program..................47 PRO 3-5 1-stage Linear IP Frequency Response Control MATLAB Program ...65 PRO 3-6 1-stage Linear IP PID Control MATLAB Simulation ..........................79 PRO 3-7 1-stage Linear IP State Space Pole Placement MATLAB Program 189 PRO 3-8 1-stage Linear IP State Space Pole Placement MATLAB

Program 2 ...................................................................................................92 PRO 3-9 1-stage Linear IP Pole Placement MATLAB Program 3(Ackermann

formula) .....................................................................................................94 PRO 3-10 1-stage Linear IP Pole Placement MATLAB Program 4(Ackermann

formula) .....................................................................................................95 PRO 3-11 1-stage Linear IP LQR Control MATLAB Program.........................103 PRO 4-1 1-stage Linear Pendulum Modeling Program.....................................113 PRO 4-2 1-stage Linear Pendulum LQR Control MATLAB Program..............127 PRO 6-1 2-stage Linear IP Modeling Mathematica Program............................144 PRO 6-2 2-stage Linear IP LQR Control MATLAB Program...........................152 PRO 7-1 3-stage Linear IP Modeling Mathematica Program............................166