Hello,

I'm learning Sympy and trying to replicate a solution for the Euler
pitch and roll angles as described in a well-known Application Note:

https://cache.freescale.com/files/sensors/doc/app_note/AN3461.pdf

In particular, Equations 24 through 26.  Here's the set up matching the
reference frame used in the note.

import sympy as sy


def x_rotation(angle):
    return sy.Matrix([[1, 0, 0],
                      [0, sy.cos(angle), sy.sin(angle)],
                      [0, -sy.sin(angle), sy.cos(angle)]])


def y_rotation(angle):
    return sy.Matrix([[sy.cos(angle), 0, -sy.sin(angle)],
                      [0, 1, 0],
                      [sy.sin(angle), 0, sy.cos(angle)]])


def z_rotation(angle):
    return sy.Matrix([[sy.cos(angle), sy.sin(angle), 0],
                      [-sy.sin(angle), sy.cos(angle), 0],
                      [0, 0, 1]])


phi, theta, psi = sy.symbols("\\phi, \\theta, \\psi")
x, y, z, g = sy.symbols("x, y, z, g")
g_v = sy.Matrix([[0, 0, g]])    # gravity vector
acc = sy.Matrix([[x, y, z]])    # acceleration vector

I can certainly reproduce the referred rotation matrix in Eq 8 (`tilt_0'
below), with a slight modification to my convention of post-multiplying
a row vector by the rotation matrix:

xyz_mat = (x_rotation(phi)
           * y_rotation(theta)
           * z_rotation(psi))
tilt_0 = g_v.subs(g, 1) * xyz_mat.T

However, solving for pitch angle `theta' doesn't give the same result as
the paper:

In [10]: sy.solve(acc - tilt_0, phi)
Out[10]: [(pi - asin(y/cos(\theta)),), (asin(y/cos(\theta)),)]

What am I missing in this derivation?

--
Seb

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/2d2b2cda-e448-4703-9cd6-a1dc13551ae4%40googlegroups.com.

Reply via email to