• Embed Doc
  • Readcast
  • Collections
  • 1
    CommentGo Back
Download
 
Control of an Inverted Pendulum
 Johnny Lam
Abstract.
The balancing of an inverted pendulum bymoving a cart along a horizontal track is a classic problemin the area of control. This paper will describe two methodsto swing a pendulum attached to a cart from an initialdownwards position to an upright position and maintain thatstate. A nonlinear heuristic controller and an energycontroller have been implemented in order to swing thependulum to an upright position. After the pendulum isswung up, a linear quadratic regulator state feedback optimal controller has been implemented to maintain thebalanced state. The heuristic controller outputs a repetitivesignal at the appropriate moment and is finely tuned for thespecific experimental setup. The energy controller adds anappropriate amount of energy into the pendulum system inorder to achieve a desired energy state. The optimal statefeedback controller is a stabilizing controller based on amodel linearized around the upright position and is effectivewhen the cart-pendulum system is near the balanced state.The pendulum has been swung from the downwardsposition to the upright position using both methods and theexperimental results are reported.
1.
 
INTRODUCTION
The inverted pendulum system is a standard problem in thearea of control systems. They are often useful todemonstrate concepts in linear control such as thestabilization of unstable systems. Since the system isinherently nonlinear, it has also been useful in illustratingsome of the ideas in nonlinear control. In this system, aninverted pendulum is attached to a cart equipped with amotor that drives it along a horizontal track. The user isable to dictate the position and velocity of the cart throughthe motor and the track restricts the cart to movement in thehorizontal direction. Sensors are attached to the cart and thepivot in order to measure the cart position and pendulum joint angle, respectively. Measurements are taken with aquadrature encoder connected to a MultiQ-3 generalpurpose data acquisition and control board.Matlab/Simulink is used to implement the controller andanalyze data.The inverted pendulum system inherently has twoequilibria, one of which is stable while the other is unstable.The stable equilibrium corresponds to a state in which thependulum is pointing downwards. In the absence of anycontrol force, the system will naturally return to this state.The stable equilibrium requires no control input to beachieved and, thus, is uninteresting from a controlperspective. The unstable equilibrium corresponds to a statein which the pendulum points strictly upwards and, thus,requires a control force to maintain this position. The basiccontrol objective of the inverted pendulum problem is tomaintain the unstable equilibrium position when thependulum initially starts in an upright position. The controlobjective for this project will focus on starting from thestable equilibrium position (pendulum pointing down),swinging it up to the unstable equilibrium position(pendulum upright), and maintaining this state.
2.
 
MODELLING
A schematic of the inverted pendulum is shown in Figure 1.
Figure 1. Inverted Pendulum Setup
A cart equipped with a motor provides horizontal motion of the cart while cart position,
 p
, and joint angle,
θ 
,measurements are taken via a quadrature encoder.By applying the law of dynamics on the invertedpendulum system, the equations of motion are:
( )( ) ( ) ( )
22222
sinsincoslgcos
 )
θ 
θ 
m
θ θ 
 Lm p Rr 
 Κ 
 K  Rr 
 Κ 
 K   L
θ 
mM - p
 p p g m g m p
&&&&
+ = ⎠ ⎞⎝ ⎛ 
(1)
( )( ) ( ) ( )( )
,cossincossincos
22222
  ⎠ ⎞⎝ ⎛  = ⎠ ⎞⎝ ⎛ 
 p Rr 
 Κ 
 K  Rr 
 Κ 
 K 
θ θ θ 
 L )
θ 
l( m 
θ 
 g 
θ 
m L -
θ 
 g m g m  p p
&&&&
(2)where
m
c
is the cart mass,
m
 p
is the pendulum mass,
 I 
is therotational inertia,
is the half-length of the pendulum,
 R
isthe motor armature resistance,
is the motor pinion radius,
 K 
m
is the motor torque constant, and
 K 
 g 
is the gearbox ratio.Also, for simplicity,
mm I  Lmm
 p p pc
2
+=+=
(3)and note that the relationship between force, F, and voltage,V, for the motor is:
 p Rr 
 Κ 
 K  Rr 
 Κ 
 K  F 
 g m g m
&
222
 =
. (4)Let the state vector be defined as:(5)Finally, we linearize the system about the unstableequilibrium (0 0 0 0)
T
. Note that
θ 
 
= 0 corresponds to the
( )
.
θ θ 
 p x
=
 p
&&
 
pendulum being in the upright position. The linearization of the cart-pendulum system around the upright position is:(6)
Cx y BV  Ax x
=+=
&
 where(7)
.0100 0001 1010
 ⎠ ⎞⎝ ⎛ = ⎠ ⎞⎝ ⎛  ⎠ ⎞⎝ ⎛ =
 ; Rr  K  K m L Rr  K  K  Lm
 B
 g m p g m p
 Finally, by substituting the parameter values that correspondto the experimental setup:(8).This system will allow us to design a controller to balancethe inverted pendulum around the point of linearization.
3
.
STABILIZING CONTROLLER DESIGN
The controller design approach for this project is broken upinto two components. The first part involves the design of an optimal state feedback controller for the linearized modelthat will stabilize the pendulum around the upright position.The second part involves the design of a controller thatswings the pendulum up to the unstable equilibrium. Whenthe pendulum approaches the linearized point, the controlwill switch to the stabilizing controller which will balancethe pendulum around the upright position.The state feedback controller responsible forbalancing the pendulum in the upright position is based on aLinear Quadratic Regulator (LQR) design using thelinearized system. In a LQR design, the gain matrix K for alinear state feedback control law
u = -Kx
is found byminimizing a quadratic cost function of the form, (9)
∫ 
+=
0
 Ru(t)dt u(t)Qx(t) x(t) J 
where
Q
and
 R
are weighting parameters that penalizecertain states or control inputs.The weighting parameters chosen in the design of the optimal state feedback controller are:
 ⎠ ⎞⎝ ⎛  ⎠ ⎞⎝ ⎛  ⎠ ⎞⎝ ⎛ =
0101000 0100010
222222
m L g  Rr  K  K m L Lm L gm Rr  K  K  Lm
 p g m p p p g m p
 A
 
.11000 01000000 0010 00010000
= ⎠ ⎞⎝ ⎛ =
 RQ
(10)Based on this design, the controller gain matrix for thelinearized system is:
( )
5668306568180444864091699
.-.-.- .- K 
=
. (11)By using this
 K 
and the control law
u = -Kx
, the system isstabilized around the linearized point (pendulum upright).Since this control law is based on the linearized system, thestate feedback optimal controller is only effective when thependulum is near the upright position.
4. STATE ESTIMATION
For the inverted pendulum experimental setup, not all thestate variables are available for measurement. In fact, onlythe cart position,
p
, and the pendulum angle,
θ 
, are directlymeasured. This means that the cart velocity and thependulum angular velocity are not immediately available foruse in any control schemes beyond just stabilization. Thus,an observer is relied upon to supply accurate estimations of the states at all cart-pendulum positions.A linear full state observer can be implementedbased on the linearized system derived earlier. Thisobserver is simple in design and provides accurateestimation of all the states around the linearized point. Theobserver is implemented by using a duplicate of thelinearized system dynamics and adding in a correction termthat is simply a gain on the error in the estimates. Theobserver gain matrix is determined by an LQR designsimilar to that used to determine the gain of the optimal statefeedback stabilizing controller. In this case, the weightingparameters are chosen to be:(12)
.10011000 01000000 0010 00010000
 ⎠ ⎞⎝ ⎛ = ⎠ ⎞⎝ ⎛ =
 RQ
 Based on this design, the observer gain matrix is:
=
  y
010
 ⎠ ⎞⎝  ⎠ ⎞⎝ ⎛  ⎠ ⎞⎛ + ⎞⎝ ⎛  ⎞⎛ = ⎠ ⎞
θ θ 
 p..
θ 
 p p....
θ 
 p p
&&&&&&&&&&
00001 330393061231000 004314150 0010
⎛ 
 p
⎝  ⎠ ⎠⎝ ⎝ 
θ θ 
8031370
⎛ 
 
 . (13)
 ⎠ ⎞⎝ ⎛ =
0490999900150 0009999
.... L
 Since the linear full state observer is based on thelinearized system, it is only effective in estimating the statevariables when the cart-pendulum system is near the uprightposition. Thus, a low-pass filtered derivative is used toestimate the two unmeasured states, cart velocity andpendulum angular velocity, when the system is not close tothe unstable equilibrium. This method approximates thecart velocity and pendulum angular velocity by using afinite difference and then passing it through a low-passfilter. The following filter is chosen for this estimationmethod:
5050
+=
 s sG(s)
. (14)The problems with such a method are that it introducessome delay and has a gain that is slightly less than one. Thestate estimates obtained from the filtered derivative,however, are reasonably accurate for the swing-upcontrollers implemented in this paper.
5
.
SWING-UP CONTROLLER DESIGN
Two different control schemes were implemented to swingthe pendulum from the downwards position to the uprightposition. The first is a heuristic controller that provides aconstant voltage in the appropriate direction and, thus,drives the cart back and forth along the track repeatedly. Itwill repeat this action until the pendulum is close enough tothe upright position such that the stabilizing controller canbe triggered to maintain this balanced state. The secondscheme is an energy controller that regulates the amount of energy in the pendulum. This controller inputs energy intothe cart-pendulum system until it attains the energy statethat corresponds to the pendulum in the upright position.Similar to the heuristic control method, the energy controlmethod will also switch to the stabilizing controller whenthe pendulum is close to the upright position. The switchthat triggers the stabilizing controller in both cases isactivated when the pendulum is within 5° of the uprightposition and the angular velocity is slower than 2.5 radiansper second.
Heuristic Controller
The heuristic controller is a logic-based control design thatdetermines the direction and the moment in time the cartshould move depending on the state of the system. Aspecific voltage gain is applied to the cart motor based onresults from repeated experimentation. This controller willmake the cart drive forward or back whenever the pendulumcrosses the downwards position and depending on thedirection that the pendulum is swinging when it reaches thedownwards position.The logic-based control design is completelydependent on the pendulum angle, one of the availablemeasured state variables. The control scheme will changethe direction of the cart movement whenever the pendulumangle crosses the downwards position. Since this controldesign is based solely on the pendulum angle, thedownwards position is the optimal moment in time to addenergy to the pendulum by moving the cart in theappropriate direction. The direction the cart moves is theopposite sign of the pendulum angle immediately after itcrosses the downwards position. When the direction of thecart movement is determined, a constant voltage gain isapplied to the cart motor in that same direction until thependulum returns to the downwards position. This controlscheme will effectively move the cart back and forth alongthe track repeatedly until the pendulum swings close enoughto the upright position.It is important to note that the nature of this controlscheme is that the same cart movement is applied regardlessof whether the pendulum is above or below the horizontalaxis (since the sign of the pendulum angle remains thesame). The nature of the cart-pendulum system, however, isthat the same cart movement that once added energy to thependulum while it was below the horizontal axis nowactually takes away energy from the pendulum. Eventually,the pendulum will reach a point where it can add no moreenergy to the pendulum system but it has yet to buildenough energy to reach the upright position. To avoid thisphenomenon, a switch has been implemented that changesthe voltage input to the cart motor to 0 when the pendulumis 135° from the downwards position. As a result, the cartwill not move to take energy away from the pendulumsystem when the pendulum is higher than 135°. This willallow the pendulum to simply return to the downwardsposition without losing anymore energy. When thependulum crosses the downwards position again, the logic-based controller will be able to add more energy to thependulum until it eventually approaches the uprightposition.The voltage gain of this control scheme isdetermined by repeated experimentation. There is a directcorrelation between the time it takes to swing the pendulumto its upright position and the magnitude of the voltage gain.A gain that is too high, though, may make the pendulumapproach the upright position with too high a velocity and,thus, the stabilizing controller will be unable to balance thependulum. On the other hand, a gain too low may notprovide enough energy to the pendulum so that it can reachthe upright position. Also, the reliability of the controller inperforming the task varies depending on the gain selected.Thus, repeated experimentation is required to finely tune thegain so that the pendulum approaches the upright positionwith just the right amount of velocity and in a reasonableamount of time with a high success rate.
Energy Controller
The swinging up of a pendulum from the downwardsposition can also be accomplished by controlling the amountof energy in the system. The energy in the pendulumsystem can be driven to a desired value through the use of feedback control. By adding in enough energy such that itsvalue corresponds to the upright position, the pendulum canbe swung up to its unstable equilibrium. When thependulum is close to the upright position, the stabilizingcontroller designed earlier can be triggered to catch thependulum and balance it around the unstable equilibrium.
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
11 / 25 / 2010This doucment made it onto the Rising List!
You must be to leave a comment.
Submit
Characters: ...