Robot Trajectory Data Generation
Generate a large-scale dataset of physically valid robot demonstrations for VLA training — where the Alex robot physically grasps, transports, and places LEGO bricks through its actuated joints, producing synchronized (observation, 17-D action) pairs at every 20 Hz control timestep.
Primary Goal
The existing ScriptedAssembler (Phase 1.2.6) bypasses the robot entirely — it teleports bricks via qpos writes and applies external forces via xfrc_applied. The robot arms never move. For VLA training, we need a demonstration controller that produces 17-D actions through the real control pipeline (SimRunner.step()), so that every recorded (state, action, image) tuple is something a learned policy could reproduce.
Fixed Upstream Decisions (from Phase 1.2)
IHMC Alex upper-body fixed-base, **17-D action space** (Δq arms + gripper), **52-D state vector**
4 frozen cameras (overhead, wrist-L, wrist-R, third-person), 320×320, 20 Hz
SimRunner at 20 Hz (25 substeps × 0.002 s), `AlexActionSpace` normalization
Soft press-fit contacts, procedural bricks {2×2, 2×4, 2×6}, 8×8 baseplate, workspace scene
`EpisodeManager` with deterministic seeded reset, 3 curriculum levels
`generate_assembly_goal()` → `PlacementTarget` sequences, `check_placement()` for success
Key Phase 2.1 Stance: Pure Jacobian Control
- Pure Jacobian control for all demonstrations in the base dataset. No xfrc_applied force-assist. If insertion accuracy is insufficient after tuning, a separately labeled assisted subset may be generated outside the clean dataset.
- Progressive generation — 5K single-brick episodes first, validate end-to-end, then 5K mixed-complexity.
- All modalities — RGB + Depth + Segmentation stored per frame (~550 GB total for 10K episodes).
- Single-arm pick-and-place — closest arm picks (Y>0 → left, Y<0 → right), other arm at rest. Bimanual is an explicit next-step extension.
Robot Trajectory Data Generation Tasks
Six critical components from the Phase 2.1 execution plan
Task-Space Demonstration Controller
Implement a Jacobian-based resolved-rate controller that produces 17-D actions from end-effector position targets. This is the core new component — without it, we cannot generate physically valid robot demonstrations.
The entire data generation pipeline depends on this controller. It must produce smooth, physically realistic joint-space actions that move the robot's end-effectors to desired poses while respecting joint limits and velocity bounds.
- Implement DemoController with step_toward to 17-D action
- Implement execute_waypoints to list of tuples at each 20 Hz step
- Damped pseudoinverse with configurable λ
- Fine-approach gain reduction within configurable radius
Controller moves EE to 10 random workspace positions with < 2 mm final error and no joint-limit violations. ---
Design
- Use mujoco.mj_jacSite() on left_tool_frame / right_tool_frame to compute the 3×N position Jacobian
- Extract columns for the active arm's joints only (8 joints: spine + 7 arm)
- Resolved-rate control law: dq = J^T (J J^T + λI)^{-1} · Kp · (x_target - x_current) (damped least squares, λ=0.01)
- Clip dq to delta_q_max bounds (from AlexActionSpace), normalize via AlexActionSpace.normalize(dq_15, gripper_cmd) → 17-D action
- Execute via SimRunner.step(action) → RobotState
- Fine-approach zone: halve gain when position error < 5 mm to prevent overshoot
- Active arm selection: Y>0 → left arm, Y<0 → right arm (Alex Y-left convention)
- Idle arm: zero deltas in the 17-D action vector
Grasp Planning & Pick-and-Place Waypoints
Implement a waypoint generator that converts a PlacementTarget (from sim/lego/task.py) into a concrete sequence of waypoints for the demo controller. This defines the physical manipulation strategy for single-arm LEGO pick-and-place.
This bridges the task system (generate_assembly_goal()) and the controller. Without a well-defined waypoint sequence, the robot cannot reliably grasp, transport, and place bricks.
- Waypoint frozen dataclass: position, gripper_cmd, tolerance, max_steps, gain_scale
- generate_pick_place_waypoints produces 8-phase sequence from PlacementTarget
- Grasp height calibration: determine grasp_z_offset by measuring tool_frame ↔ finger contact distance
- Integration test: full pick-and-place of one 2×2 brick from table to baseplate
Single-arm pick-and-place of a 2×2 brick succeeds ≥ 80% over 50 random episodes (seed-deterministic). ---
Design — 8-phase waypoint sequence for single brick placement
- Pre-grasp: EE to (bx, by, bz + 0.05), gripper open (1.0)
- Approach: EE to (bx, by, bz + grasp_z_offset), gripper open (1.0), slower gain
- Close gripper: Hold position, ramp gripper 1.0 → 0.0 over ~10 steps (0.5 s)
- Lift: EE to (bx, by, bz + 0.08), gripper closed (0.0)
- Transport: EE to (tx, ty, tz + 0.05), gripper closed (0.0)
- Lower/Insert: EE to (tx, ty, tz + grasp_z_offset), gripper closed (0.0), slow gain
- Release: Hold position, ramp gripper 0.0 → 1.0 over ~10 steps
- Retract: EE to (tx, ty, tz + 0.05), gripper open (1.0)
- Brick position read from data.xpos[body_id] at execution time (handles settle drift)
- Target position from compute_target_position() in sim/lego/task.py
- grasp_z_offset = empirical offset from tool_frame site to finger contact point (~2–3 cm, tunable)
- Top-down approach perpendicular to table surface (identity orientation)
Episode Data Recording & HDF5 Storage
Define the HDF5 per-episode storage format and implement the recording pipeline that captures synchronized (state, action, images, metadata) at 20 Hz.
The training pipeline needs efficiently loadable trajectory data with all modalities temporally aligned. The format must support random access (for batching), compression (for storage), and metadata (for reproducibility).
- EpisodeRecorder.record_step buffers in memory
- EpisodeRecorder.save flushes to HDF5 with compression
- JPEG compression for RGB, gzip for depth/segmentation
- Read-back validation: write to read to assert shapes and values match
Write and read-back a 200-step episode with all modalities. File size ~50–60 MB. DemoDataset loads it correctly. ---
HDF5 schema (per episode file)
episode_{seed:06d}.hdf5
├── metadata/ (group attributes)
│ seed, level, brick_types, n_timesteps, success,
│ assembly_result (JSON), goal (JSON), spawn_poses (JSON),
│ control_hz, version ("2.1.1"), timestamp_created (ISO 8601)
├── state/
│ raw: float64 (T, 52) # raw 52-D state vectors
│ normalized: float32 (T, 52) # normalized for training
│ timestamps: float64 (T,) # sim timestamps
├── action/
│ normalized: float32 (T, 17) # normalized 17-D actions
├── images/
│ overhead/
│ rgb: uint8 (T, 320, 320, 3)
│ depth: float32 (T, 320, 320)
│ segmentation: int32 (T, 320, 320, 2)
│ left_wrist_cam/ ...
│ right_wrist_cam/ ...
│ third_person/ ...
├── camera_metadata/ (group attributes)
│ intrinsics: JSON per camera (constant, stored once)
│ extrinsics_{cam}: float64 (T, 12) # [pos(3) + mat(9)] per step
└── labels/
phase: uint8 (T,) # waypoint phase index (0–7)
grasp_state: float32 (T,) # gripper command per step
episode_outcome: str # "success" | failure type
perturbation_type: str # "none" | perturbation type
failure_timestep: int # -1 if no failure
has_recovery: bool # true if episode contains a retry sequence
recovery_start_timestep: int # step where recovery begins (-1 if none)Storage layout
data/demonstrations/v2.1.1/
├── episodes/
│ ├── episode_000000.hdf5
│ └── ...
├── train_manifest.json
├── val_manifest.json
├── test_manifest.json
└── dataset_stats.json # per-feature mean/std for normalizationStorage estimates
- RGB images: JPEG quality 90 (~30 KB per 320×320 frame)
- Depth: float32 with gzip compression
- Segmentation: int32 with gzip compression
- Per episode (200 steps, all modalities): ~55 MB
- 10K episodes: ~550 GB
Single-Episode Demo Pipeline (End-to-End)
Build the single-episode orchestrator that ties together EpisodeManager → goal generation → waypoint planning → demo controller → camera capture → HDF5 recording into one callable function.
This is the first end-to-end integration of all components. It must work reliably before parallelizing. Every bug found here saves hours of wasted parallel generation time.
- generate_episode produces valid HDF5 from a single seed
- Determinism: same seed to identical state/action sequences
- Timing: single episode < 60 seconds on one CPU core
- Video export: render saved HDF5 images back to MP4 for visual inspection
50 Level 1 episodes generated, ≥ 80% success rate, all HDF5 files valid, deterministic replay confirmed. ---
Pipeline
def generate_episode(seed, level, output_dir, config) -> EpisodeResult:
# 1. EpisodeManager.reset(seed, level)
# 2. generate_assembly_goal(info, baseplate, ...)
# 3. For each PlacementTarget in goal:
# a. generate_pick_place_waypoints(target)
# b. DemoController.execute_waypoints(waypoints)
# c. At each step: capture 4-view frame, record (state, action, frame)
# 4. evaluate_assembly() for success metrics
# 5. EpisodeRecorder.save() to HDF5
# 6. Return EpisodeResult (metadata + success + timing)- MultiViewRenderer created once per episode, shared across all timesteps
- Controller computes action → SimRunner.step() executes → capture frame → record (strict per-timestep ordering)
- Failed grasps/insertions: episode still recorded with failure labels (useful for failure dataset)
- Success evaluation via check_placement() from sim/lego/task.py
Parallel Data Collection & 10K Generation
Build a multi-process data collection pipeline that generates 10K episodes with fault tolerance, resumption, and progress tracking.
Single-process generation would take ~170 hours. Parallel collection is required for practical generation times (~10–20 hours with 8–16 workers).
- Small-scale test: 100 episodes with 4 workers, all HDF5 files valid
- Determinism: same seeds produce identical outputs regardless of worker count
- Resumption: kill at 50%, restart, only remaining episodes generated
- Manifests: train/val/test splits are disjoint and cover all episodes
10K episodes generated, manifests created, dataset_stats.json computed, all files validated. ---
Design
- Python multiprocessing — each worker owns its own EpisodeManager + MultiViewRenderer + SimRunner (MuJoCo is not thread-safe)
- Seed management: worker w processes seeds [w * block_size, (w+1) * block_size) — reproducible regardless of worker count
- Fault tolerance: per-episode try/except, failures logged to failures.jsonl with seed + traceback; 5-minute watchdog timeout per episode
- Resumption: on restart, check which HDF5 files exist, skip completed seeds
- Progress: tqdm in master process via shared counter (multiprocessing.Value)
- Default workers: min(N_CPU - 1, 16), ~1 GB RAM per worker
Progressive generation strategy
- Wave 1: Generate 5K single-brick episodes (Level 1/2, seeds 0–4999)
- Validate: Run QC checks, measure success rate, inspect sample videos
- Wave 2: Generate 5K mixed-complexity episodes (Level 1–3, seeds 5000–9999)
- Merge: Combine manifests, recompute dataset statistics
Estimated wall time
| Workers | 5K episodes | 10K episodes |
|---|---|---|
| 8 | ~10 hours | ~20 hours |
| 16 | ~5 hours | ~10 hours |
Failure Cases, Recovery & Quality Control
(a) Generate intentional failure demonstrations with labeled perturbations and recovery attempts. (b) Run a quality control filtering pipeline on the full dataset. (c) Produce dataset statistics and a summary report.
Failure/recovery demonstrations improve policy robustness. QC filtering ensures dataset integrity — one corrupted episode in training can waste GPU-hours. Statistics provide confidence in the dataset's coverage and quality.
- Each perturbation type produces a detectable failure
- Recovery episodes contain full fail + retry sequence
- QC filter catches injected bad episodes
- Statistics report covers all metrics
Cleaned 10K-episode dataset with success/failure/recovery labels, QC report, and statistics. ---
Failure taxonomy
| Type | Fraction | Perturbation |
|---|---|---|
| Misalignment | 30% | 2–5 mm lateral offset on insertion waypoint |
| Premature release | 20% | Open gripper 3–5 cm before target height |
| Grasp miss | 15% | 5–10 mm offset on grasp approach |
| Collision/knock | 15% | Transport waypoint near existing structure |
| Drop during transport | 10% | Brief gripper open (1–2 steps at cmd=0.5) |
| Incomplete insertion | 10% | Retract before engagement |
- Perturbations modify the waypoint sequence (not controller gains) via PerturbationConfig dataclass
- Recovery: after detected failure, generate re-approach + retry. Full trajectory recorded including failure + recovery, labeled "has_recovery": true
- Target composition: 7K success + 2K failure + 1K recovery = 10K total
Quality control pipeline
- Physics: reject NaN in state/action, penetration > 5 mm, energy > 1000 J
- Actions: reject if any action exceeds [-1.05, 1.05] (5% tolerance for numerical noise)
- Images: reject if mean pixel < 10 (black) or > 245 (white)
- State continuity: reject if consecutive state jumps exceed bounds (no teleportation artifacts)
- Episode length: reject if < 50 or > 1000 steps
- Duplicates: verify no two episodes share the same seed
Dataset statistics report
- Episode length distribution (histogram)
- Per-joint action distribution (mean, std, min, max)
- Success rate by brick type and curriculum level
- EE position coverage heatmap (XY workspace)
- Failure type distribution
- Total disk usage
Key Deliverables
Expected outputs by end of Phase 2.1:
- Jacobian-based demonstration controller — produces policy-compatible 17-D actions through real physics
- 10K trajectory dataset — HDF5 per-episode with RGB+Depth+Segmentation, state, action, metadata
- Parallel generation pipeline — multi-process, fault-tolerant, resumable, ~10 hours on 16 cores
- Failure/recovery demonstrations — labeled perturbation types, recovery trajectories
- Quality control pipeline — automated validation, filtering, and dataset statistics
- PyTorch Dataset — DemoDataset for direct training integration
Definition of Done
Jacobian demo controller
The Jacobian demo controller reliably picks and places LEGO bricks (≥ 80% success rate on single-brick).
10K episodes
10K episodes are generated, validated, and stored in HDF5 with all modalities.
Train/val/test manifests
Train/val/test manifests exist with 80/10/10 split and dataset statistics.
Failure and recovery episodes
Failure and recovery episodes are included with correct labels.
QC filtering
QC filtering has been run and a clean dataset manifest exists.
DemoDataset
DemoDataset loads episodes correctly for training.
5 days