You are on page 1of 15

McGill University

ECSE 493 – Control & Robotics Laboratory

Lab Experiment #3

Inverted Pendulum

March 24th 2011

William Hoang – 260152267

1
Table of Contents
Abstract ......................................................................................................................................................... 3

Introduction .................................................................................................................................................. 3
Models ...................................................................................................................................................... 3
Stabilizing System ..................................................................................................................................... 8
Methods & Results ...................................................................................................................................... 10
PID Controller.......................................................................................................................................... 10
Lead Controller........................................................................................................................................ 11
Discussion.................................................................................................................................................... 15

2
ABSTRACT
Deriving the needed model equations to implement the inverted pendulum control lab experiment was
the first step in this exercise. Reading and understand the theories behind PID and lead controllers and
being aware of their limitations.

Creating the models in MATLAB and observing the overall system feedback values for both types of
controllers when attached to the inverted pendulum cart. Adjusting appropriate parameter values to
fine to and bring system to overall stability.

The lead controller was simple to implement but cannot stabilize the plant for more than a few seconds.
The PID controller using ZN methods was difficult to implement and displayed overshoots that had to be
tuned together with the three different parameters.

INTRODUCTION
The lab requires the balancing of an inverted pendulum apparatus by controlling the cart while it moves.
The controller methods used in the experiment to stabilize the overall system are the lead controller
and PID controller. The assumption is that the lead controller will have better stabilizing properties than
the PID is due to the amount of parameter combinations that would account for the PID system. With
the PID controller relating the angle error to motor velocity and direction, and the lead controller’s
ability to reduce oscillation with zeros pulling the poles from an unstable system, it is thus assumed it is
possible to control a simplified model of the inverted pendulum system.

The non-linear system requires that the necessary equations of motion be linearized to account for any
positional dependencies.

Models
Equation models built in the lab (state equations):

Equation: 1.0

( )

Equation: 2.0

This is obtained from the state variables:

Given that cosa = 1 and sina = a for small a.

∂L/∂x’) - ∂L/∂x = F

Equation: 3.0

3
∂L/∂a’) - ∂L/∂a = F

Equation: 4.0

(mp + mc)*x” + a”*mp*lp*cosa – mp*lp*(a’)^2*sina = F

Equation: 5.0

x”*mp*lp*cosa + a”mp*(lp)^2 – mp*g*lp*sina = a

Equation: 6.0

( )

Equation: 7.0 - Force

x’ = a’ = a = x = 0

Equation: 8.0

x’ = Ax + Bu

Equation: 9.0

Because of the non-linear system, the state-space equation is obtained by first linearizing the equation
around the equilibrium point. These equations for the inverted pendulum’s motion were derived using
Lagrangian mechanics given that K is the kinetic energy and V is the potential energy:

Equation: 10.0

Equation: 11.0

Pendulum:

Equation: 12.0

Equation: 13.0

4
Cart:

Equation: 14.0

Now need to express the system using the state space equations. Replacing k1 = km*kg/r then using the
state variables and linearizing around the equilibrium point, these values along with system parameters
are in Table 1.0 define the model of the system in the experiment.

[ ] [ ]
̇
̇

Equation 15.0

[ ]
( )
[ ] [ ]

Equation 16.0: State Space

Equation 17.0: State Space with K1

The equations with table 1 together model the experimental system.

5
Parameter Symbol Value Units

Motor Torque/ Constant Km 0.0077 N.m/amp


Back EMF constant
V/(rad/sec)

Armature Resistance Rm 2.6 Ohms

Armature Inductance Lm 180 uHenry

Maximum Voltage Vmax 5.0 Volts

Internal Gear Ratio Kg 3.7 to 1 none

Motor Gear Radius r 0.0064 m

Cart Mass mc 0.5 Kg

Extra mass m2 0.37 Kg

Linear position gain Kx 0.00228 cm/counts

Pendulum angle gain Kth 0.00153 rad/counts

Pendulum mass mp 0.127 Kg

Distance to Pendulum COG lp 0.168 m

Table 1.0: Table of Values

The matrix obtained after using the constants and experimental value for (km*kg)/r = 4.27 with kg taken
to be 3.9 is:

>> A=[0 0 1 0; 0 0 0 1; 0 -2.49 -14.87 0; 0 73.22 83.48 0]

A=

0 0 1.0000 0
0 0 0 1.0000
0 -2.4900 -14.8700 0
0 73.2200 83.4800 0

6
>> eig(A)

ans =

0
8.0084
-6.8724
-16.0060

>>

The eigenvalues of Matrix A are plotted in the figure below that resulted from investigating the poles of
the open-loop system. From the resulting pole/zero map figure, it is evident that the system is unstable
due to the existence of a pole (8.0084) in the plane that is beyond the x = 0 axis.

Pole-Zero Map
1

0.8

0.6

0.4
Imaginary Axis

0.2

-0.2

-0.4

-0.6

-0.8

-1
-20 -15 -10 -5 0 5 10
Real Axis

Figure: 1.0 – Zero/Pole plot of Open Loop System

7
Stabilizing System
By setting x’ = 0 in the a” equation, can eliminate the position dependency and thus stabilize the overall
system. This will simplify the model and will now only have the angle of the pendulum in consideration.

a” = (mp + mc)*g*a / (mc*lp) – (km*kg)/(r*Rm*mc*lp)*V

Equation 18.0

To have a more functional working equation, the Laplace transform will be performed on the system to
derive the transfer function. Upon taking the Laplace transform, the transfer function obtained is:

s^2 * a - (mp + mc)*g / (mc*lp)*a = -km*kg/(r*Rm*mc*lp)*V

Equation 19.0

H(s) = - 19.55/ (s^2 – 73.22)

x’ = Ax + Bu

Equation 20.0

Equation 21.0

Y = Cx’ + Du

Equation 22.0

Equation 23.0

Using the ss2tf function in MATLAB, able to generate the num and denom. From the state space
equation, the transfer function is obtained with the num and denom values and using the bode plot and
rlocus function, able to create the appropriate plots that shows the resultant findings.

>> A = [ 0 1; 73.22 0];


>> B = [0; -19.55];
>> C = [1 0];
>> D = [0];
>> [num, denom] = ss2tf(A,B,C,D)

8
num =

0 0 -19.5500

denom =

1.0000 -0.0000 -73.2200

>> H = tf (num,denom)

Transfer function:
-19.55
--------------------------
s^2 - 1.776e-015 s - 73.22

Figure: 2.0 Transfer Function G(s) root locus & bode plot

The first pole of the simplified system located on the root locus plot causes instability as it is placed on
the right hand plane of the x-axis. The system is able to be stabilized when open-loop transfer function
is able to reach a -180 degree phase angle in the bode plot and by introducing a PID controller or a lead
controller, the ability to potentially create a stable system is therefore possible.

The idea behind introducing a lead controller is to reduce oscillation by having the zero from the lead
pull the pole from the right hand plane to the left. This occurs when parameter K is increased thus
making the system stable. The ideal case for reducing oscillation is to have the zero as far as possible
from the pole on the right hand plane by introducing a large K to draw the pole in.

9
METHODS & RESULTS
PID Controller
The PID controller is used mainly to eliminate the steady-state error that exists within the system. This
is the difference taken between the desired output and experimental output value. The idea of the PID
controller is that by having a higher proportional term creates a faster response at the expense of
system stability.

The integral term would correct any steady-state error that would occur as it will try to ensure a correct
tracking of the reference angle. The tradeoff is that by having a higher integral control term, there exists
the chance to create oscillations that may put the system in an unstable state. The derivative term’s
purpose is used to smooth out changes in error over time. Having the PID controller before the
simplified model in the feedback system allows for the transfer function to be calculated.

K(s) = s*Kd + (1/s)*Ki + Kp

Equation 24.0

G’(s) = KG / (1 + KG) = -19.55(s^2*Kd + s*Kp + Ki) / (s^3 – 19.55*Kd*s^2 – (73.22 + 19.55*Kp)*s – 19.55

Equation 25.0 – simplified transfer function

Now able to set Kd and Ki to be both zero in order to apply the closed loop Ziegler-Nichols test. The Kp
value is adjusted accordingly until the system response becomes oscillatory and the oscillation
amplitude becomes constant.

G(s) = -19.55*Kp / (s^2 – (73.22 + 19.55Kp)

Equation 26.0

This brings the system to the boarder of stability and instability as the system oscillates when Kp and Ku
equate to -3.6.

The Kp’s purpose is to smooth out the transient response by adjusting the rise time of the system.
Along with the Ki, this parameter provides for an integral gain that was previously discussed to cancel
the steady-state error as much as possible in the system. Lastly with the Kd value contain the
percentage overshoot of the system. This is related to the damping ratio of the system and will
lengthen the transient response large Kd values.

The requirement of having all three parameters but with the right relative combination may potentially
create a more stable system. The procedure and strategy in mind for tuning the system is to have the
Kp value generate a step response from the system that is equal to 1 therefore adjust Kp accordingly.
Need to decrease the percentage overshoot and the settling time and thereby need to tune the right
combination of Kd and Ki respectively. Continuously adjusting and analyzing the system generated K
values produce: Kp = -265; Ki = -46; Kd = -65

10
The initial values of Kp, Ki, and Kd may be then be determined from the step response:

Figure 3.0

The transfer functions bode plot shows that the phase angle never reaches -180 degrees and thus
indicates that the gain/phase margins are not realizable as KG(s) does not equate to 1 when the G(s) is
less than -180. To main objective was to follow and track the responses and the ZN method did not
allow for this and thus is not a good tool for the PID. Also by using the ZN method creates exaggerated
gains and overshoots that are difficult to control which defeats the purpose of including the PID
controller. Fine tuning the three variables in a PID system was difficult to achieve balancing in ZN case.

Lead Controller
The frequency response of an unstable system may be improved by using a lead controller in order to
incorporate the pole-zero pair into the transfer function. In the derivation of the mathematical model,
we see that the following equation governs the angular acceleration of our system.

Equation 27.0 - Angular Acceleration of the system

The velocity parameter is set to zero in order set and motivate the implementation of the lead
controller. With this setting, the assumption is that when the pendulum of the system is balanced, the
cart will also be stationary and thus the term related to the cart may be eliminated. With this
motivation, the cart’s parameter will not be present to affect the controller’s ability to stabilize the
system. The angular acceleration with this assumption is now found to be:

11
Equation 18.0 - Simplified Angular Acceleration Equation

The transfer function is now derived by taking the Laplace transform of the system to get following
equation.

Equation 29.0 - Transfer Function of the angle with respect to velocity

This is slightly different than the model we have due to the sign on the C1 as it has a negative sign placed
in front of it, this however does not hold for our model. The dynamic equations derived were taken
under the consideration of the direction of the cart moving in the positive direction as well as the
positive angle. This is the opposite scenario as the angle is supposed to be taken in the opposite
direction of the carts motion and therefore a sign change placed on C1. The equation indicates that the
direction of angle supposed to be taken in the opposite direction as an indicated by the equation.

Figure 4.0 - Root Locus of G(s)

The transfer function from equation G(s) can now graphed to show the root locus plots, above. Again
the plot reveals that this is an unstable system due to the pole being on the right hand side of the plane.
A lead controller is used in this case to stabilize the overall system by shifting the pole on the right hand
place over to the left and thus achieving the ideal case.

The general transfer function of a lead controller is,

12
Equation 2 General Lead Controller Equation

Where σa and σb are positive, real numbers. The root locus of the open loop gain D*G to be the
following:

Figure 5.0 - Root locus : |σa|< |σo|< |σa|

Observed that by introducing a lead controller into the system, the pole on the right hand side is pulled
towards the left by the leading zero as K increases, thus making this system stable. Ideally want the zero
to be as far as possible from the pole on the right hand side plane in order to reduce oscillation. We will
then need a large K to draw that pole in.

Solving for parameter K in the lead controller equation was done using the RLOCFIND function through
MATLAB and selecting pole location points on the root locus plot. The strategy is to choose a point far
from the origin in order to avoid oscillations. This got a gain of K=370.

Design strategy for the Lead Controller:

1. Place the zero and pole around the crossover frequency


2. Find the value of the gain, k, for which our unstable right hand plane pole will cross over to the
left hand plane
3. Investigate the optimal value for k balancing the trade-of between a faster response by moving
the unstable pole further into the LHP and therefore farther from the origin. This will have the
remaining system poles drift apart in the complex plane as k increases. Rlocfind() function in
MATLAB allows for defining desired pole position and calculating the gain required to obtain the
outcome.

13
The experimental gain K used is 1250 which deviates from the theoretical K = 370.78 obtained. This
large difference is mainly due to the controller compensating for external factors such as over-coming
mechanical friction, heat loss, drag effects, etc.

Taking a holistic approach to obtaining the experimental K, the 1250 value presented the least amount
of oscillation to the system. To create a stable system, the lead controller’s zero was set at 7.5 while the
pole was positioned on the left hand plane at -13. The large experimental K thus pulls the pole from the
right hand plane over to the left. The observation is that as K increases, less oscillation in the angle plot
is present. The experimental data obtained from this setup is presented:

Figure: 6.0 – Lead Controller

The required behaviour is obtained by placing the pole and zero around the natural stable pole of the
plant. The natural unstable pole is pulled towards the controller’s zero, with the other stable poles
coming together and drift into the imaginary plane. Like to place the unstable pole as close as possible
to the zero, while maintaining a suitable gain. Want the pole at to move towards the left half plane.
Thus we must place a zero for it to tend to. Also would like the tragectory of the imagineary poles to be
as far away from the imaginary axis as possible. This may be achieved by strategically placing the pole
and zero. Whereas the former condition can be satisfied by using rlocfind() and setting the desired pole
the zero.

14
DISCUSSION

The lead controller was able to stabilize the cart for a few seconds. The first step in designing the
controller in the root locus scheme was to simplify the state model to a single transfer function. This
was done by assuming the position of the cart remained unchanged so to remove the variable in
association. In reality this was not the case as there was instability in the cart position due to signal
pulses. The lead controller displays the potential of having the inverted pendulum balancing on the cart
but more tools need to be incorporated to have a complete stable system.

Since our only objective from the lead controller is to stabilize the system, we can build the system in
the root locus by placing pole and zero at the appropriate locations. The lead controller performs better
in terms of stability properties as the angle exists in a limited bound.

The PID controller was unable to reach the required phase margin for it to be stable. With the bode
function in MATLAB, the gain and phase margins are results that show the stability property of the
system in test. The greater the phase margin the more stable the system is.

There were continuous tradeoffs in design and parameters for both methods and a less holistic
approach next time would save both time and energy. Understanding more on the parameter effects on
system variables would help in defining optimal results.

15