File size: 11,318 Bytes
700dd75 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | # Motion Reference Data
This page describes the motion reference data format used by the C++ deployment stack, how to create your own reference motions, and how to verify and deploy them.
The deployment stack plays back pre-loaded **reference motions** β sequences of joint positions, velocities, and full body kinematics that the policy tracks. These motions are stored as CSV files in a structured folder hierarchy. You can generate them from any source (motion capture, simulation, retargeting pipeline, etc.) as long as the output matches the format described below.
---
## Folder Structure
Each motion dataset is a directory containing one subfolder per motion clip. The C++ reader (`MotionDataReader`) auto-discovers all subfolders at startup.
```
reference/my_motions/
βββ motion_name_1/
β βββ joint_pos.csv # Joint positions
β βββ joint_vel.csv # Joint velocities
β βββ body_quat.csv # Body quaternions
β βββ body_pos.csv # Body positions
β βββ metadata.txt # Body part indexes
β βββ body_lin_vel.csv # Body linear velocities
β βββ body_ang_vel.csv # Body angular velocities
β βββ smpl_joint.csv # SMPL joint positions
β βββ smpl_pose.csv # SMPL body poses
β βββ info.txt # Detailed motion information
βββ motion_name_2/
βββ ...
```
The C++ reader scans the base directory for subfolders, reads each subfolder as one motion, and validates frame-count consistency across all files in that folder.
---
## File Formats
The C++ reader loads whichever files are present and skips missing files gracefully. However, **in practice**, most policies require:
- `joint_pos.csv`, `joint_vel.csv` β for joint-based motion tracking
- `body_quat.csv` β for anchor orientation observations (the control loop will stop if this is missing when gathering observations)
- `body_pos.csv` β for heading computation and VR 3-point observations
- `metadata.txt` β for body part index alignment when body data is present
A motion must have **at least one valid data source** (joint, body, or SMPL) to load at startup.
### `joint_pos.csv`
Joint positions in **IsaacLab order** (29 joints). Each row is one timestep at 50 Hz. The first row is a header.
| Column | Description |
|--------|-------------|
| `joint_0` β¦ `joint_28` | Joint angles in radians (IsaacLab ordering) |
Shape: `(timesteps, 29)`
### `joint_vel.csv`
Joint velocities in **IsaacLab order** (29 joints). Each row is one timestep at 50 Hz. Frame count must match `joint_pos.csv`.
| Column | Description |
|--------|-------------|
| `joint_vel_0` β¦ `joint_vel_28` | Joint angular velocities in rad/s (IsaacLab ordering) |
Shape: `(timesteps, 29)`
### `body_pos.csv`
Body part positions in the **world frame**. Each body contributes 3 columns (x, y, z). The number of bodies varies per motion. Needed for heading computation and VR 3-point observations.
| Column | Description |
|--------|-------------|
| `body_0_x`, `body_0_y`, `body_0_z` | Position of body 0 (root/pelvis) in meters |
| `body_1_x`, `body_1_y`, `body_1_z` | Position of body 1 in meters |
| β¦ | β¦ |
Shape: `(timesteps, num_bodies * 3)`
**We assume the root/pelvis is always at column group 0** (the first 3 columns).
### `body_quat.csv`
Body part orientations as quaternions in the **world frame**. Each body contributes 4 columns. The quaternion ordering is **(w, x, y, z)**. **Required for most policies** β the `motion_anchor_orientation` observation (used by most policies) will fail and stop the control system if this file is missing.
| Column | Description |
|--------|-------------|
| `body_0_w`, `body_0_x`, `body_0_y`, `body_0_z` | Quaternion of body 0 (root/pelvis) |
| `body_1_w`, `body_1_x`, `body_1_y`, `body_1_z` | Quaternion of body 1 |
| β¦ | β¦ |
Shape: `(timesteps, num_bodies * 4)`
**We assume the root/pelvis is always at column group 0** (the first 4 columns).
```{note}
The number of bodies in `body_quat.csv` can differ from `body_pos.csv`. The C++ reader tracks them independently (`num_bodies` vs `num_body_quaternions`). However, the root body (first column group) must be present for heading computation to work. You can use zero if you don't need root pos.
```
### `metadata.txt`
Contains the **body part indexes** array, which maps each column group in `body_pos.csv` / `body_quat.csv` to the corresponding IsaacLab body index. This is needed when body data is present.
```
Metadata for: motion_name
==============================
Body part indexes:
[ 0 4 10 18 5 11 19 9 16 22 28 17 23 29]
Total timesteps: 497
```
The C++ reader parses `Body part indexes:` followed by a line of space-separated integers in brackets. For example, `[0, 4, 10, 18, ...]` means column group 0 β IsaacLab body 0 (pelvis/root), column group 1 β body 4, etc.
For a **root-only** motion (only 1 body), use:
```
Body part indexes:
[0]
```
### `body_lin_vel.csv` / `body_ang_vel.csv`
Body part linear and angular velocities in the world frame. Same layout as `body_pos.csv` (3 columns per body). The number of bodies must match `body_pos.csv`.
### `smpl_joint.csv`
SMPL joint positions (typically 24 joints Γ 3 coordinates). Each row is one timestep.
Shape: `(timesteps, num_smpl_joints * 3)`
### `smpl_pose.csv`
SMPL body poses in axis-angle representation (typically 21 poses Γ 3 coordinates). Each row is one timestep.
Shape: `(timesteps, num_smpl_poses * 3)`
```{note}
The **current reference motion tracking pipeline uses joint-based tracking only** (encoder mode 0). To enable SMPL-based reference tracking (encoder mode 2), you would need to modify the code to detect the presence of SMPL data and switch the encoder mode accordingly.
```
### `info.txt`
Human-readable summary with shapes, dtypes, and value ranges. Not read by the C++ stack β purely for documentation.
---
## Creating Your Own Reference Motions
You can generate reference motions from any source β the only requirement is producing CSV files in the format above. Common approaches:
1. **Motion capture retargeting** β retarget human mocap to the G1 model, export joint positions/velocities and body kinematics.
2. **Simulation recording** β record joint states from an IsaacLab or MuJoCo simulation at 50 Hz.
3. **Procedural generation** β programmatically create joint trajectories.
### Minimal Files Needed
The **minimum** set of files to create a working motion for SONIC policy:
1. **`joint_pos.csv`** β 29 joint positions (IsaacLab order), header + one row per timestep
2. **`joint_vel.csv`** β 29 joint velocities (IsaacLab order), header + one row per timestep
3. **`body_quat.csv`** β Root quaternion (w, x, y, z), header + one row per timestep
4. **`body_pos.csv`** β Root position (x, y, z), header + one row per timestep. You can use all zeros if you don't need position tracking.
5. **`metadata.txt`** β Body part indexes (just `[0]` for root-only)
**Example files:**
`joint_pos.csv`:
```
joint_0,joint_1,joint_2,...,joint_28
0.128441,0.102713,0.020116,...,0.045231
0.130124,0.104532,0.021045,...,0.046112
...
```
`joint_vel.csv`:
```
joint_vel_0,joint_vel_1,...,joint_vel_28
0.143671,0.143864,...,0.012345
...
```
`body_quat.csv` (root quaternion only):
```
body_0_w,body_0_x,body_0_y,body_0_z
0.999123,0.000456,0.001234,0.040567
...
```
`body_pos.csv` (root position, can be all zeros):
```
body_0_x,body_0_y,body_0_z
0.000000,0.000000,0.000000
...
```
`metadata.txt`:
```
Metadata for: my_motion
==============================
Body part indexes:
[0]
Total timesteps: 100
```
This gives you a **root-only** motion (1 body = pelvis/root) that most policies can track.
### Provided Conversion Script
A convenience script `reference/convert_motions.py` is included for converting **joblib pickle** (`.pkl`) files to this format. This is just one possible source β you can use any tool or pipeline that produces the correct CSV output.
```bash
cd gear_sonic_deploy
python reference/convert_motions.py <pkl_file> [output_dir]
```
The pickle should be a dictionary where each key is a motion name and each value contains `joint_pos`, `joint_vel`, `body_pos_w`, `body_quat_w`, `body_lin_vel_w`, `body_ang_vel_w`, `_body_indexes`, and `time_step_total`.
---
## Verifying Reference Motions
### MuJoCo Visualization
Use the included visualizer to check that the motion looks correct on the G1 model:
```bash
cd gear_sonic_deploy
python visualize_motion.py --motion_dir reference/my_motions/motion_name_1/
```
**Controls:**
- **Space**: Pause / resume playback
- **R**: Reset to frame 0
- **,** / **.**: Step backward / forward one frame
- **-** / **=**: Previous / next motion (if multiple loaded)
Verify that:
- The robot stands upright and does not clip through the floor
- Joint angles look reasonable (no extreme poses)
- The motion plays smoothly without sudden jumps
- Body positions track the expected trajectory
---
## Using Reference Motions
### With `deploy.sh`
Pass the motion directory via `--motion-data`:
```bash
./deploy.sh --motion-data reference/my_motions/ sim
```
Or use the default motions (configured in `deploy.sh`):
```bash
./deploy.sh sim
```
### At Runtime
Once deployed, use the keyboard or gamepad to browse and play motions:
- **T**: Play current motion
- **N / P**: Next / Previous motion
- **R**: Restart from frame 0
See the [Keyboard tutorial](../tutorials/keyboard.md) for the full control reference.
---
## Validation Rules
The C++ reader enforces the following during loading:
- **Frame count consistency**: All CSV files within a motion folder must have the same number of rows (excluding headers). Mismatches cause the motion to be skipped with an error.
- **Joint count consistency**: `joint_pos.csv` and `joint_vel.csv` must have the same number of columns.
- **Body count consistency**: `body_lin_vel.csv` and `body_ang_vel.csv` must have the same number of body columns as `body_pos.csv`.
- **At least one data source**: A motion must have at least some valid data (joint, body, or SMPL) to be loaded.
- **Metadata parsing**: The `metadata.txt` file must contain a `Body part indexes:` line followed by a bracketed list of integers for the motion to have correct body-part alignment.
If a motion fails validation, it is skipped and a warning is printed. The deployment continues with the remaining valid motions.
---
## Notes
- All data is at **50 Hz** (0.02 s per timestep), matching the control loop frequency.
- Joint ordering follows **IsaacLab convention** (not MuJoCo). The C++ stack handles the conversion internally when sending motor commands.
- Body quaternions use **(w, x, y, z)** ordering.
- The first body (column group 0) must correspond to the root/pelvis for heading computation and anchor orientation observations to work correctly.
- While the C++ reader can load motions without `body_quat.csv`, the control loop will fail during observation gathering if the policy observes `motion_anchor_orientation` (which most policies do).
- CSV files must have a **header row** as the first line β the C++ reader skips the first line of every CSV.
- Values are parsed as `double` precision internally.
|