an n-link inverted pendulum modelingthe derivation of general equation using maple and an example...

8
An n-Link Inverted Pendulum Modeling ALEXANDER GMITERKO (SK) [email protected] MARTIN GROSSMAN (SK) [email protected] ABSTRACT In this article is the automatized procedure for deriving of n-link inverted pendulum motion equations presented. Example of 2 link inverted pendulum is included. The LQR algorithm using Maple input equations is proposed. Also the comparison between SimMechanics and Simulink is included. KEYWORDS pendulum, n-link, Maple, Simulink, chaos, SimMechanics. INTRODUCTION The inverted pendulum has become a standard benchmarking problem. At the depart- ment of Applied Mechanics and Mechatronics, we have decided to build single, double and later triple inverted pendulum. In most of the publications [1], [2], [3], [4], we see that authors use already derived equations or derive them for each case of a single, double or triple pendulum system. Nevertheless, there is a lack of general equation for the n-link pendulum. For this pur- pose, we decided to derive and automatize the process of generation of this general equation. It turned out that it was an invaluable help for us, in time of building the in- verted pendulum model in Matlab and Simulink. This paper is divided into three parts. In the first part, the geometric model is shown. In the second part will be introduced the derivation of general equation using Maple and an example will be presented. In the last part, we discuss the further possibilities, using Maple and other symbolic math- ematical software. By its mean, hopefully one gets better understanding of behavior these systems (non-minimal phase type system). PENDULUM’S GEOMETRY The basic assumptions are: Pendulum movement is in E 2 (plane). Cart and links are rigid homogeneous bodies (RBD rigid body dynamics). Joints with or without friction, but no compliance. Links are cylinders with variable lengths and masses. In the Table 1 are listed all variables and constants used in the model. From the il- lustration at the Fig. 1, we see that the n-link inverted pendulum consists of n links connected with the revolute joints. The cart motion is allowable only in x direction by translational joint. We decided not to picture the forces, since their implementation will be very straightforward using Lagrange-Euler formula. Instead, the angles between the links (which are actually measured by sensors), the angles between link and its rotation angle (u i ) from vertical position were chosen. This is just for more clear derivation. Acta Mechanica Slovaca 13 (3): 22-29, 2009 DOI: 10.2478/v10147-010-0043-z 22 VOLUME 13, No. 3, 2009

Upload: others

Post on 19-Nov-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: An n-Link Inverted Pendulum Modelingthe derivation of general equation using Maple and an example will be presented. In the last part, we discuss the further possibilities, using Maple

An n-Link Inverted Pendulum ModelingALEXANDER GMITERKO (SK) [email protected] GROSSMAN (SK) [email protected]

ABSTRACTIn this article is the automatized procedure for deriving of n-link inverted pendulummotion equations presented. Example of 2 link inverted pendulum is included. TheLQR algorithm using Maple input equations is proposed. Also the comparison betweenSimMechanics and Simulink is included.

KEYWORDSpendulum, n-link, Maple, Simulink, chaos, SimMechanics.

INTRODUCTIONThe inverted pendulum has become a standard benchmarking problem. At the depart-ment of Applied Mechanics and Mechatronics, we have decided to build single, doubleand later triple inverted pendulum. In most of the publications [1], [2], [3], [4], wesee that authors use already derived equations or derive them for each case of a single,double or triple pendulum system.Nevertheless, there is a lack of general equation for the n-link pendulum. For this pur-pose, we decided to derive and automatize the process of generation of this generalequation. It turned out that it was an invaluable help for us, in time of building the in-verted pendulum model in Matlab and Simulink. This paper is divided into three parts.In the first part, the geometric model is shown. In the second part will be introducedthe derivation of general equation using Maple and an example will be presented. Inthe last part, we discuss the further possibilities, using Maple and other symbolic math-ematical software. By its mean, hopefully one gets better understanding of behaviorthese systems (non-minimal phase type system).

PENDULUM’S GEOMETRYThe basic assumptions are:

• Pendulum movement is in E2 (plane).

• Cart and links are rigid homogeneous bodies (RBD rigid body dynamics).

• Joints with or without friction, but no compliance.

• Links are cylinders with variable lengths and masses.

In the Table 1 are listed all variables and constants used in the model. From the il-lustration at the Fig. 1, we see that the n-link inverted pendulum consists of n linksconnected with the revolute joints. The cart motion is allowable only in x direction bytranslational joint. We decided not to picture the forces, since their implementation willbe very straightforward using Lagrange-Euler formula. Instead, the angles between thelinks (which are actually measured by sensors), the angles between link and its rotationangle (ui) from vertical position were chosen. This is just for more clear derivation.

Acta Mechanica Slovaca 13 (3): 22-29, 2009DOI: 10.2478/v10147-010-0043- z

22 VOLUME 13, No. 3, 2009

Page 2: An n-Link Inverted Pendulum Modelingthe derivation of general equation using Maple and an example will be presented. In the last part, we discuss the further possibilities, using Maple

Acta Mechanica SlovacaJournal by Fakulty of Mechanical Engineering – Technical University of Košice

Acta Mechanica SlovacaJournal by Fakulty of Mechanical Engineering – Technical University of Košice

DYNAMIC BEHAVIOR AND EQU-

ATIONS

The standard method of deriving dynamical equa-tions of multi rigid body systems is using Euler-Lagrange formula. Its usage is relatively very easy,and for our purpose, it is especially adequate. Thismethod does involve only derivatives of time, speedand position and therefore is very suitable for man-ual and of course half-manual (by software usage)

procedure. We have though remember, that weare losing information about inner forces in joints.Other type of dynamical formulation will later ob-tain these.

The most important and only little more diffi-cult part of the procedure is obtaining the kineticand potential energy of the whole n-link pendulum.By inspection, we find that the kinetic energy andpotential energy of the system consisting of n linksand one cart is Ek(n) (1) and U(n) (2), respectively.

Ek(n) =12

m0

(d x(t)

d t

)2

+n

∑k=1

12

mk

[(d x(t)

d t−

k−1

∑i=1

li cos(ui(t))d ui(t)

d t− pk cos(uk(t))

d uk(t)d t

)2

+

(k−1

∑i=1

−li sin(ui(t))d ui(t)

d t− pk sin(uk(t))

d uk(t)d t

)2]+

n

∑k=1

12

Icgk

(d uk(t)

d t

)2

,

(1)

U(n) = −gn

∑k=1

(mk

(k−1

∑i=1

li cos(ui(t))+ pk cos(uk(t))))

. (2)

After deriving, the equation (1) and (2) we canput these in suitable form into any software allow-ing symbolic mathematical computation like Math-ematica, Maple, Maxima or even Matlab with sym-bolic toolbox (Maple 3.0) etc (Fig. 2). The nexteasy step is computing the Lagrangian L (3)

L = Ek(n)−U(n), (3)

and motion equations (4)

∂∂t

(∂∂ξ

L)− ∂

∂ξ(L) = Fξ, (4)

where ξ is generalized coordinate ( in our case x(t)or u(t)) and ξ is its time derivative. Fξ is gener-alized non-conservative force acting on generalizedcoordinate.

As an example, let us consider inverted pendu-lum consisting of 2 links. Then the L(2) would be(5) and the equations of motion are: (6), (7), (8)and (9) with external forces Fx (this could be inputforce acting on cart, friction of rail, damping, etc.).

L(2) =12

m0

(d x(t)

d t

)2

+12

m1

[(d x(t)

d t− p1 cos(u1(t))

d u1(t)d t

)2

+ p21 sin2(u1(t))

(d u1(t)

d t

)2]

+12

m2

[(d x(t)

d t− l1 cos(u1(t))

d u1(t)d t

− p2 cos(u2(t))d u2(t)

d t

)2

+(−l1 sin(u1(t))

d u1(t)d t

− p2 sin(u2(t))d u2(t)

d t

)2]

+12

Icg1

(d u1(t)

d t

)2

+12

Icg2

(d u2(t)

d t

)2

+g

[m1 p1 cos(u1(t))+m2

(l1 cos(u1(t))+ p2 cos(u2(t))

)].

(5)

23

Page 3: An n-Link Inverted Pendulum Modelingthe derivation of general equation using Maple and an example will be presented. In the last part, we discuss the further possibilities, using Maple

24 VOLUME 13, No. 4, 2009

Fig. 1: An n-link pendulum.

Table 1: Table of variables.

Variable description dimension

x0(t) x position of the cart m

x1...n(t) x position of the i-th link m

y1...n(t) y position of the i-th link m

u1...n(t) angle of i-th link with y axis rad

Icg1...n moment of intertia of i-th link to its center of gravity kg.m2

n number of links –

m0 mass of the cart kg

m1...n mass of the i-th link kg

l1...n length of the i-th link m

p1...ndistance of the gravity center of the i-th link (CGi)

mfrom its beginning

CGi center of gravity of the i-th link –

24 VOLUME 13, No. 3, 2009

Page 4: An n-Link Inverted Pendulum Modelingthe derivation of general equation using Maple and an example will be presented. In the last part, we discuss the further possibilities, using Maple

Acta Mechanica SlovacaJournal by Fakulty of Mechanical Engineering – Technical University of Košice

25

Fig. 2: Maple environment.

Fig. 3: Simulink LQR implementation.

Page 5: An n-Link Inverted Pendulum Modelingthe derivation of general equation using Maple and an example will be presented. In the last part, we discuss the further possibilities, using Maple

∂∂t

(∂L(2)

∂x

)− ∂L(2)

∂x= Fx. (6)

F(t)− cd x(t)

d t=m0

d2 x(t)d t2 +m1

d2 x(t)d t2 +m1 p1 sin(u1(t))

(d u1(t)

d t2

)2

−m1 p1 cos(u1(t))d2 u1(t)

d t2

+m2d2 x(t)

d t2 +m2l1 sin(u1(t))(

d2 u1(t)d t2

)2

−m2l1 cos(u1(t))d2 u1(t)

d t2

+m2 p2 sin(u2(t))(

d2 u2(t)d t2

)2

−m2 p2 cos(u2(t))d2 u2(t)

d t2 .

(7)

−m1 p1 cos(u1(t))d2 x(t)

d t2 +m1 p21

d2 u1(t)d t2 −m2l1 cos(u1(t))

d2 x(t)d t2

−m2l1 cos(u1(t))p2 sin(u2(t))(

d u2(t)d t

)2

+m2l1 cos(u1(t))p2 cos(u2(t))d2 u2(t)

d t2 +m2l21

d2 u1(t)d t2

+m2l1 sin(u1(t))p2 cos(u2(t))(

d2 u2(t)d t2

)2

+m2l1 sin(u1(t))p2 sin(u2(t))d2 u2(t)

d t2 + Icg1d2 u1(t)

d t2

+gm1 p1 sin(u1(t))+gm2l1 sin(u1(t)) = 0.

(8)

Therefore, with this procedure we can derive alln equations of motion.

Next step would be solving these equations.These equations are nonlinear differential equationsand the Matlab was used to find numerical solu-tion. Already the double inverted pendulum couldbe considered as the chaotic system, and thus it is

important to bear in mind this behavior during theprocess of finding solution.

There has been extended work done, regard-ing comparison of numeric integrators used forthis chaotic type problem using Matlab, Maple andMSC.ADAMS. We will compare these results withreal physical model.

−m2 p2 cos(u2(t))d2 x(t)

d t2 −m2 p2 cos(u2(t))l1 sin(u1(t))(

d u1(t)d t

)2

+m2 p2 cos(u2(t))l1 cos(u1(t))d2 u1(t)

d t2 +m2 p2 sin(u2(t))l1 cos(u1(t))(

d u1(t)d t

)2

+m2 p2 sin(u2(t))l1 sin(u1(t))d2 u1(t)

d t2 +m2 p22

d2 u2(t)d t2 + Icg2

d2 u2(t)d t2 +gm2 p2 sin(u2(t)) = 0.

(9)

SYMBOLIC COMPUTATION, MAPLEIn our experience Maple have many advantages butalso some disadvantages. It has relatively very sim-ple interface allowing even the beginners quick andimpromptu problem solving.

During our work we have found out, that the

version 11, have problems with handling more then3 inner sums with other then latin-2 (not Greek) let-ters and subscripts. It is also considerably slowerthen the Mathematica 5.2 (tried the same problemsolving). In addition, graphics quality of implicitequation is not satisfactory.

26 VOLUME 13, No. 3, 2009

Page 6: An n-Link Inverted Pendulum Modelingthe derivation of general equation using Maple and an example will be presented. In the last part, we discuss the further possibilities, using Maple

Acta Mechanica SlovacaJournal by Fakulty of Mechanical Engineering – Technical University of Košice

27

m2 p2d2 x(t)

d t2 +m2l1 p2d2 d1(t)

d t2 −gm2 p2d2(t)+(

m2 p22 + Izz2

)d2 d2(t)d t2 = 0

(m1 p1 +m2l1

)d2 x(t)d t2 +(−gm1 p1 −gm2l1)d1(t)+

(m1 p2

1 +m2l21 + Izz1

)d2 d1(t)d t2

+m2l1 p2d2 d2(t)

d t2 = 0

cd x(t)

d t+

(m0 +m1 +m2

)d2 x(t)d t2 +

(m1 p1 +m2l1

)d2 d1(t)d t2 +m2 p2

d2 d2(t)d t2 = 0.

(10)

Fig. 5: Cart travel; K changed using optimization.Fig. 4: Cart travel; K generated from Ricatti eq.

LQR CONTROLER DESIGN, FOR

STABILIZING THE DOUBLE IN-

VERTED PENDULUM IN UPRIGHT

POSITION

The motion equations of DIP were derived in Mapleand linearized in upright position (10) in Maple.

From (10) the A, B, C, D matrices were de-rived using Maple. After deriving state matrices,the LQR K matrix coefficients were calculated withMatlab.

These coefficient are already able to stabilizeDIP but with this approach we do not include otherobjectives and constraint as time, maximal travelin x direction or other. Therefore for the first andrough estimate of K constants we used optimiza-tion toolbox in Simulink to decrease travel of cartin x direction. This was achieved by constrainingthe maximal travel in x direction and optimizing all6 constants in K matrix.

After this parametric optimization using gradi-ent method, we were able to decrease the travel by50 % and keep the power consumption under ac-ceptable level.

SIMULINK VS. SIMMECHANICS,

CONTROL LOOP SIMULATIONThe control loop was implemented with 2 differentapproaches.

First, was using Simulink (Fig. 3). We trans-lated nonlinear equations to Simulink by means ofF(u) function blocks. Then the computed K ma-trix was implemented and optimization of K matrixparameters was performed.

The second approach, we modeled the invertedpendulum using SimMechanics, again use the gen-erated K matrix a perform optimization.

After successful stabilization in both cases, weimplemented noise disturbance in joints, wind noiseforce air friction and cart friction and damping.

On Fig. 4 and Fig. 5, we can see decrease ofcart travel by using optimization and changing co-efficients of K.

CONCLUSIONSymbolic computation software is already fewyears becoming standard tool, helping to solve en-gineering problems. The typical commercial prod-ucts are Maple and Mathematica.

The student version of Maple was used. Duringwriting this article we have come across the free

Page 7: An n-Link Inverted Pendulum Modelingthe derivation of general equation using Maple and an example will be presented. In the last part, we discuss the further possibilities, using Maple

Maxima, which we will try and possibly move allour computation to its platform.

After implementation of LQR algorithm usingSimulink and SimMechanics we can conclude thatSimMechanics gave exactly same results as stan-dard block implementation in Simulink. In factthe SimMechanics building procedure was very fastand straightforward. By using SimMechanics wegained option of Animation.

On the other hand, the simulations in SimMe-chanics were about 10 times slower. Beside that,the equations of DIP are still need for computingthe LQR K matrix. After our experience, the Sim-Mechanics is a good choice for very complicatedmodels, were deriving of equations could take longtime, in other cases we would suggest using theSimulink or Matlab itself.

ACKNOWLEDGEMENTThe authors would like to thank to Slovak GrantAgency - project VEGA 1/0454/09 ”Research onmechatronic systems imitating snake locomotion inconfined and variable area” and VEGA 1/0201/08”Research of structures and behavior of the mecha-tronics mobile engineering system on the organlevel and construction item level in order to prop-erties improvement of the mobile engineering sys-tem”.

REFERENCES[1] Niemann H., Poulsen J.K., Analysis and De-

sign of Controllers for a Double Inverted Pen-dulum, Proceedings of the American ControlConference, Denver, Colorado, USA, June 4-6, 2003.

[2] Spong M.W., The Swing Up Control Prob-lem for the Acrobot, IEEE Control Systems,February 1995, p. 49–55.

[3] Stimac A.K., Standup and Stabilization of theInverted Pendulum, MIT, master thesis, 1999.

[4] Zhong W., Rock H., Energy and PassivityBased Control of the Double Inverted Pendu-lum on a Cart, Proceedings of the 2001 IEEEInternational Conference on Control Applica-tions, Mexico City, Mexico, September 5 - 7,2001.

28 VOLUME 13, No. 3, 2009

Page 8: An n-Link Inverted Pendulum Modelingthe derivation of general equation using Maple and an example will be presented. In the last part, we discuss the further possibilities, using Maple

Acta Mechanica SlovacaJournal by Fakulty of Mechanical Engineering – Technical University of Košice

29