solving for Euler angles

23 views
Skip to first unread message

Sebastian Luque

unread,
Dec 11, 2019, 5:17:29 PM12/11/19
to sympy
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

Reply all
Reply to author
Forward
0 new messages