Motion equation generation script sharing

85 views
Skip to first unread message

2006.uchida

unread,
May 23, 2009, 9:06:08 AM5/23/09
to sympy
I made a small script in MuPAD few years ago but I had to say goodbye
to MuPAD last November, so I found Sympy and have translated it into
Sympy now. I want to share it and I'm happy if I get some comments.

What I made is the small script that generates motion equations for
multibody dynamics by using Kane's method. It handles multibody
dynamics, the dynamic behavior created with several rigid bodies that
are interconnected, for instance, double pendulum, robot arms, crank
mechanism, etc. The script allows you to get the equation easily by
setting some information of masses, positions, forces, etc.

available for download from here:
http://www.esnips.com/doc/0960cb0a-8820-4169-b582-d58a2d6c5f28/MoEqGen_Kane_v0_1

Here is a sample code and results. More details, please see the file
"smple.py" which you can download above.

[Code]
import sympy
import motionequation

def main():

# Sample for Newton's second law

mat = sympy.Matrix
t, x, m, f = sympy.symbols(
"t, x, m, f")

pos_vec = mat([x(t),0,0])
force_vec = mat([f(t),0,0])
I_mat = sympy.zeros(3)
ome_vec = sympy.zeros([3,1])
torque_vec = sympy.zeros([3,1])

result = motionequation.get_withKane(
t, [x(t).diff(t)], [m],
[pos_vec],
[I_mat],
[ome_vec],
[pos_vec], [force_vec],
[ome_vec], [torque_vec])

print "Newton's second law: "
sympy.pprint(result)

main()
[/Code]

[Console]
Newton's second law:
2
d
[m*-----(x(t)) = f(t)]
dt dt
[/Console]

You can use the feature by calling the function get_withKane in the
module motionequation. I tried and confirmed that it will return
several kinds of the motion equations, for example, Newton's second
law, Euler's equations of rigid body, etc.

ondrej.certik provided me with useful information on the project for
such a feature which is found at:
http://code.google.com/p/pydy/

I'm going to write more about how to specify the arguments of the
function to use for your own project.

Luke

unread,
May 23, 2009, 5:06:31 PM5/23/09
to sympy
This is cool, it is good to see other people who are familiar with
Kane's method, there aren't many of us :)

Are you familiar with Autolev? With PyDy, I am working to achieve
some of the same behavior as Autolev, but make it even better, and
have a lot more features. I'd love to hear your input on design
choices for PyDy if you have the time. Right now I'm working on
extending it to allow for the 12 different Euler angles, and the 12
different space fixed angles, Euler parameters, Rodrigues parameters,
and axis/angle rotations. The major work to take care of kinematics
automatically is in place, but there is definitely more to do in
regards to how to deal with constraints, definitions of generalized
speeds, etc...

What sort of systems do you use Kane's method to study? My own area
of research is two wheeled vehicle (bicycle/motorcycle) dynamics and
control.

~Luke


On May 23, 6:06 am, "2006.uchida" <2006.uch...@gmail.com> wrote:
> I made a small script in MuPAD few years ago but I had to say goodbye
> to MuPAD last November, so I found Sympy and have translated it into
> Sympy now. I want to share it and I'm happy if I get some comments.
>
> What I made is the small script that generates motion equations for
> multibody dynamics by using Kane's method. It handles multibody
> dynamics, the dynamic behavior created with several rigid bodies that
> are interconnected, for instance, double pendulum, robot arms, crank
> mechanism, etc. The script allows you to get the equation easily by
> setting some information of masses, positions, forces, etc.
>
> available for download from here:http://www.esnips.com/doc/0960cb0a-8820-4169-b582-d58a2d6c5f28/MoEqGe...

2006.uchida

unread,
May 30, 2009, 12:56:33 AM5/30/09
to sympy
Thank you for your response. I first knew Autolev.
I took a look at one of the sample test codes of Pydy named
"simplependulum.py" and didn't look into the details but it appears
that it allows us to obtain motion equations and simulations by only
connecting the class instances that represent rigid bodies, sorry if I
misunderstand.
It is a cool idea! We no longer need to transform the coordinates nor
to calculate the absolute positions of the rigid objects one by one,
which is a hard part for me in using Kane's method. Moreover, it also
provides the dynamics simulations as well as the equations. We can do
a simulation without thinking about programming for the integration of
the simulation.
I think it would be good to design the interface using a class that
represent a kind of rigid bodies, links, forces, or any other
extentions with understandable, short names and to make the setup for
the usage easy like all that we have to do to use the feature is only
to make up the relations of the class instances.
Anyway, it would already make our life easier.

Ondrej Certik

unread,
May 31, 2009, 3:28:29 PM5/31/09
to sy...@googlegroups.com
Hi,

2009/5/29 2006.uchida <2006....@gmail.com>:


>
> Thank you for your response. I first knew Autolev.
> I took a look at one of the sample test codes of Pydy named
> "simplependulum.py" and didn't look into the details but it appears
> that it allows us to obtain motion equations and simulations by only
> connecting the class instances that represent rigid bodies, sorry if I
> misunderstand.
> It is a cool idea! We no longer need to transform the coordinates nor
> to calculate the absolute positions of the rigid objects one by one,
> which is a hard part for me in using Kane's method. Moreover, it also
> provides the dynamics simulations as well as the equations. We can do
> a simulation without thinking about programming for the integration of
> the simulation.
> I think it would be good to design the interface using a class that
> represent a kind of rigid bodies, links, forces, or any other
> extentions with understandable, short names and to make the setup for
> the usage easy like all that we have to do to use the feature is only
> to make up the relations of the class instances.
> Anyway, it would already make our life easier.

Excellent. Let us know if you'd like to join the development. For
example just test pydy and report all bugs, so that Luke has some more
feedback from more people.

Ondrej

Luke

unread,
Jun 1, 2009, 11:16:43 AM6/1/09
to sympy
If you are familiar with Autolev, then you are probably familiar with
some of the behavior that makes it very convenient and easy to derive
equations of motion in. You might also be familiar with some of its
limitations. One of the main goals of PyDy is to replicate (in a more
Pythonic way) the features of Autolev, and improve upon its
deficiencies. One of the main things I have implemented so far that
is very useful is the 12 Euler and 12 Space fixed rotation
conventions, into a convenient framework for working with vector
expressions without having to deal with the rotation matrices /
transformations explicitly. This makes many things much simpler when
defining your problem.

I would love to hear your input on feature requests or overall design
approaches for PyDy. Here is all the group information:
* http://groups.google.com/group/pydy
* py...@googlegroups.com
* http://dlpeterson.com/blog

I have classes for ReferenceFrame and am working on the Point class,
my idea is to implement methods for each of these classes that can
assign inertia and/or torque (ReferenceFrame) and mass and/or force
(Point), which, combined with the kinematics of the problem, will
allow for Kane's method to be utilized and the equations of motion
generated in a very algorithmic and systematic fashion.

There are already a few example problems up there, but if you think
any others, I'd be happy to put them up -- the more the better.

~Luke

Alan Bromborsky

unread,
Jun 1, 2009, 5:25:00 PM6/1/09
to sy...@googlegroups.com
You might want to look in "Geometric Algebra for Physicists" by Doran
and Lasenby, Chapter 3 - Classical Mechanics. Especially look at the way
rotations can be handled. For example the spinor equations for planetary
motion are harmonic oscillators. Geometric algebra is being used in
robotics to simplify the modeling of robotic arms, etc. Another thing to
look at is conformal geometry (Chapter 10) where 3-dimensions are mapped
to 5-dimensions, but translations, scaling, and rotations in
3-dimensions become rotations of null vectors in 5-dimensions.

Luke

unread,
Jun 1, 2009, 9:14:27 PM6/1/09
to sympy
Alan,
I've browsed this text a little, but to be honest, I was unable to
see the direct advantage of such an approach, at least for the type of
work I'm involved with. I'm willing to trust that the mathematics are
cleaner and more complete, but I'm curious what the advantage is in
the end. Do you know specific types of systems that really benefit
from this approach? I am currently studying the rolling torus and the
Whipple bicycle model, and I would be curious to see how the GA
approach would compare to a more classical approach. Have you seen
the GA approach applied to classical examples like the rolling disc or
torus, or any other nonholonomic systetms?

Also, I have another text in electronic format called Geometric
Algebra with Applications in Engineering, by Christian Perwass. Are
you familiar with it? If so, do you recommend it as an alternative to
the book by Doran and Lasenby? Or is Doran and Lasenby available
electronically?

Thanks,
~Luke






On Jun 1, 2:25 pm, Alan Bromborsky <abro...@verizon.net> wrote:
> Luke wrote:
> > If you are familiar with Autolev, then you are probably familiar with
> > some of the behavior that makes it very convenient and easy to derive
> > equations of motion in. You might also be familiar with some of its
> > limitations. One of the main goals of PyDy is to replicate (in a more
> > Pythonic way) the features of Autolev, and improve upon its
> > deficiencies. One of the main things I have implemented so far that
> > is very useful is the 12 Euler and 12 Space fixed rotation
> > conventions, into a convenient framework for working with vector
> > expressions without having to deal with the rotation matrices /
> > transformations explicitly. This makes many things much simpler when
> > defining your problem.
>
> > I would love to hear your input on feature requests or overall design
> > approaches for PyDy. Here is all the group information:
> > *http://groups.google.com/group/pydy
> > * py...@googlegroups.com
> > *http://dlpeterson.com/blog

Alan Bromborsky

unread,
Jun 1, 2009, 9:45:35 PM6/1/09
to sy...@googlegroups.com
The problem is you have one text and I have the other. I don't know what
is in Perwass's book. If I google "geometric algebra robotics" I get
lots of links. However, they are usually articles in engineering
journals which means you either have to pay for them or have a
university library available to you. One advantage of working in physics
is that you can find free online copies of many of the journal articles.
One of the main advantages of geometric algebra is to be able to
formulate rotations simply. I have not seen a specific reference but
there are many references to robot arms. Doran and Lasenby does contain
a simple treatment of the symmetric top. The main book on mechanics
written from the perspective of geometric algebra is "New Foundations
for Classical Mechanics" by David Hestenes which covers just about
everything in classical mechanics, although not with as much depth in
some areas as one would wish for. In the Hestenes book there is a
section on rolling motion including a ball rolling inside of a cylinder
as an example.

Luke

unread,
Jun 1, 2009, 11:14:02 PM6/1/09
to sympy
Alan,
Thanks for the information. I'll check out both the Lasenby book
and the Hestenes book at the UC Davis library. If I have time this
summer, maybe I can implement some approaches for formulating the
equations of motion that utilize the machinery of what you have
implemented for Geometric Algebra within Sympy. It would be really
cool to have that capability built into PyDy. I will need to look
into this further.
Thanks,
~Luke

2006.uchida

unread,
Jun 7, 2009, 7:15:12 AM6/7/09
to sympy
Thank you for your responses and I'm sorry for my late response.

Thank you, Ondrej. I want to try to use Pydy, but I don't think I can
have time enough to help the development by testing all the features
of Pydy to find any bugs. Of course, when I use Pydy and find some
bugs, I will definitely report them on those groups. However, I'm
occupied with work in my company on all weekdays and a few weekends.

Thank you, Luke. I understood your idea in Pydy and it is useful. I'm
going to try to use the feature that you implemented looking into the
examples that you provided above. I want to let you know a few idea if
I find. But first of all, all that I have to do is to dive into the
Pydy world :) I'll start with one of the examples.

Ondrej Certik

unread,
Jun 7, 2009, 3:19:20 PM6/7/09
to sy...@googlegroups.com
On Sun, Jun 7, 2009 at 5:15 AM, 2006.uchida<2006....@gmail.com> wrote:
>
> Thank you for your responses and I'm sorry for my late response.
>
> Thank you, Ondrej. I want to try to use Pydy, but I don't think I can
> have time enough to help the development by testing all the features
> of Pydy to find any bugs. Of course, when I use Pydy and find some
> bugs, I will definitely report them on those groups. However, I'm
> occupied with work in my company on all weekdays and a few weekends.

Sure, I understand -- being busy all weekdays and weekends sounds very
familiar to me. :)

>
> Thank you, Luke. I understood your idea in Pydy and it is useful. I'm
> going to try to use the feature that you implemented looking into the
> examples that you provided above. I want to let you know a few idea if
> I find. But first of all, all that I have to do is to dive into the
> Pydy world :) I'll start with one of the examples.

Definitely. Btw, Luke created a mailinglist for pydy, see the webpage:

http://pydy.org/

and it already has some interesting threads.

Ondrej

Reply all
Reply to author
Forward
0 new messages