Archive for May, 2009

Body (Euler) fixed / Space fixed angles implemented in PyDy

Monday, May 25th, 2009

The rotate() method of the Vector() class in PyDy now supports the 12 Euler angle rotations and the 12 space fixed rotations. Additionally, it automatically calculates the angular velocity of the new reference frame with respect to the parent frame. Here is how it works:

>>> t = Symbol(‘t’)
>>> q1 = Function(‘q1′)(t)
>>> q2 = Function(‘q2′)(t)
>>> q3 = Function(‘q3′)(t)
>>> A = ReferenceFrame(‘A’)
>>> B = A.rotate(‘B’, ‘BODY123′, (q1, q2, q3))
>>> dot(A[1], B[3])
sin(q2(t))
>>> dot(A[1], B[2])
-cos(q2(t))*sin(q3(t))
>>> dot(A[1], B[1])
cos(q2(t))*cos(q3(t))
>>> B = A.rotate(‘B’, ‘SPACE321′, (q1, q2, q3))
>>> dot(A[1], B[3])
sin(q2(t))
>>> dot(A[1], B[2])
-cos(q2(t))*sin(q1(t))
>>> dot(A[1], B[1])
cos(q1(t))*cos(q2(t))
>>>

The A[i], B[i] (i=1,2,3) notation indicates the i’th unit vector fixed in each of the reference frames, with the usual right hand rule applying: cross(A[1], A[2]) == A[3]

All 24 angle set conventions are implemented, and tests have been written to ensure they return the correct result. Rotations about an arbitrary axis, as well as the use of Rodrigues parameters or Euler parameters remain to be implemented, but they should be done in the next week.

This code has highlighted the need for some serious work to be done on Sympy’s trigsimp(). Especially when calculating the angular velocity vectors, things get messy quickly and unless the trigonometric simplification routines are up to the task, things will get unnecessarily messy. In the next week I will be working to implement the rule based algorithm presented by Fu et al.:

Automated and readable simplification of trigonometric expressions

Rigid body mechanics are notorious for long nasty trigonometric expressions, so implementing this will really help Sympy and how it deals with trigonometric expressions.

PyDy Google group website and emailing list

Friday, May 22nd, 2009

The Google group page is here:

http://groups.google.com/group/pydy

The emailing list is here:

pydy@googlegroups.com

PyDy / Sympy progress

Thursday, May 21st, 2009

Sympy 0.6.5 currently doesn’t allow for you to solve an expression, or differentiate with respect to, anything but a sympy Symbol.  This is problematic for PyDy because generally the generalized coordinates that are used are not just sympy Symbols, but instead are sympy Functions, implicitly dependent upon time.  So what I did was to implement the code that would allow solve to solve for not just Symbols, but also for Functions and Derivatives. So as a trivial example, the following code now works:

>>> from sympy import *
>>> x = Symbol(‘x’)
>>> solve(1-x, x)
[1]
>>> t = Symbol(‘t’)
>>> x = Function(‘x’)(t)
>>> solve(1-x, x)
[1]
>>> solve(1-x.diff(t), x.diff(t))
[1]
>>>

The patch that allows this behavior should be pushed into the main branch of sympy pretty soon, so if you clone the repo in the next few days, you should have this functionality as well.

Like I said, the example is trivial, but now, this will allow PyDy to solve the dynamic equations of motion (linear in the second time derivatives of the coordinates and/or first time derivatives of the generalized speeds). So as long as the linear solvers are up to the task of solving long, long, expressions, PyDy should be able to get the equations of motion in a form that will be directly ready for numerical integration, a key step to the task of generating animations. This is a good step forward.

The next task I’ll be tackling is to fix diff() so that it can differentiate with respect to objects other than the sympy Symbol, i.e., so that you can differentiate with respect to Functions and Derivative instances. This should be a very similar patch and should be done very soon.

Once that is done, I plan on spending some time on improving trigsimp(). Having this function work well will really help PyDy because with these long chains of rotations, the number of trigonometric terms becomes lengthy and having the most compact representation is ideal.