# Simulation Isaac Lab / Isaac Sim workspace for v2d. This tree is **self-contained**. Scripts under `simulation/scripts/` must not import Dream or other project trees. The layout matches `reconstruction/`. ## Layout ``` simulation/ ├── run_isaaclab.sh ├── setup.sh # isolated venv (no conda) ├── config/paths.sh # data + modules; uses simulation/.venv ├── scripts/ # first-party stages ├── setup/ │ ├── 00_init_modules.sh # clone IsaacLab if missing │ └── 02_relocate_venv.sh # rewrite paths after a move ├── modules/IsaacLab/ # Isaac Lab source └── runs/ # outputs (gitignored) ``` The existing Dream venv (`env_isaaclab`) lives here as `simulation/.venv`. Isaac Lab source lives in `simulation/modules/IsaacLab`. ## Setup One isolated venv under `simulation/.venv`. No conda. ```bash cd simulation ./setup.sh source .venv/bin/activate ``` Isaac Sim 6.0.1 and Isaac Lab 3.0.0-beta2 are already installed in `.venv` (Python 3.12). `./setup.sh` only clones Isaac Lab if `modules/IsaacLab` is missing, then rewrites venv shebangs / editable install paths. ## Run ```bash cd simulation source .venv/bin/activate ./run_isaaclab.sh --help ``` ## Replay G1 Inspire + object + MANO Same idea as NVIDIA `robotic_grounding/scripts/replay_motion.py`: teleport a floating Inspire hand and the tracked object each physics step (no contact forces). Data comes from `retarget/export_isaaclab.sh` (Z-up `isaaclab_replay.npz`), not from `motion_v1` parquet. ```bash cd retarget ./export_isaaclab.sh --video-dir ../reconstruction/runs/20200709_141754_836212060125 cd ../simulation source .venv/bin/activate ./replay_v2d.sh --npz ../reconstruction/runs/20200709_141754_836212060125/obj_tracking_out/isaaclab_replay.npz --headless ``` Plays once: physics **settle** (object XY fixed, Z/rotation fall onto the table; hand stays glued to the object as in the video), then the clip, then writes `obj_tracking_out/isaaclab_replay.mp4` and exits. `--table-z` (default 0.75 m), `--settle-sec` (default 2), `--no-settle` to skip the drop. Gold/robot is the URDF articulation; green spheres are HaWoR MANO joints; the coffee-can is a dynamic rigid on a cuboid table. ## SONIC whole-body (G1 29-DoF) Frozen GEAR-SONIC v1.1 ONNX from `checkpoints/sonic/sonic_v1_1`. This is **not** `G1_MINIMAL_CFG` (locomotion USD). SONIC uses the 29-DoF G1 (`G1_29DOF_CFG`): three waist joints and three wrist joints per arm, no Inspire fingers. The DexYCB clip is a tabletop right hand. Play uses **teleop** encoder mode: standing legs + reconstructed hand root as the right-wrist target. The object is translated into the reachable wrist band (same layout as ``g1_sonic_manip``), not left at the capture's table centre. ```bash cd simulation source .venv/bin/activate ./replay_sonic.sh --headless --hands inspire \ --npz ../reconstruction/runs/20200709_142553_836212060125/obj_tracking_out/isaaclab_replay.npz ``` Writes `obj_tracking_out/sonic_replay.mp4` next to `isaaclab_replay.npz`. `--mode g1` tracks a standing 29-DoF pose only (smoke test). GPU node; `onnxruntime-gpu` is in `simulation/.venv`. ### The robot has more than 29 joints SONIC drives 29 body joints; everything else is fingers, free to use as a separate grasp action channel. Anything reading or writing joints must resolve SONIC's 29 **by name** (`play_sonic.py:_joint_ids`), never by assuming they are indices 0..28. | `--hands` | USD | fingers | total joints | | --- | --- | --- | --- | | `dex3` (default) | stock `g1.usd` | 3 per hand, 7 DoF | 43 | | `inspire` | local mirror | 5 per hand, 12 DoF | 53 + root | | `wuji` | CoordEx `g1_wuji_no_merge.usd` | 5 per hand, 20 DoF | 69 | Dex3 joints are `{left,right}_hand_{index,middle}_{0,1}_joint` and `_thumb_{0,1,2}_joint`. Inspire joints are `[LR]___joint`. Wuji joints are `{left,right}_finger<1-5>_joint<1-4>` (finger1 = thumb), which is the naming written by `g1_wuji_retarget.npz`. `wuji` is the hand the `g1_sonic_manip` task now uses. Its USD carries all 29 SONIC body joints under identical names, so SONIC's body control is unaffected by the choice, and it has no mimic joints at all. The reason to prefer it over `inspire` is not the mechanism but the software: matching CoordEx's hardware is what lets its pretrained hand VAE prior be reused as an initialization. Finger actuator gains for `wuji` are copied from CoordEx's `wuji_hands` actuator (`_HAND_GAINS` in `sonic/robot_cfg.py`) so finger dynamics match what that prior was trained against. Isaac Lab's stock `g1_29dof_inspire_hand.usd` **cannot be spawned as-is**; it is authored for a fixed-base manipulation rig and has two independent faults. Both report the same misleading symptom, because either one stops PhysX creating the articulation and the real complaints scroll past far above it: ``` Pattern '/World/Robot/root_joint' did not match any articulations ``` 1. **Mimic joints.** The finger linkages are `physxMimicJoint:*` properties (gearing -1.0 on the four fingers, -1.6 and -2.4 on the thumb) that this PhysX build cannot resolve: `failed to find internal joint object for PhysxMimicJointAPI`. Both the properties **and** the applied `PhysxMimicJointAPI` schema have to go. Dropping only the properties leaves the API applied with no `referenceJoint`, which spawns fine but logs `must have exactly 1 "referenceJoint" relationship defined` once per joint per articulation -- 12 lines per robot, 48 for four environments, enough to bury the error you actually care about. 2. **Fixed base.** `PhysicsArticulationRootAPI` sits on `root_joint`, a `PhysicsFixedJoint` anchoring the pelvis to the world. Spawning with `fix_root_link=False` disables that joint and removes the articulation root along with it. Stock `g1.usd` has no root joint and puts the API on `/g1/pelvis` instead. `scripts/fetch_inspire_hand.py` mirrors the asset into `assets/g1/` (gitignored, ~39 MB) and fixes both in its 19 KB physics layer, leaving the 39 MB mesh layer untouched. It is idempotent and self-verifying. Stripping the mimic leaves the six coupled joints per hand independently actuated. If you want the real linkage back, re-impose the gearing in software and mind the sign: `index_intermediate` is limited to `[-19.48, 116.88] deg` while gearing -1.0 on a `[0, 97.4] deg` proximal would imply `[-97.4, 0]`, so the two joint frames are oppositely oriented. ### Conventions that are easy to get wrong Both of these produce a robot that thrashes rather than an obvious crash, so check them first if SONIC misbehaves. A standing reference should yield `max|action| < 0.5`; if it is ~4-5, one of these is wrong. 1. **Joint order.** SONIC reads observations and emits actions in **Isaac Lab** joint order, while `default_angles` / `kps` / `g1_action_scale` in `policy_parameters.hpp` are in **MuJoCo** order. `constants.py` keeps both name lists and reindexes by name, so everything downstream is Isaac Lab order. Deploy bridges them in `CreatePolicyCommand`. 2. **6D rotations flatten row-wise**, `[m00, m01, m10, m11, m20, m21]` -- this is `matrix_from_quat(q)[..., :2].reshape(-1)`, not the first two columns stacked. The identity is `[1,0,0,1,0,0]`, not `[1,0,0,0,1,0]`. VR 3-point targets (`vr_3point_local_target`) are relative to the **reference motion pelvis**, not the robot pelvis, and the third point is `torso_link` offset by +0.35 m, not a head link. Proprioception history is oldest-first. ### Batched SONIC (for RL rollouts) The shipped ONNX pair is traced at batch 1, so an RL rollout would need one inference call per environment per tick. Re-export graphs that take any batch: ```bash python scripts/export_sonic_dynamic_batch.py # writes model_*_batch.onnx ./jobs/sonic_bench.sh # GPU node: equivalence + throughput ``` `SonicOnnxAgent` prefers `model_*_batch.onnx` when present and accepts either `(D,)` or `(N, D)`. Two things had to be patched, both invisible at batch 1: 1. 20 `Reshape` targets spell the batch out as a literal `1`; they become `-1`. 2. The encoder-mode one-hot is a `ScatterND` into a constant of shape `[1, 3]`, indexed by a `torch.arange(batch)` that constant-folded to `[0]`. It can only ever fill row 0, so every environment past the first would get an all-zero one-hot and therefore a zero token. It is rebuilt as `onehot[b, k] = (encoder_index[b] == k)`, which also allows per-env modes. CUDA is opt-in via `SONIC_ORT_CUDA=1`. onnxruntime-gpu 1.29 links the CUDA 13 runtime, whose wheels sit in `nvidia/cu13/lib` with nothing putting them on the loader path. `policy.py` preloads the four it needs (`libcudart`, `libcublas`, `libcublasLt`, `libcurand`) with `RTLD_LOCAL` -- not `LD_LIBRARY_PATH`, which would shadow the CUDA 12 libs torch is built against, and not `RTLD_GLOBAL`, which would expose CUDA 13 cuBLAS symbols for torch to bind to. Measured on one H100 (`jobs/sonic_bench.log`), encoder+decoder per control tick: | batch | CPU | CUDA | | ----: | ----: | ----: | | 256 | 6.5k env-steps/s | 204k env-steps/s | | 4096 | 6.2k env-steps/s | 644k env-steps/s (6.4 ms/tick) | So a frozen SONIC inner loop is affordable inside an RL rollout on GPU, and is roughly 100x too slow on CPU. ### Where the hand can actually go `scripts/probe_wrist_tracking.py` sweeps commanded right-wrist targets in the pelvis frame and records where the hand ends up (`jobs/sonic_probe.sh`, results in `runs/wrist_tracking.npz`). This bounds anything built on top of SONIC, because a policy cannot place the hand better than the controller beneath it. Tracking is **repeatable but biased**. Spread over the settling window is 1.3 mm median, so commanding the same target twice lands in the same place; but the steady-state offset is 8 cm median over a 27-point grid, and structured: | commanded | median error | signed bias on that axis | | --- | ---: | ---: | | x = 0.40 | 0.042 m | +0.013 m | | x = 0.55 | 0.101 m | −0.055 m (arm out of reach) | | y = −0.30 | 0.035 m | +0.028 m | | y = 0.00 | 0.116 m | +0.062 m (cannot cross the midline) | | z = −0.05 | 0.032 m | +0.026 m | | z = +0.25 | 0.105 m | +0.077 m | A smooth repeatable bias is learnable, so absolute wrist pose is still a usable action space; random 8 cm scatter would not have been. The practical envelope is **x 0.30-0.42, y −0.28..−0.12, z −0.05..0.15**, where error is 1-4 cm. Outside it the arm saturates. Kinematics agree: a target at x = 0.45, z = 0.03 is 0.59 m from the shoulder, about the whole arm. This rules out replaying the DexYCB layout directly. In that clip the can sits **1.10 m** in front of the pelvis and the demonstrated hand path spans x = 0.59-0.93 m, so a standing G1 cannot reach any of it — the human was leaning over the table. Worse, the capture's table is 1.2 m deep with the can at its centre, so even standing flush against the front edge leaves the can 0.60 m out. Use the clip for grasp reference; author the scene for the robot's workspace. ## Physical G1 RL env Manager-based Isaac Lab env (gravity + contacts), not kinematic replay: `simulation/source/v2d_sim/tasks/g1_table_object/` → Gym `V2D-G1-TableObject-v0` Train/play wrappers are in `../rl` (algorithm still a PPO stub): ```bash cd ../rl ./play.sh --headless --steps 200 ./train.sh --headless --num_envs 64 ``` ## Manipulation over frozen SONIC `simulation/source/v2d_sim/tasks/g1_sonic_manip/` → Gym `V2D-G1-SonicManip-v0` SONIC is frozen and owns balance and all 29 body joints. The learned policy never sees a joint: its action is a **right-wrist target in the pelvis frame (3) plus a finger closure (1)**, and `mdp/actions.py` runs SONIC inside the env to turn that into joint targets. Physics 200 Hz, SONIC 50 Hz, policy 25 Hz. Two consequences of the probe above are baked into the config. The action range is clamped to the well-tracked band rather than the arm's kinematic limit, since commanding outside it just saturates. And the scene is re-authored rather than copied from the capture: a 0.8 m deep table with the object spawning at pelvis x 0.31-0.41, y −0.27..−0.13, which is where tracking is a few centimetres. The object is the **reconstructed can with its SAM3D texture**, spawned from `obj_tracking_out/isaaclab_assets/object.urdf` (written by `retarget/export_isaaclab.sh`), not a placeholder cuboid. The spawn config sets no `visual_material`, which is what lets the URDF's own MTL and 1024px texture survive USD conversion; setting one silently replaces the texture with a flat colour. Collision is a convex hull, which suits a can and keeps startup quick. That mesh is **y-up** and the URDF applies no correction, so spawning it unrotated in a z-up world lays the can on its side. It technically balances there, but on 198 contact vertices with 1.2 cm between the support polygon and the centre of mass, so the first touch rolls it away. `OBJECT_REST_ROT` is the clip's tracked orientation with its 8.8° tilt removed, putting body +y at world +z: 2066 contact vertices and 6.1 cm of margin, standing on its base with the yaw the capture recorded. `OBJECT_REST_H` (6.94 cm) is the lowest rotated vertex in that attitude — it depends on the rotation and is *not* half the bounding box, so recompute both together if the clip or the mesh scale changes. Reset spins the can with `mdp.events.reset_object_on_table` rather than `reset_root_state_uniform`, which composes its sampled rotation on the right (`q_default * q_delta`) and so yaws about the *body* z axis. With an upright can that axis points sideways, so the stock term would tip it over by up to the sampled angle. Composing on the left keeps the axis vertical in the world. Height gained is measured from the object's **resting pose**, not the table top. The mesh origin is its centroid, so it already sits ~7 cm up when untouched; measuring from the table top pays a constant lift reward for doing nothing. Because tracking is biased, the policy is given the **achieved** wrist pose and the object-to-hand vector, not just its own command, so it closes the loop on where the hand went instead of trusting where it aimed. ```bash ./jobs/sonic_manip_smoke.sh # scripted reach/close/lift, no learning cd ../rl && ./train.sh --headless --task V2D-G1-SonicManip-v0 --num_envs 32 ``` Run the smoke test first. It answers whether the environment is sound (robot stays up, hand reaches the target, scripted grasp lifts) separately from whether the reward is learnable — after training the two are hard to tell apart. `BatchedSonicController` (`sonic/batched.py`) is the vectorised inner loop. With a fixed standing reference nearly the whole 1751-D encoder vector is constant, so it is built once and only the heading (6) and VR 3-point target (21) are rewritten per step. Its packing is bit-exact against the single-env `pack_encoder` path, and `vr3_local_batch` against `vr3_local_from_bodies`. Known limits of this first version: the wrist **orientation** target is held at the standing pose, so the policy controls position and grip only. Only wrist position tracking was measured; if grasping turns out to need a specific approach angle, orientation is the next thing to add to the action space. ## CoordEx baseline `V2D-CoorDex-WalkGrab-Play-v0` runs CoordEx's released WalkGrab policy on a reconstructed object, as a literature baseline. This is **not** SONIC: the robot is CoordEx's G1-Wuji and the whole MDP is theirs. `--clip` picks which reconstruction goes on the table, and videos are written per clip so runs do not overwrite: ```bash ./jobs/coordex_v2d_play.sh --headless --video --clip 20200709_141754_836212060125 ``` `V2D-CoorDex-WalkGrab-Stock-v0` is the control: the same policy on CoordEx's own cylinder. Use it to separate porting bugs from genuine generalization failure — it grasps and lifts, which is how we established the port is sound. On the coffee can the same policy makes contact but lifts it only ~3 mm, so the failure is out-of-distribution object geometry, not wiring and not the hand hardware.