Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
DETC2013-13470
Gilbert Gede∗, Dale L. Peterson, Angadh S. Nanjangud, Jason K. Moore, Mont Hubbard
Sports Biomechanics Laboratory
Department of Mechanical and Aerospace Engineering
University of California
Davis, California 95616
Email: {ggede, dlpeterson, asnanjangud, jkmoor, mhubbard}@ucdavis.edu
ABSTRACT INTRODUCTION
Symbolic equations of motion (EOMs) for multibody systems There are many dynamic systems which can be better or
are desirable for simulation, stability analyses, control system more effectively studied when their EOMs are accessible in a
design, and parameter studies. Despite this, the majority of en- symbolic form. For equations that may be visually inspected
gineering software designed to analyze multibody systems are (i.e., of reasonable length), symbolics are generally preferable
numeric in nature (or present a purely numeric user interface). because the interrelations of the variables and constants can give
To our knowledge, none of the existing software packages are 1) clear understanding to the nature of the problem without the need
fully symbolic, 2) open source, and 3) implemented in a popular, for numerical simulation. Many classic problems fit this cate-
general, purpose high level programming language. In response, gory, such as the mass-spring-damper, double pendulum, rolling
we extended SymPy (an existing computer algebra system imple- disc, rattleback, and tippy-top. The benefits of symbolic equa-
mented in Python) with functionality for derivation of symbolic tions of motion are not limited to these basic problems though.
EOMs for constrained multibody systems with many degrees of Larger, more complicated multibody systems can also be stud-
freedom. We present the design and implementation of the soft- ied more effectively when the equations of motion are available
ware and cover the basic usage and workflow for solving and symbolically. Advanced simplification routines can sometimes
analyzing problems. The intended audience is the academic re- reduce the length of the equations such that they are human read-
search community, graduate and advanced undergraduate stu- able and the intermediate derivation steps are often short enough
dents, and those in industry analyzing multibody systems. We that symbolic checks can be used to validate the correctness. Fur-
demonstrate the software by deriving the EOMs of a N-link pen- thermore, the symbolic form of the EOMs often evaluate much
dulum, show its capabilities for LATEX output, and how it inte- faster than their numerical counterparts, which is a significant
grates with other Python scientific libraries - allowing for nu- advantage for real time computations. Problems in biomechan-
merical simulation, publication quality plotting, animation, and ics, spacecraft dynamics, and single-track vehicles have all been
online notebooks designed for sharing results. This software fills successfully studied using symbolic EOMs.
a unique role in dynamics and is attractive to academics and
industry because of its BSD open source license which permits Having the symbolic equations of motion available permits
open source or commercial use of the code. numerical simulation, but also allows for a more mathemati-
cal study of the system in question. System behavior can be
studied parametrically by examining coefficients in the differ-
∗ Address
ential equations. This includes symbolic expressions for equi-
all correspondence to this author
q0
m0
l1
âx
q1 m1
..
.
..
.
g
lN−1
FIGURE 1. N-pendulum system, a sequence of massive links con- Another part of studying dynamic systems is simulation and
nected by revolute joints subjected to a gravitational field. visualization of the results. SymPy can only analytically solve
simple ODEs, so the equations of motion generated for more
complex systems need to be passed to other numerical integra-
before the for loop is entered; these lists are filled by the loop. tors. Currently, sympy.physics.mechanics can make use of exist-
When the final iteration of the for loop is complete, the kinemat- ing SymPy translation functions, but more advanced options to
ics and all active forces of the problem have been completely generate compiled code are being developed and guided by user
specified. The last two lines of the script take this specifica- demands. The SymPy translation function lambdify can con-
tion of kinematics and dynamics and generate Kane’s dynam- vert symbolic expressions to a NumPy compatible function. The
ical equations of motion (Fr + Fr∗ = 0) in symbolic form. At code in Figure 3 (which is executed after the previously written
this point, these equations may be manipulated as fully symbolic code) shows this method.
variables for a variety of purposes. For example, the command
NumPy is an integral part of the larger Scientific Python
mlatex(fr) generates LATEX code for the generalized active
ecosystem, focusing primarily on numerical arrays and matrices
force Fr , which renders as:
and operations on these arrays and matrices. SciPy is another
part of this ecosystem that provides quick and simple Python
gl0 m0 sin(q0 )+gl0 m1 sin(q0 )+gl0 m2 sin(q0 )+gl0 m3 sin(q0 ) wrappers to a large library of legacy scientific code. The third
gl1 m1 sin(q1 )+gl1 m2 sin(q1 )+gl1 m3 sin(q1 )
gl2 m2 sin(q2 )+gl2 m3 sin(q2 )
(1) necessary component of this ecosystem is matplotlib, a Python
gl3 m3 sin(q3 ) plotting library for visualization of the large datasets generated
by NumPy and SciPy code. Using these three Python packages,
with no further modification from the user. we can numerically integrate ODEs and plot the results, which
There are other options besides LATEX output which are use- are shown in Figure 4.
ful. Within a console, commands to “pretty print” symbolic ex- Using other Python packages, such as MayaVi, 3D anima-
pressions can be performed with mpprint, which generates the tions can be created. Use of human-interface-devices (with a suf-
output formatted just like the LATEX equation above, but within ficiently fast computer) allows for real-time interaction between
the terminal. a user and a visualized simulation.
for i in range(n):
Ai = A.orientnew(’A’ + str(i), ’Axis’, [q[i], A.z]) # Create a new frame
Ai.set_ang_vel(A, u[i] * A.z) # Set angular velocity
frames.append(Ai) # Add it to Frames list
SOFTWARE VALIDATION dent functionality in the code has a test (known input/output) in
place that guarantees correct functioning of each unit. This en-
Anytime new software is developed to generate equations
sures that not only the current code works as expected, but also
of motion, the validity and accuracy of the software comes into
that future versions are automatically checked against the same
question. We have addressed these concerns in three ways to en-
expected behavior. Thirdly, there are built in tests for well bench-
sure that our code does generate correct equations of motion for
marked problems in mutlibody dynamics. There are many prob-
arbitrarily complex systems. Firstly, the code is open source and
lems, both simple and complex, that have well known symbolic
well documented. This allows anyone to review the code and
solutions. We have chosen several benchmark problems that in-
check for bugs. Linus’s Law “given enough eyeballs, all bugs
clude sequential rotations, configuration and motion constraints,
are shallow” [3] applies, if true. Secondly, the code functionality
and examination of noncontributing forces. These problems are
is thoroughly checked with unit testing; each piece of indepen-
built into the test suite for the package. All of the software demonstrated in this paper can be readily ob-
Built in tests which validate the equations of motion that tained for free and installed on virtually any platform. Also, all
are generated include: varying degrees of freedom spring- of the packages are liberally licensed with a BSD or compatible
mass-damper systems, various pendulums, multiple rolling license and either stable releases or development branches can be
disc examples testing auxiliary and dependent speeds, and an downloaded.
inverted-pendulum cart. These are all compared to results To obtain and use the core mechanics package for sym-
found by hand (checked multiple times). The other parts of bolic equation of motion generation, one must simply down-
sympy.physics.mechanics include hundreds of tests on other load and install Python version 2.5+ and SymPy version 0.7.2+1 .
pieces of the overall functionality. Download and installation instructions for each can be found
There are also some external (non-automated) tests which on the softwares’ respective web sites, www.python.org and
are more advanced. Currently, the most complicated test vali- www.sympy.org.
dates the formulation of the equations of motion for a bicycle To run a full PyDy example from equation of motion gener-
(a system with configuration and velocity constraints), symboli- ation to simulation and visualization, Python and at least the Sci-
cally linearizes it, and compares it (successfully) to benchmark entific Python stack (SciPy) [2] must be obtained. SciPy provides
values presented in [4]. more comprehensive installation instructions than space permits
1 One of the major requirements for code added to SymPy is that every func-
USAGE
tion and object has to be thoroughly tested and documented. SymPy has over 88%
This section deals with obtaining the software demonstrated of its code tested by the automated unit-tests. This ensures that no update causes
in this paper and the available resources for learning to use it. regressions or breaks current functionality. Generally, the SymPy development
branch is more stable and contains fewer bugs than the numbered releases.