AutodeskRoboticsLab / Mimic

An open-source Maya plugin for controlling Industrial Robots. Written in Python 3.
https://www.mimicformaya.com/
172 stars 39 forks source link

matrix to euler: create new list and round to 0 if very small to prevent atan2 problems #46

Closed aatb-ch closed 9 months ago

aatb-ch commented 9 months ago

While investigating pose rotations while implementing linear export for UR in #44 i stumbled upon very strange euler angles returned by euler_angles_by_matrix, traced it to Maya returning not 0 but very small values sometimes and feeding these almost 0 values to atan2 returns wild results.

https://github.com/AutodeskRoboticsLab/Mimic/blob/3c33ea07b29c7e11268fb99078e3afe46c097971/mimic3/scripts/robotmath/transforms.py#L153

I added a step to round down to 0 very small values to prevent that, seems to fix the issue.

Example matrix returned by Mimic/Maya:

[-5.715780062744253e-16, 1.0000000000000004, -4.998281860349651e-16]
[-3.8719027983802334e-15, 4.440892098500628e-16, 1.0]
[1.0000000000000004, 2.8899813360850883e-16, 3.6914915568786455e-15]

instead of the expected

[0,1,0]
[0,0,1]
[1,0,0]

which results in [-98.39746772339547 -90.0 -89.99999999999997] instead of the correct [-90,0,-90].

evanatherton commented 9 months ago

Good catch - thanks @aatb-ch!