symbolic lagrangian multibody dynamics - … lagrangian multibody dynamics ... lagrangian mechanics...

9
Symbolic Lagrangian Multibody Dynamics Brian Guenter Microsoft Research Sung-Hee Lee Honda Research Institute Abstract Symbolic Lagrangian formulations of the equations of mo- tion of tree structured constrained mechanical systems have the potential to be both more efficient and more numerically robust than formulations which use nonlinear kinematic con- straint equations. We derive a simple recursive factorization of the Lagrangian equations of motion which, along with our extended implementation of the D* symbolic differentiation algorithm, yields empirically measured O(n) inverse dynam- ics and O(n 3 ) forward dynamics. Complex kinematic con- straints such as point on surface, point on curve, and surface on surface are easily handled by the new algorithm. Numer- ous examples demonstrate the wide range of mechanical sys- tems the algorithm can be applied to. CR Categories: I.3.7 [COMPUTER GRAPHICS ]: Three- Dimensional Graphics and Realism—Animation 1 Introduction Lagrangian mechanics is a reformulation of classical me- chanics which is particularly useful for modeling constrained mechanical systems. For tree structured systems, with holo- nomic constraints that can be expressed as differentiable parametric functions of the generalized coordinates 1 , it is al- ways possible to find a set of symbolic differential equations for the Lagrangian equations of motion. By contrast, non- Lagrangian formulations require differential equations and nonlinear algebraic equations (abbreviated DAE) [Ascher and Petzold 1998] to enforce kinematic constraints. Solv- ing DAE systems is considerably more difficult than solving differential equations alone. However, the difficulty of computing the complex derivatives email:[email protected] email:[email protected] 1 This may sound restrictive but a wide variety of mechanisms can be modeled this way, as we will show in Section 5. in the Euler-Lagrange equations 2 have prevented wide accep- tance of the approach [Herbert Goldstein 2001]. To over- come this difficulty, researchers have manually derived ef- ficient differentiation methods of the Euler-Lagrange equa- tions (see [Featherstone and Orin 2000] for an overview), but most algorithms assume a small set of simple constraint types such as revolute or prismatic joints and thus, not surprisingly, most of the current dynamics packages support only simple types of constraints. 3 Notably, an improved version of the Ar- ticulated Body Algorithm [Featherstone 1987] supports gen- eral scleronomic constraints, but the complexity of the algo- rithm makes it difficult to understand and implement [Baraff 1996]. If arbitrary parametric kinematic constraints are al- lowed then computing the derivatives is still problematic. Computer graphics researchers have used symbolic or auto- matic differentiation to compute derivatives of complex func- tions [Kass 1992; Cohen 1992; Popovi´ c et al. 2000; Grin- spun et al. 2003]. In this paper, we create symbolic equa- tions of motion by using symbolic differentiation. Specifi- cally, we derive a simple recursive factorization of the La- grangian equations of motion which, along with our extended implementation of the D* symbolic differentiation algorithm [Guenter 2007], yields empirically measured O(n) inverse dynamics and O(n 3 ) forward dynamics. (Note to review- ers: D* symbolic differentiation software will be available to public in late 2009.) In mechanics, symbolic or automatic differentiation have been employed mostly to augment multibody dynamics such as computing the derivatives of constraint equations or the mass matrix [Shi and McPhee 2000; Olsson et al. 2005; Samin and Fisette 2003]. Not only is symbolic differenti- ation used for dynamics simulation, but it is also used for linearizing the equations of motion and optimizing design parameters. However, for the core simulation of the dynam- ics, they employed existing, manually derived dynamics al- gorithms that do not require symbolic differentiation. In contrast, we derive symbolic equations of motion by us- ing symbolic differentiation. [Villard and Arnaldi 1996] ap- plied symbolic differentiation to compute the equations for the constraint forces, which are numerically calculated using either the penalty method or the Lagrange mutltiplier tech- 2 For tree structured systems naïve direct approaches for evaluating these derivatives can have computational complexity as high as O(n 4 ), where n is the number of degrees of freedom of the system. 3 SD/FAST [Hollars et al. 1994], a multibody dynamics package based on Lagrangian formulation, supports complex, user-defined constraints only by using the Lagrange multipler technique, which is not related to our symbolic Lagrangian approach.

Upload: vuthuy

Post on 26-Jun-2018

256 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Symbolic Lagrangian Multibody Dynamics - … Lagrangian Multibody Dynamics ... Lagrangian mechanics is a reformulation of classical me-chanics which is particularly useful for modeling

Symbolic Lagrangian Multibody Dynamics

Brian Guenter∗

Microsoft ResearchSung-Hee Lee†

Honda Research Institute

Abstract

Symbolic Lagrangian formulations of the equations of mo-tion of tree structured constrained mechanical systems havethe potential to be both more efficient and more numericallyrobust than formulations which use nonlinear kinematic con-straint equations. We derive a simple recursive factorizationof the Lagrangian equations of motion which, along with ourextended implementation of the D* symbolic differentiationalgorithm, yields empirically measured O(n) inverse dynam-ics and O(n3) forward dynamics. Complex kinematic con-straints such as point on surface, point on curve, and surfaceon surface are easily handled by the new algorithm. Numer-ous examples demonstrate the wide range of mechanical sys-tems the algorithm can be applied to.

CR Categories: I.3.7 [COMPUTER GRAPHICS ]: Three-Dimensional Graphics and Realism—Animation

1 Introduction

Lagrangian mechanics is a reformulation of classical me-chanics which is particularly useful for modeling constrainedmechanical systems. For tree structured systems, with holo-nomic constraints that can be expressed as differentiableparametric functions of the generalized coordinates1, it is al-ways possible to find a set of symbolic differential equationsfor the Lagrangian equations of motion. By contrast, non-Lagrangian formulations require differential equations andnonlinear algebraic equations (abbreviated DAE) [Ascherand Petzold 1998] to enforce kinematic constraints. Solv-ing DAE systems is considerably more difficult than solvingdifferential equations alone.

However, the difficulty of computing the complex derivatives

∗email:[email protected]†email:[email protected]

1This may sound restrictive but a wide variety of mechanisms can bemodeled this way, as we will show in Section 5.

in the Euler-Lagrange equations2 have prevented wide accep-tance of the approach [Herbert Goldstein 2001]. To over-come this difficulty, researchers have manually derived ef-ficient differentiation methods of the Euler-Lagrange equa-tions (see [Featherstone and Orin 2000] for an overview), butmost algorithms assume a small set of simple constraint typessuch as revolute or prismatic joints and thus, not surprisingly,most of the current dynamics packages support only simpletypes of constraints.3Notably, an improved version of the Ar-ticulated Body Algorithm [Featherstone 1987] supports gen-eral scleronomic constraints, but the complexity of the algo-rithm makes it difficult to understand and implement [Baraff1996]. If arbitrary parametric kinematic constraints are al-lowed then computing the derivatives is still problematic.

Computer graphics researchers have used symbolic or auto-matic differentiation to compute derivatives of complex func-tions [Kass 1992; Cohen 1992; Popovic et al. 2000; Grin-spun et al. 2003]. In this paper, we create symbolic equa-tions of motion by using symbolic differentiation. Specifi-cally, we derive a simple recursive factorization of the La-grangian equations of motion which, along with our extendedimplementation of the D* symbolic differentiation algorithm[Guenter 2007], yields empirically measured O(n) inversedynamics and O(n3) forward dynamics. (Note to review-ers: D* symbolic differentiation software will be available topublic in late 2009.)

In mechanics, symbolic or automatic differentiation havebeen employed mostly to augment multibody dynamics suchas computing the derivatives of constraint equations or themass matrix [Shi and McPhee 2000; Olsson et al. 2005;Samin and Fisette 2003]. Not only is symbolic differenti-ation used for dynamics simulation, but it is also used forlinearizing the equations of motion and optimizing designparameters. However, for the core simulation of the dynam-ics, they employed existing, manually derived dynamics al-gorithms that do not require symbolic differentiation.

In contrast, we derive symbolic equations of motion by us-ing symbolic differentiation. [Villard and Arnaldi 1996] ap-plied symbolic differentiation to compute the equations forthe constraint forces, which are numerically calculated usingeither the penalty method or the Lagrange mutltiplier tech-

2For tree structured systems naïve direct approaches for evaluating thesederivatives can have computational complexity as high as O(n4), where n isthe number of degrees of freedom of the system.

3SD/FAST [Hollars et al. 1994], a multibody dynamics package based onLagrangian formulation, supports complex, user-defined constraints only byusing the Lagrange multipler technique, which is not related to our symbolicLagrangian approach.

Page 2: Symbolic Lagrangian Multibody Dynamics - … Lagrangian Multibody Dynamics ... Lagrangian mechanics is a reformulation of classical me-chanics which is particularly useful for modeling

nique. By contrast, our algorithm generates minimal coor-dinate motion equations that eliminate all constraint forces.[Turner 2003] applied their automatic differentiation algo-rithm to Lagrange’s equation to generate motion equationsfor very simple mechanisms, but they did not generalize theirmethod to handle a broad scope of mechanisms.

One advantage of using symbolic differentiation for dynam-ics simulation is that one can easily incorporate complexconstraints. In general, one needs to compute derivativesof the constraint equations up to the second order. Com-plex constraints have very complex derivatives, which aredifficult to derive. By employing symbolic differentiation,one need only provide the constraint equations; the deriva-tives are computed by the symbolic differentation. Section5 demonstrates that some constraints whose derivatives arevery complex to derive manually can be easily simulated byour method. Some of our example mechanical systems aresimilar to those presented in [Kry and Pai 2003] and [Leeand Terzopoulos 2008] but the dynamics algorithms to cre-ate the examples are very different in that the former manu-ally derived derivatives of the general surface constraints andthe latter employed easily differentiable constraint functions,both under the framework of existing dynamics algorithms.

1.1 Contributions

To address the problem of applying symbolic Lagrangian me-chanics to tree structured systems we present in this paper asimple and efficient factorization of the symbolic Lagrangianequations of motion which directly leads to an O(n) algo-rithm for inverse dynamics. For the forward dynamics prob-lem we have extended our implementation of the D∗symbolicdifferentiation algorithm [Guenter 2007] to give an O(n3) al-gorithm. The new algorithm has several attractive properties:

∙ Because the symbolic Lagrangian equations alwaysmaintain kinematic constraints it is possible, in somecases, to use very large time steps. These large timesteps would cause convergence problems for nonlinearconstraint solvers.

∙ Mechanisms incorporating complex constraints whichare challenging to simulate using existing techniques,such as point on surface, point on curve, surface on sur-face, are easily and robustly simulated.

The remainder of this paper is organized as follows: after de-riving the Lagrangian equations of motion from the Newton-Euler dynamics equation (Section 2), we present a simple re-cursive factorization of the Lagrangian equation (Section 3).Then we show inverse and forward dynamics methods (Sec-tion 4) followed by numerous examples (Section 5). Finally,we report the performance of our methods (Section 6) andconclude the paper (Section 7).

W

tcmrw

p

world frame

rcmt

rigid body frame

Figure 1: rcm and tcm is the center of mass with respect tothe world and body frame, respectively. rw and p refer toa point of a rigid body with respect to the world and bodyframe, respectively.

2 Lagrangian Equations of Motion

We start by deriving the Langrangian equations of mo-tion of a multibody system. We assume a tree structuredmultibody system in which n generalized coordinates, q =(q0, . . . ,qn−1), completely specify the configuration of everyrigid body in the system. Each local transformation for rigidbody i, Ai, with respect to its parent is determined by somenumber of generalized coordinates qi, and its transformationWi in world coordinates is expressed as the product of localtransformations of its ancestors, or in recursive form, as:

Wi(q) =[

R(qi) t(qi)0 1

]= Wpi(q)Ai(qi) (1)

where pi denotes i’s parent.

If the inertia matrix is defined in the center of mass coordi-nate frame then the Newton-Euler equations of motion for asystem of n rigid bodies are:

n

∑i=1

mircmi =n

∑i=1

fi (2)

n

∑i=1

hcmi =n

∑i=1

τi (3)

where mi is the mass of a rigid body i and rcmi = Witcmi is itscenter of mass (Fig. 1). hcmi = Iiωi is the angular momentumabout the center of mass where Ii is the rotational inertia and

ωi =˜(RT

i Ri).4 The force fi and torque τi include external and

internal forces and torques, respectively; i.e., fi = fexti + fintiand τi = τexti + τinti . By projecting the Newtonian motionequations onto the kinematic constraint manifold we obtainthe Lagrangian equations of motion, which completely elim-inate constraint forces ; i.e., we project (2) onto

∂rcmi∂q j

. Con-straint forces have zero projection on this vector so they all

4The ~ operator converts between vector and a skew-symmetric matrixrepresentation; i.e., an angular velocity ω relates to the time derivative of therotation matrix R as follows:

ω =

⎡⎣ 0 −ωz ωyωz 0 −ωx−ωy ωx 0

⎤⎦ , RT R = ω.

Page 3: Symbolic Lagrangian Multibody Dynamics - … Lagrangian Multibody Dynamics ... Lagrangian mechanics is a reformulation of classical me-chanics which is particularly useful for modeling

vanish per d’Alembert’s principle of virtual work:

n

∑i=1

(mircmi − fexti)T ∂rcmi

∂q j=

n

∑i=1

fTinti

∂rcmi

∂q j

n

∑i=1

aTi

∂rcmi

∂q j= Qf j (4)

where ai = mircmi− fexti and Qf j is the generalized force, dueto forces, associated with generalized coordinate q j. Like-wise, we project the torques onto the constraint manifold:

n

∑i=1

(hcmi − τexti

)Tωq j =

n

∑i=1

τTintiωq j

n

∑i=1

bTi ωq j = Qτ j (5)

where ωq j =˜(RT

i∂Ri∂q j

), bi = hcmi−τexti , and Qτ j is the gener-

alized force due to torques. We get a single set of differentialequations by adding the two generalized forces.

n

∑i=1

(aT

i∂rcmi

∂q j+bT

i ωq j

)= Q j (6)

where Q j = Qf j +Qτ j . We have derived Lagrangain equa-tions of motion (Eq. (6)) from Newton-Euler motion equa-tions (Eqs. (2) and (3)) for a multibody system. However,this is not yet a computationally efficient form of the equa-tions; the inverse dynamics equations generated by the D∗

algorithm using (6) is O(n2), n times more than today’s man-ually optimized O(n) inverse dynamics algorithms. In Sec-tion 3, we develop a novel factorization that yields an O(n)inverse dynamics algorithms.

3 Factoring the Equations of Motion

The factorization of the motion equations is most easily ap-proached by considering the force and torque equations sep-arately. Substituting rcmi = Witcmi (Fig. 1) into (4) gives usthis set of equations for Qf j .

n

∑i=1

aTi

∂Wi

∂q jtcmi = Qf j .

For n = 3 we get this system of equations:

aT0

∂W0

∂q0tcm0 +aT

1∂W1

∂q0tcm1 +aT

2∂W2

∂q0tcm2 = Qf0

aT0

∂W0

∂q1tcm0 +aT

1∂W1

∂q1tcm1 +aT

2∂W2

∂q1tcm2 = Qf1

aT0

∂W0

∂q2tcm0 +aT

1∂W1

∂q2tcm1 +aT

2∂W2

∂q2tcm2 = Qf2

To simplify these equations start with two observations. First,because5

∂Ai

∂q j= 0 i ∕= j (7)

we can rewrite ∂Wi∂q j

as

∂Wi

∂q j= W j−1

∂A j

∂q jA j+1 . . .Ai (8)

Second∂W j

∂qk= 0 for k ≥ j

where the expression k ≥ j means that the rigid body k isfurther toward the leaves of the tree than the rigid body j.Apply these two observations to our equations of motion toget an upper triangular set of equations

aT0

∂A0

∂q0tcm0 +aT

1∂A0

∂q0A1tcm1 +aT

2∂A0

∂q0A1A2tcm2 = Qf0

aT1 W0

∂A1

∂q1tcm1 +aT

2 W0∂A1

∂q1A2tcm2 = Qf1

aT2 W1

∂A2

∂q2tcm2 = Qf2

Notice that ∂Ai∂qi

is included in every term in the LHS andwe can factor out theses common terms by moving the aT

iterms from the left to the right hand side. The productsaT

i Wi−1∂Ai∂q j

tcmi are of the form

xT y where xT = aTi and y = Wi−1

∂Ai

∂q jtcmi .

Using the identity

tr(yxT ) = xT y, (9)

our three equations of motion become

tr(

∂A0

∂q0tcm0 aT

0 +∂A0

∂q0A1tcm1 aT

1 +∂A0

∂q0A1A2tcm2 aT

2

)= Qf0

tr(

W0∂A1

∂q1tcm1 aT

1 +W0∂A1

∂q1A2tcm2 aT

2

)= Qf1

tr(

W1∂A2

∂q2tcm2 aT

2

)= Qf2

Factoring out common terms, we get

tr(

∂A0

∂q0

(tcm0aT

0 +A1(tcm1aT

1 +A2tcm2aT2)))

= Qf0

tr(

W0∂A1

∂q1

(tcm1 aT

1 +A2tcm2aT2))

= Qf1

tr(

W1∂A2

∂q2

(tcm2aT

2))

= Qf2

5We are ignoring a technical detail that would unnecessarily complicatethe equations at this point: the matrix A j may be a function of up to six gen-eralized coordinates qk so the indices of the matrix A j and the generalizedcoordinate may not be the same. This does not materially change the formof the equations or the factorization.

Page 4: Symbolic Lagrangian Multibody Dynamics - … Lagrangian Multibody Dynamics ... Lagrangian mechanics is a reformulation of classical me-chanics which is particularly useful for modeling

Because of common subexpression elimination in D* it takesO(n) time to compute the equations in this form.

Let us turn now to the torque equations (5):

Qτ j =n

∑i=1

˜RT

i∂Ri

∂q j

T

bi.

We will show how we can move the term ∂Ri/∂q j in frontfor effecient factorization. To this end, we introduce the fol-lowing identity

tr(ab)

= tr

⎧⎨⎩⎡⎣ 0 −az ay

az 0 −ax−ay ax 0

⎤⎦⎡⎣ 0 −bz bybz 0 −bx−by bx 0

⎤⎦⎫⎬⎭= −2aT b.

Using this relation, we can rewrite the ωTq j

bi terms

ωTq j

bi = −.5tr(ωq j bi

)= tr

(−1

2RT

i∂Ri

∂q jbi

)= tr

(−1

2∂Ri

∂q jbiRT

i

)(10)

where we used the relation tr (AB) = tr (BA) for (10). Nowwe can rewrite the torque equations with ∂Ri

∂q jon the left-hand

side where everything will factor nicely:

Qτ j =n

∑i=1

ωTq j

bi (11)

= tr

{n

∑i=1

∂Ri

∂q j

(−1

2biRT

i

)}(12)

Define two new matrices,

Ui =

[Ri 00 0

], Bi =

[bi 00 0

]to rewrite the torque equations using the full transformationWi instead of Ri:

∂Ri

∂q j

(−1

2biRT

i

)=

∂Wi

∂q j

(−1

2BiUT

i

).

Using the same 3 degree of freedom system that we used forthe force equations we get the following three torque equa-tions

−12

tr{

∂W0

∂q0

(B0UT

0)+

∂W1

∂q0

(B1UT

1)+

∂W2

∂q0

(B2UT

2)}

= Qτ0

−12

tr{

∂W0

∂q1

(B0UT

0)+

∂W1

∂q1

(B1UT

1)+

∂W2

∂q1

(B2UT

2)}

= Qτ1

−12

tr{

∂W0

∂q2

(B0UT

0)+

∂W1

∂q2

(B1UT

1)+

∂W2

∂q2

(B2UT

2)}

= Qτ2

As in the force relation, we transform the equations into up-per triangular form using (7) and (8), and factor out commonterms

−12

tr{

∂A0

∂q0

((B0UT

0)+A1

(B1UT

1 +A2(B2UT

2)))}

= Qτ0

−12

tr{

W0∂A1

∂q1

(B1UT

1 +A2(B2UT

2))}

= Qτ1

−12

tr{

W1∂A2

∂q2

(B2UT

2)}

= Qτ2

Algorithm 1 coefficient algorithmnd: node to find coefficient oflc: true if left child graph of this contains ndrc: true if right child graph of this contains ndcoeff(function nd)if this is leaf return thiselse

foreach (node c in this.children){c.coeff(nd)}if (this.type not one of {+,-,*,/}) ERRORif (this is * && lc && rc) ERRORif (this is / && rc) ERRORif (!(this is + || this is -)) return thiselse if (lc && !rc){return this.leftchild}else if (rc && !lc){return this.rightchild}else return this

Because they share common factors we can combine the gen-eralized force and torque equations to get an equation foreach of the generalized forces Q0,Q1,Q2 illustrated in Fig. 2.Finally, we get the following efficient form of the Lagrangainequations of motion:

tr{W j−1∂A j

∂q jφ j}= Q j (13)

φ j = tcm j aTj −

12

B jUTj +A j+1φ j+1

4 Forward and Inverse Dynamics

For the inverse dynamics problem, we can use the mo-tion specification, q(t), and (13) to compute the generalizedforces. Q j is a function of q(t), q(t), q(t), all of which arecomputed from the motion specification. Computing the gen-eralized forces takes O(n) time.

The general dynamics formula of (13) is not in the properform to directly solve the forward dynamics problem. How-ever, the equations of motion have the following structure:

M(q)q+ c(q, q) = Q. (14)

We can see that Mi j, the (i, j) entry of M is the coefficient ofq j of the i-th equation. Also, if we set q = 0, then the LHSof (13) becomes c(q, q).

We derive a symbolic expression for M and c using D* . Forthis, we have added two new functions, coefficient andsubstitute, to our implementation of D*. These makeit trivial to reorganize these equations into an easily solvedform.

Given a D* function, fi, which computes fi(q, q, q) and aD* variable, qiddt, which corresponds to qi, the functionfi.coefficient(qiddt)returns the symbolic expressionwhich represents the coefficient of qi. Since M is a sym-metric matrix, we can create a symbolic expression of M bycalling this function for q j in each fi for i ≥ j. The ci(q, q)are computed by calling

Page 5: Symbolic Lagrangian Multibody Dynamics - … Lagrangian Multibody Dynamics ... Lagrangian mechanics is a reformulation of classical me-chanics which is particularly useful for modeling

tr{

∂A0

∂q0

(tcm0aT

0 −12

B0UT0 +A1

(tcm1aT

1 −12

B1UT1 +A2

(tcm2aT

2 −12

B2UT2

)))}= Q0

tr{

W0∂A1

∂q1

(tcm1aT

1 −12

B1UT1 +A2

(tcm2aT

2 −12

B2UT2

))}= Q1

tr{

W1∂A2

∂q2

(tcm2aT

2 −12

B2UT2

)}= Q2

Figure 2: Combined force and torque equations

fqq(q)f(q)

fq(q)n

p

b

Figure 3: Traveling coordinate frame defined by the tangent,fq(q), and second derivative, fqq(q) of the curve f(q)

S2

S1

Figure 4: Surface-surface coordinate frame constraints

fi.substitute(new[]{q0ddt,...qnddt},new[]{0,...,0})

This will substitute zero for all the qi leaving just ci(q, q) .Forward dynamics is performed by solving

Mq = Q− c

using standard linear algebra algorithms. The Cholesky de-composition method is a good choice in this case since M ispositive definite.

5 Examples of Complex Constraints

Systems are built by connecting rigid bodies with motionconstraints, represented as a transformation matrix which isa function of up to 6 generalized coordinates. To create andsimulate a mechanism the user has only to define these trans-formation matrices of rigid bodies with respect to their par-ents as functions of generalized coordinates. This is in con-trast to conventional, numerical dynamics packages in whichone must provide the derivatives of the transformations up tothe second order. This can be very complicated as will be

seen in some of our examples.6

The Frenet frame along a curve could be used, for example,to constrain beads to slide along a wire, or to make a rollercoaster or train roll along a track. If the curve f(q) has a con-tinuous, nonzero second derivative everywhere in a region,then it is easy to define a coordinate frame that travels alongthe curve

C(q) =[

b p n f0 0 0 1

],

where b =fq

∥fq∥ , n =b×fqq

∥b×fqq∥ , and p = n×b.

Assume we want to constrain an object to move along a spacecurve, f(qp) : ℝ1 → ℝ3, so that the x axis in object modelspace always points in the direction of the tangent, fqp , to thecurve, and the object can rotate by qr about the axis of thetangent vector. The combined constraint will use two trans-formation matrices: the curve orientation and translation con-straint matrix, and a rotation about the x axis

Apath = C(qp)RrotX (qr).

An example of several systems constrained this way is shownin Fig. 5(a).

Moving up one dimension from curves we can define a sur-face frame whose origin is on the surface with two axes tan-gent to the surface. For the parametric surface

f(q1,q2) = [ fx(q1,q2), fy(q1,q2), fz(q1,q2)]T

we use the two tangent vectors of unit lengths

p0 =∂ f

∂q1/∣∣ ∂ f

∂q1∣∣ p1 =

∂ f∂q2

/∣∣ ∂ f∂q2∣∣

and the unit normal vector n = p0× p1 to create a surfaceframe

S =

[p0 n×p0 n f0 0 0 1

].

We can force the surface frames of two surfaces, shown inFig. 4, to align by using this transformation

S1,2 = S1S−12 (15)

6Note that some of the example constraints have singularity problems,but this is a separate issue from the main subject of this paper.

Page 6: Symbolic Lagrangian Multibody Dynamics - … Lagrangian Multibody Dynamics ... Lagrangian mechanics is a reformulation of classical me-chanics which is particularly useful for modeling

(a) Path constraint (b) Surface surface constraint (c) Rolling constraint

(d) Tong-like mechanism (e) Ellipsoidal ball rolling over ellip-soidal surface

(f) Multiple systems

Figure 5: Example mechanisms

where S1 and S2 define the two surface frames. Thematrix S1,2 is a function of four generalized coordinatesq1, q2, q3, q4. We can make a chain of torii, shown inFig. 5(b), by applying (15) to the sequence of torus objects.

It is also possible to simulate certain types of rolling contact.In Fig. 5(c) the wheels are constrained to roll without slid-ing. Assume the wheels lie in the xy plane and rotate aboutthe z axis. The relative transformation of the bigger wheel(colored yellow and green) can be parameterized by a singlegeneralized coordinate q; the position of the body frame is[cosq,sinq,0]T , and, due to the non-slip constraint, the ori-entation is also defined as a function of q,

R = RrotZ(r1

r2q)

where r1 is the radius of the half circle and r2 is the radius ofthe wheel. The relative transformation of the smallest wheelcan be defined similarly.

Fig. 5(d) shows an example in which the generalized coor-dinates can be defined for a closed loop mechanism. A totalof 32 rigid bodies is constrained such that each joint angleof the link can be defined as a function of a single general-ized coordinate, i.e., qi = qi(q) for all i. A “fish” object isconnected to a tong-like chain via a universal joint. In thiscase, our algorithm creates an ODE with only three indepen-dent variables. In contrast, non-symbolic, conventional La-grangian dynamics algorithms such as the Articulated-BodyAlgorithm [Featherstone 1987] cannot achieve this level ofreduction for the closed loop system because they endow in-dependent coordinates to each mobile rigid body followedby enforcing the loop constraints using Lagrange multipli-ers. For this example, they will obtain a 34 dimensional ODE

coupled with 31 holonomic closed loop constraints. Newto-nian dynamics algorithms will generate a 33×6 dimensionalODE for this type of mechanism.

Fig. 5(e) shows an ellipsoidal ball rolling over an ellipsoidalsurface with the rolling constraint enforced using the La-grange multipliers. To establish a rolling constraint betweentwo surfaces let (R1, t1) and (R2, t2) denote the orientationand position of the surface frames of the two surfaces. Whenthe two surfaces do not slip, the relative velocity of the twosurface frames must be same, i.e., RT

1 t1 = RT2 t2 which yields

this constraint equation:

Pq = 0, P =

[RT

1dt1dq−RT

2dt2dq

]. (16)

Note that one must derive P, the time derivative of P, in or-der to use Lagrange multipliers. D* computes P as well asthe derivatives in (16) so one need not worry about manuallycomputing them.

6 Results

Because the symbolic Lagrangian algorithm performs alge-braic simplification and common subexpression eliminationthe operations count is not just a function of the number ofdegrees of freedom in the system, as it is for previously pub-lished forward and inverse dynamics algorithms. We mea-sured the time complexity of the new algorithm on two sys-tems and present those results here.

Results for the inverse dynamics problem are shown in Fig.6. Fig. 6(a) shows the total number of operations as a func-tion of the number of degrees of freedom for a simple linear

Page 7: Symbolic Lagrangian Multibody Dynamics - … Lagrangian Multibody Dynamics ... Lagrangian mechanics is a reformulation of classical me-chanics which is particularly useful for modeling

0

200

400

600

800

1000

1200

1400

1600

1800

2 3 4 5 6 7 8 9 10 11 12

op

era

tio

ns

Degrees of freedom

(a)

0

2000

4000

6000

8000

10000

6 10 14 18 22 26 30 34 38 42 46

op

era

tio

ns

Degrees of freedom

(b)

Figure 6: Inverse dynamics, arithmetic operations versusnumber of generalized coordinates: (a) linear revolute chain(not illustrated). (b) torus chain (Fig. 5(b)). Growth is wellapproximated by a best fit line.

0

2000

4000

6000

8000

10000

12000

14000

16000

18000

2 3 4 5 6 7 8 9 10 11 12

op

era

tio

ns

Degrees of freedom

(a)

0

10000

20000

30000

40000

50000

60000

70000

80000

90000

6 10 14 18 22 26 30

op

era

tio

ns

Degrees of freedom

(b)

Figure 7: Forward dynamics, arithmetic operations versusnumber of generalized coordinates: (a) linear revolute chain(not illustrated). (b) torus chain (Fig. 5(b)). Growth is wellapproximated by a best fit quadratic curve.

chain of revolute joints. Fig. 6(b) shows the total number ofoperations for a linear chain of torii, of the type shown in Fig.5(b). Both systems are well approximated by a best fit line.

For the forward dynamics problem Fig. 7 shows the mea-sured number of operations in the equations of motion forthe same systems of Fig. 6. The operation count is increas-ing quadratically in both cases. Because eventually the O(n3)matrix solution time will dominate the overall complexity offorward dynamics will be O(n3).

Existing forward and inverse dynamics algorithms are usu-ally limited to a very restricted set of joint types, often justrevolute or translational joints – other joint types require sig-nificant effort on the part of the end-user to implement. Bothof these facts make direct comparison of our algorithm to ex-isting algorithms problematic; the capabilities of the two setsof algorithms are very different so it is hard to make an applesto apples comparison.

We created a nonbranching system consisting of six 1 DOFrevolute joints, connected in a linear chain, and used this as acomparison test case. Roughly best and worst case results forthe symbolic Lagrangian algorithm are compared in Table 1to the most efficient hand derived algorithms [Balafoutis andPatel 1991] that requires manual differentiation of the con-straints. Our algorithm is competitive even in this restrictedclass, and, of course, it can easily be applied to a much widerrange of joint types.

algorithm ± *

Symb. best 328 365Balafoutis 386 450

Symb. worst 509 971

(a) Inverse dynamics

algorithm ± *

Symb. best 818 943Balafoutis 790 956

Symb. worst 1875 2389

(b) Forward dynamics

Table 1: Operations count comparison for a 6 degree of free-dom chain of revolute joints: symbolic Lagrangian vs. Bal-afoutis.

In practice the new algorithm generates efficient dynamicscode. For example, Fig. 5(b), which has the largest number ofgeneralized coordinates (14) of the examples shown in Fig. 5,requires only 0.02 miliseconds to evaluate the motion equa-tion. Solving the matrix motion equation using Choleskydecomposition takes an additional 1.3× 10−3 milisecondson a 2.66Hz Intel Core 2 Quad CPU. Our code is not mul-tithreaded so only a single processor is used for the mo-tion equation computation. Comparing the compute time ofthe motion equation (O(n2)) and that of the matrix solution(O(n3)) suggests that the two procedures will take the sameamount of time when the DOFs of the system are about 200.For models with ≪ 200 DOFs, the algorithm is dominatedby the evaluation of the O(n2) motion equation procedure.

7 Discussion and Conclusion

Because the Lagrangian formulation always maintains kine-matic constraints, it is possible to take very large time stepswhen precise modeling of the true dynamics is unnecessary.In computer games and animation for film or television it israrely necessary to model dynamics to high precision, sincehuman viewers don’t notice small dynamic errors. By com-parison, kinematic constraint errors are much more notice-able, since they result in parts of the mechanism failing toconnect properly.

Fig. 8 shows two frames, (a), (b), from a dynamic simula-tion of a bead constrained to move along a wire: (a) showsa step along the tangent to the constraint manifold, as wouldbe done when using nonlinear constraint equations, and (b)shows the step taken by our symbolic Lagriangian formula-tion. The tangent step moves the bead far off the constraintmanifold; convergence of a nonlinear constraint solver to thecorrect point on the constraint manifold is highly unlikely.To guarantee convergence a much smaller time step wouldbe necessary to correctly maintain the kinematic constraints.

We have taken advantage of this robustness property of sym-bolic Lagrangian dynamics in all the animations, includedin the supplemental materials for this paper, which have atimestep of one frame time (either 1

60 th or 130 th second).

We do not deal with simulating contact and collision in thispaper since it is a separate problem that is resolved after com-puting the dynamics of a system. Any collision and contact

Page 8: Symbolic Lagrangian Multibody Dynamics - … Lagrangian Multibody Dynamics ... Lagrangian mechanics is a reformulation of classical me-chanics which is particularly useful for modeling

(a) (b)

Figure 8: (a) Yellow arrow shows step along tangent to con-straint manifold. (b) Step taken by our algorithm.

handling techniques for minimal coordinate approaches canbe used with the new algorithm. For example, [Kokkevis andMetaxas 1998] can be used for simulating collision response,enforcing unilateral and bilateral constraints as well as jointlimits, and computing contact or friction forces when the sys-tem is in contact with environment.

The most significant limitation of the new algorithm is that itcan only be applied to systems with parameterizable kinemat-ics. In general, closed loop systems do not have a closed formparametric description, although simple closed loop systems,such as 4 bar linkages, do. In some cases even open loop sys-tems do not have closed form parametric kinematics. How-ever, in practice parameterizability is not generally a limi-tation since the universe of mechanisms which can be de-scribed this way is very large.

Another issue is handling topology change. If we can pre-define a set of sub-systems that a system can break into, thenwe can compute the motion equations of the sub-systems off-line and the switch between the equations in real time. How-ever, if one wants to simulate completely general topologicalchanges, such as breaking a system into every single rigidbodies, a maximal coordinate approach will probably be abetter choice.

The great strength of the new algorithm is that complex jointscan be easily specified and robustly and rapidly simulated.For example, a common weakness of human figure anima-tions is that the knee joint is modeled as a hinge when it ismore accurately modeled as a four bar linkage. This givesnatural human knees a significantly larger range of motionthan artificial knee joints, which are simple hinges. Similarly,the human scapula is a complex joint which can be modeledas a surface-surface joint type. Incorporating these complexjoints in a human body simulation would be straightforwardwith our algorithm but considerably more problematic usingexisting algorithms. In addition, the robustness, efficiency,and simplicity of the algorithm make it an attractive choicefor real-time applications, such as computer simulations orgames, where numerical simulation failure is not an option.

References

ASCHER, U. M., AND PETZOLD, L. R. 1998. Com-

puter Methods for Ordinary Differential Equations andDifferential-Algebraic Equations. SIAM.

BALAFOUTIS, C. A., AND PATEL, R. V. 1991. DynamicAnalysis of Robot Manipulators: A Cartesion Tensor Ap-proach. Kluwer Academic Publishers.

BARAFF, D. 1996. Linear-time dynamics using lagrangemultipliers. In Proceedings of SIGGRAPH 96, ComputerGraphics Proceedings, Annual Conference Series, 137–146.

COHEN, M. F. 1992. Interactive spacetime control for ani-mation. Computer Graphics (Proceedings of SIGGRAPH92 (July), 293–302.

FEATHERSTONE, R., AND ORIN, D. 2000. Robot dynamics:equations and algorithms. IEEE Int’l Conf. on Roboticsand Automation (IROS) 2000, 826–834.

FEATHERSTONE, R. 1987. Robot Dynamics Algorithms.Kluwer Adademic Publishers, Boston.

GRINSPUN, E., HIRANI, A. N., DESBRUN, M., ANDSCHRCDER, P. 2003. Discrete shells. 2003 ACM SIG-GRAPH / Eurographics Symposium on Computer Anima-tion (aug), 62–67.

GUENTER, B. 2007. Efficient symbolic differentiation forgraphics applications. ACM Transactions on Graphics 26,3 (July), 108:1–108:12.

HERBERT GOLDSTEIN, CHARLES P. POOLE, J. L. S. 2001.Classical Mechanics.

HOLLARS, M. G., ROSENTHAL, D. E., AND SHERMAN,M. A. 1994. SD/FAST User’s Manual.

KASS, M. 1992. Condor: Constraint-based dataflow. Com-puter Graphics (Proceedings of SIGGRAPH 92) (July),321–330.

KOKKEVIS, E., AND METAXAS, D. 1998. Efficient dy-namic constraints for animating articulated figures. Multi-body System Dynamics, 89–114.

KRY, P. G., AND PAI, D. K. 2003. Continuous contact simu-lation for smooth surfaces. ACM Transactions on Graphics22, 1 (Jan.), 106–129.

LEE, S.-H., AND TERZOPOULOS, D. 2008. Spline jointsfor multibody dynamics. ACM Transactions on Graphics27, 3 (aug), 22:1–22:8.

OLSSON, H., TUMMESCHEIT, H., AND ELMQVIST, H.2005. Using automatic differentiation for partial deriva-tives of functions in modelica. Proceedings of the 4th In-ternational Modelica Conference (Mar.), 105–112.

POPOVIC, J., SEITZ, S. M., ERDMANN, M., POPOVIC, Z.,AND WITKIN, A. P. 2000. Interactive manipulation ofrigid body simulations. Proceedings of ACM SIGGRAPH2000 (July), 209:1–209:9.

Page 9: Symbolic Lagrangian Multibody Dynamics - … Lagrangian Multibody Dynamics ... Lagrangian mechanics is a reformulation of classical me-chanics which is particularly useful for modeling

SAMIN, J.-C., AND FISETTE, P. 2003. Symbolic Modelingof Multibody Systems. Springer.

SHI, P., AND MCPHEE, J. 2000. Dynamics of flexible multi-body systems using virtual work and linear graph theory.Multibody System Dynamics 4, 4, 355–381.

TURNER, J. D. 2003. Automated generation of high-orderpartial derivative models. AIAA Journal 41, 8, 1590–1598.

VILLARD, D., AND ARNALDI, B. 1996. Symbolic differen-tiation library for simulation of multibody rigid systems.Mathematics and Computers in Simulation 42, 4-6, 659–673.