Skip to content

posemath: fix negative pitch singularity in ZYX conversion - #4623

Open
Rimas2200 wants to merge 1 commit into
LinuxCNC:masterfrom
Rimas2200:fix/gomath-euler-singularities
Open

Rimas2200 wants to merge 1 commit into
LinuxCNC:masterfrom
Rimas2200:fix/gomath-euler-singularities

Conversation

@Rimas2200

@Rimas2200 Rimas2200 commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

At pitch -pi/2, pmMatZyxConvert() recovers roll from m->y.z, which vanishes at the pole. Use -atan2(m->y.x, m->y.y) to preserve the rotation with yaw set to zero, matching pmMatRpyConvert().

Retarget the remaining ZYX fix to posemath following #4676. Port the regression tests to a component loaded after tpmod, which exports the matrix conversions and their quaternion wrappers. The 322 conversion checks cover both poles, their neighborhoods, ordinary rotations, and both quaternion signs using an independent rotation-matrix oracle.

Validation: uspace build and pycheck passed; tests/posemath/euler-singularities and tests/kins-jacobian passed. The Euler test reproduces the negative-pole ZYX failure with the original formula.

@grandixximo

Copy link
Copy Markdown
Contributor

Pointing at 2.9, again we might want it on master first @andypugh @BsAtHome ?

@BsAtHome

BsAtHome commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Yes, target master branch. Then, wouldn't it be better to look at consolidating all these routines? There is overlap between gomath and posemath IIRC.

@rmu75 rmu75 added the NML label Oct 9, 2026
@rmu75

rmu75 commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

As these routines currently live in libnml and we want to remove that it is probably a good idea to consolidate the math routines and put them into a more appropriate library.

@grandixximo

Copy link
Copy Markdown
Contributor

please point to master

@grandixximo

Copy link
Copy Markdown
Contributor

@Rimas2200 thanks for tracking this down. Following the consolidation suggestion above, I opened #4676, which moves genserkins, the only user of gomath, onto posemath and removes gomath, so this PR would have no gomath left to change. posemath's pmMatRpyConvert() already takes the -pi/2 branch the way your fix does, so #389 is fixed there for genser; I credited your analysis in that PR.

Your ZYX half is still needed, though, in posemath now: pmMatZyxConvert() checks -pi/2 correctly but recovers the roll from m->y.z, which is zero at that pitch, the same mistake you fixed in go_mat_zyx_convert(). Nothing in the tree calls it today, so it is latent. If you want to retarget this PR to that fix, your pole tests would carry over to pmMatRpyConvert() and pmMatZyxConvert(), written as a component loaded after a module that exports them, like tests/kins-jacobian, since tests that compile tree sources break as soon as those sources gain EXPORT_SYMBOL (#4670).

@Rimas2200

Copy link
Copy Markdown
Contributor Author

Sure, no problem. I’ll get to it closer to the weekend. I’m currently fighting with some hardware issues on a Delta robot, so I’m a bit tied up 😄 Thanks for the detailed pointers!

@Rimas2200
Rimas2200 force-pushed the fix/gomath-euler-singularities branch from 40b3a39 to e06d24a Compare October 14, 2026 18:37
@Rimas2200 Rimas2200 changed the title gomath: fix negative pitch singularities in RPY and ZYX conversion posemath: fix negative pitch singularity in ZYX conversion Oct 14, 2026
@Rimas2200
Rimas2200 changed the base branch from 2.9 to master October 14, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants