Skip to content

Extract grasp validation and use physical labels in atomic skills - #1297

Merged
matafela merged 20 commits into
mainfrom
cj/validator-get-grasp-pose
Nov 28, 2026
Merged

matafela merged 20 commits into
mainfrom
cj/validator-get-grasp-pose

Conversation

@matafela

@matafela matafela commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR targets main.

  1. Standalone GraspValidator. The simulator API runs a batch of object-local TCP poses for one hand and a dynamic target. Each arena closes, lifts, optionally moves 3 cm out and back along world X and Y, and measures retention during a three-second hold. Callers can drop the target into a measured resting pose and restore it between trials. The validator owns its simulation and supports PhysX and Newton/DexUni.
  2. Grasp labeling. embodichain label-grasps samples stable object placements and upper-hemisphere approaches, validates candidates in physics, applies pose NMS and saves object-local TCPs, opening widths and placement provenance in a PyTorch file. Per-direction checkpoints support --resume. The cup example resolves the standalone CobotMagic V100 hand from the existing robot catalog. Custom URDFs and meshes can be supplied explicitly.
  3. Atomic skill selection. PickUp, HandOver, AxisAlign, Slide, OpenDoor and CoordinatedPickment reuse physical labels keyed by the hand URDF, scaled mesh and validation settings, including the mounted finger drives and pad contact properties. Eligible grasps are ordered by closing-axis and contact-center cost, then by TCP +Z alignment for equal costs. The arm checks the required waypoints in groups of 50 candidates. Nominal planning selects the first reachable label. Affordance branches use distinct reachable labels and can match a preferred object-local pose. Antipodal requires a physical label cache and two contact pads. PickUp and prototype refinement execute the same TCP that passed validation, including any configured grasp_frame_to_eef calibration. Existing configs that set opening_weight must remove it. Opening widths are still used for eligibility and are saved with the labels.

Generate labels for the CobotMagic cup

From the repository root with the simulation environment active, run the full example with five placements, 64 directions and up to 100 candidates per direction.

conda activate py312_bk
python -m embodichain label-grasps \
  --config examples/toolkits/grasp_labeling/cobotmagic_cup.yaml \
  --output outputs/grasp-labeling/cobotmagic_cup.pt

Run PickUp and HandOver in a native window

Use the same environment from a graphical desktop. Each command runs one episode automatically. --filter-dataset-saving skips dataset recording. The first grasp waits for physical validation if the hand and mesh are missing from the local cache. Subsequent runs reuse the labels. When enabled, force_refresh or the tutorial flag --force_reannotate regenerates each key once per service instance. This revision uses a new cache key for OBJ mesh transfer to the native worker.

Franka PickUp runs the repeated pick-and-place task.

python -m embodichain.lab.scripts.run_task \
  --gym_config embodichain/extensions/tasks/configs/tasks/manipulation/repeated_pick_place/task.franka.yaml \
  --no-headless --renderer fast-rt --max_episodes 1 --filter-dataset-saving

Dual UR5 HandOver uses DH PGI grippers to pick up, transfer and place the can. Each direction admits up to 200 candidates. The source and receiving TCP approach tolerances are 10° and 30°.

python -m embodichain.lab.scripts.run_task \
  --gym_config embodichain/extensions/tasks/configs/tasks/manipulation/hand_over/task.dual_ur5_dh_pgi_140_80.yaml \
  --no-headless --renderer fast-rt --seed 7 --max_episodes 1 --filter-dataset-saving

Validation

  • The full CobotMagic V100 cup example produced 12,972 distinct physically validated TCP poses and an aligned opening width for each pose.
  • 20 standalone validator tests passed, including native three-arena tests on both PhysX and Newton/DexUni. The tests cover misses and centered grasps, mount calibration, close dwell, disturbance and retention.
  • 2,555 tests passed, 18 skipped, 2 deselected across atomic skills, motion-generation benchmarks, grasp labeling, gripper defaults, the validator and Task Program integration.
  • The Franka pickup and dual UR5 handover each completed a headless episode on the new base. The native-window commands were also exercised in the earlier revision.
  • The dual UR5 seed-7 run generated 7,235 distinct grasps with the mounted PGI settings and completed pickup, handover and placement in 1,779 steps. The Franka run generated 13,617 labels and reused them across three pickups.
  • The default UR5/Pika embodiment-switching tutorial generated 10,280 physical labels, lifted the block 10.0 cm and placed it within 3.35 mm of the target.

Type of change

  • New feature
  • Breaking configuration change for users of the removed opening_weight option

Checklist

  • Formatted with Black 26.10.1.
  • Updated the validator and labeling API reference, the task examples and project context. Checked API documentation coverage.
  • Checked the PR diff against main. The standalone API, labeling command and atomic skills run using the existing catalog assets.

@matafela matafela added feature New user-facing capabilities. performance Performance, memory, throughput and synchronization-cost improvements. toolkit Standalone robotics tools, including GraspKit and URDF assembly. labels Nov 26, 2026
@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The latest changes appear safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[High impact] The latest changes appear safe to merge.

Summary

This PR adds standalone physical grasp validation and labeling, then lets atomic skills select from prepared physical labels.

  • Grasp candidates can now be tested in physics and saved as reusable labels.
  • Atomic skills now pick reachable poses from physically tested grasps.
  • Affordance types and sampling now live in a shared simulation package.
  • The task catalog now includes a dual UR5 handover with Robotiq grippers.
  • Collision snapshots now align capsules along their actual long axis.
  • Existing examples and tests now use the updated grasp-label planning setup.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Resolve invocation] --> B[Prepare matching physical labels]
  B --> C[Read labels during planning]
  C --> D[Rank eligible grasps]
  D --> E[Check waypoint reachability]
  E --> F[Compile trajectory]
Loading

Reviews (19) · Last reviewed commit: "fix(grasp): prepare caches for standalon..." · Reviewed by Greptile

Comment thread embodichain/lab/scripts/label_grasps.py Resolved
@matafela
matafela force-pushed the cj/validator-get-grasp-pose branch from 47323b0 to 93ec91f Compare November 26, 2026 14:39
@matafela matafela changed the title Add physically validated grasp pose labeling Extract grasp validation and use physical labels in atomic skills Nov 26, 2026
@matafela
matafela changed the base branch from codex/physical-grasp-benchmark to main November 26, 2026 14:39

@han-xudong han-xudong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I found one blocking regression in Affordance expansion and seven additional issues in grasp validation, configuration compatibility, and cache handling. The inline comments include the conditions that trigger each issue. The focused suite passed 760 tests with the pinned DexSim version.

Comment thread embodichain/lab/sim/grasp_validation.py Resolved
Comment thread embodichain/lab/sim/grasp_validation.py Resolved
Comment thread embodichain/lab/sim/grasp_validation.py Resolved
Comment thread examples/sim/atomic_skill/support.py Resolved

@han-xudong han-xudong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Follow-up review of 866ab81c. The Affordance branch and TCP calibration fixes passed focused probes. The inline findings cover remaining gaps in physical-label validation and the horizontal handover tutorial.

Comment thread embodichain/lab/sim/grasp_validation.py Resolved
Comment thread examples/sim/atomic_skill/support.py Resolved
Comment thread examples/sim/atomic_skill/support.py Resolved

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

Follow-up ideas for grasp labeling

I ran the CobotMagic V100 cup on 93ec91f with DexSim 0.6.1rc1, then checked the sampling, batching, and output paths at ebb642d. The numbers below are from the earlier run.

  1. Sample across support modes. The two placements retained in the quick cup run differed by 179.5° in overall rotation and both settled on their sides. For the cup, allocate part of the placement budget to each of upright, side-lying, and inverted. For general meshes, group settled poses by the object-frame support normal and contact region, then retain some yaw diversity inside each group. The 3×3 demonstration produced all three cup modes and successful grasps in each.

  2. Pack different placements into one physics batch. Extend restore_placement to accept one transform per arena while keeping the single-transform input for existing callers. Track the placement, direction, and candidate index per row when pooling pending trials across placements. This would let another placement use the spare slots in a partial batch. The drop stage could also use a smaller scene sized to its own budget. The defaults currently allocate 2,400 arenas for at most 100 drop attempts, and drop_objects fills the remaining arenas with the final rotation.

  3. Keep validation evidence with each label. Preserve the tested TCP, placement, backend, and grasp-quality measurements such as slip, rotation, and bilateral contact fraction. In the paired cup run, two TCPs passed on both backends and moved 5.67 mm and 6.97 mm relative to the gripper during the DexUni hold. When pose NMS groups nearby labels, retain each original trial and its evidence. That would let a consumer prefer a steadier grasp among the candidates that satisfy its geometry and IK checks.

  4. Precompute common asset caches before planning. The final-TCP consistency issue from the earlier revision is covered by the calibration fix. A precompute path using the same cache identity would also let commonly used hand and object pairs avoid synchronous labeling on the first planning call.

For verification, run the same three placements and nine TCPs once grouped by placement and once in a mixed batch. Compare per-candidate outcomes and placement provenance. On the full cup labeling run, report coverage per support mode, the fraction of arena slots assigned to real candidates, and passing labels after NMS per wall-clock second.

Comment thread embodichain/lab/sim/grasp_validation.py Resolved
Pool trials across settled placements, retain NMS membership and measured contact quality, and precompute mounted-hand labels with the planning cache identity.
@matafela

Copy link
Copy Markdown
Collaborator Author

@yuecideng, all four items from your grasp-labeling follow-up are implemented in b7d96a54e.

  • The cup sampler targets upright, side-lying and inverted starts, then classifies the settled poses. For general meshes, selection uses the object-frame support normal and measured contact region, with rotation diversity within a group.
  • restore_placement now accepts either one transform or one per arena. The drop scene uses only the arenas needed for drops. Validation pools trials across placements and directions and preserves each row’s placement, direction and candidate indices.
  • The output retains every trial’s tested TCP, placement, backend, hold/disturbance slip, rotation and bilateral contact fraction. Passing trials reference their NMS representative, so their individual evidence remains available after deduplication.
  • The deployment can precompute a mounted hand/object pair using the same cache key as planning, including the effective hand commands and TCP adjustment.

On the full CobotMagic cup run (seed 0, GPU PhysX, DexSim 0.6.0), the five placements covered two upright, two side-lying and one inverted. They yielded 6,890, 5,695 and 3,904 labels after NMS, respectively. Real trials occupied 20,698/21,600 slots (95.82%). The CLI produced 16,489 labels in 146.38 s, or 112.65 labels/s end to end.

For the three-placement, nine-TCP replay, all nine restored placements matched their recorded transforms within 4.8e-7 maximum matrix-element error. With each candidate assigned to its original arena, grouped and mixed batches matched on all nine outcomes and failure stages. Reassigning arenas reproduced eight of nine outcomes and seven of nine stages. Full results and replay details

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

Architecture follow-up

Keep the split between reusable Affordance geometry, physical label preparation, and robot-specific planning. The offline CLI and the isolated cache worker already share the labeling implementation. Preparation and lookup also share the key builder, which is important for parity.

  • Group the validator, labeling pipeline, and cache under embodichain/lab/sim/affordance/grasp/, as clarified in the directory discussion. Keep existing public Affordance imports available through thin re-exports.
  • Have each host resolve the effective grasp request once and use it for preparation and lookup. The deployment CLI currently enumerates commands and TCP adjustments from templates, while planning resolves those values from the invocation. The deployment adapter can own the Gym assembly and no-render event setup, with the CLI responsible for argument handling and reporting.

I added the standalone cold-cache trace and regression suggestion to the existing thread.

Returns:
Padded candidates with explicit validity.
"""
from embodichain.lab.sim.grasp.cache import validated_label_provider

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.

[P2] Keep physical-cache enforcement at the Atomic Skill boundary

This shared query now calls validated_label_provider() before dispatching to the supplied generator. A geometry-only AntipodalGraspPoseGenerator with its default validated_labels=None therefore raises ValueError before get_valid_grasp_poses(). The same public query on the base branch delegates directly to the supplied geometry generator.

Please let the shared Affordance query use the injected candidate service, and apply the physical-label requirement at the Atomic Skill entry point. A focused regression can cover both the geometry-only query and the skill's physical-label requirement.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in f244eacc0. AntipodalAffordance.get_grasp_candidates() delegates to the injected generator's get_valid_grasp_poses(), so it works with a geometry-only Antipodal generator. Atomic Skill service registration enforces the physical-label requirement, and Antipodal skill planning reads the validated cache.

A focused regression uses the same generator with validated_labels=None in both paths. The shared query returns the candidate rows and their validity mask. Registering that generator for an Atomic Skill raises the expected error.

@matafela

Copy link
Copy Markdown
Collaborator Author

@yuecideng, following up on your architecture review. The validator, labeling pipeline and cache now live together under embodichain/lab/sim/affordance/grasp/. The existing public Affordance imports remain available through thin re-exports.

f244eacc0 moves Gym assembly and no-render camera setup into the deployment adapter. The CLI parses the arguments and reports the files it prepared. The adapter lowers the selected program calls with the same compiler used by planning. Preparation reads the resolved object's mesh and physical properties, each distinct effective open/grasp command pair, and the final TCP adjustment. If the requested hand, object and affordance do not appear in a sampled-grasp invocation, the CLI reports that explicitly.

The standalone host now resolves each invocation once, prepares its labels, and hands that same request to the planner. Regression tests cover an invocation-level command override and mirrored TCP, plus a batch with different closing commands and a 12 mm TCP offset. On DexSim 0.6.1rc1, standalone PickUp launched one labeling worker from an empty cache and zero on the warm run. The handover regression also generated and reused both hands' label files.

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

Verified the host-side cold-cache fix at 47f5947bc. The standalone sampled-grasp examples and tutorials use the shared preparation path before planning. Motion benchmarks prepare the keys during case generation and planner setup, outside timed compilation.

Both the cube and Rubik's-cube PickUp regressions passed with real GPU simulation. Each cold run launched one labeling worker and each warm run reused its cache. The 220 focused tests, Black, and API documentation checks passed.

The validator, labeling, and cache modules are under affordance/grasp/. The shared Affordance query delegates to the geometry generator.

@matafela
matafela merged commit 9a69af5 into main Nov 28, 2026
14 checks passed
@matafela
matafela deleted the cj/validator-get-grasp-pose branch November 28, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New user-facing capabilities. performance Performance, memory, throughput and synchronization-cost improvements. toolkit Standalone robotics tools, including GraspKit and URDF assembly.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants