Download as pdf or txt
Download as pdf or txt
You are on page 1of 90

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/343152347

SIMULATION OF AN INVERTED PENDULUM

Book · July 2008

CITATIONS READS
0 1,125

1 author:

Firmansyah David
Institut Teknologi Padang
18 PUBLICATIONS 48 CITATIONS

SEE PROFILE

All content following this page was uploaded by Firmansyah David on 23 July 2020.

The user has requested enhancement of the downloaded file.


SIMULATION OF AN INVERTED
PENDULUM

Firmansyah David, M.Eng.

Hayfa Press

Padang

ISBN 978 – 979 – 1134 – 121 – 0


TABLE OF CONTENTS

TABLE OF CONTENTS ....................................................... i

LIST OF FIGURES............................................................. iii

LIST OF TABLES ............................................................... vi

ACKNOWLEGMENT .......................................................... vi

INTRODUCTION................................................................. 1

MODEL DEVELOPMENT ................................................... 3

2.1 The Simulink model of an Inverted Pendulum .................................. 6


2.2 The physical model of an Inverted Pendulum ................................... 8
2.3 Introduction of Matlab SimMechanics .............................................. 9
2.4 Build the Model ............................................................................... 10
2.4.1 Development of Pulleys, Belt Conveyor and Cart .................... 12
2.4.2 Development of Pendulum Set ................................................ 16
2.4.3 Mechanical Properties of Model .............................................. 17
2.5 Actuate the Model........................................................................... 19
2.6 Run and Visualize the Model ........................................................... 21
2.7 Verification of Model....................................................................... 25
2.7.1 Dimensions Verification............................................................ 25
2.7.2 Dynamics Verification ............................................................... 26
CONTROLLER DESIGN ................................................... 30

3.1 Transfer Function ............................................................................ 30


3.2 State-Space ...................................................................................... 35
i
3.3 Regulator Design Using Pole Placement.......................................... 38
3.3.1 Stability Criteria as Applied to Transfer Function Models ........ 39
3.3.2 Stability Criteria as Applied to Linear State Models ................. 41
3.3.3 Full-State Feedback .................................................................. 43
3.3.3.1 Obtaining the Possible Close-Loop Poles ......... 43

3.3.3.2 Defining the state feedback gain Matrix K ......... 45

3.4 Estimator Design Using Pole Placement.......................................... 47


3.5 Construct Complete Regulator from State Estimator plus Feedback
Gain K..................................................................................................... 51
3.6 Adding the input R ........................................................................... 54
3.7 Assembly of Inverted Pendulum with Controller ............................ 55
3.8 Controlling Cart Position using PI Controller ................................... 57
RESULTS AND DISCUSSIONS ....................................... 59

4.1 Visualize the Model Animation ....................................................... 59


4.2 Dynamic Characteristics of Model................................................... 63
CONCLUSIONS ................................................................ 75

REFERENCES.................................................................. 77

ii
LIST OF FIGURES

Figure 1 : The inverted pendulum system ........................... 3

Figure 2 : Force analysis of an inverted pendulum .............. 5

Figure 3 : Simulink representation of building an inverted pendulum ...... 7

Figure 4 : the complete model of inverted pendulum [2] ...... 7

Figure 5: The physical model of an inverted pendulum ....... 8

Figure 6 : World Coordinate System ................................. 11

Figure 7 : the block representation of pulleys, cart and belt conveyor ..... 13

Figure 8 : the block representation of pendulum set .......... 17

Figure 9: the input force representation to pulley A ........... 20

Figure 10: the friction representation on a cart .................. 21

Figure 11 : the sensor representation on a pendulum Joint22

Figure 12 : the sensor representation at the Prismatic Joint ........ 22

Figure 13 : the sensor representation at the pendulum Joint ....... 23

Figure 14 : the two main parts of an inverted pendulum .... 25

Figure 15 : the complete representation of inverted


pendulum ..................................................................................... 25

Figure 16: the angle (deg) vs. time(s) on simple pendulum oscillation .... 27

iii
Figure 17: dialog box of pendulum.mdl ............................. 33

Figure 18: Pole-zero Map.................................................. 41

Figure 19 : the complete form of plant and regulator [2] .... 51

Figure 20 : adding the input R to plant .............................. 55

Figure 21 : Assembly of Inverted Pendulum with Controller ........ 56

Figure 22 : Controlling of cart position using PI controller.. 58

Figure 23: the SimMechanics model of inverted pendulum in


XY axis ......................................................................................... 60

Figure 24: the inverted pendulum model with Equivalent Ellipsoid .......... 61

Figure 25: the SimMechanics model of inverted pendulum in XZ axis .... 61

Figure 26: the SimMechanics model of inverted pendulum in XYZ axis .. 63

Figure 27: Input signal and Cart Position with Ko = 40, K i = 0.06 ..... 64

Figure 28: Input signal and Pendulum angle with Ko = 40, K i = 0.06. 66

Figure 29: Input signal and Cart Position with Ko = 60, K i = 0.06 ...... 67

Figure 30: Input signal and Pendulum Angle with Ko = 60, K i = 0.06 68

Figure 31: Input signal and Cart Position with Ko = 98, K i = 2,7 ........ 69

Figure 32: Input signal and Pendulum Angle with Ko = 98, K i = 2.7 .. 70

Figure 33: The noise block on the inverted pendulum model .................. 71

Figure 34: The noise wave ................................................ 72

Figure 35: Input signal and Cart Position with noise .......... 73
iv
Figure 36: Input signal and Pendulum Angle with noise .... 74

v
LIST OF TABLES

Table 1: Coordinate Systems of Bodies and Constraint .... 15

Table 2: Inverted Pendulum data ...................................... 26

vi
ACKNOWLEGMENT

I would like to express my appreciation to my professors,


Prof.Dr.rer.nat. Ruediger Goetting and Prof.Dr.Manfred Vogel
for their outstanding guidance without which, my research
could not have been possible. It is always a pleasure to work
along with them

vi
CHAPTER 1

INTRODUCTION

The inverted pendulum system is a basic problem in


the field of control engineering. It is used to accommodate
the concepts of controlling such as the stabilization of
unstable conditions. The inverted pendulum system has two
equilibriums; one is stable and the other one is unstable [1].
The stable equilibrium corresponds to a state when the
pendulum acts like simple pendulum, i.e. swinging and
pointing according to the gravity vector. Furthermore, the
unstable equilibrium corresponds to a condition when the
pendulum swinging and pointing upwards against gravity
vector, therefore, it requires a controlled force to maintain
such position.

The developing of inverted pendulum model will be


done by using SimMechanics, mechanical simulation
software of Matlab. SimMechanics will take part
simultaneously translates the mechanical properties such as
mass, motions and degree of freedom within the dynamics
Newtonian standard directly into blocks representation [2]. By
1
applying SimMechanics, it is not only can replace the
complicated blocks of the Matlab/Simulink simulation but also
visualize the result of simulation as animation in three
dimensions. Furthermore, the block diagrams in
SimMechanics also replace the differential equations of
machine system.

The aim of controlling the inverted pendulum system is


to maintain the upward position of pendulum. The control
perspective on this project will focus to maintain the unstable
condition when the pendulum initially starts in an upright
position. The characteristics of the model will be shown by
sensors and actuated by actuators. Furthermore, the design
of controller is built separately in Matlab/Simulink, later; the
inverted pendulum model will be featured by the controller.
To obtain the real condition of simulation, all the values that
applied to model are based on laboratory measurement.

2
CHAPTER 2

MODEL DEVELOPMENT

The physical form of inverted pendulum is shown with


the following figure. The system of inverted pendulum can be
described as equations of motion on the Equation 2.1 and 2.2.
With the notation x - cart position,  - pendulum angle and F –
applied force on system.


bx

x

x

Figure 1 : The inverted pendulum system

M&x&  bx&  N  F (2.1)

N  m&x&  ml && cos   ml& 2 sin  (2.2)


3
Substitute Equation 2.2 into Equation 2.1 will derive the
equation of motion:

( M  m ) &x&  bx&  ml && cos   ml & 2 sin   F (2.3)

l&&  &x& cos   g sin    f  & (2.4)

Where M and m define as the cart and the pendulum


mass, respectively, L refers to pendulum length, g the
gravitational constant, b friction of the cart, x position of cart
and f  the friction coefficient in case of link where the

pendulum is attached to the cart [3]. For defining the second


equation of motion, sum all the forces perpendicular to the
pendulum; thus; deriving an equation of torques. Furthermore
the equation will be described as Equation 2.5.

2
I


x
y


bx

x

x

4
Figure 2 : Force analysis of an inverted pendulum

Based on Figure 2 the equation is defined as:

P sin   N cos   mg sin   ml &&  m&x& cos  (2.5)

To make clearer with the equation above, sum all the moments
around the center of the pendulum and get the following
equation:

 Pl sin   Nl cos   I&& (2.6)

The second dynamic equation denotes as:


( I  ml 2 )&&  mgl sin    ml&x& cos  (2.7)

For the linear functions purposes, all the equations


should be linearized about    [4]. Take a note as     
(  is referred to a small angle from the vertical upward
direction at y axis as shown in Figure 2).
and d dt   0 and u as
2
Furthermore, cos   1 sin   
input. As the result after linearization of the Equation 2.3 and
2.7 will be described as:

(M  m) &x&  bx&  ml&&  u (2.8)

( I  ml 2 )&&  mgl   ml&x& (2.9)

5
2.1 The Simulink model of an Inverted Pendulum

The Simulink model of an Inverted Pendulum is already


built in Inverted Pendulum Simulink example [2]. The complete
model has an input and two outputs (Figure 4). To obtain the
blocks representation, the user can select the Look under Mask
option, after clicking; it will be shown as Figure 3. The
derivation of cart position x and pendulum angle  are referred
to the Block Function Parameter f (u ) as shown in Figure 3,
and the F is considered as input u. The f(u)s are defined as:


&x&  F
m

 g sin cos 
l& 2 sin
M sin 2  (10)
m

 F cos  (M  m)g sin l 2 F sin cos



&&  (2.11)
m l(M  sin2 )
m
The variables of the inverted pendulum model are cart
mass (kg), pendulum mass (kg), length of pendulum (m) and
vector of gravity g ( m / s 2 ). To modify the variables, the dialog
box will show up when the complete model is clicking by user.
Furthermore, if the user wants to edit the input variables, it can
be done by modifying the dialog box with choosing the option
Edit Mask. This model will be taken to be the standard model
as comparison model in order to verify the SimMechanics
6
inverted pendulum model. Last, it will be saved as
pendulum.mdl file.

Figure 3 : Simulink representation of building an inverted pendulum


[2]

Figure 4 : the complete model of inverted pendulum [2]

7
2.2 The physical model of an Inverted Pendulum

Developing of inverted pendulum model is based on


simple pendulum model which have one degree of movement
freedom. By using the SimMechanics Blocks, all the physical
properties such as mass and motion of rigid body would be
translated into blocks simulation. The physical model of an
inverted pendulum is consisting of pendulum set, cart, two
pulleys and belt conveyor. All parts are compacted into a unit
and, respectively, cart can be sliding back and forth if the
external force F is applied. Figure 5 shows the principle of an
inverted pendulum model.

Figure 5: The physical model of an inverted pendulum


8
As general, the inverted pendulum model unit can be
divided into four sections. First; pulley and belt conveyor,
second; cart unit, third; the pendulum set (including the axis,
rod and cylinder) and the last part is the external force F which
is applied to the pulley. External force will consider as input u, it
can be a torque which delivers force to rotate the pulleys.

2.3 Introduction of Matlab SimMechanics

SimMechanics is a block modelling toolbox that can be


applied to the engineering design and simulation of rigid body
machines and their motions, using the standard Newtonian
dynamics of forces and torques [2]. SimMechanics consist of
sets of block libraries, mechanical modeling and simulation
tools. The SimMechanics blocks can be connected to normal
Simulink blocks such as Sensor and Actuator blocks. The
blocks in these libraries are the elements that needed to model
the mechanical systems consisting of any number of rigid
bodies, several joints that representing translational and
rotational degrees of freedom. SimMechanics can represent a
mechanical system with components organized into
subsystems, as in normal Simulink models.

9
The four major steps to build and run a model
representation of a mechanical system, with more detailed
explanations [2]:

 Specify body inertial properties, degrees of freedom,


constraints, and coordinate systems set up to bodies.

 Set up sensors to monitoring motions and forces, as well


as actuators and force elements to initiate motions and
also including a friction.

 Start the simulation with using the Simulink solvers to


determine the motions of the system, while maintaining
any constraints.

 Visualize the machine while building the model and


animate the simulation, using the SimMechanics
Visualization Window.

2.4 Build the Model

For building the model representation in SimMechanics,


the sections of inverted pendulum have to be translated into
block diagram. Each of blocks should have an exact data
originated from physical inverted pendulum body modeled on
Figure 5 i.e. a cart is modeled by one body block.

10
In SimMechanics, the Coordinate System (CS) is called
World CS. The World CS has a position at (0, 0, 0) and a
principle of right-handed triad, orthogonal coordinate axes [2].
The World coordinate axes are determined as +x points right,
+y points up (gravity vector g in -y direction points downward)
and +z points out of the screen. The vertical direction or
upward and downward are defined by the gravity vector
direction relative to the frame of World axes. User can modify
the gravity g properties before starting the simulation; however
it does not dynamically change during a simulation.

Figure 6 : World Coordinate System

11
The development of model will follow the World CS and
starts with CS (0, 0, 0) along x – axis. The model will be built
step by step with following process:

2.4.1 Development of Pulleys, Belt Conveyor and Cart

SimMechanics libraries provide the particular blocks that


can be used to create the machine representation. The
principle of body joint connection is body – joint – body – … –
body [2]. Pulleys are created by two wheels both on the left and
the right side and connected to ground by Revolute joint.
Therefore, the pulleys can rotate clockwise and
counterclockwise regarding to torque direction from input force
F. Belt conveyor is driven by pulleys, the movements of pulleys
against belt conveyor are defined as ratio of the angular and
linear velocity. The angular velocity is defined with the
coordinate in z (the rotation of pulleys wheel based on z axis).
The linear velocity is determined by the coordinate in x (the
translation of belt along x – axis). The cart will be connected on
both sides by belt conveyor (Conveyor A and B), respectively;
the Prismatic joint will connect the cart to ground.

On Machine Environment (ENV), the properties of the


system are being specified such as gravity vector (9, 81 m/s 2 ),
linear and angular tolerances and etc. Furthermore, the ENV

12
block should be connected to Ground block before continuing
build the mechanical block system. Each machine must have
one or more Ground blocks [2]. At Ground block the reference
coordinate of the system starts at position (x, y, z) = (0.8, 0, 0).

Figure 7 : the block representation of pulleys, cart and belt conveyor

In case of fixing the pulleys onto Ground and so that


they can rotate, the Revolute joint must be connected to
pulleys. Revolute joint represents one rotational degree of
freedom (DoF), the Follower (F) rotates relative to the Base (B)
13
about a single axis going through collocated body coordinate
system origins

The body of pulleys is designed as wheel with the radius


of r, mass m and inertia J. The coordinate system takes part as
the size, position and orientation of body. Since the pulleys are
wheel shaped, thus, the center of gravity (CG) of coordinates
will take position at the same coordinate with CS1 (Coordinate
System 1: the first coordinate from the Ground block to the
wheel) at (0, 0, 0). Another coordinate is CS2 (Coordinate
System 2: the coordinate which gives connection to belt
conveyor) at (0.02, 0, 0) (the radius of wheel is 2 cm), and also
more Coordinate Systems (CSs) to connect the bodies with
Sensor and Actuator ports. These conditions are applied for
both pulleys.

The belt conveyor is represented by Ideal Belt


Constraint block. The chain of the block connection is pulley
(body) – belt – cart (body) – belt – pulley (body). From pulley to
cart the set of belt constraints is specified by angular velocity at
Base (B); at pulley body and linear velocity at Follower (F);
which is connected to the cart. For the next part from cart to
pulley the set of belt constraint is specified by linear velocity at
Base (B); at cart and angular velocity at Follower (F); at pulley.

14
All the block coordinates are showing in Table 1. The values of
r1a, l2a and l3a are determined at initial file (init.m).

Table 1: Coordinate Systems of Bodies and Constraint

Center
Translate
Coordinate of Base Follower
Parts origin
System (CS) Gravity (B) (F)
from
(CG)
CS1 [0 0 0}
Adjoining,
Pulley A CS2 [0.02 0 [0 0 0] - -
CS1
0]
Belt
Conveyor [0 0
- - [1.6 0 0] World
from A to 0.02]
Cart
CS1 [0.075 0
0}
Cart [0 0 0] - - World
CS2 [-0.075
0 0]
Belt
Conveyor [1.6 0 Adjoining,
- - [0 0 0.02]
from Cart 0] CS1
to B

Pendulum CS1 [0 0 0} Adjoining,


[0 0 0] - -
Axis CS2 [0 r1a 0] CS1

Pendulum CS1 [0 0 0} [0 l2a/2 Adjoining,


- -
Rod CS2 [0 l2a 0] 0] CS1

Pendulum [0 l3a/2 Adjoining,


CS1 [0 0 0} - -
Cylinder 0] CS1

15
CS2 [0 l3a 0]

The Prismatic block represents one translational degree


of freedom [3]. It connects the cart body to Ground which
allowing the body slides along the x – axis in back and forth
direction. At the Base (B) of Prismatic should be connected into
Ground1 at (0, 0, 0) position. The last ground (Ground 2)
should be placed at the end of pulley B at position (x, 0, 0). The
x determines the distance between pulley A and B to World
coordinate (0, 0, 0). Last, the cart will be connected to the
pendulum at cart’s Center of Gravity coordinate.

2.4.2 Development of Pendulum Set

The next section of an inverted pendulum model is


pendulum set. It can swing 360  and fixed on cart with the
Revolute joint. The coordinate connection is CS1 at (0, 0, 0) is
translated from Adjoining of cart’s CS2 coordinate. It means
that the pendulum coordinates will start at reference of (0, 0, 0)
originally from cart’s CS2 coordinate, not refers to World
Coordinate frame. The Adjoining system creates the easy way
to plug and unplug a body to an existing body by ignoring the
World Coordinate.

16
The pendulum set is consist of three different parts; axis
(part 1), rod (part 2), and cylinder (part 3). The mechanical
properties of the bodies would define as m1a, m2a and m3a as
masses and J1a, J2a and J3a as inertia tensor I . Last
properties are radius r and length of body l. The Weld joint
connect a body to another body without Degree of Freedom
(DoF); bodies will standstill, three parts of body are connected
with two Weld joints and those are assumed as one rigid body.
The block representation of pendulum set is shown in Figure 8.

Figure 8 : the block representation of pendulum set

2.4.3 Mechanical Properties of Model

Each of blocks has its own input data in order to


configure the block properties. For inverted pendulum model,
as mentioned before, the variables of mass m, length l, radius r
17
and inertia I should be created in Matlab m-file instead enter
the value into SimMechanics block dialog. Consequently, it will
be easy to modify and configure the value of variables. The
formulas of inertia I are written in an m-file and the result of
running program will give the source values to blocks. The
formulas are described below:

% initpart1a.m (file name)


% Axis, part 1a: calculate inertia of Axis Part
1
m1a = 642.4/1000 % [kg] (mass)
r1a = 10/1000 % [m] (radius)
l1a = 186/1000 % [m] (length)
Ixxa1 = m1a*(r1a^2)/2 % (inertia refers to x
axis)
Iyya1 = m1a*(l1a^2)/12 % (inertia refers to y
axis)
Izza1 = Iyya1; % (inertia of z axis)
J1a= [Izza1,0,0; 0, Iyya1,0; 0,0,Ixxa1] %
(Matrice of Inertia)

The m-file should be created for pulleys, cart and


pendulum set. All the m-files are collected together,
respectively; the init.m file (initial file) will be created as follows:

initpart1a % Axis (Part 1)


initpart2a % Rod (Part 2)
initpart3a % Cylinder (Part 3)
initpart01a % Cart
initpulley_a % pulley A
initpulley_b % pulley B

18
2.5 Actuate the Model

The current model is stated as static model without any


mechanical forces such as torques and frictions. The model is
then developing to more attractive by applying torques at Joint
Revolute; this condition will show the dynamic behavior of
model. Furthermore, the value of frictions should have to be
considered on every joint; Prismatic and Revolute joint. The
torque considered as input force will be applied at a pulley; in
this case; torque is applied on Pulley A. On SimMechanics
window, the input block is taken from Simulink libraries which
named as Input Signal; it is named as Input Force as described
in Figure 9. Then the input block can be connected to the
desire torque signal. In case to translate the value of Simulink
to SimMechanics value, the pulley’s Joint needs actuating
block as named as Actuator. For Joint block the name is Joint
Actuatuor.

19
Figure 9: the input force representation to pulley A

On Revolute Joint the additional port can be added at


Base (B). The additional port is then connected to Joint
Actuator which declares the torque unit in Nm. The torque
value out of Input Force u is equal to gain back and forth of
pulleys and belt conveyor. The other force that affected on
Joint is frictions. Frictions as well as Input Force are connected
to Joint by using port Actuator. The Friction Actuator block
provides the Kinetic Friction (Nm) and Static Friction (Nm)
values. The value of such variables can be modified on Friction
Actuator dialog block. Figure 10 describes the connection
between Prismatic joint block and Friction Actuator block. At
Friction Actuator block there are two ports which can be
connected to Scope, later; the graphical presentation of Kinetic
Friction (Nm) and Static Friction (Nm) characteristic can be
evaluated.

20
Figure 10: the friction representation on a cart

2.6 Run and Visualize the Model

There is one more step that should follow before running


the simulation. The step is measuring the dynamical variables
of model such as angular velocity (rad/s), angle (deg), torques
on pulley (Nm), belt reaction (Nm), friction (Nm) and etc. All
those values can be directly measured based on Joint Sensor,
Friction Actuator Block and Ideal Belt Constraint. The additional
port on Base (B) and Follower (F) is considered as source of
measured value. The graphical presentation of value will be
displayed using Scope out of Simulink libraries. On Figure 11,
the pendulum angle (deg) is measured based on Revolute’s
Base (B). The output block is then connected to Scope to
present the angle graphic.

21
Figure 11 : the sensor representation on a pendulum Joint

Figure 12 : the sensor representation at the Prismatic Joint

22
Figure 13 : the sensor representation at the pendulum Joint

On Prismatic joint, the sensor is connected to Follower


(F) of joint as shown on Figure 12. Basically, the sensor can
also be attached to Base (B) of joint; however, the Base (B) is
occupied by Actuator (Kinetic and Friction Actuator). So the
additional port will be added at Follower (F) automatically. The
cart position is measured by joint Sensor and it is displayed in
Position (m). For belt conveyor, two values can be evaluated.
First Torque (Equivalent Torque on Pulley); it is measured the
torque from Follower (pulleys). The value is measured on z
component; because the pulleys are rotating based on z axis.

23
The belt tension is measured at Base (B), and the value will be
shown on x axis; because the belt is sliding along x axis.

SimMechanics supports of animating the model using


the Visualization Window. The animation will not visualize the
exact model shape but refers to the Equivalent Ellipsoid [2].
This condition is occurred because SimMechanics does not
use the full geometric shape and mass distribution of the body
and only needs certain mass properties and simplified
geometric information about the Body [2].

After all necessary blocks and initializations have been


completely set up. It is time to run the model. As general, the
complete model will divide into three different parts; the force
as input u, the Cart - Pulley and the Pendulum Set. The
subsystem has to be set up for creating the parts, it means i.e.
the Cart - Pulley is regarded as one subsystem as well as the
Pendulum Set. Based on Figure 7 and 8, two subsystems can
be created as part of inverted pendulum; as shown in Figure
14. Then these two subsystems are combined to make one
subsystem. The single subsystem is named by Inverted
Pendulum which has an input u and two outputs (pendulum
angle (deg) and cart position (m)). Figure 15 is shown the
complete system of the model.

24
Figure 14 : the two main parts of an inverted pendulum

Figure 15 : the complete representation of inverted pendulum

2.7 Verification of Model

2.7.1 Dimensions Verification

Model verification is based on physical inverted


pendulum in laboratory experiment. All the dimension values

25
are resulted from measurement. Table 2 contains the inverted
pendulum data.

Table 2: Inverted Pendulum data

Mass Length Width Radius


Parts Subparts
(kg) (m) (m) (m)
Axis 0,642 0,18 - 0,01
Pendulum
Rod 0,098 0,275 - 0,006
Set
Cylinder 0,167 0,05 - 0,02
Cart - 0,947 0,18 0,15 -
Pulleys (A &
- 0,01 - - 0,02
B)
Belt
- - 1,6 0,05 -
Conveyor

2.7.2 Dynamics Verification

Based on laboratory experiment the pendulum period T


is approximately 1,12 s and the frequency f 0,89 Hz.
Furthermore, the pendulum SimMechanics model dynamic
behavior with no friction condition is shown by following graph:

26
Figure 16: the angle (deg) vs. time(s) on simple pendulum oscillation
based on SimMechanics Model

From the graph, the period T is approximately 1,3 s and


the frequency f is approaching 0, 76 Hz; thus; the model is
approximately correct. However, the characteristic wave of
laboratory model is influenced by frictions on joint; thus; the
wave will be damped as shown in Figure 17.

27
Figure 17: the angle (deg) vs. time(s) on simple pendulum oscillation
based on lab experiment

Next, for determining the cart speed (v) (belt speed) is


derived from following data: Max DC motor 3000 rpm, ratio of
pulley 60 mm/rotation, note with the maximum speed of motor:

3000 rotation 60 mm
v  (max rpm ) xratio  x  3m / s
60 s rotation

Cart speed in SimMechanics model can be measured by


using Joint Sensor. The sensor is attached to the Prismatic

28
joint. Using the DC motor model from Matlab (3000 rpm; 50 V)
the speed of cart was measured as 3.5 m/s.

CHAPTER 3
29
CONTROLLER DESIGN

The aim of the controller is to maintain the upright


position of the pendulum. The controller will try to balance the
pendulum by moving cart back and forth. The angle
displacement indicates the direction of cart. If the center of
mass of pendulum is pointing to the right side, then cart
automatically moves to the right and balances the pendulum;
respectively; in opposite way.

3.1 Transfer Function

In order to get the transfer function of linearized system


equations analytically, the equations should be transformed
using the Laplace transform [4]. The Equation 2.8 and 2.9 are
changed into:

( M  m ) X ( s ) s 2  bX ( s ) s  ml  ( s ) s 2  U ( s ) (3.1)

( I  ml 2 ) ( s ) s 2  mgl  ( s )  mlX ( s ) s 2 (3.2)

Initial conditions are applied to be zero for both


equations. For obtaining the angle  as output, solve the
Equation 3.2 for X(s):

30
 ( I  ml 2 ) g 
X (s)    2  ( s ) (3.3)
 ml s 

Substituting into the Equation 3.1:

 ( I  ml 2 ) g   (I  ml 2 ) g 
(M  m)  2 (s)s 2  b  2 (s)s  ml(s)s 2  U (s)
 ml s   ml s 

(3.4)

The transfer function will be:

ml 2
s
 (s) q
 (3.5)
U ( s) 4 b( I  ml 2 ) 3 ( M  m)mgl 2 bmgl
s  s  s  s
q q q

And q is defined as:


q  (M  m)(I  ml 2 )  (ml) 2  (3.6)

The transfer function shown that there is both a pole and


a zero at the origin. These conditions can be canceled and the
Equation 3.5 will describe as:

ml
s
 ( s) q
 (3.7)
U ( s) 3 b( I  ml 2 ) 2 (M  m)mgl bmgl
s  s  s
q q q

If friction b = 0 then the Equation 3.7 as described as:


31
ml
s
 ( s) q
 (3.8)
U ( s) (M  m)mgl
s3  s
q

For obtaining the position x as output, solve the


Equation 3.2 as:

mlX ( s ) s 2
 ( s)  (3.9)
( I  ml 2 ) s 2  mgl

Substituting into the Equation 3.1, the equation will be:

X ( s) ( I  ml 2 ) s 2  mgl
 (3.10)
U (s) b( I  ml 2 ) 3 ( M  m)mgl 2 bmgl
s4  s  s  s
q q q

The physical model of inverted pendulum has cart mass


M =1,589 kg, pendulum mass m = 0, 265 kg, length of
pendulum l = 0,3 m, gravity vector = 9,81 ( m / s 2 ) and
assuming no friction b = 0. For getting the transfer function, the
model of pendulum.mdl can be used and all the values above
will input into dialog box.

32
Figure 17: dialog box of pendulum.mdl

Using the Matlab command, the transfer function of


pendulum.mdl is defined as following step [5]:

[A,B,C,D]=linmod('pendulum');
Gss= ss(A,B,C,D)
Gtf=tf(Gss)

Since Matlab can not operate with non linear system


directly, therefore, the pendulum model should be linearized
and extracted [4]. Simulink Libraries provides linmod function to
solve this problem. The variable A, B, C and D are state-space
matrices (will be explained on Section 3.2). The second

33
command tf converts the state model into transfer function.
After executing the command, the results will be:

Transfer function from input to output...


0.6293 s^2 - 1.286e-014 s - 20.58
#1: ---------------------------------
s^4 - 8.882e-016 s^3 - 38.15 s^2

-2.098
#2: --------------------------
s^2 - 8.882e-016 s - 38.15

The model has an input and two outputs; respectively;


the input will be described by denumerator [1 -0 -38 0 0] =
( s 4  38s 2 ) (which agrees with Equation 3.5). Furthermore the
two outputs (position x and angle  ) are described by transfer
function #1 and #2. The angle  is shown as numerator [0 0 -
2.09 0 0] = (  2,09s 2 ). Then, the transfer function of input u and
output  :

 ( s)  2,09s 2
 (3.11)
U ( s) s 4  38s 2

And divided by s, the transfer function will be:

34
 ( s)  2,09s  2,09
  (3.12)
U ( s) s 3  38s s 2  38

This agrees with Equation 3.8

For position x, it is described on numerator [0 0 0.6 0 -


20], and the transfer function of input and output will be
(assumption b = 0):

X ( s) 0.6s 2  20
 (3.13)
U ( s) s 4  38s 2

The result is agreed with Equation 3.10

3.2 State-Space

The state-space equation of the model is described as


Equation 3.14:

x&  Ax  Bu (3.14)

The equation of the model generates A as square (n x n)


matrix, and B is generated with n rows and m columns, with m
are the number of inputs. Note that x and u are column vectors
with dimensions n x 1 and m x 1. Notice also that the
multiplication of A and x and the multiplication of B and u
generates identically (n x 1) matrices. Any manipulation of
symbolic equations must be performed in such manner that
maintains the integrity of the matrix relationship [5].
35
The dependent variables which are not selected as state
variables can be noted as a linear combination of the state
variables and the inputs. Furthermore, variables which are of
special interest to the designer can be assumed as output
variables and included in an algebraic output equation that
relates output variables to state variables and inputs [5]. With
the addition of an output equation:

y  Cx  Du (3.15)

Finally, after solving linearized inverted pendulum


equations can also be represented in Equation 3.10 and 3.11
[2]:

0 1 0 0  0 
x&  (I  ml2 )b m gl2 2
x  I  ml2 
&x& 0 2
0   
    I (M  m)  Mml I (M  m)  Mml2 x& 2
    I (M  m)  Mml u
& 0 0 0 1  0 
 &&   mlb mgl(M  m)     ml 
 0 0  &
 I (M  m)  Mml
2
I (M  m)  Mml2   I (M  m)  Mml2 
(3.16)

x
1 0 0 0   x&  0 
y  0  u (3.17)
0 0 1 0     
 &
 

With friction b = 0 then the Equation 3.10 will be:


36
0 1 0 0  0 
 x&   m 2 gl 2  x  I  ml 2 
 &x& 0 0 0    2 
  I ( M  m )  Mml 2 x&
     I ( M  m )  Mml  u
&  0 0 0 1     0 
 &&  mgl ( M  m )   &  ml 
  0 0 0  
  I ( M  m )  Mml 2 
 I ( M  m )  Mml 2
(3.18)

Rearrange the variables:

0 0 0 1  0 
 x&  0 0 
1 0  x   0 
&   mgl ( M  m)    I  ml 2 
   0 0 0     u
&&  I ( M  m)  Mml 2  &   I ( M  m)  Mml 2 
   m 2 gl 2    ml 
 &x& 0 0 0  x&   
 I ( M  m)  Mml 2   I ( M  m)  Mml 2 
(3.19)

The C matrix is 2 by 4, it is considered from both cart


position and pendulum positions are part of the output [2]. In
case of state space design problem, the controller will be
controlling the multi output systems, therefore, the observing
the cart position from the first row of output and the pendulum
with the second row [2]. By using the Matlab command ss
(state space):

[A,B,C,D]=linmod('pendulum');

37
Gpend=ss(A,B,C,D)

The A, B, C and D matrices will display as:

a = x1 x2 x3 x4
x1 0 0 0 1
x2 0 0 1 0
x3 0 38.15 0 0
x4 0 -1.636 0 0
b = u1
x1 0
x2 0
x3 -2.098
x4 0.6293

c = x1 x2 x3 x4
y1 1 0 0 0
y2 0 1 0 0

d = u1
y1 0
y2 0

3.3 Regulator Design Using Pole Placement

The design of controller and compensator with the pole


placement techniques such the dominant closed-loop poles,
38
have a desired damping ratio  and undamped natural

frequency wn [6]. By choosing an appropriate gain matrix for

state feedback, it is possible to force the system to have close-


loop poles at the desired locations. At the pole placement
approach to the design of control systems, it assumes that all
state variables are available for feedback [6].

3.3.1 Stability Criteria as Applied to Transfer Function


Models

Considering the transfer function as shown on Equation


3.11 and 3.13, the location of the poles of the transfer function
determines the characteristic of the natural response as
evaluated at the output. If all of the poles are located in the left
half of the s-plane, then the composition that constructs the
natural response will decay asymptotically to zero [5].

The asymptotic decay is also configured by internal


variables of the model, excluding for this case; there must be
no pole-zero cancellations that exist on the jw axis or in the
right half of the s-plane [5]. The left-half-plane (LHP) location
for all poles is sufficient assurance that all of the composition of
the natural response will decay asymptotically to zero
(regardless of the point of evaluation). This condition is known
as asymptotic stability [5].

39
Consider the Equation 3.8 with the numerator and
denumerator as [0 0 -2.09 0 0] and [1 0 -38 0 0], the Matlab
commands to define the open-loop zero poles are described
below:

n=[0 0 -2.0978 0 0];


d=[1 0 -38 0 0];
[z, p]=tf2zp(n,d)
pzmap(Gpend)

The tf2zp means convert the transfer function into zero pole,
and the result will be:

z = 0
0
p = 0
0
6.1644
-6.1644

There is one on right-half-plane (RHP) pole at 6.1644;


thus; the system is unstable in open loop.

40
Figure 18: Pole-zero Map

3.3.2 Stability Criteria as Applied to Linear State Models

The linear model of system is described as [5]:


x (t )  Ax (t )  Bu (t ) (3.20)

And the system will stable if all the composition of the


state transition matrix approach zero as time approaches
infinity [5]. The system will get stabile if:

lim  (t )  0 (3.21)


The Laplace transform of Equation 3.21 is:


41
adj ( sI  A)
 ( s )  ( sI  A) 1  (3.22)
det( sI  A)
With I is identity matrix and the denominator polynomial of each
term of  ( s ) is defines by evaluation of det (sI – A). The
asymptotic stability is fulfilled if all the roots of det (sI – A) are
located in the LHP. The characteristic equation is:

det( sI  A)  0 (3.23)

The roots of the characteristic equation above are also


known as Eigen-values of A. Using Matlab the open-loop roots
of pendulum.mdl can be determined by using command eig:

p = eig (A)

And the result will be:

p = 0
0
6.1768
-6.1768

Then, the result will show the approximately same


values with the tf2zp where there is one result on right-half-

42
plane pole at 6.1768. So, the system will be unstable at open
loop.

3.3.3 Full-State Feedback

The next step in the design process is to assume that


the system will have full-state feedback and the vector K which
assume as feedback control law [2]. The closed-loop poles
have to be determined in advance before determining the K
vector.

3.3.3.1 Obtaining the Possible Close-Loop Poles


With a linear state model that describes on Equation
3.19 in a close-loop system, stability can determine the location
of poles of the characteristic equation as obtained using det (sI
- A) = 0. Considering the conversion of matrix A of Equation
3.19 as follows [5]:

 0 0 0 1 
 1 0 0 0  0 
   0 1 0  
 0 1 0 0   mgl ( M  m ) 
det  s   0 2
0 0   0
0  I ( M  m )  Mml 
  0 0 1
  
 0 m 2 gl 2

0 0 1  0
2
0 0  
  I ( M  m )  Mml  
(3.24)

Then the Equation 3.24 takes form as:

43
 s 0 0  1 
 
 0 s  1 0  
 mgl ( M  m) 
det  0  s 0   0 (3.25)
 I ( M  m)  Mml 2 
 
 0  m 2 gl 2
 0 s  
 I ( M  m)  Mml 2  

s 4  a 3 s 3  a 2 s 2  a1 s  a 0  0 (3.26)

In case of obtaining the reasonable speed and damping


in the response of the designed system, next step is choosing
the desired close-loop poles at s =  i ( i  1, 2 ,3, 4 ,5 ) [6]. To the

model, the chosen poles are described below:

 1  2  j 2 ,  2  2  j 2 ,  3  16 ,  4  20

This is the possible set of desired closed-loop poles [6].


Other sets can be chosen. Then the desired characteristic of
Equation 3.26 will be:

( s   1 )( s   2 )( s   3 )( s   4 )  0

( s  2  j 2)( s  2  j 2)( s  16)( s  20)  0

s 4  40 s 3  466 s 2  1352 s  640  0

On Matlab the poles are written as:

pNeuK= 4*[-0.5+i/2,-0.5-i/2,-4,-5]

44
The result will be:

pNeuK = -2.0000 + 2.0000i -2.0000 - 2.0000i -16.0000 -


20.0000

3.3.3.2 Defining the state feedback gain Matrix K


For computing the matrix K, the values of poles (pNeuk)
will consider as a vector p of desired self-conjugate closed-loop
pole locations [2]. The state-feedback on Equation 3.27 will
place the closed-loop poles at the locations p and the Matlab
command place will compute a gain matrix K.

u   Kx (3.27)

Substitute into Equation 3.14, it will result in:



x  Ax  BKx (3.28)


x  ( A  BK ) x (3.29)

The Eigenvalues of Equation 3.29 match with the entries


of p (up to the ordering) [2]. The command p will compute a
feedback gain matrix K that defining the desired closed-loop
pole locations p, assuming all the inputs of the plant are control
inputs. The length of p must match the row size of matrix A [2].
45
Using the poles from pNeuk above, the Matlab command for
computing the gain matrix K as follows:

K = place(Gpend.a,Gpend.b,pNeuK)

Gpend.a and Gpend.b are describing the matrix A and


B. After running the program the result will be:

K = -124.3988 -280.5098 -41.9263 -76.1943

After the values of K are determined, the complete


matrix A, B, C and D will compute of plant including regulator:

Gpend_reg=ss(Gpend.a-
Gpend.b*K,Gpend.b,Gpend.c,Gpend.d)

The result will be:

a = x1 x2 x3 x4
x1 0 0 0 1
x2 0 0 1 0
x3 -261 -550.3 -87.95 -159.8
x4 78.29 174.9 26.39 47.95
b = u1

46
x1 0
x2 0
x3 -2.098
x4 0.6293

c = x1 x2 x3 x4
y1 1 0 0 0
y2 0 1 0 0
d = u1
y1 0
y2 0

As mentioned on Equation 3.29 the Eigenvalue is


described by command Gpend.a-Gpend.b*K, the new Gpend
will name as Gpend_reg (reg: regulator) that evaluated the
original matrix A, B, C and D with the new one.

3.4 Estimator Design Using Pole Placement

If the state of the plant can be estimated, then feedback


compensation can be implemented by using the estimated
state [5]. On Matlab the estimator is produced by command
estim. The estim will produce the state/output estimator. For a
continuous-time plant with the equations:

x  Ax  Bw (3.30)

47
y  Cx  Dw (3.31)


The estim command will derive the plant output y and

state estimated x as given by the following model [3]:


  
x  A x  L ( y  C x) (3.32)


  
x  A x  L Cx  Ly (3.33)


 
x  ( A  L C ) x  Ly (3.34)

Pole values on pNeuk can be used as pole placement in


case of designing the estimator gain L. Furthermore, notice
that the estimator poles (Eigenvalues of A – LC) should be
faster than the plant dynamics (Eigenvalues of A) to ensure
accurate estimation [2]. To determine the gain L, it can use the
place command for estimator gain by transposing the A matrix
into A’ and substituting the C’ for B. But first, take the poles of
pNeuk as pNeuL [2]:

pNeuL= 20*pNeuK
L = place(Gpend.a',Gpend.c',pNeuL)

48
The result will be:

pNeuL = 1.0e+002 *
-0.4000 + 0.4000i -0.4000 - 0.4000i -3.2000 -
4.0000
L = 1.0e+005 *
0.0001 -0.0031 -0.4244 0.1764
0.0019 0.0079 1.0344 -0.3334

After values of L are determined and transposed, now


the plant can be estimated (1 and 2 are the inputs; here cart
position x and pendulum angle  ):

Gest=estim(Gpend,L',[1,2],[1])

The result will be:

a =
x1 x2 x3
x4
x1 -9.788 -190.6 0
1
x2 314.9 -790.2 1
0
x3 4.244e+004 -1.034e+005 0
0
x4 -1.764e+004 3.333e+004 0
0
b = u1 u2 u3

49
x1 0 9.788 190.6
x2 0 -314.9 790.2
x3 -2.098 -4.244e+004 1.034e+005
x4 0.6293 1.764e+004 -3.334e+004

c = x1 x2 x3 x4
y1 1 0 0 0
y2 0 1 0 0
y3 1 0 0 0
y4 0 1 0 0
y5 0 0 1 0
y6 0 0 0 1
d = u1 u2 u3
y1 0 0 0
y2 0 0 0
y3 0 0 0
y4 0 0 0
y5 0 0 0
y6 0 0 0
Input groups:
Name Channels
KnownInput 1
Measurement 2,3
Output groups:
Name Channels
OutputEstimate 1,2
StateEstimate 3,4,5,6
Continuous-time model.

50
3.5 Construct Complete Regulator from State Estimator
plus Feedback Gain K

Regulator is built by combining the state-space Gpend,


L and K gains [2]. The gains L and K are typically designed
using pole placement.


x

Figure 19 : the complete form of plant and regulator [2]

The regulator state Greg is obtained by connecting the


state-feedback law u= -Kx and the state estimator with gain
matrix L (see Section 3.4).

For a plant with equations:

51

x  Ax  Bu (3.35)

y  Cx  Du (3.36)

The yield of regulator can be derived as [3]:

 
x  Ax  LC  ( B  LD ) K  x  Ly (3.37)


u  K x (3.38)

On Matlab, the command reg will regulate the state-


feedback (Gpend) and the estimator gains (L and K), the last
state will be named as Greg:

Greg = reg(Gpend,K,L')

The result will be:

a = x1 x2 x3
x4

x1 -9.788 -190.6 0
1

x2 314.9 -790.2 1
0

x3 4.218e+004 -1.04e+005 -87.95


-159.8

52
x4 -1.757e+004 3.351e+004 26.39
47.95

b = u1 u2

x1 9.788 190.6

x2 -314.9 790.2

x3 -4.244e+004 1.034e+005

x4 1.764e+004 -3.334e+004

c = x1 x2 x3 x4

y1 124.4 280.5 41.93 76.19

d = u1 u2

y1 0 0

Input groups:

Name Channels

Measurement 1,2

Output groups:

Name Channels

Controls 1

Continuous-time model.

The complete state-space controller is called by


design01.m. This file should be attached in init.m before start
the simulation.
53
%% State-Space Controller: Inverted Pendulum
% design01.m
% Define plant first (compare values of mass etc.
in "pendulum.mdl"
[A,B,C,D]=linmod('pendulum');
Gpend=ss(A,B,C,D);
%% Design Regulator Using Pole Placement
% Design by pole-placement
pNeuK= 4*[-0.5+i/2,-0.5-i/2,-4,-5]
K = place(Gpend.a,Gpend.b,pNeuK)
Gpend_reg=ss(Gpend.a-
Gpend.b*K,Gpend.b,Gpend.c,Gpend.d)
%% Design Estimator Using Pole Placement
% Design by pole-placement
pNeuL= 20*pNeuK
L = place(Gpend.a',Gpend.c',pNeuL)
Gest=estim(Gpend,L',[1,2],[1])
%% Construct Complete from Estimator plus
Regulator
Greg = reg(Gpend,K,L')

3.6 Adding the input R

The more complete of the schematic control system is


shown on Figure 19. The R represents as input to the cart. The
A, B, C and D matrix represents the position and velocity of the

54
cart and the angel and angular velocity of the pendulum. The
output y contains both position of the cart and the angle of the
pendulum. With adding the reference point R, the cart should
move to the new position as stated in reference point; with the
condition initial angle of pendulum is zero. The R also can be
replaced by other signals and then the dynamical characteristic
of model will be evaluated.


x

Figure 20 : adding the input R to plant

3.7 Assembly of Inverted Pendulum with Controller

Three main basics of the simulation model are the


inverted pendulum block, the regulator block and the sensor. In
Figure 20, the inverted pendulum block is taken from the block

55
on Figure 15 (SimMechanics model). The init (initial) block is
creating based on init files as described on sec 2.4.3. At the
Scope block; respectively; the cart position, the pendulum
angle and the force will be displayed. The reference block set
the orientation of direction of cart movement and the saturation
block defines limit of lower and upper of input signal.

Figure 21 : Assembly of Inverted Pendulum with Controller

The initial condition of cart will set on Joint Initial


Condition (IC) that attached on Prismatic Joint. Furthermore,
the pendulum initial angle is being set by Joint Initial Condition

56
(IC). After all the values are set; and all the files in the same
directory, the steps to run the simulation are; click on init; wait
until all the values are calculated and click on Start Simulation.
The animation window will be shown automatically on X – Y
axis.

3.8 Controlling Cart Position using PI Controller

A proportional plus integral (PI) controller introduces the


roots into the forward-path function, and an ideal realization
places the pole at origin [5]. An equation of a PI controller and
the locations of the roots are shown on Equation 3.39. The
transfer-function of PI as follows:

K i K o (s   )
Gc ( s)  K o   (3.39)
s s

Ki
 (3.40)
Ko

The terms of K o and  is useful when considering a

variation in gain with a fixed zero location. The PI controller


helps reduce the steady-state error and as being controlled, the
cart position is assuming to follow of input R values in a range
of pulley A and B [5]. By using Simulink PI block the gains K o

and K i can be easily modified. On Figure 22, the Sin Wave

57
Block is considered as input signal. After running the
simulation, the cart movement is projected to follow the sin
wave; sliding back and forth.

Figure 22 : Controlling of cart position using PI controller

58
CHAPTER 4

RESULTS AND DISCUSSIONS

The result will be categorized into two sections; visualize


the graphic-animation of inverted pendulum model and observe
dynamic characteristics of the model. The visualization is
projected the model into three dimensions and assumed the
model shape in advance. The dynamic characteristic of the
model leads into responses of inverted pendulum in addition of
external input.

4.1 Visualize the Model Animation

Matlab Graphic – based visualization is built into


SimMechanics. After all the block is completely constructed,
the next step is choosing Simulation – Configuration Parameter
– SimMechanics and mark on show animation during
simulation. Then Run the simulation within infinity time or
certain time (time can be set up in a particular value) and the
graphic will be shown as following figures:

59
Figure 23: the SimMechanics model of inverted pendulum in XY axis

The display of model covers by Center of Gravity (CG),


Coordinate System (CS) and Equivalent Ellipsoid (EE) (Figure
23 and 24). The belt conveyor is not displayed on animation
because SimMechanics Visualisation only considers Bodies to
display on visualization window [2].

60
Figure 24: the inverted pendulum model with Equivalent Ellipsoid

Figure 25: the SimMechanics model of inverted pendulum in XZ axis


61
Cart is projected as rectangle shape and respectively;
Axis (part 1) is jointed on cart. To observe the construction of
cart and Axis, the set of view should be changed into XZ axis
as shown in Figure 25. The other feature is Body Surface; it will
render the body in simply way based on coordinate system
(CS). Figure 26 describes the model in three dimensions (XYZ
axis).

The vector of gravity g will point to axis y negative and


the initial angle of pendulum will be 0 degree referred to axis y
positive. The initial position of cart as shown in Figure 25 is 0 m
referred to World (0, 0, 0); it can be changed by modifying joint
Initial Condition (IC) that attached to Prismatic joint.

62
Figure 26: the SimMechanics model of inverted pendulum in XYZ axis

4.2 Dynamic Characteristics of Model

Using the model diagram on Figure 22, the dynamic


characteristic of model will be observed. The regulator Greg is
balancing the pendulum and the PI controller gives gain to
cart’s movements in order to follow reference input (sin wave).
The variation of gains; respectively K o and K i ; would give a

certain distance of cart to slide back and forth. Figure 27 gives


the characteristic of cart position and input signal at PI
condition; K o = 40, K i = 0.06 and input signal sin = 1;
frequency f = 0.1 rad/sec. The duration of simulation takes to 6
minutes and set the solver at ode15s. The input signal is
shown by blue graph and cart position by red graph.

63
1 0,8

0,8
0,6
0,6
0,4
0,4

Input Signals (Nm)


0,2

Cart Position (m)


0,2

0 0

-0,2
-0,2
-0,4
-0,4
-0,6
-0,6
-0,8

-1 -0,8
0 50 100 150 200 250 300 350 400
Time (s)

Figure 27: Input signal and Cart Position with Ko = 40, K i = 0.06

From the graph, it is clear that the cart movement refers


to input signal. When the input signal gets first period at peak
value; 1 Nm; respectively the position of cart is located to left at
~0,55 m. Note that cart initial position at (0, 0, 0) and the
distance from initial position to left pulley (B) and right pulley
(A) is 0.8 m. When the signal turns to the opposite way (second
period); the position of cart is located at ~0,55 m to the right
(pulley A). The second period the cart position reaches both
~0,4 m to the right and left; and keep remains to rest period.

64
The angle of pendulum is also observed at this K o and

K i conditions. The initial pendulum angle is set at 0 deg; with


the initial upright position along y axis. Figure 28 shows the
characteristic of pendulum angle and input signal. At first
period of input signals the pendulum angle is swinging at 0,06
degree and -0,09 degree. The plus and minus sign indicates
pendulum swinging to the left and right (regarded to vertical y
axis). Otherwise, on the second period the angle reduce to
~0,04 degree both to the right and left; third period the angle
reduce to ~0,02 and this condition remains constant to the rest
of period. The amplitude of the angle indicates that pendulum
stabile.

65
1 0,1

0,8

0,6 0,06

0,4

P en d u lu m A n g le (d eg )
In p u t S ig n als (N m ) 0,2 0,02

-0,2 -0,02

-0,4

-0,6 -0,06

-0,8

-1 -0,1
0 50 100 150 200 250 300 350 400
Time (s)

Figure 28: Input signal and Pendulum angle with Ko = 40, K i = 0.06

Since the system has the distance between pulley A and


B as 1,6 m, the position of cart at peak input value can be
increased by modifying the gain of PI controller. By setting the
PI gains; K o = 60, K i = 0.06, the position of cart will increase

respectively. On the previous position (Figure 27) the cart at


the peak value is located at ~0,59 m, now it increases nearly to
~0,6 m both on the left and right position.

66
1 0,8

0,8
0,6
0,6
0,4
0,4

In p ut S ig n als (N m )
0,2

C art P os itio n (m )
0,2

0 0

-0,2
-0,2
-0,4
-0,4
-0,6
-0,6
-0,8

-1 -0,8
0 50 100 150 200 250 300 350 400
Time (s)

Figure 29: Input signal and Cart Position with Ko = 60, K i = 0.06

The pendulum angle amplitude is also changed as PI


gains changed. Because the cart moves farther; respectively;
the amplitude of angle will increase. The maximum amplitude
of angle for first period is approximately 0,1 and -0,12 degree;
for the rest period the angle pointed at ~0,04 and -0,04 degree
(Figure 30). However, pendulum is still stabile within the
condition.

67
1 0,2

0,8 0,16

0,6 0,12

0,4 0,08

P endulum A ngle (deg)


Input S ignals (N m)
0,2 0,04

0 0

-0,2 -0,04

-0,4 -0,08

-0,6 -0,12

-0,8 -0,16

-1 -0,2
0 50 100 150 200 250 300 350 400
Time (s)

Figure 30: Input signal and Pendulum Angle with Ko = 60, K i = 0.06

Both gains K o = 40 and K o = 60 have not putting the

optimize position of cart. There are errors still occurred,


because the system cannot reach the output signal at exactly
level as the input. In this case, when the input signal reaches
the peak value at 1 Nm; respectively the cart position should
follow approximately at ~0,8 m. To reduce the errors, the
solution is increasing the gains K o and K i . The chosen gains

K o and K i are 98 and 2,7. These values are the optimized


values to maintain the output (cart position) at the same level of
68
input signal (sin wave). Figure 31 is shown the input signal and
cart position, when the input signal reach the peak value 1 Nm;
respectively; cart position reach ~0,8 m.

1 0,8

0,8
0,6
0,6
0,4
0,4
Input S ignals (N m)

0,2

C art P osition (m)


0,2

0 0

-0,2
-0,2
-0,4
-0,4
-0,6
-0,6
-0,8

-1 -0,8
0 50 100 150 200 250 300 350 400
Time (s)

Figure 31: Input signal and Cart Position with Ko = 98, K i = 2,7

69
1 0,3

0,8

0,6

0,4

Pendulum A ngle (deg)


0,1

Input Signals (N m)
0,2

-0,2
-0,1
-0,4

-0,6

-0,8

-1 -0,3
0 50 100 150 200 250 300 350 400
Time (s)

Figure 32: Input signal and Pendulum Angle with Ko = 98, K i = 2.7

The maximum amplitudes of angle occur at ~0,2


degrees. If it compares to K o = 40 and K o = 60, the angle

amplitude is increasing because the gains ( K o = 98 K i =2,7)

make the pendulum system will slide farther and faster. Further
condition is addition of disturbances to model system. The
disturbances are represented by Simulink block Band – limited
White Noise. This high frequency noise has power 2 and at
sample time 0,1 s. Figure 31 shows the implementation of
noise on the model. Furthermore, Figure 32 shows the noise
signal block is adding as the disturbances for pendulum. After
70
fixing the block, the influence of disturbances to pendulum
characteristic (position and angle) will be observed.

Figure 33: The noise block on the inverted pendulum model

71
20

15

10

5
Noise Power
0

-5

-10

-15

-20
0 50 100 150 200 250 300 350
Time (s)

Figure 34: The noise wave

The cart position characteristic after applying the noise


is shown on Figure 35. Using the K o = 98, K i = 2,7, it seems

that the cart position would remain in range 0,8 and -0,8 m.
Hence, the noise does not affect to cart position. In the other
way, the pendulum angle with small vibration regard to the
frequency of noise in range ~0,2 and -0,2 degrees. However,
the system is still stabile within the disturbance.

72
1 0,8

0,8
0,6
0,6
0,4
0,4

In pu t S ig nals (N m )
0,2

C art P os itio n (m )
0,2

0 0

-0,2 -0,2
-0,4
-0,4
-0,6

-0,8 -0,6

-1 -0,8
0 50 100 150 200 250 300 350
Time (s)

Figure 35: Input signal and Cart Position with noise

73
1 0,3

0,8

0,6

0,4

P en d u lu m A n g le (d eg )
0,1
In p u t S ig n als (N m ) 0,2

-0,2
-0,1
-0,4

-0,6

-0,8

-1 -0,3
0 50 100 150 200 250 300 350
Time (s)

Figure 36: Input signal and Pendulum Angle with noise

74
CHAPTER 5

CONCLUSIONS

The SimMechanics as development tool to build the


inverted pendulum model has given good performance in case
of constructing, modifying, and running the model. In other
word, build the model in SimMechanics saves more time if
compares to build the model in Matlab/Simulink blocks;
because it needs to solve the complicated equations. But,
however, the initial setting such as coordinate systems, solver
and constraints must be fixed in correct way; otherwise the
simulation will not run properly. Furthermore, all the values
from laboratory measurement have to be added in order to get
the real result of simulation.

The regulator is capable of successfully maintaining the


upward position of the pendulum. The PI controller regulates
the pendulum’s cart sliding in range of the track. The cart will
follow the input signal to slide back and forth and not hit the
end of pulleys. Two different values of gains in PI controller are
implemented to the pendulum model. It has purpose to
evaluate the movement of cart whenever the cart reach the end
75
of the track or even override. Both proportional gains ( K o = 40;

K i = 0.06 and K o = 60; K i = 0.06) indicate the cart slides

approach to the end of track; however; with K o  98 and K i =

2,7 the optimum distance of cart can be achieved.

To represent the external disturbance while the


pendulum running, the noise block is implemented. This also
evaluates the reliability of the controller. From the pendulum
angle graph, the pendulum still on stabile condition; thus; the
pendulum will vibrate in high frequency regard to frequency of
noise. This condition was not happened to cart; cart keep
moving normal according to the input signal. Overall, it is seen
that the system is stable within the disturbance conditions.

76
REFERENCES

[1] Lam, Jonny. Control of an Inverted Pendulum.


http://www.ece.ucsb.edu/~roy/

student_projects /Johnny_Lam_report_238.pdf.
Accessed on February 14th, 2008.

[2] The Mathworks. Matlab SimMechanics User Guide.


http://www.mathworks.
com/access/helpdesk/help/toolbox/physmod/mech/in
dex.html.Accessed on February 14th, 2008.

[3] Linköping. Control of an Inverted Pendulum.


http://www.control.isy.liu.se/

student/ tsrt15/material/lab3engpm.pdf. Accessed


on February 14th, 2008.

[4] Mellon, Carnegie. Control Tutorials for Matlab Example:


Modeling an Inverted Pendulum. Michigan
University. http://www.engin.umich.edu/group/ctm/

examples/pend/invpen.html. Accessed on February


14th, 2008.

77
[5] Yang Chang, Lewis Paul. Basic Control Systems
Engineering. Prentice-Hall, Inc. New Jersey. 1997.

[6] Ogata Katsuhiko. Designing Linear Control Systems with


Matlab. Prentice-Hall, Inc. New Jersey. 1994.

78
Firmansyah David, ST, M.Eng was born on 3rd
August 1982 in Sei.Geringging, Pariaman,
Indonesia. He received Master degree in
Technical Management from Fachhochschule
Oldenburg/Ostfriesland/Wilhemshaven,Germa
ny (2008) and finished Bachelor degree in
Electrical Engineering at Andalas University,
Indonesia (2005). He follows several
researches in electrical engineering
particularly on Power System and High
Voltage Engineering.
One of the international publication which entitled “The
Leakage Current Analysis on Porcelain Suspension Insulator
Contamined by Salt and Cement Dust” had been presented
in Bali, Indonesia (2006).

ISBN 978 – 979 – 1134 – 121 – 0

79
SIMULATION OF AN INVERTED PENDULUM

Firmansyah David, ST, M.Eng

Hak Cipta Dilindungi Undang – undang

All Right Reserved

Cetakan ke – 1
Juli, 2008
1. Pendidikan i. Judul
2. Firmansyah David ii. Nama
3. Keteknikan iii. Kelompok

Perpustakaan Nasional : Katalog Dalam Penerbitan


Firmansyah David
Simulation of an Inverted Pendulum
Firmansyah David, ST, M.Eng
Cetakan ke – 1, Juli, 2008
Padang, Hayfa Press
Jalan Bandar Purus no 57 c Padang
Ix, 75 hlm, 16,5 x 21,5
ISBN: 978 – 979 – 1134 – 121 – 0

80
81

View publication stats

You might also like