﻿ Inverted pendulum and state space representation

The free essay below has been submitted to us by a student. The essay is the student's work and is not an example of our expert essay writers' work.

Get an Instant Quote

# INVERTED PENDULUM AND STATE SPACE REPRESENTATION

### 1. LITERATURE REVIEW

The project is based on control tutorials for Matlab developed by members at the University of Michigan (UMICH) and Carnegie Mellon University (CMU). They are good sources which are designed to help us how to use Matlab for the analysis and design of automatic control systems. The material taught at the University of the West of England (UWE) by professor Zhu, Q. is a background for this research. This project is also covered by Modern control engineering book written by Ogata, K. (2002) and combined by other useful websites to provide a good survey.

Chapter 1 presents a brief introduction and an outline of the project. An inverted pendulum is described in detail from introduction to its importance in control system design field. This report also gives the math background for an inverted pendulum with main contents which are fixed pivot point, pendulum mounted on a cart and pendulum with oscillatory base (Wikipedia, 2008). This chapter also briefly introduce the state space representation of single-input and single-output (SISO) systems and multi-input and multi-output (MIMO) systems which are based on the lectures which taught by professor Zhu, Q. (2008-2009) in UWE.

Chapter 2 covers setup and analysis in dynamic model based on UMICH and CMU websites (1997). The design requirements of inverted pendulum system in this project are similar with the other inverted pendulum models, but different parameters. After analysing the model, the Simulink is used to build the dynamic model to test the responses. This section is also based on UMICH and CMU websites (1997) and a knowledge background based on the lectures of professor Zhu, Q. (2008-2009) to use Matlab program.

Chapter 3 gives initially design of inverted pendulum control by state space method. The state space representation this project is covered by Modern control engineering book written by Ogata, K. (2002). Then, a full order state feedback control is designed to balance the inverted pendulum. This section has included by the materials based on UMICH and CMU websites (1997-1998), Ogata, K. (2002) and the lectures taught by professor Zhu, Q. (2008-2009).

Chapter 4 proposes for the work in level-M. Adaptive nonlinear control scheme will be upgraded to stabilise the inverted pendulum. A novel control design technique called backstepping control will be used to make inverted pendulum rod upwards (Altinoz, O.T., 2007). This part is also covered by Adaptive control book which is written by Astrom, K.J. and Wittenmark, B. (1995).

Good sources are an essential basis to support this project. The project is also supported by other sources which are given detail in references. This project uses the similar way with other projects about inverted pendulum and combines with my own knowledge about control systems design to perform.

### 2.1 INTRODUCTION

The inverted pendulum has been researched by many authors in control system design field with various ways which are good references. In this project the inverted pendulum is setup and analysed with similar design requirements, but with different parameters. For PID, root locus, and frequency response method cannot be applied in the control of inverted pendulum. This is because these techniques can only be applied for single-input and single-output (SISO) systems, but the inverted pendulum is a multi-input and multi-output (MIMO) system. Thus, a design of control systems in state space is decided to use in this research. The aims of the project are to do a survey from introduction to application for the inverted pendulum system, and the state space representation of the SISO systems and the MISO systems are also briefly introduced. Then setup and analyse the inverted pendulum system in model, and also give detail the requirements need to be satisfied for the system. After that, the model is built by using Simulink (Block diagrams) on Matlab program to test and analyse the response. Finally, design of a full order state feedback controller is performed on calculation and on Matlab program to implement the design by running the simulation tests and the analysis on the results. This report also outlines the future work for the M-level in next year.

### 2.2 WHAT IS INVERTED PENDULUM?

An inverted pendulum is a physical device which has a pendulum (or a bar) with its mass above a pivot point. The pivot point is mounted on a cart (or a carriage) that can move on a horizontal direction. Because of the combination of the pivot point and a cart in a system, an inverted pendulum may be also called a cart and pole. An inverted pendulum is different from a pendulum at stability. While a pendulum is always stable at bottom vertical position, an inverted pendulum naturally tends to fall down from the top vertical position, which is an unstable position. To balance an inverted pendulum or to stabilize a pendulum on the top vertical, one of two methods can be used by applying a torque at the pivot point or by moving the pivot point on a horizontal direction as a part of a feedback system.

There is another method to balance for the inverted pendulum by oscillating the support rapidly up and down. This way is performed without requiring any feedback or control mechanism. In terms of acceleration and amplitude, if the oscillation is strong enough then the inverted pendulum can stabilise from the bottom vertical to the top vertical. However, if the point moves harmonically, the motion equation of the pendulum will perform following the Mathieu equation.

### 2.3 IMPORTANCE IN APPLICATION

The inverted pendulum has been used in the most applications of dynamics and control theory. For testing control algorithms, it is applied very popular such as PID controllers, neural networks, fuzzy control, genetic algorithms, etc. In these applications, the inverted pendulum controller is running by allowing the motion of the cart to be controlled while keeping the pendulum upright, and balancing the cart-pendulum system on a see-saw.

This inverted pendulum is used in rocket and missile with role of balance or keeping direction, where it is a thrust at the bottom of a tall vehicle. For the similar problem, the inverted pendulum is applied to Segway which is the first two-wheeled, self-balancing, electric transportation device to help you move easily, efficiently, intelligently, and simply. The largest performance of the inverted pendulum application is on big lifting cranes on shipyards. With characteristic of the inverted pendulum, the cranes can move perfectly and stop quickly the huge shipping containers without swings and sways under the control of operator.

### From vertical unstable equilibrium position, the equation of motion for an inverted pendulum is

Put (3) into the above equations of motion, then obtain the equations of motion of the inverted pendulum

Both of equations are nonlinear, however, to balance the inverted pendulum or to keep the pendulum upright, these equations can be linear with

### 2.5 INTRODUCTION TO STATE SPACE REPRESENTATION

A state space representation is a mathematical model of a physical system in control engineering. It is a set of inputs, outputs and state variables which are related by the first order differential equations. In the state space representation, the variables which are inputs, outputs and states are expressed as vectors, the differential and algebraic equations are written in matrix form. It is known as the time domain approach and is the good way to model and analyse the multi-input and multi-output systems. With m inputs and n outputs, the information of a system can be encoded by m × n Laplace transforms. The state space representation can be applied without limit to systems with linear components and zero initial conditionals. In the phrase "state space", it means the space whose axes are state variables and the state can be represented as a vector within the space.

A general state space representation of a linear time invariant system with m inputs, l outputs, and n state variables can be expressed as

### 2.5.2 MULTI-INPUT AND MUTI-OUTPUT (MIMO) SYSTEMS

MIMO systems can be expanded easily from the SISO systems with state space equations. Change the input u(t) into a vector U(t) to represent multiple inputs, and also change the output y(t) into a vector Y(t) to represent multiple outputs. With the state space method of MIMO systems the outputs must be linearly dependant on the input vector and the state vector.

Assume that the system has two inputs, u1and u2, and two outputs, y1 and y2. In this system these inputs and outputs are related through the differential equations

Assign state variables and produce the first-order differential equations

x1 = y1

x4 = y2

x1' = y1' = x2

x2' = − a1x2 − a0(x1 + x4) + u1(t)

x4' = − a2(x4 − x1) + u2(t)

Then assemble the state equations of the MIMO system

The state space representation of MIMO systems is not unique. There are infinitely many ways of representation for MIMO systems.

### 3.1 SETUP AND DESIGN REQUIREMENTS

From figure 9 the cart is affected by an impulse force F. In the design assume that the inverted pendulum keeps balancing or it doesn't move more than a few degrees away from the upright position. So, the dynamic equations of motion for the inverted pendulum system need to be determined, and the angle between the pendulum and the vertical is about 0 (

### 3.2 ANALYSIS OF A SYSTEM MODEL

The system is shown in figure 2 at appendix A, the pin joint between the cart and pendulum which reduces freedom. This is the problem for modeling the system in Simulink. Both of cart and pendulum have one degree of freedom which respectively are the X and the

To include the interaction forces N and P between the cart and the pendulum, the additional x and y dynamics of the pendulum are required to model.

Then represent the derivatives of

These equations then will be expressed for N and P.

Before model the system in Simulink, firstly need to summarise the main force equations in the previous section.

Insert two Integrator blocks from the commonly used blocks, and connect them in series.

Draw a line from the second Integrator block, and label it "x" by double clicking where you want to go.

Put the label "dx/dt" for the line between the two integrators, and draw a line leading the first integrator with the label "d^2(x)/dt^2" (It means d2x/dt2).

Insert a Gain block from the commonly used blocks to the left of the two integrator blocks, and connect it to the d2x/dt2 line. Then edit the value of the gain by double clicking on this block, change it to "1/M", and label it "Cart Mass".

Insert a Sum block from the Math operations (sum of elements) to the left of the cart mass with the label "Sum forces on cart", change its signs to "-+-". Connect this block to the cart mass.

Insert a Gain block above the cart mass with the value "b", the label "Damping" and flip this block left to right by right clicking Format-Flip Block or Ctr+I, and connect its input to the "dx/dt" line, its output to the top negative sign of the sum forces on cart input.

The model of the equation (1) is given in figure 10:

### Equation (2):

Construct the second equation with the similar way as the previous equation, and change the label "x" into "theta". The Gain block should have the value "1/I" and the label "Sum Inertia". The Sum block should have the label "Sum Torques on Pendulum" and its signs "++".

Insert two Trigonometric function blocks from the Math operations and put them above the second theta integrator.

Edit an upper Math block with the value "cos" and the label "Vertical".

Keep the value "sin" for a lower Math block and label it "Horizontal".

Flip both of them left to right.

Connect the output of the second theta Integrator block to the inputs of the Sin block and the Cos block by drawing the lines between these blocks.

Insert a Gain block to the left of the Cos block, and then edit the value to "L" with the label "Pendulum length".

Flip this block left to right and connect its input to the output of the Cos block.

By the same way, insert a Gain to the left of the Sin block. Edit the value to "L" with the label "Pendulum length 1". Then flip it left to right and connect its input to the output of the Sin block.

Draw long horizontal lines leading from the outputs of both of Pendulum length blocks. Put the label "Lcos(theta)" for the upper line and "Lsin(theta)" for the lower line.

Insert two Product blocks from the Math operations next to each other to the left and above the Sum Torques block. They are used to multiply for the forces N and P by their components.

Rotate these Product blocks 90 degrees by right clicking them and select Format, then select Rotate Block or Ctr+R.

Connect the left Product block to the lower input of the Sum Torques block and also connect the right Product block to the upper input of the Sum Torques block.

Connect the Lsin(theta) line to the right input of the right Product block.

Connect the Lcos(theta) line to the right input of the left Product block.

The model of the equation (2) is given in figure 11.

### Equation (3) and (4):

Insert a Gain block to the under Sum forces on Cart block and edit its value to "m" and its label to "Pendulum mass". Flip this block left to right and connect its output to the N line. Then draw a short line leading from the input of this Gain block and label it "d^2(xp)/dt^2".

Copy the pendulum mass block and put under that block with a new label "Pendulum mass 1". Connect its input to the line P.

Insert a Sum block to the right of the pendulum mass 1 block with its signs "++". Flip this block left to right and connect its output to the input of the pendulum mass 1 block.

Draw a short line leading from the input of the Sum 2 block and label it "d^2(yp)/dt^2".

Insert a Constant block from commonly used blocks to the right of the new Sum block. Then change its value to "g" and its label to "Gravity". Connect its output to the Sum 2, and then obtain the model in figure 12.

### Equation (5):

Insert a Sum block to the right of the pendulum mass block, and change its signs into "++-". Connect the upper plus sign input of this Sum block to the line d^2(x)/dt^2.

Also insert two Product blocks, one to the right of the Gravity block, then flip this block left to right and rotate it 90 degrees. Connect the output of this block to the minus sign input of the Sum 1 block. Connect one input of this Product block to the line Lcos(theta) and another input is connected to the line d^2(theta)/dt^2.

Another Product block is inserted to the above Cos block. Flip this block left to right and rotate it 90 degrees. Then connect its output to the middle plus sign input of the Sum 1 block. One input of this block is connected to the line Lsin(theta). After that, insert another Product block to the above line d(theta)/dt with two inputs of this Product block are connected to that line. This Product block is a model of (d(theta)/dt)^2 and connect its input to one input of the Product 2 block. Figure 13 shows the model after inserting equation 5.

### Equation (6):

Similar to the equation (5), insert a Sum block with its signs "--". Connect the output of this block to the upper plus sign input of the Sum 2 block. Also insert a Product block with one input connected to the output of the Product block which is to model for (d(theta)/dt)^2, another input connected to the line Lcos(theta). Then the output of this Product block is connected to one input of the new Sum block.

Insert a Product block with one input connected to the line Lsin(theta), and one input connected to the line (d^2(theta)/dt^2). Connect the output of this block to the input of the Sum block as figure 14.

Now, apply a unit impulse force input F and view the pendulum angle and cart position.

Insert a Pulse Generator block from the sources in Simulink library browser and connect it to the force F.

Insert two Scopes from the commonly used blocks in Simulink library browser. One scope is connected to the theta output, and another one is connected to the x output. Then, figure 15 is obtained:

### 4.1 STATE SPACE REPRESENTATION

Base on figure 2 at appendix A, perform some calculation to obtain the equations of state space representation for the inverted pendulum system:

Summing the forces in the free body diagram of the cart in the horizontal direction:

Then, obtain two equations of motion:

After linearization the two equations of motion become:

(9)

Substitute (9) in (8),

From the definition of the state variables and equations (10) and (12),

Substitute M=1, m=0.25, b=0.1, I=0.006, g=9.8, L=0.25 in the above state space equations, obtains the equations

Use Matlab to check the results of state space representation. This section is shown at program No.1 in appendix B. The results on a command window are the same on calculation.

### 4.2 DESIGN OF A FULL ORDER STATE FEEDBACK

After obtaining the state space equations, to design a full order state feedback the following design steps need to do:

Design step 1: Check for controllability and observability of the system. They play an important role in the design of control systems in state space to make sure that the system is completely controllable and observable to use the following steps for finding a state feedback matrix and a state observer matrix.

Design step 2: Design a state feedback controller to estimate the state variables for feedback. Find the state feedback matrix by the quadratic optimal control method. An advantage of this method over the pole placement method is that the former provides a systematic way of computing the state feedback control gain matrix. Moreover, the inverted pendulum system is a MIMO system which is not easy to choose a desired closed loop poles for the state feedback if using the pole placement method. The schematic of this control system is shown in figure 19.

Design step 3: Adding the reference input to eliminate a steady state error. In the step 2, by multiplying the gain vector K, and then subtract this result from the reference. This uses to measure all states. To remove this error, need to scale the reference input to make it equal to K*x steady state. In this project, the reference input is one of four values in the matrix K. The scheme of the control system after adding a reference is shown in figure 20.

Design step 4: Design a state observer controller to estimate unavailable state variables for feedback. Find a state observer matrix by using the desired closed loop observer poles which are faster 10 times than the desired closed loop poles state feedback poles. In this step, use Matlab program to get the desired closed loop state feedback poles from the state feedback matrix K. Then, the desired closed loop observer poles are 10 times the desired closed loop state feedback poles. The schematic of the control system now is shown in figure 21.

Next, perform 4 design steps which have just presented above. Most of these steps need to use Matlab to compute. Because there are matrixes (4×4), they are quite difficult to manipulate.

### Controllability

A criterion to check the state controllability:

### Observability

A criterion to check the observability:

### Add to the last M-file these commands:

co=ctrb(A,B)%Compute the controllability matrix.

Controllability = rank (co)%provides an estimate of the number of linearly

%independent rows or columns of a matrix co.

ob = obsv (A,C)%Compute the observability matrix.

Observability = rank (ob)% provides an estimate of the number of linearly

%independent rows or columns of a matrix ob.

### On the command window, the results are:

co =

0 2.7027 -0.2527 89.5050

2.7027 -0.2527 89.5050 -9.5791

0 0.9351 -0.0874 4.4822

0.9351 -0.0874 4.4822 -0.8375

Controllability =

4

ob =

1.0000 0 0 0

0 0 1.0000 0

0 1.0000 0 0

0 0 0 1.0000

33.1081 0 0 -0.2703

1.6554 0 0 -0.0935

-0.4474 33.1081 0 0.0253

-0.1548 1.6554 0 0.0087

Observability =

4

Hence, the system is completely state controllable and observable.

### DESIGN STEP 2:

Using the reduced-matrix Riccati equation to find P:

Where Q is a positive-definite or a real symmetric matrix:

In Q matrix, the element in the 1,1 position will be used to weight the pendulum's angle and the element in the 3,3 position will be used to weight the cart's position.

R is a positive-definite or real symmetric matrix: R= [1]

The optimal feedback gain matrix K is obtained as

With the state feedback control, the state equation now is:

Hence,

### Add these commands to the M-file and run it:

x=1;

y=1;

Q=[x 0 0 0;

0 0 0 0;

0 0 y 0;

0 0 0 0];

R = 1;

K = lqr(A,B,Q,R)%Compute optimal state feedback gain matrix.

Ac = [(A-B*K)];%New value of matrix A in state feedback controller

Bc = [B];

Cc = [C];

Dc = [D];

T=0:0.01:5;

U=0.2*ones(size(T)); %Apply step input 0.2 to the cart.

[Y,X]=lsim(Ac,Bc,Cc,Dc,U,T); % plots the time response of the system to the

% input signal described by U and T

plot(T,Y)

legend('Pendulum','Cart')

### The results of K and a response plot in figure 22 on the command window are:

K =

30.5845 5.4007 -1.0000 -2.0369

### DESIGN STEP 3:

From the design step 3,

Put each value of K into Bcn=kdesired*B in the M-file, and then run it to get the chosen k for the reference input. After testing 4 times, the reference input should be KI= kdesired =-70.7107.

### Add these commands to the M-file:

Bcn=[-70.7107*B];

[Y,X]=lsim(Ac,Bcn,Cc,Dc,U,T);

### Then obtain the new response of the system in figure 24:

Thus,

A matrix A becomes

### Add these texts to the M-file:

P =eig(Ac);%To get the desired closed loop poles of the state feedback.

Pe=10*P; % To obtain the desired closed loop poles of the state observer.

Ke = place(A',C',Pe)'%To find a state observer matrix.

Ace = [A-B*K B*K;

zeros(size(A)) (A-Ke*C)];%zero(size(A))is the same size as A and all %zeros.

Bce = [Bcn;zeros(size(B))];

Cce = [Cc zeros(size(Cc))];

Dce = [0;0];

T = 0:0.01:5;

U = 0.2*ones(size(T));

[Y,X] = lsim(Ace,Bce,Cce,Dce,U,T);

plot(T,Y)

legend('Pendulum','Cart')

### 5. CHAPTER 4: PROPOSALS FOR THE WORK IN LEVEL-M

Next year a nonlinear design technique called backstepping that will be upgraded for designing the inverted pendulum. The key idea of backstepping is to derive an error equation and to construct a control law and a parameter adjustment law such that the state of the error equation goes to zero. The adaptive backstepping controller for inverted pendulum will be designed by using the general motion control model. Based on Lyapunov design approach backstepping is a novel nonlinear control technique, used when higher derivatives of parameter estimation appear. In the project the mathematical model of the inverted pendulum will be converted into the motion control model for easy parameter adaption. This will be performed by taking functions of unknown parameters and dynamics of the system. By using this method, the inverted pendulum will be simulated without any information about not only parameters but also measurable dynamics. Then, these results will be compared with adaptive backstepping.

This project will also present a survey on nonlinear adaptive control. Especially, it will focus on surveying on adaptive backstepping to help readers and applicant easily to follow the design procedure. Finally, the project will compare and analyse the adaptive backstepping and the state space design based results by running Matlab simulations.

### 6. CONCLUSIONS

The main aims of this project are to do a survey for the inverted pendulum and to investigate and design a full order state feedback controller. This project gave a survey from introduction to application for the inverted pendulum system, and also introduced the state space representation of the SISO systems and the MISO systems. The inverted pendulum was setup and analysed in math background and simulation with the design requirements. The design of a full order state feedback controller were completed is the most successful achievement in this project. The inverted pendulum system balanced with similar rise time and settling time as the previous projects, however the negative overshoot of the pendulum reduced 2% when compared with the results on UMICH and CMU websites.

This project has also proposed for the work in level-M to expand the development of controlling of inverted pendulum system by introducing a design of an adaptive backstepping scheme.

This project has shown the importance of modelling and controlling of inverted pendulum systems in applications. In conclusions, the automatic control has played a vital role in the advance of engineering and science, so most of mechatronical engineers and scientists should now have a good understanding of this field.

### 7. REFERENCES

a. ZHU. Q. 2009. Control system design. Lecture notes, UWE. Unpublished.

b. OGATA. K. 2002.Modern control engineering.4th edn. Prentice Hall.

c. WIKIPEDIA.2008. Inverted Pendulum. http://en.wikipedia.org/wiki/Inverted_pendulum[25th December 2008]

d. BOLOGNINI. G. 2001. Real-time inverted pendulum. http://shark.sssup.it/contrib/pendulum/main.htm [25th December 2008]

e. RUBI. J. 1999. Double inverted pendulum. http://www.tecnun.es/asignaturas/control1/proyectos/pdobleinv/eresumen.htm [25th December 2008]

f. WIKIPEDIA.2008. State space (controls) .http://en.wikipedia.org/wiki/State_space_(controls). [29th December 2008]

h. UMICH.1997.Modelling an inverted pendulum.http://www.engin.umich.edu/group/ctm/examples/pend/invpen.html [9th February 2009]

i. WIKIBOOKS. 2008. Control Systems/MIMO Systems. http://en.wikibooks.org/wiki/Control_Systems/MIMO_Systems [16th February 2009]

j. CONTROLTHEORYPRO. 2009. Pole placement. http://wikis.controltheorypro.com/index.php?title=Pole_Placement[23th April 2009]

k. UMICH. 1997. Digital control example: Inverted pendulum using state-space method. http://www.engin.umich.edu/group/ctm/examples/pend/digINVSS.html [25th April 2009]

l. UMICH. 1997. State space tutorial. http://www.engin.umich.edu/group/ctm/state/state.html [25th April 2009]

m. ASTROM, K.J and WITTENMARK, B. 1995. Adaptive control. 2nd edn. Addition-Wesley.

n. ALTINOZ, O.T. 2007. Adaptive integral backstepping motion control for inverted pendulum. http://www.waset.org/pwaset/v23/v23-51.pdf [4th May 2009]

### Create an M-file, and then type these texts:

M = 1;

m = 0.25;

b = 0.1;

I = 0.006;

g = 9.8;

L = 0.25;

A=[0 1 0 0;

(m*g*L*(M+m))/(I*(M+m)+M*m*L^2) 0 0 -(m*L*b)/(I*(M+m)+M*m*L^2);

0 0 0 1;

(g*(m*L)^2)/(I*(M+m)+M*m*L^2) 0 0 -((I+m*L^2)*b)/(I*(M+m)+M*m*L^2)]

B=[ 0;

(m*L)/(I*(M+m)+M*m*L^2);

0;

(I+m*L^2)/(I*(M+m)+M*m*L^2)]

C=[1 0 0 0;

0 0 1 0]

D=[0;0]

### The results on the command window are:

A =

0 1.00000 0

33.1081 00 -0.2703

0 00 1.0000

1.6554 00 -0.0935

B =

0

2.7027

0

0.9351

C =

1 0 0 0

0 0 1 0

D =

0

0