# Isaac Sim / Isaac Lab RUNBOOK: Golf Cart Robot Driver (Research)

> Research and simulation project only. Do not install this device in a real vehicle or attempt to drive a vehicle with it. It has not been built or tested on any vehicle.

**Simulation-tested · Not built.** Nothing here implies a physical prototype exists.

This folder is the Isaac project. It runs in Isaac Lab's own Python, never the project's uv environment. Only files cross between the two:
- **In:** `robot/robot.urdf` and `robot/robot.usd`.
- **Out:** `docs/sim-tests/*.json` now; checkpoints (in `runs/`) and `models/policy.onnx` from Phase 5.

The folder holds the USD tools (Phase 3b, `tools/usd_*.py`) and the Phase 5 RL task `Isaac-GolfCartDriver-PathFollow-v0` (`golf_cart_isaac/`, `tools/probe_env.py`, `tools/eval_policy.py`).

## Environment (as run on 2026-10-11)

| Item | Value | Source |
|---|---|---|
| Isaac Sim | 6.1.0-rc.26 (`C:\isaacsim\VERSION`), Kit 110.3.0 | conversion log |
| Isaac Lab | 3.0.0 at `C:\isaac-sim\IsaacLab` (`isaaclab.bat`, bundled Python 3.12) | `C:\isaac-sim\IsaacLab\VERSION` |
| URDF importer | "URDF USD Converter v0.3.2" (`isaacsim.asset.importer.urdf`), through `isaaclab.sim.converters.UrdfConverter` | `customLayerData.creator` in robot.usd |
| GPU | NVIDIA GeForce RTX 5060 Ti 16 GB, driver 591.86 (Warp reports CUDA 12.9 toolkit, driver 13.1) | `nvidia-smi`, Warp banner |
| Physics backend for the checks | PhysX (`isaaclab_physx.physics.PhysxCfg`), dt 0.002 s | `docs/sim-tests/usd_load.json` |

`tasks.py` (through `taskdefs/_common.py: isaac()`) calls `C:\isaac-sim\IsaacLab\isaaclab.bat -p <script>` from the Isaac Lab folder. Before the call it removes `VIRTUAL_ENV`, `UV_PROJECT_ENVIRONMENT`, `PYTHONHOME`, `PYTHONPATH` and the project's `.venv` from the environment, and sets `PYTHONPATH` to this folder.

The launcher prints `_isaac_sim\setup_conda_env.bat is missing`. This warning is harmless here: the bundled Python runs anyway.

Isaac Sim does not support A100/H100 GPUs. A cloud fallback needs an RTX-class GPU.

## Phase 3b: URDF to USD (queue: gpu, about 45 s)

```
uv run tasks.py describe          # robot/robot.urdf (+ MJCF); no shared queue
uv run tasks.py usd               # GPU queue: steps 1-4 below
uv run tasks.py usd --skip-convert   # reuse runs/usd_import (steps 2-4)
```

These are the commands `taskdefs/usd.py` runs. Paths are absolute, quoted because they contain spaces, and the working directory is `C:\isaac-sim\IsaacLab`:

```
set PYTHONHASHSEED=0
set PXR_WORK_THREAD_LIMIT=1
isaaclab.bat -p scripts\tools\convert_urdf.py "<repo>\package\robot\robot.urdf" "<repo>\runs\usd_import" --fix_base --joint_stiffness 0 --joint_damping 0
isaaclab.bat -p "<repo>\package\simulation\isaac\tools\usd_flatten_dump.py" "<repo>\runs\usd_import\robot\robot.usda" "<repo>\package\robot\robot.usd" "<repo>\package\docs\sim-tests\usd_dump.json"
isaaclab.bat -p "<repo>\package\simulation\isaac\tools\usd_load_check.py" "<repo>\package\robot\robot.usd" "<repo>\package\docs\sim-tests\usd_load.json" --seconds 2.0
isaaclab.bat -p "<repo>\package\simulation\isaac\tools\usd_load_check.py" "<repo>\package\robot\robot.usd" "<repo>\package\docs\sim-tests\usd_load_mimic_si_to_physx.json" --seconds 2.0 --mimic_si_to_physx
isaaclab.bat -p "<repo>\package\simulation\isaac\tools\usd_load_check.py" "<repo>\package\robot\robot.usd" "<repo>\package\docs\sim-tests\usd_load_no_self_collisions.json" --seconds 2.0 --no_self_collisions
isaaclab.bat -p "<repo>\package\simulation\isaac\tools\usd_load_check.py" "<repo>\package\robot\robot.usd" "<repo>\package\docs\sim-tests\usd_load_fix_root_link.json" --seconds 2.0 --fix_root_link
<repo>\.venv\Scripts\python.exe "<repo>\package\src\model_checks.py"
```

`convert_urdf.py` in Isaac Lab 3.0 has no `--headless` flag; it runs headless by default.

### Converter settings and why

| Setting | Reason |
|---|---|
| `--fix_base` | The kit's base link `seat_frame` is fixed (ZMass `base.type: fixed`, DESIGN_LOG D15). |
| `--joint_stiffness 0 --joint_damping 0` (target type `position`, drive type `force`) | No position-drive gains are baked into the USD. The actuator models live in the MJCF, and for RL in the Isaac Lab task config. |
| `merge_fixed_joints` off (default) | One rigid body per URDF link (10), so masses compare link by link. |
| Physics variant `physics` (importer default) | This is what `Flatten()` composes. `robot.usd` has no variant set left. |

### Outputs

| File | What |
|---|---|
| `robot/robot.usd` (Git LFS, 2.34 MB) | One self-contained, flattened layer. It holds ASCII (usda) content; USD reads either encoding from `.usd`. Instancing prototypes are renamed in a canonical order. Two fresh conversions on 2026-10-11 gave identical bytes (sha256 `d488e3b6…`). The root prim is `tn__golfcartrobotdriver_aS9F`, the importer's USD-safe encoding of `golf-cart-robot-driver`; link and joint prim names equal the URDF names. |
| `docs/sim-tests/usd_dump.json` | Every rigid body (mass, COM, diagonal inertia, principal axes, rebuilt tensor, world pose, collision prims) and every joint, with: type, bodies, axis in body0, limits (revolute in degrees, prismatic in metres), rest-pose body1-in-body0 transform, drive / `newton:*` / `urdf:*` attributes, mimic. |
| `docs/sim-tests/usd_load.json` | MODEL-LOAD (USD part): the file spawned as converted, on PhysX, stepped 2 s passive plus 2 s driven, then the mimic probe. |
| `docs/sim-tests/usd_load_mimic_si_to_physx.json`, `usd_load_no_self_collisions.json`, `usd_load_fix_root_link.json` | Diagnostics for Phase 5. These are not criteria. |
| `docs/sim-tests/model_consistency.json/.md` | MODEL-LOAD and MODEL-CONSIST, now with the USD file and the PhysX runtime values compared against the URDF. |

### Results (2026-10-11)

- **MODEL-LOAD, USD part: PASS.**
  - The file has 10 rigid bodies, the same as the URDF's 10 links.
  - It has 10 joints: the URDF's 9 plus the world `root_joint`.
  - PhysX builds a 5-DOF articulation with 10 bodies.
  - All states stay finite over 2,000 steps passive plus 2,000 steps driven.
  - Base-link drift is 2.7e-7 m.
- **MODEL-CONSIST, USD part: PASS.** The worst relative error, over the USD file and the PhysX runtime against the URDF, is 5.6e-7 against the 1 % limit. Items compared:
  - masses, COM and the full inertia tensor;
  - joint type and bodies, axis, limits and origin;
  - effort and velocity limits;
  - mimic leader, multiplier and offset (as written in the file).
- **Overall:** MODEL-LOAD **PASS** and MODEL-CONSIST **PASS** (MJCF, URDF, CAD and USD), per `docs/sim-tests/model_consistency.md`.

## Findings that the Phase 5 RL task must handle

These were measured on 2026-10-11 and are listed in `usd_load*.json`. DESIGN_LOG D19 covers them.

1. **Mimic couplings are enforced under PhysX, but the brake coupling is in the wrong unit.**
   - The importer writes the URDF `<mimic>` as `NewtonMimicAPI` (`newton:mimicJoint`, `newton:mimicCoef1` = multiplier). It writes no `PhysxMimicJointAPI`.
   - The Newton schema and Newton's importer treat `coef1` as dimensionless SI (m/rad here).
   - Kit 110.3's PhysX path applies `coef1` in USD position units instead: m per degree for an angular leader with a linear follower. PhysX's own `gearing` attribute is documented that way ("angular to linear: distance / degrees").
   - Measured effective multipliers (`usd_load.json` `mimic_under_physx`):

     | Coupling | Effective | URDF | Ratio |
     |---|---|---|---|
     | `brake_slider_joint` ← `brake_drum_joint` | 0.3437 m/rad | 0.006 | ×57.3 |
     | `throttle_lever_joint` ← `throttle_drum_joint` (revolute ← revolute) | 0.12506 | 0.125 | ×1.000 |

   - As converted, the brake slider reaches its 75 mm stop when the drum has turned 12.5°, not 12.5 rad.
   - **Workaround, tested:** at spawn, author `newton:mimicCoef1 = 0.006 · π / 180` on `brake_slider_joint` (`usd_load_check.py --mimic_si_to_physx`). The effective multiplier is then 0.006184 (×1.031). The 3 % residual is in a run where both joints are at their velocity limits.
   - The shipped `robot.usd` keeps the schema-correct SI value, so Newton and other readers stay right.
   - The MJCF models both cords as one-sided tendons (slack allowed: latch drop, decoupler release), not hard mimics. Phase 5 must decide whether the RL task needs the brake and throttle drums at all, or commands the pedal joints through the spec's maps. Record that decision in `policy_io.yaml` / D19.
2. **The base is held by an external joint, not a fixed-base articulation.**
   - With `--fix_base`, the importer puts `ArticulationRootAPI` on the `seat_frame` rigid body plus a world `FixedJoint` (`root_joint`).
   - PhysX therefore builds a floating-base articulation held by a maximal-coordinate joint: `is_fixed_base` False, drift 2.7e-7 m in 4 s.
   - Isaac Lab's `ArticulationRootPropertiesCfg(fix_root_link=True)` fails on this asset in Isaac Lab 3.0. It raises `RuntimeError: Failed to remove '/World/Robot/Geometry/seat_frame.newton:selfCollisionEnabled' from the former articulation root.` (`usd_load_fix_root_link.json`): the property is authored in the referenced file, so the relocation cannot delete it.
   - Use the asset as converted (no root-state writes are needed for a fixed kit), or move the root in a post-processing step and re-run the checks.
3. **Joint friction is not read by PhysX.**
   - The URDF `<dynamics friction>` values are in the file as `newton:friction`: 1 / 0.25 / 38.25 N / 0.196 / 0.09.
   - The PhysX runtime friction is 0 on every joint.
   - Set friction explicitly in the actuator config from `robot_description.json` / spec if the task needs it.
4. **Springs, armature and actuator dynamics are not in the URDF/USD.**
   - Brake spring: 1,000 N/m, 420 N preload.
   - Throttle return spring: 5→10 N.
   - Armature, the steering clutch cap and the cart (pedals, steering column, wheels) exist only in the MJCF and scene files (D15).
   - The RL task must build them from `spec.yaml` / `docs/sim-tests/robot_description.json` (rule 4), not hand-copy them.
5. **Self-collisions.**
   - The importer disables them only through `newton:selfCollisionEnabled = 0`, which PhysX does not read, so PhysX self-collisions are on.
   - With `PhysxArticulationRootPropertiesCfg(enabled_self_collisions=False)`, the end-of-phase joint positions and the mimic multipliers are identical to the default run (largest difference 0.0; `usd_load_no_self_collisions.json`).
   - Whether self-collisions should be on for RL depends on which contacts the RL task keeps (the MJCF kit collides with itself, D15). Phase 5 decides this.
6. **Joint limits and velocity limits come through unchanged:** steer ±7.854 rad, brake drum 0–12.5 rad, slider 0–75 mm, throttle drum 0–4.712 rad, lever 0–0.589 rad. The effort limits are the URDF efforts: steer 15 N·m (clutch cap), brake drum 6.149 N·m, throttle drum 2.942 N·m.
7. **Only V1 geometry is converted.** If RL needs V2, write `describe.urdf("V2", ...)` into `runs/` and convert it with the same commands; keep it out of the package unless it is listed.

## Phase 5: RL task `Isaac-GolfCartDriver-PathFollow-v0` (queue: gpu)

The task package is `golf_cart_isaac/` (registered by `--external_callback golf_cart_isaac.register`). Its numbers come from `golf_cart_isaac/params.json`, which `src/gen_isaac.py` writes from `spec.yaml` and the Phase 4 MuJoCo harness (`src/simlib.CartSim`). The policy I/O contract is `models/policy_io.yaml`, written by the same generator. DESIGN_LOG D21 records the decisions.

### What the task simulates

| Part | Where | Model |
|---|---|---|
| Kit joints (`steer_hub_joint`, `brake_drum_joint` + `brake_slider_joint`, `throttle_drum_joint` + `throttle_lever_joint`) | **PhysX** articulation from `robot/robot.usd` | Armature from the MJCF; the hub also carries the steering chain (column, wheel, knuckles through the ratio) from MuJoCo's inertia matrix. Mimic couplings enforced by PhysX, with the brake coefficient authored in PhysX units at spawn (finding 1). Measured ratio to the URDF over a scripted run: 1.0000-1.0001 (brake) and 1.0000-1.0041 (throttle). |
| Actuator MCU and motors | `env.py`, every physics step | As `src/simlib.py`: 200 Hz trapezoidal setpoint shaping and PD (kp, kv from the MJCF), torque-speed line while motoring, stall torque while braking or holding, slip clutch on the steering. |
| Brake spring, cords, pedals, steering resistance | `env.py`, as joint efforts | Spring 1000 N/m preloaded 420 N; one-sided cord (slack where the pedal pushes back harder than the spring); slider and lever friction; pedal maps (A4) with floor stops; steering dry park to rolling Coulomb torque (A5) plus column damping. |
| Brake drum latch (D38, D41) | `env.py`, MCU ticks | As `simlib._drum_latch`: engage after `engage_dwell_s` settled at ready, retract `engage_overtravel_rad`, pawl stop as a one-sided penalty torque (100 N·m/rad, 1.0 N·m·s/rad; MuJoCo: the drum joint's upper limit), release after request latency + magnet release with the load hand-over capped at `handover_cap_frac` x the measured holding torque; payout ramp `apply_accel_time_s`. |
| Cart | `env.py` (torch) | Kinematic bicycle about the rear axle with simlib's drive, brake (100 ms build-up) and rolling-resistance maps, tyre-friction limits and the wheels' spin inertia (A50). |
| Physics step | `rl.physics_dt` = 0.005 s | The MCU period. The step time is Python-bound, and 0.005 s is 2.5 times faster than 0.002 s. The scripted check at 0.002 s differs by at most 0.003 m/s in speed (A53). |

Other settings:
- **Observations (18) and actions (3):** see `models/policy_io.yaml`. Actions are mapped by `src/policy_actions.py` (brake interlock and the onboard speed-limit filter on the speed estimate, the same code the MuJoCo sim-to-sim uses; D41) and reach the MCU at the 30 ms chain deadline, plus a randomized latency: in training 0-3 policy steps weighted toward 2 (`rl.randomization_extra.train_action_latency`), in the evaluation 0-2 uniform (`randomization.action_latency_steps`, unchanged).
- **Reward:** weights and sigmas from `spec.yaml` `rl.reward` (D41), through `params.json`.
- **Randomization:** spec `randomization` plus `rl.randomization_extra` and `rl.disturbances`.
- **Courses:** the spec course (25 % of training episodes, and the whole evaluation) plus 512 random courses (`rl.courses`).
- **Terminations:** |cross-track| > 1.5 m or |heading error| > 1.0 rad.
- **Not in the task:** the safety supervisor (obstacle stop, e-stop) is rule-based outside the policy.

The PhysX warning `Cloning joints .../root_joint without a body rel may cause issues` comes from the importer's world joint (finding 2). The kit base does not move: the probe shows constant joint origins.

### Commands (from the repo root)

```
uv run tasks.py train                 # gen_isaac.py, then 1000 iterations, 8192 envs, seed 20261011 (spec rl)
                                      #   console log -> runs/rl/train_final.log
                                      #   checkpoints -> runs/logs/rsl_rl/golf_cart_path_follow/<date>_final/
                                      #   last checkpoint -> runs/checkpoints/policy_final.pt (LFS), curves -> docs/sim-tests/training_curves.*
uv run tasks.py train --run smoke --max_iterations 15   # quick plumbing run (not copied)
uv run tasks.py export                # runs/checkpoints/policy_final.pt -> models/policy.onnx (+ ONNX check)
                                      #   100-episode randomized eval -> docs/sim-tests/rl_isaac_eval.json (RL-ISAAC)
                                      #   same, randomization off -> docs/sim-tests/rl_isaac_eval_nominal.json (information)
```

Equivalent raw commands. Set `PYTHONPATH=<repo>\package\simulation\isaac` and `PYTHONDONTWRITEBYTECODE=1`, and run from `<repo>\runs`:
```
<repo>\.venv\Scripts\python.exe <repo>\package\src\gen_isaac.py
C:\isaac-sim\IsaacLab\isaaclab.bat train --rl_library rsl_rl --task Isaac-GolfCartDriver-PathFollow-v0 --external_callback golf_cart_isaac.register --num_envs 8192 --seed 20261011 --max_iterations 1000 --run_name final
C:\isaac-sim\IsaacLab\isaaclab.bat -p <repo>\package\simulation\isaac\tools\eval_policy.py <repo>\runs\checkpoints\policy_final.pt <repo>\runs\export\policy.onnx <repo>\package\docs\sim-tests\rl_isaac_eval.json
<repo>\.venv\Scripts\python.exe <repo>\package\src\onnx_finalize.py <repo>\runs\export\policy.onnx <repo>\package\models\policy.onnx
```

### Pre-training checks

`tools/probe_env.py <out.json>` runs a scripted action sequence with randomization off (V1). `--timing_envs N` times N random-action envs instead, and `--physics_dt` overrides the step.

`src/isaac_mj_compare.py <probe.json> [<probe at 0.002 s>]` replays the same actions in the MuJoCo harness and writes `docs/sim-tests/isaac_mujoco_actuators.json` and `.png` (a diagnostic, not a criterion):
- **Kit joints:** steering within 0.0024 rad over a 2.7 rad range. Brake drum within 0.16 rad over 6.5 rad (brake slider 0.8 mm), throttle drum within 0.005 rad.
- **Cart:** curvature for a given steering angle agrees within 0.5 %. Speed agrees within 0.34 m/s, with MuJoCo slower mainly in turns: its rear tyres scrub, which the kinematic model does not have (A50). Phase 6 measures the effect on the policy.

Timing on the RTX 5060 Ti at dt 0.005 s, 8192 envs: 0.099 s per policy step, about 2.8 s per PPO iteration (24 steps per env), and less than 0.1 GB of GPU memory.

### Results (2026-10-11)

**Training** (`runs/rl/train_final.log`, `docs/sim-tests/training_curves.png/.json`):
- 1000 iterations, 196,608,000 env steps, 49.4 min.
- Final mean reward 491. Episodes last the full 900 steps with no terminations; true cross-track RMS 0.10 m.
- The first attempt crawled and was stopped after 161 iterations (D21). Its log is `runs/rl/train_attempt1_crawl.log`.

**Evaluation** (`docs/sim-tests/rl_isaac_eval.json`): **RL-ISAAC PASS**, 98/100 randomized episodes.
- The two failures reached the end with a max cross-track of 0.77 m and 0.70 m.
- With randomization off (`rl_isaac_eval_nominal.json`): 100/100.

**Export:** `models/policy.onnx` (one file, metadata names `models/policy_io.yaml`) reproduces the torch policy within 9.5e-7.

**GPU time used in this step:** about 85 min in total. The probes took about 12 min, the first attempt about 9 min, the final run 51 min, and the evaluation and export about 6 min.

**Retrain (Fix Engineer WP3, 2026-10-11, DESIGN_LOG D41):** the task gained the onboard speed-limit filter (`src/policy_actions.py`), the drum latch and payout ramp, training latency 0-3 steps weighted toward 2, the spec reward block, and the accelerometer low-pass (`rl.obs_lowpass_tau_s`, also in sim2sim and onboard). Run 1 (1000 iterations, 55.6 min) is the committed policy. Run 2 (no accelerometer input, 600 iterations) collapsed to standing still and was not used. With the 0.10 s low-pass: RL-ISAAC 0.96 (96/100), nominal 100/100; ONNX vs torch 6.0e-07. GPU time held in that step: about 2 h 40 min (usd, smoke, two isaac-compare, two trainings, four exports).

### Policy rate on the real hardware (`models/policy_io.yaml` `rate_feasibility`)

The policy runs at 20 Hz inside the 50 ms chain's plan stage. Its cost per step:

| Item | Cost | Notes |
|---|---|---|
| Actor network | 45,760 multiply-adds per step (0.9 M per second) | Negligible on a Cortex-A76 core |
| Pi to actuator MCU | 20 B per command, 400 B/s | |
| STS3215 bus | 0.35 ms per update at 50 Hz (1.75 % load) | At 1 Mbps |
| Actuator MCU | 200 Hz loop | Runs the PD and the setpoint shaping, as in simulation |
