Skip to content

fix(ik): abandon a search whose joint angles diverge, and restart it - #948

Merged
petercorke merged 2 commits into
mainfrom
fix/ik-abandon-diverged-search
Nov 17, 2026
Merged

petercorke merged 2 commits into
mainfrom
fix/ik-abandon-diverged-search

Conversation

@petercorke

Copy link
Copy Markdown
Owner

What

A Gauss-Newton or Newton-Raphson search can diverge from a bad start. With the compiled fkine an infinite joint angle gives NaN, and the search burned iterations until ilimit. With the pure-Python fkine, rotz(inf) raises ValueError: math domain error, which escaped solve() and ended the whole call.

_solve() now abandons the search as soon as q or E is no longer finite, and restarts it, as it already does for numpy.linalg.LinAlgError. The failure reason says how many searches diverged. A ValueError with a finite q is still raised: step() updates q in place, so q shows which case it is (checked for IK_NR, IK_LM, IK_GN and IK_QP).

Found by the new pure-Python coverage leg in #946. test_IK_GN1 failed on a Mac and test_IK_NR8 on the Ubuntu runner: the searches are chaotic, and a 1e-13 change to the target flipped the outcome, so which test failed depended on the platform.

Refs #898.

Behaviour

  • On the pure-Python path a diverging search used to raise ValueError; it now restarts.
  • On the compiled path a NaN search is now abandoned at once instead of running to ilimit. The result is the same, but iterations can be lower in those cases.

What I ran, and what I could not

  • New TestDivergedSearch in tests/test_IK.py: a step that diverges by raising, one that diverges by returning NaN, a failure message that names the cause, and an unrelated ValueError that must still propagate. Three of the four fail without the change.
  • In a clean venv built from the pure wheel, the settings of test_IK_GN1 and test_IK_NR8 now succeed at all six target perturbations (0 to 1e-9); before, they raised or failed at most of them.
  • tests/test_IK.py and tests/test_Robot.py there show no new failures. The ones left need the compiled extension, or are fixed by fix(robot): update link scene-node transforms without the compiled extension #947, which this branch does not include.
  • Could not run the compiled path locally (no compiled build here), so CI's compiled legs are the check for it.

AI assistance

Written with Claude Code (Claude Sonnet 5.5), reviewed by the maintainer.

🤖 Generated with Claude Code

A Gauss-Newton or Newton-Raphson search can diverge from a bad start. With
the compiled fkine the infinite joint angles give NaN, and the search burned
iterations until ilimit; with the pure-Python fkine, rotz(inf) raises
ValueError: math domain error, which escaped solve() and ended the whole
call. Which of test_IK_GN1 and test_IK_NR8 failed depended on the platform:
a 1e-13 change to the target flipped the outcome.

_solve() now abandons the search as soon as q or E is no longer finite, as it
already does for LinAlgError, and says so in the failure reason. A ValueError
with a finite q is still raised. step() updates q in place, so q shows which
case it is.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 19 complexity · 0 duplication

Metric Results
Complexity 19
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit ea35e42 into main Nov 17, 2026
22 of 23 checks passed
@petercorke
petercorke deleted the fix/ik-abandon-diverged-search branch November 17, 2026 06:53
@github-actions github-actions Bot mentioned this pull request Nov 17, 2026
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