Skip to content

To euler fix #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions PythonClient/airsim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,32 @@ def write_file(filename, bstr):

# helper method for converting getOrientation to roll/pitch/yaw
# https:#en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles

def to_eularian_angles(q):
z = q.z_val
y = q.y_val
x = q.x_val
w = q.w_val
ysqr = y * y

# roll (x-axis rotation)
t0 = +2.0 * (w*x + y*z)
t1 = +1.0 - 2.0*(x*x + ysqr)
roll = math.atan2(t0, t1)

# pitch (y-axis rotation)
t2 = +2.0 * (w*y - z*x)
if (t2 > 1.0):
t2 = 1
if (t2 < -1.0):
t2 = -1.0
pitch = math.asin(t2)

# yaw (z-axis rotation)
t3 = +2.0 * (w*z + x*y)
t4 = +1.0 - 2.0 * (ysqr + z*z)
yaw = math.atan2(t3, t4)
test = +2.0 * (w*y - z*x)
#pitch near -90 or 90 need to be handled differently
if (abs(test) > 0.999999):
pitch = math.pi/2 * test
yaw = 2 * math.atan2(z,w)
roll = 0
else:
#not sigularity
pitch = math.asin(test)
# roll (x-axis rotation)
t0 = +2.0 * (w*x + y*z)
t1 = +1.0 - 2.0*(x*x + ysqr)
roll = math.atan2(t0, t1)
# yaw (z-axis rotation)
t2 = +2.0 * (w*z + x*y)
t3 = +1.0 - 2.0 * (ysqr + z*z)
yaw = math.atan2(t2, t3)

return (pitch, roll, yaw)

Expand Down