twp: split the machine maths out of the tilted work plane remap - #4551
Open
grandixximo wants to merge 2 commits into
Open
grandixximo wants to merge 2 commits into
grandixximo wants to merge 2 commits into
Conversation
The remap carried the geometry of every supported machine as branches on the (primary, secondary) letter pair inside its four kinematics functions, so adding a machine meant adding a branch to each. The generic half is remap.py now and the machine half a remap_funcs_twp.py beside each config, imported by name: eleven functions the generic side asks a machine, which joint angles reach a tool orientation, how to build the transformation, the default tool x, what to write on the module pins. The split and the generic file are David Mueller's, from https://github.com/Sigma1912/LinuxCNC_Demo_Configs/tree/main/5axis-twp. Adapted: the ini is read through linuxcnc.ini, the kinematics switch is G12.1 rather than the deprecated motion.switchkins-type pin, the angles reach the module pins in degrees, pin names unchanged. Three fixes come with it: kins_calc_primary collected only the last candidate's primary angle, so P1 and P2 failed where a solution existed; candidate angles were compared in radians against limits in degrees; on xyzbca-trsrn G53.6, G68.3 and one G53.3 case reported success without activating the plane. Both configs verified over eight orientations under every code against the run before the change, tool vectors identical to 1e-9.
A tool vector in a principal plane raised "math domain error" from asin() in kins_calc_primary: the vector is a column of a product of rotations, a unit vector only to rounding, and a zero component lands the argument a rounding error outside plus or minus one. Sweeping every reachable orientation in five degree steps gave 47 failures of 5184 at the configured nutation, and every failure is a vector with a zero component, what G68.2 with I0 or J0 asks for. Clamp an argument within rounding of the limit and leave anything further out to raise, since that is an unreachable orientation rather than an artefact. kins_calc_possible_joint_angles then fell through to an unassigned variable on that failure; it returns no solution, which the caller handles.
BsAtHome
reviewed
Sep 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The tilted work plane remap in the two trsrn sim configs carried every supported machine as branches inside its kinematics functions, so adding a machine meant a branch in each. This splits it: remap.py is the generic half, and a remap_funcs_twp.py beside each config answers the eleven questions the generic side asks a machine (which joint angles reach a tool orientation, how the transformation is built, the default tool x, what to write on the module pins).
The split and the generic file are David Mueller's (@Sigma1912), from his 5axis-twp demo configs, adapted to read the ini through linuxcnc.ini, to switch kinematics with G12.1 instead of the deprecated pin, and to pass angles to the module in degrees. Pin names are unchanged.
Fixes that come with it: kins_calc_primary kept only the last candidate's primary angle, so P1 and P2 failed where a solution existed; candidate angles were compared in radians against limits in degrees; on xyzbca-trsrn G53.6, G68.3 and one G53.3 case reported success without activating the plane; and a tool vector in a principal plane, G68.2 with I0 or J0, raised "math domain error" from asin() on an argument a rounding error outside its range, 47 of 5184 orientations in a five degree sweep.
Both configs verified over eight orientations under every code against the run before the change, tool vectors identical to 1e-9.
Part of the plan in #4374: this python is the oracle the native G68.2 work is checked against.