Skip to content

fix: check numerical IK convergence before solver step - #667

Merged
petercorke merged 2 commits into
petercorke:mainfrom
tahazarif10:fix/664-ik-prestep-convergence
Sep 12, 2026
Merged

fix: check numerical IK convergence before solver step#667
petercorke merged 2 commits into
petercorke:mainfrom
tahazarif10:fix/664-ik-prestep-convergence

Conversation

@tahazarif10

Copy link
Copy Markdown
Contributor

Thanks for contributing to RTB!

Summary

Fix the shared numerical IK solve loop so an initial configuration that already satisfies the target pose is accepted before attempting a solver update.

Currently, IKSolver._solve() calls step() before checking whether the current configuration has already converged. This can cause an unnecessary linear algebra failure even when q0 is already an exact solution — notably with a redundant Panda robot using IK_LM(method="chan").

This change:

  • evaluates the residual for the initial configuration before any solver update;
  • checks convergence before attempting the next step;
  • makes NR, LM, GN, and QP step() implementations return the residual associated with the updated configuration;
  • preserves existing joint-limit and search behavior;
  • adds a regression test covering exact-q0 convergence for LM, NR, and GN with zero solver iterations.

Related issue

Fixes #664

Checklist

  • PR title follows Conventional Commits
  • Tests pass locally (pytest)
  • Added/updated tests for this change, if applicable
  • New/changed code is type-hinted where applicable
  • Docstrings remain consistent with the updated solver contract
  • PR is small/focused on a single issue
  • No project-specific test files, data files, or notebooks are included

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (b53f255) to head (8b0eb83).

Files with missing lines Patch % Lines
src/roboticstoolbox/robot/IK.py 0.00% 15 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #667   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files        143     143           
  Lines      14050   14055    +5     
=====================================
- Misses     14050   14055    +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@petercorke
petercorke force-pushed the fix/664-ik-prestep-convergence branch from 78bc948 to 8b0eb83 Compare September 12, 2026 18:48
@petercorke

Copy link
Copy Markdown
Owner

Thanks @tahazarif10 for the fix, and @niamorg for originally flagging this. Glad to see people are using the IK functions. While looking at this fix I found yet another thing to fix, see #668.

@petercorke
petercorke merged commit c734816 into petercorke:main Sep 12, 2026
23 checks passed
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.

IK solvers perform unnecessary and dangerous last update (can return success=False even when valid solution was found)

2 participants