Skip to content

genhexkins: screw-lead rates in the forward and the Jacobian, and NaN handling - #4903

Open
Ash-Pera wants to merge 1 commit into
LinuxCNC:masterfrom
Ash-Pera:genhex-screw
Open

Ash-Pera wants to merge 1 commit into
LinuxCNC:masterfrom
Ash-Pera:genhex-screw

Conversation

@Ash-Pera

Copy link
Copy Markdown
Contributor

Three fixes in genhexkins, with checks for each in tests/genhexkins-forward. With screw-lead at 0, its default, only the first changes anything.

  • NaN. Where the seed already fits, a NaN strut length or a singular Jacobian (as with no lead and the platform turned 90° at home) came back as success with a NaN pose. Both now fail.
  • Rates. With a screw lead, the forward's Newton step left out the correction's rates. Over the test's 600 poses with a lead of 5, from a cycle off, 455 did not converge within 8 iterations; at the default limit of 120, 24 still did not and 9 came back off the pose. With the rates none takes more than 5. genhex_jacobian() takes the same rates, in closed form, instead of differencing the inverse.
    From a seed well off, as the one from home after a failure, a full step could lead to another pose with the same strut lengths, or not converge. With a lead set, a step that moves roll, pitch or yaw by more than 0.2 rad is now shortened to that. From a cycle away no step is that long in practice (3 of a million seeds).
  • asin(). Where a strut's twist is at a quarter turn, asin() could give NaN, in the inverse or in a step of the forward, and next to it the forward took more iterations: with the rates but with asin(), 621 of 2049 poses there failed at the test's limit of 8. It is now atan2() of the sine and |cosine|, the same angle.

Numbers from a harness outside LinuxCNC, lead 5 and the default geometry:

  • The inverse is within 1e-9 of master's over 200000 random poses.
  • Motion reseeds from home after a failure. From there, over 50000 random poses in the box of the test's grid, 23 fail and 238 come back as another pose with the same strut lengths; without the shortening 62 and 290, on master 372 and 221. With limit-iterations at 8, 1463 fail, against 351 without the shortening; on master all do.
  • With a lead of -5, one of the 600 poses comes back as another with the same strut lengths. With the axes level and across each strut at home none does, at 5 or -5.

The correction still folds at a quarter turn; that is #4902. pentakins has the same NaN tests; I've left it.

🤖 Generated with Claude Code

…dling

The forward tested its errors for convergence with >, which is false for
a NaN, and after the step, so it returned a NaN pose as success where the
seed already fits and a strut length is NaN, or the Jacobian is singular,
as with no lead and the platform turned 90 degrees at home, or flat in the
base's plane.  Require the step to be finite.  A NaN length difference
makes it NaN.

With genhexkins.screw-lead set, each strut length carries a correction
that changes with the pose, but the forward's Newton step left its rates
out of the Jacobian rows.  Over the 600 poses of tests/genhexkins-forward
with a lead of 5, each seeded a cycle away, 455 did not converge within 8
iterations; at the default limit of 120, 24 still did not and 9 came back
off the pose.  Add the rates to the rows, as the gradient of the twist
about the strut; none of the poses takes more than 5 iterations.

From a seed well off, as the one from home after a failure, a full step
can lead to another pose that has the same strut lengths, or not converge.
With a lead set, shorten a step that moves roll, pitch or yaw by more than
0.2 radian.  One cycle away the steps are almost always shorter than that.

genhex_jacobian() differenced the inverse when a lead was set.  It takes
the same rates now, in closed form, and tests/kins-jacobian's lead-5 case
checks them.

The correction was asin() of the sine of the twist, taken as the dot
product of two normalised vectors.  At a quarter turn rounding can carry
the product past +-1, and asin() is NaN, in the strut lengths of the
inverse or in a step of the forward.  Next to one asin() loses half the
digits, and the forward takes more iterations.  Take atan2() of the
twist's sine and |cosine|, which is the same angle and does neither.

tests/genhexkins-forward checks a NaN strut and a singular Jacobian, and
its own comparison now fails on a NaN pose rather than pass it.  It runs
its grid a second time with a lead of 5, with three far poses from home
that need the shortened step, and 2049 poses next to a quarter turn, where
621 failed with the rates but with asin(), on amd64.  It also pins the
correction of a strut past a quarter turn.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant