Skip to content

feat(ik): IKSolution is a sequence of the rows of q, true if successful - #717

Open
petercorke wants to merge 1 commit into
mainfrom
feat/iksolution-sequence
Open

petercorke wants to merge 1 commit into
mainfrom
feat/iksolution-sequence

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

IKSolution now behaves as a sequence of the joint vectors of the poses it holds, so a solution for a single pose and for a trajectory are used the same way (numeric or analytic):

  • len(sol) is the number of poses: 1 for a single pose, N for a trajectory, 0 if q is None
  • for q in sol, sol[i] and slices give the rows of q. sol[i] is np.atleast_2d(sol.q)[i], an array and not an IKSolution, because success, residual and reason apply to the whole solution
  • bool(sol) is sol.success
  • sol.astuple() returns the six fields as a tuple
  • printing: a trajectory shows the number of poses and a long q is abbreviated (first three and last two poses); the residual of a failed solution is no longer rounded to zero; an analytic solution shows its residual if it has one. The single pose format is otherwise unchanged.

This prepares the analytic IK work, which needs one result type for single poses, trajectories and "all solutions of one pose".

Incompatible change

Iterating an IKSolution used to give its six fields (added in 1.4.2 for code written against the old bare tuple), so q, success, ... = sol and sol[1] no longer work. Use the attributes or sol.astuple(). This is a small incompatible change, committed as a feat (no major version bump), as is usual for such changes here.

I searched for uses of the old form in this repo (code, docstrings, .rst, notebooks, examples), the wiki, and the RVC3-python, MVTB, bdsim and rvc-* repos. The only ones were in tests, the __main__ demo at the bottom of IK.py, and one README snippet (which also showed an out-of-date result format), all updated here. External users are unknown.

Notes

Test plan

  • tests/test_IK.py, test_ik_joint_limits.py, test_Robot.py, test_DHRobot.py, test_ETS.py, test_trajectory.py: 473 passed
  • new tests: single pose is one row, trajectory rows / slices / index arrays / IndexError, NumPy sees the rows, q is None is empty, bool(sol) is success (also with rows present), astuple, a real solver trajectory, and the print cases (trajectory, long trajectory abbreviated, failed residual not rounded, analytic without a residual)
  • the five ik_* tests that read success with sol[1] and the old tuple tests are rewritten to use attributes
  • CI

🤖 Generated with Claude Code

An IKSolution now behaves as a sequence of the joint vectors of the poses it
holds, so a solution for a single pose and for a trajectory are used the same
way:

- len(sol) is the number of poses, 1 for a single pose, 0 if q is None
- for q in sol, sol[i] and slices give the rows of q, sol[i] is
  np.atleast_2d(sol.q)[i], an array and not an IKSolution since success,
  residual and reason apply to the whole solution
- bool(sol) is sol.success
- sol.astuple() returns the six fields as a tuple

Iterating an IKSolution used to give its six fields, so q, success, ... = sol
and sol[1] no longer work, use the attributes or astuple().  Nothing in this
repository, its docs and examples, or RVC3, MVTB and bdsim used that form,
apart from tests, the __main__ demo and a README snippet which are updated.

Printing is improved: a trajectory shows the number of poses and a long q is
abbreviated, the residual of a failed solution is no longer rounded to zero,
and an analytic solution shows its residual if it has one.  The format for a
single pose is otherwise unchanged.

This is a small incompatible change, released as a feat as is usual for such
changes here.

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 27 complexity · -2 duplication

Metric Results
Complexity 27
Duplication -2

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.

@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (acc6842) to head (6d4fc42).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/roboticstoolbox/robot/IK.py 0.00% 36 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #717   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files        143     143           
  Lines      14269   14293   +24     
=====================================
- Misses     14269   14293   +24     

☔ 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.

This branch has not been deployed

No deployments
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