cmvr-es/model/README.md
lgv aabc5a9fef feat(model): add xiaozhao MuJoCo model and joint limit tooling
Add the pedestal-free xiaozhao URDF, mesh assets, and separate MuJoCo robot,
environment, and position-actuator XML files. Align joint frames, rotation
directions, inertial transforms, and limits with the calibrated URDF, including
the mirrored right hand, and retain the original SolidWorks URDF export.

Add a model-selectable CSV limit updater with unit conversion, validation,
dry-run support, and rollback on write failures. Synchronize the calibration
CSV, document the workflow, add regression tests, and ignore export logs.

Validation: 14 joint-limit tests passed; all joint and actuator ranges agree
with the URDF. Kinematics and inertial checks passed, along with a 3000-step
MuJoCo 3.3.7 simulation and desktop scene loading.
2026-11-12 13:39:08 +08:00

83 lines
3.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 模型工具
## 从 CSV 同步关节限位
脚本为 `model/update_joint_limits.py`,使用 `--模型目录名` 选择模型。
例如 `--xiaozhao` 选择脚本旁边的 `xiaozhao/`,自动使用:
```text
model/
├── update_joint_limits.py
└── xiaozhao/
├── config/joint_limits.csv
├── urdf/xiaozhao.urdf
└── xml/
├── xiaozhao.xml
├── actuators.xml
├── environment.xml
└── scene.xml
```
其他目录按同样规则使用 `--目录名`;URDF 和机器人 XML 的文件名默认与目录名一致。
文件命名不同时可以用下面的路径参数覆盖。一次必须选择且只能选择一个模型;
缺少配置或目标文件时会报错,不会改动其他模型。
只需要 Python 3.10+ 标准库,无需安装 MuJoCo。编辑
`model/xiaozhao/config/joint_limits.csv`,然后执行:
```bash
# 先查看差异,不写文件
python3 model/update_joint_limits.py --xiaozhao --dry-run
# 应用 CSV 中的限位
python3 model/update_joint_limits.py --xiaozhao
```
默认同步以下三处:
- `model/xiaozhao/urdf/xiaozhao.urdf` 的 `limit lower/upper`
- `model/xiaozhao/xml/xiaozhao.xml` 的关节 `range`
- `model/xiaozhao/xml/actuators.xml` 的位置执行器 `ctrlrange`
CSV 已填入当前 14 个关节的限位。`unit` 为 `rad`(弧度)或 `deg`(角度),
可以逐行选择;省略整个 `unit` 列时按弧度处理。例如,把某个关节改为 ±90°:
```csv
joint_name,lower,upper,unit
joint2-left,-90,90,deg
```
可以只列出需要修改的关节,其余保持原值。上下限是相对于该关节 URDF `axis`
方向的有符号角度,不按左右手自动反转。必须满足 `lower < upper`;若要固定关节,
应单独修改关节类型,不能把上下限设为同一个值。
加载其他 CSV 或指定目标文件:
```bash
python3 model/update_joint_limits.py --xiaozhao \
--csv model/xiaozhao/config/joint_limits.csv \
--urdf model/xiaozhao/urdf/xiaozhao.urdf \
--mjcf model/xiaozhao/xml/xiaozhao.xml \
--actuators model/xiaozhao/xml/actuators.xml
```
也支持 SolidWorks 导出 CSV 的 `Joint Name`、`Limit Lower`、`Limit Upper` 列,
按弧度读取,跳过无关节名的根链接行。SolidWorks 格式 CSV 和另一份原始 URDF 不会由限位脚本自动修改。
当前 SolidWorks 格式 CSV 的关节坐标、轴向、限位及链接原点已按 `xiaozhao.urdf` 同步。
该格式每个链接仅记录一组 visual/collision,右手额外的镜像手掌几何仍以当前 URDF/XML 为准;
另一份原始 URDF 保留为历史导出。
目标 MJCF 必须是包含关节定义的机器人文件,不是仅含 `include` 的 `scene.xml`。
当前工具适用于 `revolute`/`hinge` 关节和 `gear=1` 的位置执行器;不更改速度、力矩、
增益或碰撞设置,也不递归修改 MJCF include 文件。
为防止写入的范围未实际启用,若目标文件的默认类设置了 `limited="false"` 或
`ctrllimited="false"`,工具会拒绝更新(即使该默认类暂未使用)。
脚本先验证整份输入及三个目标,再写入;未知或重复关节、非法单位、非有限数值、
缺失目标等都会报错。只替换对应属性值,保留注释、排版、换行和文件权限。
URDF 始终写弧度,MJCF `range` 跟随其 `compiler angle`,执行器控制范围写弧度。
模型目录相对于脚本所在的 `model/` 文件夹解析,因此从其他工作目录运行也可以。
应用后在 MuJoCo 中按 **Ctrl+L** 重新加载 `model/xiaozhao/xml/scene.xml`,
新的限位和控制滑块范围才会生效;脚本不会自动操作当前仿真窗口。