Skip to content

Fix prismatic IK folding and harden joint-travel grasp ranking - #1324

Merged
Yuan-Xinyi merged 8 commits into
mainfrom
feat/least-joint-motion-ik-and-grasp
Dec 4, 2026
Merged

Yuan-Xinyi merged 8 commits into
mainfrom
feat/least-joint-motion-ik-and-grasp

Conversation

@Yuan-Xinyi

@Yuan-Xinyi Yuan-Xinyi commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The first two commits of this branch reached main through #1325. They added the opt-in options
PytorchSolverCfg.ik_wrap_to_seed, PickUpOptions.prefer_least_joint_motion and
HandOverOptions.receive_prefer_least_joint_motion. Against current main (41610e5e2), this PR fixes the problems
review found in them, plus one older IK bug that also affects default settings: prismatic joints were folded by
2π. Apart from that IK fix, behaviour and registration identity with the options off are unchanged.

Each item below gives what happens on main, where it comes from, and the fix. The numbers come from one probe
script run on main 41610e5e2 and on this branch (CPU).

1. Prismatic joints are folded by 2π (also with the options off)

_qpos_map_to_limits
shifts every joint by whole turns of 2π
(L427).
_wrap_candidates_to_reference
also shifts any joint whose range exceeds 2π. On one prismatic joint with [-4, 4] m limits and a +3 m seed,
both still report success:

target main, wrap off main, wrap on this PR (off / on)
x = +3.5 m −2.783 m +3.500 m +3.500 m
x = −3.0 m −3.000 m +3.283 m −3.000 m

Fix: both mappings shift only revolute joints, read from the chain's joint types
(BaseSolver.get_periodic_joint_mask). The whole-turn rule now lives in
compute.kinematics.nearest_periodic_equivalents and is applied through
BaseSolver.nearest_periodic_equivalents, so other backends can adopt it. Moving the weighted scoring and
SolverCfg-level opt-in into the shared layer is left until the next backend adopts the rule.

2. ik_wrap_to_seed shifted the positional arguments of PytorchSolverCfg

The field sits before the seed-selection fields
(L99).
On main, the positional parameters after ik_solution_selection are ik_wrap_to_seed, enable_seed_selection, seed_db_size, so an existing positional tail (True, 2048, 0.25) sets enable_seed_selection=2048. The field
is now keyword-only and the order is back to enable_seed_selection, seed_db_size, seed_rot_scale.

3. Least-motion ranking mixed travel with fixed cost offsets

  • PickUp's sampled path
    (L1403-L1416)
    drops every reachable grasp beyond least_motion_candidates, so a second sampling branch can be left with
    nothing.
  • The validated-label path
    (_grasp_selection.py L655-L656)
    gives unscored labels 1e7 + rank and adds 1e-6 * rank to the travel of scored ones.

With four reachable labels and travel |x − 0.2|:

case main this PR
joint weights ×1e8, 1 label compared label 1 (an uncompared label wins) label 0
travel 0, −1e-8, −2e-8, −3e-8 label 0 (rank offset outweighs travel) label 3

Fix: motion_ranked_costs orders reachable candidates in three groups: compared ones with finite travel (by
travel), other compared ones, then the rest. The cache or geometric rank breaks equal travel, and each candidate's
position in this order becomes its cost. Both paths use it, and no reachable grasp is dropped.

4. Travel ignored the initial lift

With initial_lift_height, execution moves start → clearance waypoint → pre-grasp, but
_joint_motion_cost
seeds the pre-grasp IK at the start
(L1645).
Grasp, roll-variant and fixed-twin ranking now seed and measure from the clearance waypoint, and add the lift's
own travel.

5. Pre-grasp and grasp IK were solved twice

Screening solves pre-grasp and grasp IK, then the travel pass solves them again. This happens in PickUp's sampled
path (L1403-L1416), its validated-label path
(L1598-L1614)
and the HandOver receiver
(L2316-L2361).
With 50 sampled grasps this costs 400 IK targets per environment on main and 300 here. When a least-motion option
is on, screening now returns its own travel:

  • _select_feasible_grasp_variants(return_travel=True);
  • reachable_path(..., return_joints=True);
  • select_ranked_grasp accepts (reachable, travel) from feasible.

With the options off, screening is called as before.

6. A failed half-turn twin had no fallback

The fixed grasp's twin is chosen from waypoint IK
(L992),
and only the chosen pose gets a full trajectory
(L1042).
If the planner rejects the twin, the pickup fails even when the authored grasp would plan. Rows whose twin
trajectory fails are now planned with the authored grasp and keep it where that succeeds.

7. workspace_joint screened a grasp that might not run

The binding check
screens the authored fixed_object_to_eef, but with prefer_least_joint_motion the pick may execute its twin.
Binding now rejects that combination.

8. joint_motion_weights: [] was rejected

_finite_tuple
rejects an empty list (main: ValueError: options.joint_motion_weights must not be empty), although
PickUpOptions accepts () for all weights 1. The list now decodes to (), and each supplied weight is still
checked as finite and non-negative.

Docs (compute and solver API pages, built-in skills) and agent context (ik-solvers, atomic-actions,
expansion-engine) are updated.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which improves an existing functionality)

Validation

  • Probe script, CPU, run on main 41610e5e2 and on this branch: tables and counts above.
  • New or extended tests:
    • prismatic IK-to-FK round trip above π (options off and on), prismatic joints left by the whole-turn shift,
      keyword-only field;
    • order-based ranking (equal travel, small distinct travel, weights ×1e8) and screened travel reused without
      calling the travel callbacks;
    • travel from the clearance waypoint;
    • twin fallback to the authored grasp;
    • workspace_joint rejection;
    • empty weight list.
  • Same CPU suite on main and on this branch, CUDA hidden (tests/sim/motion/solvers, tests/sim/atomic_skills,
    tests/compute/kinematics, tests/lab/expansion, test_configured_integration.py, -m "not sim"): main 2142 passed, this branch 2151 passed (the 9 new). Both have the same 5 failures and 57
    errors, all simulation tests that cannot start without a GPU (CUDA_ERROR_NO_DEVICE).
  • black 26.10.1, python docs/scripts/check_api_docs.py (5081/5081), context.py check.
  • Not run here: the GPU simulation tests.

Checklist

  • I have run the black . command to format the code base.
  • I reviewed affected documentation and agent context, updated it where needed, or explained why no update was needed.
  • Public API changes are reflected in the API docs (python docs/scripts/check_api_docs.py), if applicable
  • I verified appropriate behavioral coverage, reviewed the necessity of added or extended tests, and explained when no new tests were needed.
  • Dependencies have been updated, if applicable. (none)

🤖 Generated with Claude Code

Two choices could send an arm through a large joint swing for a pose it
could reach directly:

- PytorchSolver "nearest" selection folds every multi-start candidate into
  [-pi, pi] before measuring its distance to the seed. On a joint whose
  limits allow more than one turn, a candidate just across +-pi then looks
  almost a turn away, and a flipped-wrist branch can win for nearly the
  same TCP pose. PytorchSolverCfg.ik_wrap_to_seed compares and returns each
  candidate at its whole-turn equivalent nearest the seed (nearest the
  previous waypoint in continuous path selection).
- PickUp keeps the first reachable grasp in cache order and picks the
  half-turn roll variant by TCP rotation error, which cannot tell the two
  variants apart from an upright start pose.
  PickUpOptions.prefer_least_joint_motion ranks the first
  least_motion_candidates reachable grasps, and the roll variant, by IK
  joint travel from the current arm posture (joint_motion_weights); a
  fixed_object_to_eef grasp may be replaced by its half-turn twin.
  HandOverOptions.receive_prefer_least_joint_motion ranks the receiving
  grasp the same way.

All options default off; inactive options are omitted from the Task
Program integration identity.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Yuan-Xinyi Yuan-Xinyi added enhancement Improvements to existing capabilities; use feature for new capabilities. kinematics FK, IK, Jacobians, reachability and kinematic solvers; not physics solvers. atomic-skill Atomic Skill goals, planning, execution, verification and recovery. task-program Task Program language, semantics, compiler, runtime and integration contracts. labels Dec 2, 2026
@greptile-apps

greptile-apps Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge; no blocking issues remain.

Summary

Adds opt-in choices that reduce joint travel when selecting IK solutions and grasps. Defaults remain unchanged.

  • IK candidates can stay near the seed across whole-turn angles.
  • Pickup and handover can choose reachable grasps by joint travel.
  • Workspace-joint expansion rejects pickup choices its screen cannot cover.

Reviews (8) · Last reviewed commit: "docs(atomic-skill): describe the least-m..." · Reviewed by Greptile

- select_ranked_grasp: rank only the first motion_candidates reachable
  labels by motion cost; labels kept in a larger pool (check_selection
  retries, sampling branches) follow them in cache order, and the motion
  cost is evaluated only for the compared labels.
- PickUp fixed-grasp twin comparison: with approach_along_grasp_axis the
  pre-grasp follows the grasp's TCP +Z (shared by the twin), as the pickup
  does, instead of the configured approach direction.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@yuecideng yuecideng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6d27d39 with focused CPU checks. The inline findings cover the remaining solver, grasp planning, and configuration issues.

Yuan-Xinyi and others added 2 commits December 3, 2026 13:18
…osture

- prefer_least_joint_motion no longer drops reachable sampled grasps beyond
  least_motion_candidates: the shortlist is ranked by joint travel ahead of
  them, and the rest keep their geometric cost order (as on the
  validated-label path), so other sampling branches can still take them.
- With initial_lift_height, grasp, roll-variant and fixed-twin ranking seed
  the pre-grasp IK at the clearance waypoint and measure travel from there
  (plus the lift itself), as the execution moves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main already carries the first two commits of this branch through the
squash merge of #1325, so each conflicted file takes main's version and
only the last commit of this branch (post-lift travel origin, unranked
grasps kept) is reapplied on top.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Yuan-Xinyi and others added 2 commits December 3, 2026 18:53
…toff

The shortlist mixed joint travel with a fixed 1e7 cost for the other
reachable grasps, so large joint_motion_weights could push a compared
grasp behind an uncompared one. Reachable grasps now get their position
in the lexicographic order (shortlist with finite travel, rest of the
shortlist, other reachable; then travel; then geometric order) as cost,
which does not depend on the travel's scale.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Move the whole-turn rule into compute.kinematics.nearest_periodic_equivalents
  and apply it through BaseSolver.nearest_periodic_equivalents with the
  chain's joint types, so prismatic joints are never shifted.
- Make PytorchSolverCfg.ik_wrap_to_seed keyword-only to keep the positional
  order of the seed-selection fields.
- Rank least-motion label groups by an explicit order (shortlist by travel,
  then the rest; cache rank breaks equal travel) in the shared selection.
- Reuse the joint travel of the reachability screening in the sampled and
  validated PickUp paths and in the HandOver receiver instead of solving
  the same pre-grasp and grasp IK again.
- Plan the authored fixed grasp where its half-turn twin's trajectory fails.
- Reject prefer_least_joint_motion under workspace_joint screening, which
  only covers the authored fixed grasp.
- Accept an empty joint_motion_weights list in configured skill options.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Yuan-Xinyi
Yuan-Xinyi requested a review from yuecideng December 4, 2026 06:05
Yuan-Xinyi and others added 2 commits December 4, 2026 15:52
_qpos_map_to_limits shifted every joint by whole turns of 2*pi, so a
prismatic solution above pi (x = +3.5 m within [-4, 4] m) came back as
x = -2.78 m with success, with or without ik_wrap_to_seed. Only revolute
joints are now shifted; a CPU IK-to-FK round trip covers the case.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Yuan-Xinyi Yuan-Xinyi changed the title Opt-in joint-travel choice of IK solutions and grasps Fix prismatic IK folding and harden joint-travel grasp ranking Dec 4, 2026
@Yuan-Xinyi Yuan-Xinyi added the bug Incorrect existing behavior or a fix restoring the intended behavior. label Dec 4, 2026
@Yuan-Xinyi
Yuan-Xinyi merged commit 398ac8e into main Dec 4, 2026
7 of 9 checks passed
@Yuan-Xinyi
Yuan-Xinyi deleted the feat/least-joint-motion-ik-and-grasp branch December 4, 2026 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

atomic-skill Atomic Skill goals, planning, execution, verification and recovery. bug Incorrect existing behavior or a fix restoring the intended behavior. enhancement Improvements to existing capabilities; use feature for new capabilities. kinematics FK, IK, Jacobians, reachability and kinematic solvers; not physics solvers. task-program Task Program language, semantics, compiler, runtime and integration contracts.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants