Add portable BONES-SEED G1 MT and Isaac converters
Browse files- .gitignore +11 -0
- LICENSE.md +15 -0
- README.md +163 -0
- THIRD_PARTY_NOTICES.md +26 -0
- docs/DATA_FORMAT.md +205 -0
- requirements.txt +3 -0
- scripts/batch_convert.py +194 -0
- scripts/converter_common.py +359 -0
- scripts/csv_to_isaac.py +134 -0
- scripts/csv_to_mt.py +137 -0
- scripts/validate_npz.py +202 -0
.gitignore
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.py[cod]
|
| 3 |
+
.venv/
|
| 4 |
+
.cache/
|
| 5 |
+
*.log
|
| 6 |
+
*.csv
|
| 7 |
+
*.npz
|
| 8 |
+
*.tar
|
| 9 |
+
*.tar.gz
|
| 10 |
+
data/
|
| 11 |
+
outputs/
|
LICENSE.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Code License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 the repository author(s). All rights reserved.
|
| 4 |
+
|
| 5 |
+
The source code in this repository is made available for inspection. No
|
| 6 |
+
permission is granted to copy, modify, redistribute, sublicense, or use it
|
| 7 |
+
except with the copyright holder's prior written permission.
|
| 8 |
+
|
| 9 |
+
This notice applies only to the conversion code authored for this repository.
|
| 10 |
+
It does not grant any rights to BONES-SEED motion data, metadata, Unitree
|
| 11 |
+
assets, MuJoCo models, names, trademarks, or other third-party materials.
|
| 12 |
+
|
| 13 |
+
Before publishing this repository under an open-source license, the repository
|
| 14 |
+
owner may replace this file with the full text of the selected code license,
|
| 15 |
+
such as Apache-2.0 or MIT.
|
README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pretty_name: BONES-SEED Unitree G1 Converters
|
| 3 |
+
tags:
|
| 4 |
+
- robotics
|
| 5 |
+
- motion-capture
|
| 6 |
+
- humanoid-robotics
|
| 7 |
+
- unitree-g1
|
| 8 |
+
- mujoco
|
| 9 |
+
- timeseries
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# BONES-SEED Unitree G1 Converters
|
| 13 |
+
|
| 14 |
+
将 BONES-SEED Unitree G1 CSV 动作转换为 MT 或 Isaac NPZ 格式。
|
| 15 |
+
|
| 16 |
+
本仓库**只包含转换代码和格式文档**,不包含 BONES-SEED CSV、MT/Isaac NPZ、元数据、MuJoCo 模型或其他运动数据。用户必须从 BONES-SEED 官方渠道取得数据,并遵守其许可证。
|
| 17 |
+
|
| 18 |
+
## 仓库内容
|
| 19 |
+
|
| 20 |
+
```text
|
| 21 |
+
bones-seed-g1/
|
| 22 |
+
├── README.md
|
| 23 |
+
├── LICENSE.md
|
| 24 |
+
├── THIRD_PARTY_NOTICES.md
|
| 25 |
+
├── requirements.txt
|
| 26 |
+
├── docs/
|
| 27 |
+
│ └── DATA_FORMAT.md
|
| 28 |
+
└── scripts/
|
| 29 |
+
├── converter_common.py
|
| 30 |
+
├── csv_to_mt.py
|
| 31 |
+
├── csv_to_isaac.py
|
| 32 |
+
├── batch_convert.py
|
| 33 |
+
└── validate_npz.py
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
## 输入要求
|
| 37 |
+
|
| 38 |
+
转换脚本要求用户自行准备:
|
| 39 |
+
|
| 40 |
+
1. BONES-SEED 的 Unitree G1 CSV 文件。
|
| 41 |
+
2. 与 CSV 关节定义匹配的 Unitree G1 MuJoCo MJCF XML。
|
| 42 |
+
|
| 43 |
+
脚本不会下载或分发这些第三方文件。MJCF 模型必须包含一个自由根节点和 29 个 G1 关节,并且关节顺序必须与 `scripts/converter_common.py` 中的 `MT_JOINT_NAMES` 完全一致。脚本会在转换前进行检查。
|
| 44 |
+
|
| 45 |
+
输入 CSV 默认约定:
|
| 46 |
+
|
| 47 |
+
- 采样率:120 FPS;
|
| 48 |
+
- 根节点平移:厘米;
|
| 49 |
+
- 根节点旋转:XYZ 欧拉角,单位为度;
|
| 50 |
+
- 关节角:度;
|
| 51 |
+
- 关节列名称:`{joint_name}_dof`。
|
| 52 |
+
|
| 53 |
+
完整字段说明见 [docs/DATA_FORMAT.md](docs/DATA_FORMAT.md)。
|
| 54 |
+
|
| 55 |
+
## 安装
|
| 56 |
+
|
| 57 |
+
```bash
|
| 58 |
+
python -m venv .venv
|
| 59 |
+
source .venv/bin/activate
|
| 60 |
+
python -m pip install -r requirements.txt
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
建议记录实际使用的 Python、MuJoCo、NumPy 和 SciPy 版本,以便复现实验。
|
| 64 |
+
|
| 65 |
+
## 单文件转换
|
| 66 |
+
|
| 67 |
+
### 转换为 MT
|
| 68 |
+
|
| 69 |
+
```bash
|
| 70 |
+
python scripts/csv_to_mt.py \
|
| 71 |
+
--input /path/to/g1/csv/group/motion.csv \
|
| 72 |
+
--output /path/to/output/mt/group/motion.npz \
|
| 73 |
+
--g1-xml /path/to/g1.xml \
|
| 74 |
+
--source-fps 120 \
|
| 75 |
+
--target-fps 50
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
### 转换为 Isaac
|
| 79 |
+
|
| 80 |
+
```bash
|
| 81 |
+
python scripts/csv_to_isaac.py \
|
| 82 |
+
--input /path/to/g1/csv/group/motion.csv \
|
| 83 |
+
--output /path/to/output/isaac/group/motion.npz \
|
| 84 |
+
--g1-xml /path/to/g1.xml \
|
| 85 |
+
--source-fps 120 \
|
| 86 |
+
--target-fps 50
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
## 批量转换
|
| 90 |
+
|
| 91 |
+
同时生成 MT 和 Isaac:
|
| 92 |
+
|
| 93 |
+
```bash
|
| 94 |
+
python scripts/batch_convert.py \
|
| 95 |
+
--input-dir /path/to/g1/csv \
|
| 96 |
+
--output-dir /path/to/output \
|
| 97 |
+
--g1-xml /path/to/g1.xml \
|
| 98 |
+
--format both \
|
| 99 |
+
--source-fps 120 \
|
| 100 |
+
--target-fps 50 \
|
| 101 |
+
--workers 16
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
输出目录会保留输入 CSV 的相对路径:
|
| 105 |
+
|
| 106 |
+
```text
|
| 107 |
+
/path/to/output/
|
| 108 |
+
├── mt/{relative_path}.npz
|
| 109 |
+
└── isaac/{relative_path}.npz
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
也可以只生成一种格式:
|
| 113 |
+
|
| 114 |
+
```bash
|
| 115 |
+
# 只生成 MT
|
| 116 |
+
python scripts/batch_convert.py ... --format mt
|
| 117 |
+
|
| 118 |
+
# 只生成 Isaac
|
| 119 |
+
python scripts/batch_convert.py ... --format isaac
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
默认跳过已经存在的输出;使用 `--overwrite` 可重新生成。首次运行建议使用 `--limit 10` 做小规模检查。
|
| 123 |
+
|
| 124 |
+
## 验证输出
|
| 125 |
+
|
| 126 |
+
验证单个文件或整个目录:
|
| 127 |
+
|
| 128 |
+
```bash
|
| 129 |
+
python scripts/validate_npz.py /path/to/output/mt/motion.npz
|
| 130 |
+
python scripts/validate_npz.py /path/to/output
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
校验内容包括必需字段、形状、数据类型、有限值、四元数单位长度、关节名称和局部根节点位置。
|
| 134 |
+
|
| 135 |
+
## 格式摘要
|
| 136 |
+
|
| 137 |
+
MT 格式保存:
|
| 138 |
+
|
| 139 |
+
- `root_pos`、`root_rot`;
|
| 140 |
+
- MT 顺序的 `dof_pos`;
|
| 141 |
+
- 根坐标系下的 `local_body_pos`;
|
| 142 |
+
- `joint_names`、`body_names` 和 `fps`。
|
| 143 |
+
|
| 144 |
+
Isaac 格式保存:
|
| 145 |
+
|
| 146 |
+
- Isaac 顺序的 `joint_pos`、`joint_vel`;
|
| 147 |
+
- 世界坐标系下的刚体位置、四元数、线速度和角速度;
|
| 148 |
+
- `fps`。
|
| 149 |
+
|
| 150 |
+
注意:MT 根四元数为 `xyzw`,Isaac 刚体四元数为 `wxyz`。
|
| 151 |
+
|
| 152 |
+
## 数据与许可
|
| 153 |
+
|
| 154 |
+
本仓库不授予 BONES-SEED 数据、Unitree G1 模型或其他第三方资产的任何权利。代码许可见 [LICENSE.md](LICENSE.md),第三方声明见 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。
|
| 155 |
+
|
| 156 |
+
根据 BONES-SEED 的署名要求:
|
| 157 |
+
|
| 158 |
+
> Motion Data by [Bones Studio](https://bones.studio/). Use of the underlying dataset is subject to the BONES Motion Capture Dataset License Agreement.
|
| 159 |
+
|
| 160 |
+
官方资源:
|
| 161 |
+
|
| 162 |
+
- BONES-SEED:https://bones.studio/datasets/seed
|
| 163 |
+
- 数据许可证:https://bones.studio/info/seed-license
|
THIRD_PARTY_NOTICES.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Third-Party Notices
|
| 2 |
+
|
| 3 |
+
## BONES-SEED
|
| 4 |
+
|
| 5 |
+
This repository contains conversion code only. It does not contain or
|
| 6 |
+
redistribute BONES-SEED motion files, metadata, annotations, or derived motion
|
| 7 |
+
files.
|
| 8 |
+
|
| 9 |
+
Users must obtain BONES-SEED from its official distribution channel and comply
|
| 10 |
+
with the license in effect for their use:
|
| 11 |
+
|
| 12 |
+
- Dataset page: https://bones.studio/datasets/seed
|
| 13 |
+
- License: https://bones.studio/info/seed-license
|
| 14 |
+
|
| 15 |
+
Required attribution:
|
| 16 |
+
|
| 17 |
+
> Motion Data by [Bones Studio](https://bones.studio/). Use of the underlying
|
| 18 |
+
> dataset is subject to the BONES Motion Capture Dataset License Agreement.
|
| 19 |
+
|
| 20 |
+
## Unitree G1 and MuJoCo assets
|
| 21 |
+
|
| 22 |
+
No Unitree G1 MJCF, mesh, texture, or other robot asset is included. Users are
|
| 23 |
+
responsible for obtaining a compatible model and complying with its license.
|
| 24 |
+
|
| 25 |
+
MuJoCo is a third-party dependency. Its software and license are not included
|
| 26 |
+
in this repository; see https://mujoco.org/ for official information.
|
docs/DATA_FORMAT.md
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Unitree G1 CSV、MT 与 Isaac 数据格式
|
| 2 |
+
|
| 3 |
+
本文档定义本仓库转换脚本使用的输入 CSV,以及输出的 MT 和 Isaac NPZ 格式。
|
| 4 |
+
|
| 5 |
+
## 通用约定
|
| 6 |
+
|
| 7 |
+
- `T`:输出动作的帧数。
|
| 8 |
+
- 位置:米(m)。
|
| 9 |
+
- 关节角:弧度(rad)。
|
| 10 |
+
- 线速度:米每秒(m/s)。
|
| 11 |
+
- 角速度:弧度每秒(rad/s)。
|
| 12 |
+
- 时序浮点字段:`float32`。
|
| 13 |
+
- `fps`:形状 `(1,)` 的 `int64` 数组。
|
| 14 |
+
- 输出帧数:`max(1, round(T_source × target_fps / source_fps))`。
|
| 15 |
+
- 位置与关节角使用线性插值,四元数使用 SLERP。
|
| 16 |
+
|
| 17 |
+
坐标轴方向由用户提供的 G1 MJCF 模型决定。
|
| 18 |
+
|
| 19 |
+
## 输入 CSV
|
| 20 |
+
|
| 21 |
+
每行表示一帧。CSV 通常包含 `Frame`,转换必需的是根节点和 29 个
|
| 22 |
+
关节字段:
|
| 23 |
+
|
| 24 |
+
```text
|
| 25 |
+
Frame # 可选,不参与时间计算
|
| 26 |
+
root_translateX
|
| 27 |
+
root_translateY
|
| 28 |
+
root_translateZ
|
| 29 |
+
root_rotateX
|
| 30 |
+
root_rotateY
|
| 31 |
+
root_rotateZ
|
| 32 |
+
{joint_name}_dof # 29 列
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
输入约定:
|
| 36 |
+
|
| 37 |
+
| 内容 | 单位/表示 |
|
| 38 |
+
|---|---|
|
| 39 |
+
| `root_translate*` | 厘米 |
|
| 40 |
+
| `root_rotate*` | XYZ 欧拉角,度 |
|
| 41 |
+
| `*_dof` | 关节角,度 |
|
| 42 |
+
|
| 43 |
+
CSV 的 29 个 DOF 使用以下 MT 顺序:
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
MT_JOINT_NAMES = [
|
| 47 |
+
"left_hip_pitch_joint", "left_hip_roll_joint", "left_hip_yaw_joint",
|
| 48 |
+
"left_knee_joint", "left_ankle_pitch_joint", "left_ankle_roll_joint",
|
| 49 |
+
"right_hip_pitch_joint", "right_hip_roll_joint", "right_hip_yaw_joint",
|
| 50 |
+
"right_knee_joint", "right_ankle_pitch_joint", "right_ankle_roll_joint",
|
| 51 |
+
"waist_yaw_joint", "waist_roll_joint", "waist_pitch_joint",
|
| 52 |
+
"left_shoulder_pitch_joint", "left_shoulder_roll_joint",
|
| 53 |
+
"left_shoulder_yaw_joint", "left_elbow_joint",
|
| 54 |
+
"left_wrist_roll_joint", "left_wrist_pitch_joint",
|
| 55 |
+
"left_wrist_yaw_joint",
|
| 56 |
+
"right_shoulder_pitch_joint", "right_shoulder_roll_joint",
|
| 57 |
+
"right_shoulder_yaw_joint", "right_elbow_joint",
|
| 58 |
+
"right_wrist_roll_joint", "right_wrist_pitch_joint",
|
| 59 |
+
"right_wrist_yaw_joint",
|
| 60 |
+
]
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
时间间隔由 `--source-fps` 指定。
|
| 64 |
+
|
| 65 |
+
## MT NPZ
|
| 66 |
+
|
| 67 |
+
| 字段 | 形状 | 类型 | 含义 |
|
| 68 |
+
|---|---:|---|---|
|
| 69 |
+
| `root_pos` | `(T, 3)` | `float32` | 根节点世界坐标位置 |
|
| 70 |
+
| `root_rot` | `(T, 4)` | `float32` | 根节点世界坐标四元数,`xyzw` |
|
| 71 |
+
| `dof_pos` | `(T, 29)` | `float32` | MT 顺序的关节角 |
|
| 72 |
+
| `local_body_pos` | `(T, 27, 3)` | `float32` | 根坐标系下的刚体位置 |
|
| 73 |
+
| `joint_names` | `(29,)` | Unicode | `dof_pos` 的关节名称 |
|
| 74 |
+
| `body_names` | `(27,)` | Unicode | `local_body_pos` 的刚体名称 |
|
| 75 |
+
| `fps` | `(1,)` | `int64` | 输出帧率 |
|
| 76 |
+
|
| 77 |
+
局部刚体位置定义:
|
| 78 |
+
|
| 79 |
+
```text
|
| 80 |
+
local_body_pos = inverse(root_rot) · (body_pos_w - root_pos)
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
MT 刚体顺序:
|
| 84 |
+
|
| 85 |
+
```python
|
| 86 |
+
MT_BODY_NAMES = [
|
| 87 |
+
"pelvis",
|
| 88 |
+
"left_hip_pitch_link", "left_hip_roll_link", "left_hip_yaw_link",
|
| 89 |
+
"left_knee_link", "left_ankle_pitch_link", "left_ankle_roll_link",
|
| 90 |
+
"right_hip_pitch_link", "right_hip_roll_link", "right_hip_yaw_link",
|
| 91 |
+
"right_knee_link", "right_ankle_pitch_link", "right_ankle_roll_link",
|
| 92 |
+
"torso_link",
|
| 93 |
+
"left_shoulder_pitch_link", "left_shoulder_roll_link",
|
| 94 |
+
"left_shoulder_yaw_link", "left_elbow_link", "left_wrist_roll_link",
|
| 95 |
+
"right_shoulder_pitch_link", "right_shoulder_roll_link",
|
| 96 |
+
"right_shoulder_yaw_link", "right_elbow_link", "right_wrist_roll_link",
|
| 97 |
+
"head_mimic", "left_hand_mimic", "right_hand_mimic",
|
| 98 |
+
]
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
当前实现使用以下近似:
|
| 102 |
+
|
| 103 |
+
- `head_mimic` 复制 `torso_link` 的位置;
|
| 104 |
+
- `left_hand_mimic` 复制 `left_wrist_roll_link` 的位置;
|
| 105 |
+
- `right_hand_mimic` 复制 `right_wrist_roll_link` 的位置。
|
| 106 |
+
|
| 107 |
+
## Isaac NPZ
|
| 108 |
+
|
| 109 |
+
| 字段 | 形状 | 类型 | 含义 |
|
| 110 |
+
|---|---:|---|---|
|
| 111 |
+
| `fps` | `(1,)` | `int64` | 输出帧率 |
|
| 112 |
+
| `joint_pos` | `(T, 29)` | `float32` | Isaac 顺序的关节角 |
|
| 113 |
+
| `joint_vel` | `(T, 29)` | `float32` | Isaac 顺序的关节角速度 |
|
| 114 |
+
| `body_pos_w` | `(T, 30, 3)` | `float32` | 刚体世界坐标位置 |
|
| 115 |
+
| `body_quat_w` | `(T, 30, 4)` | `float32` | 刚体世界坐标四元数,`wxyz` |
|
| 116 |
+
| `body_lin_vel_w` | `(T, 30, 3)` | `float32` | 刚体世界坐标线速度 |
|
| 117 |
+
| `body_ang_vel_w` | `(T, 30, 3)` | `float32` | 刚体世界坐标角速度 |
|
| 118 |
+
|
| 119 |
+
Isaac 关节顺序:
|
| 120 |
+
|
| 121 |
+
```python
|
| 122 |
+
ISAAC_JOINT_NAMES = [
|
| 123 |
+
"left_hip_pitch_joint", "right_hip_pitch_joint", "waist_yaw_joint",
|
| 124 |
+
"left_hip_roll_joint", "right_hip_roll_joint", "waist_roll_joint",
|
| 125 |
+
"left_hip_yaw_joint", "right_hip_yaw_joint", "waist_pitch_joint",
|
| 126 |
+
"left_knee_joint", "right_knee_joint",
|
| 127 |
+
"left_shoulder_pitch_joint", "right_shoulder_pitch_joint",
|
| 128 |
+
"left_ankle_pitch_joint", "right_ankle_pitch_joint",
|
| 129 |
+
"left_shoulder_roll_joint", "right_shoulder_roll_joint",
|
| 130 |
+
"left_ankle_roll_joint", "right_ankle_roll_joint",
|
| 131 |
+
"left_shoulder_yaw_joint", "right_shoulder_yaw_joint",
|
| 132 |
+
"left_elbow_joint", "right_elbow_joint",
|
| 133 |
+
"left_wrist_roll_joint", "right_wrist_roll_joint",
|
| 134 |
+
"left_wrist_pitch_joint", "right_wrist_pitch_joint",
|
| 135 |
+
"left_wrist_yaw_joint", "right_wrist_yaw_joint",
|
| 136 |
+
]
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
Isaac 刚体顺序:
|
| 140 |
+
|
| 141 |
+
```python
|
| 142 |
+
ISAAC_BODY_NAMES = [
|
| 143 |
+
"pelvis",
|
| 144 |
+
"left_hip_pitch_link", "right_hip_pitch_link", "pelvis_contour_link",
|
| 145 |
+
"left_hip_roll_link", "right_hip_roll_link", "waist_roll_link",
|
| 146 |
+
"left_hip_yaw_link", "right_hip_yaw_link", "torso_link",
|
| 147 |
+
"left_knee_link", "right_knee_link",
|
| 148 |
+
"left_shoulder_pitch_link", "right_shoulder_pitch_link",
|
| 149 |
+
"left_ankle_pitch_link", "right_ankle_pitch_link",
|
| 150 |
+
"left_shoulder_roll_link", "right_shoulder_roll_link",
|
| 151 |
+
"left_ankle_roll_link", "right_ankle_roll_link",
|
| 152 |
+
"left_shoulder_yaw_link", "right_shoulder_yaw_link",
|
| 153 |
+
"left_elbow_link", "right_elbow_link",
|
| 154 |
+
"left_wrist_roll_link", "right_wrist_roll_link",
|
| 155 |
+
"left_wrist_pitch_link", "right_wrist_pitch_link",
|
| 156 |
+
"left_wrist_yaw_link", "right_wrist_yaw_link",
|
| 157 |
+
]
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
根节点为刚体索引 `0`:
|
| 161 |
+
|
| 162 |
+
```python
|
| 163 |
+
root_pos_w = data["body_pos_w"][:, 0]
|
| 164 |
+
root_quat_wxyz = data["body_quat_w"][:, 0]
|
| 165 |
+
```
|
| 166 |
+
|
| 167 |
+
`pelvis_contour_link` 在当前实现中复制 `pelvis` 的状态。Isaac NPZ 不保存名称数组,读取方必须使用上述固定顺序。
|
| 168 |
+
|
| 169 |
+
## MT 与 Isaac 的差异
|
| 170 |
+
|
| 171 |
+
| 项目 | MT | Isaac |
|
| 172 |
+
|---|---|---|
|
| 173 |
+
| 关节角字段 | `dof_pos` | `joint_pos` |
|
| 174 |
+
| 关节顺序 | 按肢体分组 | 左右交替 |
|
| 175 |
+
| 根四元数 | `root_rot`,`xyzw` | `body_quat_w[:, 0]`,`wxyz` |
|
| 176 |
+
| 刚体位置 | 根节点局部坐标 | 世界坐标 |
|
| 177 |
+
| 刚体数量 | 27 | 30 |
|
| 178 |
+
| 速度 | 不保存 | 保存 |
|
| 179 |
+
| 名称数组 | 保存 | 不保存 |
|
| 180 |
+
|
| 181 |
+
四元数重排:
|
| 182 |
+
|
| 183 |
+
```python
|
| 184 |
+
# wxyz -> xyzw
|
| 185 |
+
quat_xyzw = quat_wxyz[..., [1, 2, 3, 0]]
|
| 186 |
+
|
| 187 |
+
# xyzw -> wxyz
|
| 188 |
+
quat_wxyz = quat_xyzw[..., [3, 0, 1, 2]]
|
| 189 |
+
```
|
| 190 |
+
|
| 191 |
+
## 加载示例
|
| 192 |
+
|
| 193 |
+
```python
|
| 194 |
+
import numpy as np
|
| 195 |
+
|
| 196 |
+
with np.load("motion_mt.npz", allow_pickle=False) as data:
|
| 197 |
+
fps = int(data["fps"][0])
|
| 198 |
+
dof_pos = data["dof_pos"]
|
| 199 |
+
root_rot_xyzw = data["root_rot"]
|
| 200 |
+
|
| 201 |
+
with np.load("motion_isaac.npz", allow_pickle=False) as data:
|
| 202 |
+
fps = int(data["fps"][0])
|
| 203 |
+
joint_pos = data["joint_pos"]
|
| 204 |
+
root_quat_wxyz = data["body_quat_w"][:, 0]
|
| 205 |
+
```
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy>=1.24,<3
|
| 2 |
+
scipy>=1.10,<2
|
| 3 |
+
mujoco>=3.1,<4
|
scripts/batch_convert.py
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Batch-convert BONES-SEED G1 CSV files to MT, Isaac, or both."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import multiprocessing
|
| 8 |
+
import time
|
| 9 |
+
from functools import partial
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
from csv_to_isaac import convert_csv_to_isaac
|
| 13 |
+
from csv_to_mt import convert_csv_to_mt
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def convert_one(
|
| 17 |
+
csv_path: Path,
|
| 18 |
+
*,
|
| 19 |
+
input_dir: Path,
|
| 20 |
+
output_dir: Path,
|
| 21 |
+
formats: tuple[str, ...],
|
| 22 |
+
g1_xml: Path,
|
| 23 |
+
source_fps: int,
|
| 24 |
+
target_fps: int,
|
| 25 |
+
overwrite: bool,
|
| 26 |
+
) -> tuple[int, int, list[str]]:
|
| 27 |
+
"""Convert one source file. Return completed, skipped, and error messages."""
|
| 28 |
+
relative_path = csv_path.relative_to(input_dir).with_suffix(".npz")
|
| 29 |
+
completed = 0
|
| 30 |
+
skipped = 0
|
| 31 |
+
errors = []
|
| 32 |
+
|
| 33 |
+
for output_format in formats:
|
| 34 |
+
output_path = output_dir / output_format / relative_path
|
| 35 |
+
if output_path.exists() and not overwrite:
|
| 36 |
+
skipped += 1
|
| 37 |
+
continue
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
if output_format == "mt":
|
| 41 |
+
convert_csv_to_mt(
|
| 42 |
+
csv_path=csv_path,
|
| 43 |
+
output_path=output_path,
|
| 44 |
+
g1_xml=g1_xml,
|
| 45 |
+
source_fps=source_fps,
|
| 46 |
+
target_fps=target_fps,
|
| 47 |
+
verbose=False,
|
| 48 |
+
)
|
| 49 |
+
else:
|
| 50 |
+
convert_csv_to_isaac(
|
| 51 |
+
csv_path=csv_path,
|
| 52 |
+
output_path=output_path,
|
| 53 |
+
g1_xml=g1_xml,
|
| 54 |
+
source_fps=source_fps,
|
| 55 |
+
target_fps=target_fps,
|
| 56 |
+
verbose=False,
|
| 57 |
+
)
|
| 58 |
+
completed += 1
|
| 59 |
+
except Exception as error: # keep the batch running and report failures
|
| 60 |
+
errors.append(f"{output_format}\t{csv_path}\t{error}")
|
| 61 |
+
|
| 62 |
+
return completed, skipped, errors
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def parse_args() -> argparse.Namespace:
|
| 66 |
+
parser = argparse.ArgumentParser(
|
| 67 |
+
description="Batch-convert BONES-SEED G1 CSV files"
|
| 68 |
+
)
|
| 69 |
+
parser.add_argument(
|
| 70 |
+
"--input-dir",
|
| 71 |
+
required=True,
|
| 72 |
+
type=Path,
|
| 73 |
+
help="Directory recursively containing G1 CSV files",
|
| 74 |
+
)
|
| 75 |
+
parser.add_argument(
|
| 76 |
+
"--output-dir",
|
| 77 |
+
required=True,
|
| 78 |
+
type=Path,
|
| 79 |
+
help="Output root; results are written under mt/ and/or isaac/",
|
| 80 |
+
)
|
| 81 |
+
parser.add_argument(
|
| 82 |
+
"--g1-xml",
|
| 83 |
+
required=True,
|
| 84 |
+
type=Path,
|
| 85 |
+
help="Compatible Unitree G1 MJCF XML",
|
| 86 |
+
)
|
| 87 |
+
parser.add_argument(
|
| 88 |
+
"--format",
|
| 89 |
+
choices=("mt", "isaac", "both"),
|
| 90 |
+
default="both",
|
| 91 |
+
help="Output format (default: both)",
|
| 92 |
+
)
|
| 93 |
+
parser.add_argument("--source-fps", type=int, default=120)
|
| 94 |
+
parser.add_argument("--target-fps", type=int, default=50)
|
| 95 |
+
parser.add_argument(
|
| 96 |
+
"--workers",
|
| 97 |
+
type=int,
|
| 98 |
+
default=max(1, multiprocessing.cpu_count() - 2),
|
| 99 |
+
help="Worker processes (default: CPU count minus two)",
|
| 100 |
+
)
|
| 101 |
+
parser.add_argument(
|
| 102 |
+
"--overwrite",
|
| 103 |
+
action="store_true",
|
| 104 |
+
help="Replace output files that already exist",
|
| 105 |
+
)
|
| 106 |
+
parser.add_argument(
|
| 107 |
+
"--limit",
|
| 108 |
+
type=int,
|
| 109 |
+
help="Convert only the first N files (useful for smoke tests)",
|
| 110 |
+
)
|
| 111 |
+
return parser.parse_args()
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def main() -> None:
|
| 115 |
+
args = parse_args()
|
| 116 |
+
input_dir = args.input_dir.expanduser().resolve()
|
| 117 |
+
output_dir = args.output_dir.expanduser().resolve()
|
| 118 |
+
g1_xml = args.g1_xml.expanduser().resolve()
|
| 119 |
+
|
| 120 |
+
if not input_dir.is_dir():
|
| 121 |
+
raise SystemExit(f"Input directory not found: {input_dir}")
|
| 122 |
+
if not g1_xml.is_file():
|
| 123 |
+
raise SystemExit(f"G1 MJCF file not found: {g1_xml}")
|
| 124 |
+
if args.workers <= 0:
|
| 125 |
+
raise SystemExit("--workers must be positive")
|
| 126 |
+
if args.limit is not None and args.limit <= 0:
|
| 127 |
+
raise SystemExit("--limit must be positive")
|
| 128 |
+
|
| 129 |
+
csv_files = sorted(input_dir.rglob("*.csv"))
|
| 130 |
+
if args.limit is not None:
|
| 131 |
+
csv_files = csv_files[: args.limit]
|
| 132 |
+
if not csv_files:
|
| 133 |
+
raise SystemExit(f"No CSV files found under: {input_dir}")
|
| 134 |
+
|
| 135 |
+
formats = ("mt", "isaac") if args.format == "both" else (args.format,)
|
| 136 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 137 |
+
|
| 138 |
+
worker = partial(
|
| 139 |
+
convert_one,
|
| 140 |
+
input_dir=input_dir,
|
| 141 |
+
output_dir=output_dir,
|
| 142 |
+
formats=formats,
|
| 143 |
+
g1_xml=g1_xml,
|
| 144 |
+
source_fps=args.source_fps,
|
| 145 |
+
target_fps=args.target_fps,
|
| 146 |
+
overwrite=args.overwrite,
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
total_outputs = len(csv_files) * len(formats)
|
| 150 |
+
print(f"CSV files: {len(csv_files)}")
|
| 151 |
+
print(f"Formats: {', '.join(formats)}")
|
| 152 |
+
print(f"Expected outputs: {total_outputs}")
|
| 153 |
+
print(f"Workers: {args.workers}")
|
| 154 |
+
print(f"Output root: {output_dir}")
|
| 155 |
+
|
| 156 |
+
start_time = time.time()
|
| 157 |
+
completed = 0
|
| 158 |
+
skipped = 0
|
| 159 |
+
failures = []
|
| 160 |
+
|
| 161 |
+
with multiprocessing.Pool(args.workers) as pool:
|
| 162 |
+
for index, result in enumerate(
|
| 163 |
+
pool.imap_unordered(worker, csv_files), start=1
|
| 164 |
+
):
|
| 165 |
+
done_count, skipped_count, errors = result
|
| 166 |
+
completed += done_count
|
| 167 |
+
skipped += skipped_count
|
| 168 |
+
failures.extend(errors)
|
| 169 |
+
|
| 170 |
+
if index % 1000 == 0 or index == len(csv_files):
|
| 171 |
+
elapsed = max(time.time() - start_time, 1e-6)
|
| 172 |
+
rate = index / elapsed
|
| 173 |
+
print(
|
| 174 |
+
f"[{index}/{len(csv_files)}] "
|
| 175 |
+
f"done={completed} skipped={skipped} "
|
| 176 |
+
f"failed={len(failures)} files={rate:.1f}/s"
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
if failures:
|
| 180 |
+
failure_log = output_dir / "conversion_failures.log"
|
| 181 |
+
failure_log.write_text("\n".join(failures) + "\n", encoding="utf-8")
|
| 182 |
+
print(f"Failure details: {failure_log}")
|
| 183 |
+
|
| 184 |
+
elapsed = time.time() - start_time
|
| 185 |
+
print(
|
| 186 |
+
f"Finished in {elapsed / 60:.1f} min: "
|
| 187 |
+
f"done={completed}, skipped={skipped}, failed={len(failures)}"
|
| 188 |
+
)
|
| 189 |
+
if failures:
|
| 190 |
+
raise SystemExit(1)
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
if __name__ == "__main__":
|
| 194 |
+
main()
|
scripts/converter_common.py
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Shared definitions and utilities for BONES-SEED G1 converters."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from functools import lru_cache
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
import mujoco
|
| 9 |
+
import numpy as np
|
| 10 |
+
from scipy.spatial.transform import Rotation as R
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
MT_JOINT_NAMES = [
|
| 14 |
+
"left_hip_pitch_joint",
|
| 15 |
+
"left_hip_roll_joint",
|
| 16 |
+
"left_hip_yaw_joint",
|
| 17 |
+
"left_knee_joint",
|
| 18 |
+
"left_ankle_pitch_joint",
|
| 19 |
+
"left_ankle_roll_joint",
|
| 20 |
+
"right_hip_pitch_joint",
|
| 21 |
+
"right_hip_roll_joint",
|
| 22 |
+
"right_hip_yaw_joint",
|
| 23 |
+
"right_knee_joint",
|
| 24 |
+
"right_ankle_pitch_joint",
|
| 25 |
+
"right_ankle_roll_joint",
|
| 26 |
+
"waist_yaw_joint",
|
| 27 |
+
"waist_roll_joint",
|
| 28 |
+
"waist_pitch_joint",
|
| 29 |
+
"left_shoulder_pitch_joint",
|
| 30 |
+
"left_shoulder_roll_joint",
|
| 31 |
+
"left_shoulder_yaw_joint",
|
| 32 |
+
"left_elbow_joint",
|
| 33 |
+
"left_wrist_roll_joint",
|
| 34 |
+
"left_wrist_pitch_joint",
|
| 35 |
+
"left_wrist_yaw_joint",
|
| 36 |
+
"right_shoulder_pitch_joint",
|
| 37 |
+
"right_shoulder_roll_joint",
|
| 38 |
+
"right_shoulder_yaw_joint",
|
| 39 |
+
"right_elbow_joint",
|
| 40 |
+
"right_wrist_roll_joint",
|
| 41 |
+
"right_wrist_pitch_joint",
|
| 42 |
+
"right_wrist_yaw_joint",
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
ISAAC_JOINT_NAMES = [
|
| 46 |
+
"left_hip_pitch_joint",
|
| 47 |
+
"right_hip_pitch_joint",
|
| 48 |
+
"waist_yaw_joint",
|
| 49 |
+
"left_hip_roll_joint",
|
| 50 |
+
"right_hip_roll_joint",
|
| 51 |
+
"waist_roll_joint",
|
| 52 |
+
"left_hip_yaw_joint",
|
| 53 |
+
"right_hip_yaw_joint",
|
| 54 |
+
"waist_pitch_joint",
|
| 55 |
+
"left_knee_joint",
|
| 56 |
+
"right_knee_joint",
|
| 57 |
+
"left_shoulder_pitch_joint",
|
| 58 |
+
"right_shoulder_pitch_joint",
|
| 59 |
+
"left_ankle_pitch_joint",
|
| 60 |
+
"right_ankle_pitch_joint",
|
| 61 |
+
"left_shoulder_roll_joint",
|
| 62 |
+
"right_shoulder_roll_joint",
|
| 63 |
+
"left_ankle_roll_joint",
|
| 64 |
+
"right_ankle_roll_joint",
|
| 65 |
+
"left_shoulder_yaw_joint",
|
| 66 |
+
"right_shoulder_yaw_joint",
|
| 67 |
+
"left_elbow_joint",
|
| 68 |
+
"right_elbow_joint",
|
| 69 |
+
"left_wrist_roll_joint",
|
| 70 |
+
"right_wrist_roll_joint",
|
| 71 |
+
"left_wrist_pitch_joint",
|
| 72 |
+
"right_wrist_pitch_joint",
|
| 73 |
+
"left_wrist_yaw_joint",
|
| 74 |
+
"right_wrist_yaw_joint",
|
| 75 |
+
]
|
| 76 |
+
|
| 77 |
+
MT_BODY_NAMES = [
|
| 78 |
+
"pelvis",
|
| 79 |
+
"left_hip_pitch_link",
|
| 80 |
+
"left_hip_roll_link",
|
| 81 |
+
"left_hip_yaw_link",
|
| 82 |
+
"left_knee_link",
|
| 83 |
+
"left_ankle_pitch_link",
|
| 84 |
+
"left_ankle_roll_link",
|
| 85 |
+
"right_hip_pitch_link",
|
| 86 |
+
"right_hip_roll_link",
|
| 87 |
+
"right_hip_yaw_link",
|
| 88 |
+
"right_knee_link",
|
| 89 |
+
"right_ankle_pitch_link",
|
| 90 |
+
"right_ankle_roll_link",
|
| 91 |
+
"torso_link",
|
| 92 |
+
"left_shoulder_pitch_link",
|
| 93 |
+
"left_shoulder_roll_link",
|
| 94 |
+
"left_shoulder_yaw_link",
|
| 95 |
+
"left_elbow_link",
|
| 96 |
+
"left_wrist_roll_link",
|
| 97 |
+
"right_shoulder_pitch_link",
|
| 98 |
+
"right_shoulder_roll_link",
|
| 99 |
+
"right_shoulder_yaw_link",
|
| 100 |
+
"right_elbow_link",
|
| 101 |
+
"right_wrist_roll_link",
|
| 102 |
+
"head_mimic",
|
| 103 |
+
"left_hand_mimic",
|
| 104 |
+
"right_hand_mimic",
|
| 105 |
+
]
|
| 106 |
+
|
| 107 |
+
ISAAC_BODY_NAMES = [
|
| 108 |
+
"pelvis",
|
| 109 |
+
"left_hip_pitch_link",
|
| 110 |
+
"right_hip_pitch_link",
|
| 111 |
+
"pelvis_contour_link",
|
| 112 |
+
"left_hip_roll_link",
|
| 113 |
+
"right_hip_roll_link",
|
| 114 |
+
"waist_roll_link",
|
| 115 |
+
"left_hip_yaw_link",
|
| 116 |
+
"right_hip_yaw_link",
|
| 117 |
+
"torso_link",
|
| 118 |
+
"left_knee_link",
|
| 119 |
+
"right_knee_link",
|
| 120 |
+
"left_shoulder_pitch_link",
|
| 121 |
+
"right_shoulder_pitch_link",
|
| 122 |
+
"left_ankle_pitch_link",
|
| 123 |
+
"right_ankle_pitch_link",
|
| 124 |
+
"left_shoulder_roll_link",
|
| 125 |
+
"right_shoulder_roll_link",
|
| 126 |
+
"left_ankle_roll_link",
|
| 127 |
+
"right_ankle_roll_link",
|
| 128 |
+
"left_shoulder_yaw_link",
|
| 129 |
+
"right_shoulder_yaw_link",
|
| 130 |
+
"left_elbow_link",
|
| 131 |
+
"right_elbow_link",
|
| 132 |
+
"left_wrist_roll_link",
|
| 133 |
+
"right_wrist_roll_link",
|
| 134 |
+
"left_wrist_pitch_link",
|
| 135 |
+
"right_wrist_pitch_link",
|
| 136 |
+
"left_wrist_yaw_link",
|
| 137 |
+
"right_wrist_yaw_link",
|
| 138 |
+
]
|
| 139 |
+
|
| 140 |
+
ROOT_TRANSLATION_COLUMNS = [
|
| 141 |
+
"root_translateX",
|
| 142 |
+
"root_translateY",
|
| 143 |
+
"root_translateZ",
|
| 144 |
+
]
|
| 145 |
+
ROOT_ROTATION_COLUMNS = [
|
| 146 |
+
"root_rotateX",
|
| 147 |
+
"root_rotateY",
|
| 148 |
+
"root_rotateZ",
|
| 149 |
+
]
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def validate_fps(source_fps: int, target_fps: int) -> None:
|
| 153 |
+
if source_fps <= 0 or target_fps <= 0:
|
| 154 |
+
raise ValueError("source_fps and target_fps must both be positive")
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def load_csv_motion(csv_path: str | Path) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
|
| 158 |
+
"""Load root position, root quaternion (xyzw), and MT-order DOF positions."""
|
| 159 |
+
csv_path = Path(csv_path)
|
| 160 |
+
if not csv_path.is_file():
|
| 161 |
+
raise FileNotFoundError(f"CSV file not found: {csv_path}")
|
| 162 |
+
|
| 163 |
+
data = np.genfromtxt(csv_path, delimiter=",", names=True)
|
| 164 |
+
data = np.atleast_1d(data)
|
| 165 |
+
if data.size == 0 or data.dtype.names is None:
|
| 166 |
+
raise ValueError(f"CSV contains no motion frames: {csv_path}")
|
| 167 |
+
|
| 168 |
+
required_columns = (
|
| 169 |
+
ROOT_TRANSLATION_COLUMNS
|
| 170 |
+
+ ROOT_ROTATION_COLUMNS
|
| 171 |
+
+ [f"{name}_dof" for name in MT_JOINT_NAMES]
|
| 172 |
+
)
|
| 173 |
+
missing = [name for name in required_columns if name not in data.dtype.names]
|
| 174 |
+
if missing:
|
| 175 |
+
raise ValueError(
|
| 176 |
+
f"CSV is missing {len(missing)} required column(s): {', '.join(missing)}"
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
root_pos = np.column_stack([data[name] for name in ROOT_TRANSLATION_COLUMNS])
|
| 180 |
+
root_pos = root_pos.astype(np.float32) / 100.0
|
| 181 |
+
|
| 182 |
+
root_euler_xyz_deg = np.column_stack(
|
| 183 |
+
[data[name] for name in ROOT_ROTATION_COLUMNS]
|
| 184 |
+
)
|
| 185 |
+
root_rot_xyzw = R.from_euler(
|
| 186 |
+
"xyz", root_euler_xyz_deg, degrees=True
|
| 187 |
+
).as_quat().astype(np.float32)
|
| 188 |
+
|
| 189 |
+
dof_pos_deg = np.column_stack(
|
| 190 |
+
[data[f"{name}_dof"] for name in MT_JOINT_NAMES]
|
| 191 |
+
).astype(np.float32)
|
| 192 |
+
dof_pos = np.deg2rad(dof_pos_deg).astype(np.float32)
|
| 193 |
+
|
| 194 |
+
for name, value in (
|
| 195 |
+
("root_pos", root_pos),
|
| 196 |
+
("root_rot_xyzw", root_rot_xyzw),
|
| 197 |
+
("dof_pos", dof_pos),
|
| 198 |
+
):
|
| 199 |
+
if not np.isfinite(value).all():
|
| 200 |
+
raise ValueError(f"{name} contains NaN or Inf: {csv_path}")
|
| 201 |
+
|
| 202 |
+
return root_pos, root_rot_xyzw, dof_pos
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
@lru_cache(maxsize=8)
|
| 206 |
+
def load_g1_model(g1_xml: str) -> mujoco.MjModel:
|
| 207 |
+
"""Load and validate a G1 MJCF model, cached once per worker process."""
|
| 208 |
+
xml_path = Path(g1_xml).expanduser().resolve()
|
| 209 |
+
if not xml_path.is_file():
|
| 210 |
+
raise FileNotFoundError(f"G1 MJCF file not found: {xml_path}")
|
| 211 |
+
|
| 212 |
+
model = mujoco.MjModel.from_xml_path(str(xml_path))
|
| 213 |
+
expected_nq = 7 + len(MT_JOINT_NAMES)
|
| 214 |
+
if model.nq != expected_nq:
|
| 215 |
+
raise ValueError(
|
| 216 |
+
f"Expected G1 model nq={expected_nq}, but {xml_path} has nq={model.nq}"
|
| 217 |
+
)
|
| 218 |
+
|
| 219 |
+
model_joint_names = []
|
| 220 |
+
for joint_id in range(model.njnt):
|
| 221 |
+
if model.jnt_type[joint_id] == mujoco.mjtJoint.mjJNT_FREE:
|
| 222 |
+
continue
|
| 223 |
+
name = mujoco.mj_id2name(
|
| 224 |
+
model, mujoco.mjtObj.mjOBJ_JOINT, joint_id
|
| 225 |
+
)
|
| 226 |
+
if name:
|
| 227 |
+
model_joint_names.append(name)
|
| 228 |
+
|
| 229 |
+
if model_joint_names != MT_JOINT_NAMES:
|
| 230 |
+
raise ValueError(
|
| 231 |
+
"G1 MJCF joint order does not match the expected MT order.\n"
|
| 232 |
+
f"Expected: {MT_JOINT_NAMES}\n"
|
| 233 |
+
f"Found: {model_joint_names}"
|
| 234 |
+
)
|
| 235 |
+
return model
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def require_body_id(model: mujoco.MjModel, body_name: str) -> int:
|
| 239 |
+
body_id = mujoco.mj_name2id(
|
| 240 |
+
model, mujoco.mjtObj.mjOBJ_BODY, body_name
|
| 241 |
+
)
|
| 242 |
+
if body_id < 0:
|
| 243 |
+
raise ValueError(f"G1 MJCF is missing required body: {body_name}")
|
| 244 |
+
return body_id
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def output_frame_count(frame_count: int, source_fps: int, target_fps: int) -> int:
|
| 248 |
+
return max(1, int(round(frame_count * target_fps / source_fps)))
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def interpolate_linear(array: np.ndarray, new_frame_count: int) -> np.ndarray:
|
| 252 |
+
"""Linearly resample an array along its first dimension."""
|
| 253 |
+
old_frame_count = len(array)
|
| 254 |
+
if new_frame_count == old_frame_count:
|
| 255 |
+
return array.copy()
|
| 256 |
+
if old_frame_count == 1:
|
| 257 |
+
return np.repeat(array, new_frame_count, axis=0)
|
| 258 |
+
|
| 259 |
+
new_times = np.linspace(0, old_frame_count - 1, new_frame_count)
|
| 260 |
+
result = np.empty(
|
| 261 |
+
(new_frame_count,) + array.shape[1:], dtype=np.float32
|
| 262 |
+
)
|
| 263 |
+
for index, time in enumerate(new_times):
|
| 264 |
+
lower = int(np.floor(time))
|
| 265 |
+
upper = min(lower + 1, old_frame_count - 1)
|
| 266 |
+
fraction = time - lower
|
| 267 |
+
result[index] = array[lower] + fraction * (
|
| 268 |
+
array[upper] - array[lower]
|
| 269 |
+
)
|
| 270 |
+
return result
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def interpolate_quaternions(
|
| 274 |
+
quaternions: np.ndarray, new_frame_count: int
|
| 275 |
+
) -> np.ndarray:
|
| 276 |
+
"""SLERP quaternion arrays along the first dimension."""
|
| 277 |
+
old_frame_count = len(quaternions)
|
| 278 |
+
if new_frame_count == old_frame_count:
|
| 279 |
+
result = quaternions.copy()
|
| 280 |
+
elif old_frame_count == 1:
|
| 281 |
+
result = np.repeat(quaternions, new_frame_count, axis=0)
|
| 282 |
+
else:
|
| 283 |
+
result = np.empty(
|
| 284 |
+
(new_frame_count,) + quaternions.shape[1:], dtype=np.float32
|
| 285 |
+
)
|
| 286 |
+
new_times = np.linspace(0, old_frame_count - 1, new_frame_count)
|
| 287 |
+
for index, time in enumerate(new_times):
|
| 288 |
+
lower = int(np.floor(time))
|
| 289 |
+
upper = min(lower + 1, old_frame_count - 1)
|
| 290 |
+
fraction = time - lower
|
| 291 |
+
|
| 292 |
+
q0 = quaternions[lower]
|
| 293 |
+
q1 = quaternions[upper]
|
| 294 |
+
dot = np.sum(q0 * q1, axis=-1, keepdims=True)
|
| 295 |
+
q1 = np.where(dot < 0.0, -q1, q1)
|
| 296 |
+
dot = np.clip(np.abs(dot), 0.0, 1.0)
|
| 297 |
+
|
| 298 |
+
theta = np.arccos(dot)
|
| 299 |
+
sin_theta = np.sin(theta)
|
| 300 |
+
small = sin_theta < 1e-6
|
| 301 |
+
denominator = np.maximum(sin_theta, 1e-6)
|
| 302 |
+
weight0 = np.where(
|
| 303 |
+
small,
|
| 304 |
+
1.0 - fraction,
|
| 305 |
+
np.sin((1.0 - fraction) * theta) / denominator,
|
| 306 |
+
)
|
| 307 |
+
weight1 = np.where(
|
| 308 |
+
small,
|
| 309 |
+
fraction,
|
| 310 |
+
np.sin(fraction * theta) / denominator,
|
| 311 |
+
)
|
| 312 |
+
result[index] = weight0 * q0 + weight1 * q1
|
| 313 |
+
|
| 314 |
+
norms = np.linalg.norm(result, axis=-1, keepdims=True)
|
| 315 |
+
if np.any(norms < 1e-8):
|
| 316 |
+
raise ValueError("Encountered a zero-length quaternion during resampling")
|
| 317 |
+
return (result / norms).astype(np.float32)
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
def finite_difference(array: np.ndarray, fps: int) -> np.ndarray:
|
| 321 |
+
"""Compute a time derivative using forward/backward and central differences."""
|
| 322 |
+
derivative = np.zeros_like(array, dtype=np.float32)
|
| 323 |
+
if len(array) == 1:
|
| 324 |
+
return derivative
|
| 325 |
+
|
| 326 |
+
dt = 1.0 / fps
|
| 327 |
+
derivative[0] = (array[1] - array[0]) / dt
|
| 328 |
+
derivative[-1] = (array[-1] - array[-2]) / dt
|
| 329 |
+
if len(array) > 2:
|
| 330 |
+
derivative[1:-1] = (array[2:] - array[:-2]) / (2.0 * dt)
|
| 331 |
+
return derivative
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
def body_angular_velocity_wxyz(
|
| 335 |
+
body_quat_wxyz: np.ndarray, fps: int
|
| 336 |
+
) -> np.ndarray:
|
| 337 |
+
"""Compute world-frame body angular velocity from wxyz quaternions."""
|
| 338 |
+
angular_velocity = np.zeros(
|
| 339 |
+
body_quat_wxyz.shape[:-1] + (3,), dtype=np.float32
|
| 340 |
+
)
|
| 341 |
+
if len(body_quat_wxyz) == 1:
|
| 342 |
+
return angular_velocity
|
| 343 |
+
|
| 344 |
+
dt = 1.0 / fps
|
| 345 |
+
for frame in range(len(body_quat_wxyz) - 1):
|
| 346 |
+
q0_xyzw = body_quat_wxyz[frame][:, [1, 2, 3, 0]]
|
| 347 |
+
q1_xyzw = body_quat_wxyz[frame + 1][:, [1, 2, 3, 0]]
|
| 348 |
+
rotation0 = R.from_quat(q0_xyzw)
|
| 349 |
+
rotation1 = R.from_quat(q1_xyzw)
|
| 350 |
+
delta = rotation1 * rotation0.inv()
|
| 351 |
+
angular_velocity[frame] = delta.as_rotvec() / dt
|
| 352 |
+
angular_velocity[-1] = angular_velocity[-2]
|
| 353 |
+
return angular_velocity
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
def ensure_output_parent(output_path: str | Path) -> Path:
|
| 357 |
+
output_path = Path(output_path)
|
| 358 |
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 359 |
+
return output_path
|
scripts/csv_to_isaac.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Convert one BONES-SEED Unitree G1 CSV file to Isaac-style NPZ format."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
import mujoco
|
| 10 |
+
import numpy as np
|
| 11 |
+
|
| 12 |
+
from converter_common import (
|
| 13 |
+
ISAAC_BODY_NAMES,
|
| 14 |
+
ISAAC_JOINT_NAMES,
|
| 15 |
+
MT_JOINT_NAMES,
|
| 16 |
+
body_angular_velocity_wxyz,
|
| 17 |
+
ensure_output_parent,
|
| 18 |
+
finite_difference,
|
| 19 |
+
interpolate_linear,
|
| 20 |
+
interpolate_quaternions,
|
| 21 |
+
load_csv_motion,
|
| 22 |
+
load_g1_model,
|
| 23 |
+
output_frame_count,
|
| 24 |
+
require_body_id,
|
| 25 |
+
validate_fps,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def convert_csv_to_isaac(
|
| 30 |
+
csv_path: str | Path,
|
| 31 |
+
output_path: str | Path,
|
| 32 |
+
g1_xml: str | Path,
|
| 33 |
+
source_fps: int = 120,
|
| 34 |
+
target_fps: int = 50,
|
| 35 |
+
verbose: bool = True,
|
| 36 |
+
) -> Path:
|
| 37 |
+
"""Convert a single CSV motion to Isaac format and return the output path."""
|
| 38 |
+
validate_fps(source_fps, target_fps)
|
| 39 |
+
root_pos, root_rot_xyzw, dof_pos_mt = load_csv_motion(csv_path)
|
| 40 |
+
|
| 41 |
+
model = load_g1_model(str(Path(g1_xml).expanduser().resolve()))
|
| 42 |
+
model_data = mujoco.MjData(model)
|
| 43 |
+
|
| 44 |
+
body_ids = {}
|
| 45 |
+
for body_name in ISAAC_BODY_NAMES:
|
| 46 |
+
source_name = "pelvis" if body_name == "pelvis_contour_link" else body_name
|
| 47 |
+
body_ids[body_name] = require_body_id(model, source_name)
|
| 48 |
+
|
| 49 |
+
mt_indices = np.asarray(
|
| 50 |
+
[MT_JOINT_NAMES.index(name) for name in ISAAC_JOINT_NAMES],
|
| 51 |
+
dtype=np.int64,
|
| 52 |
+
)
|
| 53 |
+
joint_pos = dof_pos_mt[:, mt_indices]
|
| 54 |
+
|
| 55 |
+
body_pos_w = np.zeros(
|
| 56 |
+
(len(root_pos), len(ISAAC_BODY_NAMES), 3), dtype=np.float32
|
| 57 |
+
)
|
| 58 |
+
body_quat_w = np.zeros(
|
| 59 |
+
(len(root_pos), len(ISAAC_BODY_NAMES), 4), dtype=np.float32
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
for frame in range(len(root_pos)):
|
| 63 |
+
model_data.qpos[:3] = root_pos[frame]
|
| 64 |
+
model_data.qpos[3:7] = root_rot_xyzw[frame, [3, 0, 1, 2]]
|
| 65 |
+
model_data.qpos[7:] = dof_pos_mt[frame]
|
| 66 |
+
mujoco.mj_forward(model, model_data)
|
| 67 |
+
|
| 68 |
+
for output_index, body_name in enumerate(ISAAC_BODY_NAMES):
|
| 69 |
+
body_id = body_ids[body_name]
|
| 70 |
+
body_pos_w[frame, output_index] = model_data.xpos[body_id]
|
| 71 |
+
body_quat_w[frame, output_index] = model_data.xquat[body_id]
|
| 72 |
+
|
| 73 |
+
target_frames = output_frame_count(
|
| 74 |
+
len(root_pos), source_fps, target_fps
|
| 75 |
+
)
|
| 76 |
+
joint_pos = interpolate_linear(joint_pos, target_frames)
|
| 77 |
+
body_pos_w = interpolate_linear(body_pos_w, target_frames)
|
| 78 |
+
body_quat_w = interpolate_quaternions(body_quat_w, target_frames)
|
| 79 |
+
|
| 80 |
+
joint_vel = finite_difference(joint_pos, target_fps)
|
| 81 |
+
body_lin_vel_w = finite_difference(body_pos_w, target_fps)
|
| 82 |
+
body_ang_vel_w = body_angular_velocity_wxyz(
|
| 83 |
+
body_quat_w, target_fps
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
output_path = ensure_output_parent(output_path)
|
| 87 |
+
np.savez(
|
| 88 |
+
output_path,
|
| 89 |
+
fps=np.asarray([target_fps], dtype=np.int64),
|
| 90 |
+
joint_pos=joint_pos.astype(np.float32),
|
| 91 |
+
joint_vel=joint_vel.astype(np.float32),
|
| 92 |
+
body_pos_w=body_pos_w.astype(np.float32),
|
| 93 |
+
body_quat_w=body_quat_w.astype(np.float32),
|
| 94 |
+
body_lin_vel_w=body_lin_vel_w.astype(np.float32),
|
| 95 |
+
body_ang_vel_w=body_ang_vel_w.astype(np.float32),
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
if verbose:
|
| 99 |
+
print(
|
| 100 |
+
f"Saved Isaac: {output_path} "
|
| 101 |
+
f"({len(joint_pos)} frames @ {target_fps} fps)"
|
| 102 |
+
)
|
| 103 |
+
return output_path
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def parse_args() -> argparse.Namespace:
|
| 107 |
+
parser = argparse.ArgumentParser(
|
| 108 |
+
description="Convert one BONES-SEED G1 CSV motion to Isaac NPZ"
|
| 109 |
+
)
|
| 110 |
+
parser.add_argument("--input", required=True, help="Input G1 CSV file")
|
| 111 |
+
parser.add_argument(
|
| 112 |
+
"--output", required=True, help="Output Isaac NPZ file"
|
| 113 |
+
)
|
| 114 |
+
parser.add_argument(
|
| 115 |
+
"--g1-xml", required=True, help="Compatible Unitree G1 MJCF XML"
|
| 116 |
+
)
|
| 117 |
+
parser.add_argument("--source-fps", type=int, default=120)
|
| 118 |
+
parser.add_argument("--target-fps", type=int, default=50)
|
| 119 |
+
return parser.parse_args()
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def main() -> None:
|
| 123 |
+
args = parse_args()
|
| 124 |
+
convert_csv_to_isaac(
|
| 125 |
+
csv_path=args.input,
|
| 126 |
+
output_path=args.output,
|
| 127 |
+
g1_xml=args.g1_xml,
|
| 128 |
+
source_fps=args.source_fps,
|
| 129 |
+
target_fps=args.target_fps,
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
if __name__ == "__main__":
|
| 134 |
+
main()
|
scripts/csv_to_mt.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Convert one BONES-SEED Unitree G1 CSV file to MT NPZ format."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
import mujoco
|
| 10 |
+
import numpy as np
|
| 11 |
+
from scipy.spatial.transform import Rotation as R
|
| 12 |
+
|
| 13 |
+
from converter_common import (
|
| 14 |
+
MT_BODY_NAMES,
|
| 15 |
+
MT_JOINT_NAMES,
|
| 16 |
+
ensure_output_parent,
|
| 17 |
+
interpolate_linear,
|
| 18 |
+
interpolate_quaternions,
|
| 19 |
+
load_csv_motion,
|
| 20 |
+
load_g1_model,
|
| 21 |
+
output_frame_count,
|
| 22 |
+
require_body_id,
|
| 23 |
+
validate_fps,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
MIMIC_BODY_SOURCES = {
|
| 28 |
+
"head_mimic": "torso_link",
|
| 29 |
+
"left_hand_mimic": "left_wrist_roll_link",
|
| 30 |
+
"right_hand_mimic": "right_wrist_roll_link",
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def convert_csv_to_mt(
|
| 35 |
+
csv_path: str | Path,
|
| 36 |
+
output_path: str | Path,
|
| 37 |
+
g1_xml: str | Path,
|
| 38 |
+
source_fps: int = 120,
|
| 39 |
+
target_fps: int = 50,
|
| 40 |
+
verbose: bool = True,
|
| 41 |
+
) -> Path:
|
| 42 |
+
"""Convert a single CSV motion to MT format and return the output path."""
|
| 43 |
+
validate_fps(source_fps, target_fps)
|
| 44 |
+
root_pos, root_rot_xyzw, dof_pos = load_csv_motion(csv_path)
|
| 45 |
+
|
| 46 |
+
model = load_g1_model(str(Path(g1_xml).expanduser().resolve()))
|
| 47 |
+
model_data = mujoco.MjData(model)
|
| 48 |
+
|
| 49 |
+
physical_body_names = [
|
| 50 |
+
name for name in MT_BODY_NAMES if name not in MIMIC_BODY_SOURCES
|
| 51 |
+
]
|
| 52 |
+
body_ids = {
|
| 53 |
+
name: require_body_id(model, name) for name in physical_body_names
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
body_pos_w = np.zeros(
|
| 57 |
+
(len(root_pos), len(MT_BODY_NAMES), 3), dtype=np.float32
|
| 58 |
+
)
|
| 59 |
+
for frame in range(len(root_pos)):
|
| 60 |
+
model_data.qpos[:3] = root_pos[frame]
|
| 61 |
+
model_data.qpos[3:7] = root_rot_xyzw[frame, [3, 0, 1, 2]]
|
| 62 |
+
model_data.qpos[7:] = dof_pos[frame]
|
| 63 |
+
mujoco.mj_forward(model, model_data)
|
| 64 |
+
|
| 65 |
+
for body_name, body_id in body_ids.items():
|
| 66 |
+
output_index = MT_BODY_NAMES.index(body_name)
|
| 67 |
+
body_pos_w[frame, output_index] = model_data.xpos[body_id]
|
| 68 |
+
|
| 69 |
+
for mimic_name, source_name in MIMIC_BODY_SOURCES.items():
|
| 70 |
+
body_pos_w[:, MT_BODY_NAMES.index(mimic_name)] = body_pos_w[
|
| 71 |
+
:, MT_BODY_NAMES.index(source_name)
|
| 72 |
+
]
|
| 73 |
+
|
| 74 |
+
root_rotation_inverse = R.from_quat(root_rot_xyzw).inv().as_matrix()
|
| 75 |
+
local_body_pos = np.einsum(
|
| 76 |
+
"tij,tbj->tbi",
|
| 77 |
+
root_rotation_inverse,
|
| 78 |
+
body_pos_w - root_pos[:, None, :],
|
| 79 |
+
).astype(np.float32)
|
| 80 |
+
|
| 81 |
+
target_frames = output_frame_count(
|
| 82 |
+
len(root_pos), source_fps, target_fps
|
| 83 |
+
)
|
| 84 |
+
root_pos = interpolate_linear(root_pos, target_frames)
|
| 85 |
+
root_rot_xyzw = interpolate_quaternions(
|
| 86 |
+
root_rot_xyzw, target_frames
|
| 87 |
+
)
|
| 88 |
+
dof_pos = interpolate_linear(dof_pos, target_frames)
|
| 89 |
+
local_body_pos = interpolate_linear(local_body_pos, target_frames)
|
| 90 |
+
|
| 91 |
+
output_path = ensure_output_parent(output_path)
|
| 92 |
+
np.savez(
|
| 93 |
+
output_path,
|
| 94 |
+
root_pos=root_pos.astype(np.float32),
|
| 95 |
+
root_rot=root_rot_xyzw.astype(np.float32),
|
| 96 |
+
dof_pos=dof_pos.astype(np.float32),
|
| 97 |
+
local_body_pos=local_body_pos.astype(np.float32),
|
| 98 |
+
joint_names=np.asarray(MT_JOINT_NAMES),
|
| 99 |
+
body_names=np.asarray(MT_BODY_NAMES),
|
| 100 |
+
fps=np.asarray([target_fps], dtype=np.int64),
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
if verbose:
|
| 104 |
+
print(
|
| 105 |
+
f"Saved MT: {output_path} "
|
| 106 |
+
f"({len(root_pos)} frames @ {target_fps} fps)"
|
| 107 |
+
)
|
| 108 |
+
return output_path
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def parse_args() -> argparse.Namespace:
|
| 112 |
+
parser = argparse.ArgumentParser(
|
| 113 |
+
description="Convert one BONES-SEED G1 CSV motion to MT NPZ"
|
| 114 |
+
)
|
| 115 |
+
parser.add_argument("--input", required=True, help="Input G1 CSV file")
|
| 116 |
+
parser.add_argument("--output", required=True, help="Output MT NPZ file")
|
| 117 |
+
parser.add_argument(
|
| 118 |
+
"--g1-xml", required=True, help="Compatible Unitree G1 MJCF XML"
|
| 119 |
+
)
|
| 120 |
+
parser.add_argument("--source-fps", type=int, default=120)
|
| 121 |
+
parser.add_argument("--target-fps", type=int, default=50)
|
| 122 |
+
return parser.parse_args()
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def main() -> None:
|
| 126 |
+
args = parse_args()
|
| 127 |
+
convert_csv_to_mt(
|
| 128 |
+
csv_path=args.input,
|
| 129 |
+
output_path=args.output,
|
| 130 |
+
g1_xml=args.g1_xml,
|
| 131 |
+
source_fps=args.source_fps,
|
| 132 |
+
target_fps=args.target_fps,
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
if __name__ == "__main__":
|
| 137 |
+
main()
|
scripts/validate_npz.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Validate MT and Isaac NPZ files produced by this repository."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
|
| 11 |
+
from converter_common import MT_BODY_NAMES, MT_JOINT_NAMES
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
MT_FIELDS = {
|
| 15 |
+
"root_pos",
|
| 16 |
+
"root_rot",
|
| 17 |
+
"dof_pos",
|
| 18 |
+
"local_body_pos",
|
| 19 |
+
"joint_names",
|
| 20 |
+
"body_names",
|
| 21 |
+
"fps",
|
| 22 |
+
}
|
| 23 |
+
ISAAC_FIELDS = {
|
| 24 |
+
"fps",
|
| 25 |
+
"joint_pos",
|
| 26 |
+
"joint_vel",
|
| 27 |
+
"body_pos_w",
|
| 28 |
+
"body_quat_w",
|
| 29 |
+
"body_lin_vel_w",
|
| 30 |
+
"body_ang_vel_w",
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def infer_format(keys: set[str]) -> str:
|
| 35 |
+
if MT_FIELDS.issubset(keys):
|
| 36 |
+
return "mt"
|
| 37 |
+
if ISAAC_FIELDS.issubset(keys):
|
| 38 |
+
return "isaac"
|
| 39 |
+
raise ValueError(f"Cannot infer format from fields: {sorted(keys)}")
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def require_shape(
|
| 43 |
+
data: np.lib.npyio.NpzFile,
|
| 44 |
+
name: str,
|
| 45 |
+
expected: tuple[int, ...],
|
| 46 |
+
) -> None:
|
| 47 |
+
actual = data[name].shape
|
| 48 |
+
if actual != expected:
|
| 49 |
+
raise ValueError(f"{name}: expected shape {expected}, found {actual}")
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def require_float32(data: np.lib.npyio.NpzFile, fields: list[str]) -> None:
|
| 53 |
+
for name in fields:
|
| 54 |
+
if data[name].dtype != np.float32:
|
| 55 |
+
raise ValueError(
|
| 56 |
+
f"{name}: expected dtype float32, found {data[name].dtype}"
|
| 57 |
+
)
|
| 58 |
+
if not np.isfinite(data[name]).all():
|
| 59 |
+
raise ValueError(f"{name}: contains NaN or Inf")
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def validate_mt(data: np.lib.npyio.NpzFile) -> None:
|
| 63 |
+
missing = MT_FIELDS - set(data.files)
|
| 64 |
+
if missing:
|
| 65 |
+
raise ValueError(f"Missing MT fields: {sorted(missing)}")
|
| 66 |
+
|
| 67 |
+
frame_count = data["dof_pos"].shape[0]
|
| 68 |
+
if frame_count < 1:
|
| 69 |
+
raise ValueError("MT motion contains no frames")
|
| 70 |
+
|
| 71 |
+
require_shape(data, "root_pos", (frame_count, 3))
|
| 72 |
+
require_shape(data, "root_rot", (frame_count, 4))
|
| 73 |
+
require_shape(data, "dof_pos", (frame_count, 29))
|
| 74 |
+
require_shape(data, "local_body_pos", (frame_count, 27, 3))
|
| 75 |
+
require_shape(data, "joint_names", (29,))
|
| 76 |
+
require_shape(data, "body_names", (27,))
|
| 77 |
+
require_shape(data, "fps", (1,))
|
| 78 |
+
require_float32(
|
| 79 |
+
data, ["root_pos", "root_rot", "dof_pos", "local_body_pos"]
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
if data["fps"].dtype != np.int64 or int(data["fps"][0]) <= 0:
|
| 83 |
+
raise ValueError("fps must be a positive int64 array with shape (1,)")
|
| 84 |
+
if data["joint_names"].tolist() != MT_JOINT_NAMES:
|
| 85 |
+
raise ValueError("joint_names does not match the MT joint order")
|
| 86 |
+
if data["body_names"].tolist() != MT_BODY_NAMES:
|
| 87 |
+
raise ValueError("body_names does not match the MT body order")
|
| 88 |
+
|
| 89 |
+
quat_norm = np.linalg.norm(data["root_rot"], axis=-1)
|
| 90 |
+
if not np.allclose(quat_norm, 1.0, atol=1e-4):
|
| 91 |
+
raise ValueError("root_rot contains non-unit quaternions")
|
| 92 |
+
if not np.allclose(data["local_body_pos"][:, 0], 0.0, atol=1e-4):
|
| 93 |
+
raise ValueError("pelvis local_body_pos is not approximately zero")
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def validate_isaac(data: np.lib.npyio.NpzFile) -> None:
|
| 97 |
+
missing = ISAAC_FIELDS - set(data.files)
|
| 98 |
+
if missing:
|
| 99 |
+
raise ValueError(f"Missing Isaac fields: {sorted(missing)}")
|
| 100 |
+
|
| 101 |
+
frame_count = data["joint_pos"].shape[0]
|
| 102 |
+
if frame_count < 1:
|
| 103 |
+
raise ValueError("Isaac motion contains no frames")
|
| 104 |
+
|
| 105 |
+
require_shape(data, "fps", (1,))
|
| 106 |
+
require_shape(data, "joint_pos", (frame_count, 29))
|
| 107 |
+
require_shape(data, "joint_vel", (frame_count, 29))
|
| 108 |
+
require_shape(data, "body_pos_w", (frame_count, 30, 3))
|
| 109 |
+
require_shape(data, "body_quat_w", (frame_count, 30, 4))
|
| 110 |
+
require_shape(data, "body_lin_vel_w", (frame_count, 30, 3))
|
| 111 |
+
require_shape(data, "body_ang_vel_w", (frame_count, 30, 3))
|
| 112 |
+
require_float32(
|
| 113 |
+
data,
|
| 114 |
+
[
|
| 115 |
+
"joint_pos",
|
| 116 |
+
"joint_vel",
|
| 117 |
+
"body_pos_w",
|
| 118 |
+
"body_quat_w",
|
| 119 |
+
"body_lin_vel_w",
|
| 120 |
+
"body_ang_vel_w",
|
| 121 |
+
],
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
if data["fps"].dtype != np.int64 or int(data["fps"][0]) <= 0:
|
| 125 |
+
raise ValueError("fps must be a positive int64 array with shape (1,)")
|
| 126 |
+
quat_norm = np.linalg.norm(data["body_quat_w"], axis=-1)
|
| 127 |
+
if not np.allclose(quat_norm, 1.0, atol=1e-4):
|
| 128 |
+
raise ValueError("body_quat_w contains non-unit quaternions")
|
| 129 |
+
if not np.allclose(
|
| 130 |
+
data["body_pos_w"][:, 0], data["body_pos_w"][:, 3], atol=1e-6
|
| 131 |
+
):
|
| 132 |
+
raise ValueError("pelvis_contour_link must duplicate pelvis position")
|
| 133 |
+
if not np.allclose(
|
| 134 |
+
data["body_quat_w"][:, 0], data["body_quat_w"][:, 3], atol=1e-6
|
| 135 |
+
):
|
| 136 |
+
raise ValueError("pelvis_contour_link must duplicate pelvis rotation")
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def validate_file(path: Path, expected_format: str) -> str:
|
| 140 |
+
with np.load(path, allow_pickle=False) as data:
|
| 141 |
+
actual_format = infer_format(set(data.files))
|
| 142 |
+
if expected_format != "auto" and actual_format != expected_format:
|
| 143 |
+
raise ValueError(
|
| 144 |
+
f"expected {expected_format}, inferred {actual_format}"
|
| 145 |
+
)
|
| 146 |
+
if actual_format == "mt":
|
| 147 |
+
validate_mt(data)
|
| 148 |
+
else:
|
| 149 |
+
validate_isaac(data)
|
| 150 |
+
return actual_format
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def parse_args() -> argparse.Namespace:
|
| 154 |
+
parser = argparse.ArgumentParser(description="Validate MT/Isaac NPZ files")
|
| 155 |
+
parser.add_argument("path", type=Path, help="NPZ file or directory")
|
| 156 |
+
parser.add_argument(
|
| 157 |
+
"--format", choices=("auto", "mt", "isaac"), default="auto"
|
| 158 |
+
)
|
| 159 |
+
parser.add_argument(
|
| 160 |
+
"--limit", type=int, help="Validate only the first N files"
|
| 161 |
+
)
|
| 162 |
+
return parser.parse_args()
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def main() -> None:
|
| 166 |
+
args = parse_args()
|
| 167 |
+
target = args.path.expanduser().resolve()
|
| 168 |
+
if target.is_file():
|
| 169 |
+
paths = [target]
|
| 170 |
+
elif target.is_dir():
|
| 171 |
+
paths = sorted(target.rglob("*.npz"))
|
| 172 |
+
else:
|
| 173 |
+
raise SystemExit(f"Path not found: {target}")
|
| 174 |
+
|
| 175 |
+
if args.limit is not None:
|
| 176 |
+
if args.limit <= 0:
|
| 177 |
+
raise SystemExit("--limit must be positive")
|
| 178 |
+
paths = paths[: args.limit]
|
| 179 |
+
if not paths:
|
| 180 |
+
raise SystemExit(f"No NPZ files found: {target}")
|
| 181 |
+
|
| 182 |
+
failures = []
|
| 183 |
+
counts = {"mt": 0, "isaac": 0}
|
| 184 |
+
for path in paths:
|
| 185 |
+
try:
|
| 186 |
+
actual_format = validate_file(path, args.format)
|
| 187 |
+
counts[actual_format] += 1
|
| 188 |
+
except Exception as error:
|
| 189 |
+
failures.append((path, error))
|
| 190 |
+
print(f"FAIL\t{path}\t{error}")
|
| 191 |
+
|
| 192 |
+
print(
|
| 193 |
+
f"Validated {len(paths)} file(s): "
|
| 194 |
+
f"mt={counts['mt']}, isaac={counts['isaac']}, "
|
| 195 |
+
f"failed={len(failures)}"
|
| 196 |
+
)
|
| 197 |
+
if failures:
|
| 198 |
+
raise SystemExit(1)
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
if __name__ == "__main__":
|
| 202 |
+
main()
|