Sunteți pe pagina 1din 19

ENME560 Project: Inverted Pendulum

Control
Marc Russel
10017882
Chris Macdonald
10075289
Safwan Bhuiyan
10168831
Tara Gholami
10056821

Introduction:
The inverted pendulum is a typical problem in the study of control systems. The unstable, nonlinear nature of the system poses many challenges to the controls engineer. Design and implementation
of a control system on an inverted pendulum has ideas that can be extended to many problems in
control.
The system we will be using for this project is an inverted pendulum system by Quanser, the
IPO2 linear servo based system. This system consists of three major components a pendulum, cart and
track. The cart seats on the track interfacing through a gear system, the pendulum is attached to the
cart through a shaft and bearing system so that there is very little friction acting on the spin of the
pendulum. For this system there is two feedbacks, the position of the pendulum from an optical encoder
and the position of the cart through a potentiometer. This two feedbacks can also be used to find two
more outputs, the velocities of both the pendulum and cart. The input to the system is through a voltage
applied to a DC motor that applies force to the cart through a gear system. The control of the system
will be implemented and designed using MATLAB/Simulink.
The pendulum systems has two equilibrium points one in the upright 180, inverted pendulum,
and one in the downwards 0, gantry crane, positions. For the project we will study both of these cases.
The downward case will be studied first based on the stable nature of the system, the system will
naturally tend to this equilibrium position. The ladder case will be studied once we are familiarized with
the system from the downward case. Once a stabilizing control for the upwards case in designed and
implemented the last challenge of swing up control will be explored. The swing up control is taking the
system from the downward equilibrium position to the upward equilibrium position where it can be
then controlled by the controller for the configuration.

Modeling:
A schematic of the pendulum can be seen in figure 1 along with the free body forces, including
inertial forces in green. In this model the force exerted by the motor, F, was initially externally
represented. Afterwards the relationship between the motor parameters, voltage and exerted force was
determined. Also, it is assumed that the joint between the cart and the pendulum is frictionless.

Figure 1. Free body diagram of the inverted pendulum system.

F
N
P
Ff
M
m

Force exerted by motor


Horizontal coupled forced between cart and pendulum
Vertical coupled force between cart and pendulum
Friction force on the cart
Mass of the cart
Mass of the pendulum
Half the length of the pendulum
Moment of inertia of pendulum
Coefficient of friction of cart

N
N
N
N
Kg
Kg
m
Kgm2
Kg/s

Table 1. Symbol definition for the pendulum-cart system

From the free body of the cart and newtons second law of motion:
=
Substituting in the definition of friction force into the above we can get the dynamic model of the cart:
+ + =

From the free body of the pendulum, P and N can be determined:


By summing forces in the horizontal direction:
= + 2
Substituting N into the dynamic model of the cart gives:
( + ) + + 2 =
This is the first equation of motion for the system
The second equation of motion can be found by summing the forces on the pendulum along the
perpendicular axis. This greatly simplifies the algebra.
+ = +
Also, summing the moments about the centroid of the pendulum gives:
=
Combining the above two equations gives:
( + 2 ) + =
The following two equations therefore comprise the model of the dynamics of the pendulum-cart sub
system:
1) ( + ) + + 2 =
2) ( + 2 ) + =
This is a non-linear model which makes modeling in MATLAB, using standard transfer functions very
complicated if not impossible. The model is therefore linearized l about the vertically upward
equilibrium position, where = and assume that the pendulum stays within a small angle, ,
neighborhood of this position. The following approximations can be made:
= cos( + ) 1
= sin( + )
2 = 2 0
=
Substituting these liberalization approximations into the model gives:
1) ( + ) + =
2) ( + 2 ) =

Now the relationship between the force exerted by the DC motor and the voltage input to the motor
needs to be determined: required to be determined, as the input to the system is voltage and not force.
To do this the following parameters must be considered:

Figure 2 Schematic of a DC motor

T
e

R
L
V
b
Ke
Kt
Kg
i
r
J

Torque generated by the DC motor


Back emf of the motor
Angle of motor
Resistance of the motor
Inductance of motor
Voltage of motor
Motor friction constant
Electromotive force constant
Motor torque constant
Gear box ratio of motor
Current through the motor
Radius of the pinion gear
Moment of inertia of the motor

Nm
V
rad

H
V
Kgm/s
V/rad/sec
Nm/Amp
Amp
m
Kgm2

Table 2. Symbol definition for the DC motor system

The torque of the motor is given by:


=
The back emf of the motor can be calculated from:
=
Newtons second law and sum of the torques on the motor gives:
+ =
Kirchhoffs voltage law gives:

+ =

These relationships can be further simplified to a final expression relating force and voltage1:
=(


)(
+ )

It can be seen from this equation that the force exerted on the cart is dependent on both the input
voltage and the momentum of the cart. This model assumes that the DC motor is 100% efficient.
The complete model is therefor given by:
1) ( + ) + =
2) ( + 2 ) =

3) = (

)(

+ )

Equations 1 and 3 can be combined to give:


( + ) + ( +

2

) =

Therefore the model can be simplified in two equations as:


2


1) ( + ) + ( + 2 ) =
2) ( + 2 ) =

Applying Laplace transform to equations 1 and 2 gives:


1) ( + ) 2 () + ( +

2
2

) () 2 () =

2) ( + 2 ) 2 () () = 2 ()

()

To simplify the analysis from here on the following constants will be defined:
= ( + )
= ( +

2
)
2

=
=

= ( + 2 )
=

So that the equations will be in the following form:


1) 2 () + () 2 () = ()
2) 2 () () = 2 ()
Equation 2 determines the relationship between the pendulum angle and cart position:
() =

2
()
2

Substitution in equation 1 gives the relationship between the pendulum angle and input voltage:
2
() =
()
( 2 ) 4 + 3 2
Therefore:
() =

()
2
=
() ( 2 ) 4 + 3 2

The relationship between the voltage and the cart position is also needed and can be determined as:
() =

2
()
( 2 ) 4 + 3 2

Where the additional constants H and K are given by:


Thus:
() =

()
2
=
() ( 2 ) 4 + 3 2

State Space:
In order to turn equations 1 and 2 into state space form, they are first rearranged to ensure and do
not explicitly depend on each other:
1) + =
2) =
Plug 2 into 1:
+
+ (
) =

( 2 ) + =
=

( 2 )
( 2 )
( 2 )

Plug 1 into 2:
= (

+
)

= 2 +
=

+ +
2

The equations to be used in state space form are:

3) = ( 2 ) + ( 2 ) + ( 2 )
4) =

Now the state space is defined as:


= +
= +
Where:

= [ ]

= []
From equations 3 and 4:
1 = 2
2 =

2 +
3 +

2
2
( )
( )
( 2 )
3 = 4

4 =

2
3
2
2
2

0
2
=
0
0

[0 2
=[

( 2 )
0

2
1 0
0 0

0
( 2 )
+

1
0

0]
[ 2 ]

0 0
0
] + [ ]
1 0
0

Thus:
0
0
=

0
[0

2
0

( 2 )
0

( 2 )
=
0

[ 2 ]
1 0
=[
0 0

0 0
]
1 0

0
=[ ]
0

0
0
1
0]

The value of the parameters for this specific experiment are as follows:
M

0.37 kg

0.23 kg

2.6

Kg

3.71

Kt

0.00767 Nm/amp

Km

0.00767 V.s/rad

6.35E-003 m

0.1 kg/s

0.6413m

0.0315 kgm2

Table 3. Numerical value of parameters needed for modeling

Control of Regular Pendulum:


To begin with, it was decided that we would first attempt to control the non-inverted pendulum,
keeping the pendulum as vertical as possible. Using the modelling parameters above, the transfer
function relating motor voltage to angular position of the pendulum was estimated to be:
-0.01962
G(s) =

-----------------------0.05392 s^2 + 0.8682

The root locus for this system is shown below:

Figure 3 - Root locus of Hanging Pendulum

After some experimentation, a controller was settled upon that used a lead compensator, with its zero
set at -4.79, and its pole at -43.1. This controller had a gain of -125. The root locus diagram of the system
using this controller is shown below. The control moves the system into a much more stable region, and
allows the system to be more damped, but also more responsive.

Figure 4 - Root Locus of Controlled Hanging Pendulum

This controller was implemented into an actual system, and the following data was taken. The figure
below shows the angular displacement of the pendulum, (in encoder counts) in response to an impulse
at t = 0. There are approximately 11 counts in one degree of angular displacement. As can be seen, the
system moves by a maximum of 7 degrees, recovers fully in under 2 seconds, and has a steady state
error of less than 1 degree.

Figure 5 - Angular Response (in degrees) to Impulse signal of Hanging Pendulum

Figure Control of Regular Pendulum via Lead Compensation

Fuzzy logic was then implemented to attempt to improve the systems behaviour. Adapting the model
developed in lab 8, we were able to achieve a much better level of control than by using the lead
compensator. For fuzzification, we used memberships that had a range of 100 counts for the encoder
position, and 50 counts per second for the encoder velocity. The figure below shows the response of this
system to the same impulse as before:

Figure 6 - Angular Response (in degrees) to Impulse Signal using Fuzzy Logic

In this case, the maximum displacement was much lower, at less than 1.5 degrees, and after 2 seconds,
the oscillation is both smaller than using lead compensation, and is decreasing.

Figure 7 - Simulink Model of Fuzzy Logic Control

Control of Inverted Pendulum:


The approach that we decided to take for control of the inverted pendulum was a state based
control approach. For this approach the four output states of the system are feedback and taking into
consideration for control. To design the feedback gains the LQR (Linear-Quadratic-Regulator) was used
with tuning of the R and Q matrix based on behaviour. The system modal was also put into a state based
form, shown above, so that this could easily be done using the built in MATLAB feature.

The LQR method is a method to find the optimal stabilizing control of a system based on tunable
parameters Q and R. The Q matrix can be seeing as almost a weighting factor for each state if only the
diagonal has values. Each value of the diagonal can be looked at as weighting factors for each state, the
higher the value the more emphasize will be put on controlling that state. The R matrix can be looked at
as a weighting factor as to how aggressive you want the control to be. Two factors were tuned through
an iterative process testing each control found on the system and following trends to gain the desired
control of the system.

Figure 8 - Control of Inverted Pendulum using the LQR Method

Angle Upon Impulse


0.01

Angle (radians)

0.005
0
17

18

19

20

21

22

23

24

25

-0.005
-0.01
-0.015
-0.02

Time (s)

Figure 9 - Inverted Pendulum Angle (in degrees) in Response to Cart Position Step Change using LQR Tuning

26

27

Position Upon Impulse


0.15
0.1

Position (m)

0.05
0
17

18

19

20

21

22

23

24

25

26

27

-0.05
-0.1
-0.15
-0.2
-0.25

Time (s)

Figure 10 - Cart position (in meters) in response to Cart Position Step change of Inverted Pendulum with LQR Tuning

Swing up Control:
Finally with both control of the inverted and regular pendulum designed and examined we went
on to design of a swing up control for the system. This will be implemented into a hierarchal control
system, with the swing up control happening first with then the inverted control taking over. The system
will have a trigger once the pendulum reaches an angle inside the set angle range of the inverted
control.
The approach that will be used to try and design the controller for swing up is an energy
approach. This energy approach will try and get the inverted pendulum into a zero energy state which
will be set in the upright position by setting the datum of the pendulum appropriately. Through adding
energy into the system through movement of the cart the pendulum can be swung up to the upright
position. To start the system will be in a negative energy state, so to get the pendulum to zero energy
state energy needs to be added into the system. An energy balance between the potential energy and
kinetic energy will be used, so at certain points when the pendulum change velocity or drops below a
certain point the cart will change direction and eventually be turned off when approaching the top
equilibrium position. The block diagram for the swing up controller is shown in Figures 11 and 12

Figure 11 - Simulink Model for Control of Swing Up

Figure 12 - Simulink Model for Subsystem Block of Swing Up Control

As the system runs, the controller continues to add energy to the system, causing the pendulum to
swing higher and higher. Figure 13 shows the resulting pendulum position, and Figure 14 shows the cart
motion used.

Angle of Pendulum
1
0

Angle (rad)

-1

10

15

20

-2
-3
-4
-5
-6
-7

Time (s)

Figure 13 - Angle of Pendulum (in degrees) Resulting from Swing Up Control

25

Position of the Cart


0.05
0
-0.05 0

10

15

Position (m)

-0.1
-0.15
-0.2
-0.25
-0.3
-0.35
-0.4
-0.45

Time (s)

Figure 14 - Cart Position (in meters) resulting from Swing Up Control

20

25

S-ar putea să vă placă și