kinematics: six fixes found by round-tripping every module - #4546
Merged
Merged
Conversation
BsAtHome
reviewed
Sep 15, 2026
BsAtHome
reviewed
Sep 15, 2026
The inverse turns the x and z offsets through the B tilt in the conventional sense, while the forward turns them in whichever sense the conventional-directions pin selects. With the pin false, which is the default, and any of x-offset, z-offset or tool-offset set, a pose does not survive the round trip: the position comes back out by twice sin(b) times the offset. xyzac has no term of this kind. Found by tests/kins-jacobian, which multiplies the derivative of the inverse by differences of the forward and expects the identity.
The forward sets the flag that makes the inverse negate its arc cosine when joint 1 is below 90 degrees, so for an elbow between 0 and 90 the inverse returns the other arm and the pose does not survive the round trip. The sign of the arc cosine is the sign of the elbow angle, so the test is against zero.
The forward decides the shoulder, elbow and wrist branches by comparing a joint angle with the value the inverse's formula gives, within a fuzz, and does not wrap the difference. A joint standing a whole turn from that value, which the differences of two atan2 results produce freely, fails the comparison and the inverse is sent down the other branch. The difference is brought into (-pi, pi] first.
…ns up once, at load These four build their pins on the first kinematicsType() call behind an is_setup flag nothing sets, so every later call runs the setup again, reassigns haldata and fails to create pins already taken; motion asks twice when num_extrajoints is set. Move the setup to EXTRA_SETUP(), which halcompile runs once before the component is ready, as the two trsrn modules already do. The pins exist from load, kinematicsType() only answers, and the hal_set_unready()/hal_ready() dance goes with it. userkins is the template for out of tree modules, so its description says where the pins go.
Two faults left kinematicsForward and kinematicsInverse disagreeing whenever the head is tilted, and nothing in tree could show it: max5 is the only config that loads the module and it ships B_PIVOT_LENGTH = 0 with six joints, so the pivot to tip distance is zero and U, V and W never leave zero. The forward took the U axis apart into xv and zv and subtracted both from the position it reports, while the inverse added xv back and subtracted zv again: X inverted and Z did not, in the same function, the shape of a typo rather than of a convention. The inverse now adds zv back. The forward also rotated the table and saddle into the workpiece frame and then subtracted the B, U and V corrections from the result, so those landed in the rotated frame; the inverse un-rotates first and adds them back in the machine frame. The vismach model says which is right: max5gui builds the head as tool, spindle, head, brotary, zslide, column, and the workpiece separately as crotary, table, saddle, so the head hangs off the Z slide and does not turn with the C table. The corrections are machine frame, they apply before the rotation, and the inverse had it right. The forward now subtracts them from the joint values and rotates the sum. A sweep of 40000 random poses, pivot lengths to 300 and tool lengths to 37.5, round trips to 2.7e-13, against 666 mm before. Reported world coordinates move for anyone running maxkins with the head tilted and the table turned; they were wrong by that amount, and the DRO and the machine now agree. Nothing moves at C0, and nothing moves at all on the max5 sim. tests/maxkins drives the machine through poses with the pivot length, the tool length and each of B, C, U, V and W away from zero and compares the position that comes back with the one commanded: motion runs the inverse to turn the pose into joints and the forward to turn the joint feedback into a position, so a pose that survives the round trip is one the two directions agree on. Both settings of conventional-directions are covered. Against the old code the pose with B 40 and U 15 came back 19.284 mm out in Z, twice u sin(b), and the pose with B 40 and C 30 landed 10.765 mm out in X and 40.174 mm out in Y.
grandixximo
force-pushed
the
kins-fixes
branch
from
September 15, 2026 12:27
4076f1b to
011d250
Compare
…refused handle_kinematicsSwitch() switched the module, then ran the new forward kinematics on the joints and, when that failed, reported it and kept the position it knew. The module stayed in the new type, so from the next cycle the inverse ran the joints to wherever that kept position lands in the new kinematics: on the hexapod that is a jump of twenty units on every strut, with no move commanded. The joints are where they are, and a kinematics whose forward cannot solve them is not one the machine can run in from there. Switch the module back before anything else sees the new type, report which type is still in force, and abort as before. Nothing moves and a later switch is taken on its own merits. tests/kins-switch-unsolved loads the hexapod with identity first, homes at zero, asks for the hexapod and checks that the type, the joints and the position are all as they were, that the failure was reported, that a move afterwards follows the identity inverse and that a switch to the type in force is accepted.
grandixximo
force-pushed
the
kins-fixes
branch
from
September 16, 2026 01:07
011d250 to
91dfff8
Compare
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.
Six independent fixes, each found by driving a pose through a module's inverse and back through its forward and expecting the same pose back. No interface changes.
Part of the plan in #4374.