|
| 1 | +# Motion Preprocessing |
| 2 | + |
| 3 | +This directory contains scripts for preprocessing motion data for motion tracking tasks. |
| 4 | + |
| 5 | +## CSV to NPZ Conversion |
| 6 | + |
| 7 | +The `csv_to_npz.py` script converts motion data from CSV format to NPZ format with precomputed forward kinematics. |
| 8 | + |
| 9 | +### Input Format |
| 10 | + |
| 11 | +CSV files should contain motion data in Unitree's generalized coordinate convention: |
| 12 | +- Columns 0-2: Base position (x, y, z) |
| 13 | +- Columns 3-6: Base quaternion (x, y, z, w) - will be converted to wxyz internally |
| 14 | +- Columns 7+: Joint angles (29 joints for G1) |
| 15 | + |
| 16 | +### Output Format |
| 17 | + |
| 18 | +NPZ files contain: |
| 19 | +- `fps`: Frame rate (integer) |
| 20 | +- `joint_pos`: Joint positions (N_frames × N_joints) |
| 21 | +- `joint_vel`: Joint velocities (N_frames × N_joints) |
| 22 | +- `body_pos_w`: Body positions in world frame (N_frames × N_bodies × 3) |
| 23 | +- `body_quat_w`: Body quaternions in world frame (N_frames × N_bodies × 4, wxyz) |
| 24 | +- `body_lin_vel_w`: Body linear velocities (N_frames × N_bodies × 3) |
| 25 | +- `body_ang_vel_w`: Body angular velocities (N_frames × N_bodies × 3) |
| 26 | + |
| 27 | +### Usage |
| 28 | + |
| 29 | +```bash |
| 30 | +# Basic usage |
| 31 | +uv run python scripts/motion/csv_to_npz.py \ |
| 32 | + --input_file path/to/motion.csv \ |
| 33 | + --output_file path/to/motion.npz \ |
| 34 | + --input_fps 30 \ |
| 35 | + --output_fps 50 |
| 36 | + |
| 37 | +# With custom model file |
| 38 | +uv run python scripts/motion/csv_to_npz.py \ |
| 39 | + --input_file path/to/motion.csv \ |
| 40 | + --output_file path/to/motion.npz \ |
| 41 | + --input_fps 30 \ |
| 42 | + --output_fps 50 \ |
| 43 | + --model_file path/to/model.xml |
| 44 | + |
| 45 | +# Process specific line range |
| 46 | +uv run python scripts/motion/csv_to_npz.py \ |
| 47 | + --input_file path/to/motion.csv \ |
| 48 | + --output_file path/to/motion.npz \ |
| 49 | + --input_fps 30 \ |
| 50 | + --output_fps 50 \ |
| 51 | + --line_range 100 500 |
| 52 | +``` |
| 53 | + |
| 54 | +### Parameters |
| 55 | + |
| 56 | +- `--input_file`: Path to input CSV file (required) |
| 57 | +- `--output_file`: Path to output NPZ file (required) |
| 58 | +- `--input_fps`: Frame rate of input CSV (default: 30) |
| 59 | +- `--output_fps`: Desired output frame rate (default: 50) |
| 60 | +- `--model_file`: MuJoCo model file (default: G1 flat scene) |
| 61 | +- `--line_range`: Line range to process [start, end] (optional) |
| 62 | + |
| 63 | +### Notes |
| 64 | + |
| 65 | +- The script uses LERP for position interpolation and SLERP for quaternion interpolation |
| 66 | +- Velocities are computed using numerical differentiation |
| 67 | +- Forward kinematics is computed using MuJoCo for all bodies |
| 68 | +- The output FPS should match the control frequency of your training environment (typically 50 Hz) |
0 commit comments