commit a886dbb124bcf1f30369c1da13d97f3a8d904e58 Author: liyang <836021389@qq.com> Date: Tue Oct 27 14:16:39 2026 +0800 Publish Superspider models, policies and teacher-student training workflow diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7340b2a --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.venv/ +__pycache__/ +*.pyc +logs/ +wandb/ +.cache/ diff --git a/LICENSE.upstream b/LICENSE.upstream new file mode 100644 index 0000000..7b72d42 --- /dev/null +++ b/LICENSE.upstream @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2024 The Isaac Lab Project Developers + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/NOTICE.md b/NOTICE.md new file mode 100644 index 0000000..eec6a66 --- /dev/null +++ b/NOTICE.md @@ -0,0 +1,9 @@ +# 来源 + +训练适配代码摘自 unitreerobotics/unitree_rl_mjlab 的本地 Superspider 开发版本;上游 Apache-2.0 许可保留于 LICENSE.upstream。 + +本仓库整理修改:仅注册 Superspider 本地任务;模型按源码相对位置解析;移除机械臂资产强制导入;修复 PPO/蒸馏分型加载;补充分阶段训练入口、验证、依赖与说明。奖励和物理参数沿用源配置。 + +模型与权重来自自制 Superspider 项目。上游代码许可证不应被解释为第三方 CAD 或硬件商标的授权。 + +额外兼容修正:蒸馏 obs_groups 使用与配置类型一致的 tuple,保留原观测顺序与训练语义。 diff --git a/README.md b/README.md new file mode 100644 index 0000000..09ecd97 --- /dev/null +++ b/README.md @@ -0,0 +1,78 @@ +# Superspider RL + +六足蜘蛛机器人强化学习项目,18 个主动关节。最终路线:**PPO 平地预训练 → 盲走台阶微调 → 高度图教师 → 本体感知学生蒸馏**。 + +## 文件 + +| 内容 | 位置 | +| --- | --- | +| 最终 URDF、STL | `models/superspider/` | +| RL 用 MJCF、网格 | `models/superspider_mjlab/` | +| 环境、奖励、蒸馏配置 | `src/tasks/velocity/config/custom_dog/dogs/superspider.py` | +| 键盘控制 | `scripts/superspider_teleop.py` | +| 策略回放 | `scripts/play.py` | +| 训练入口 | `scripts/train_stage.py` | +| 训练方法 | [TRAINING.md](TRAINING.md) | +| 权重及 SHA-256 | `checkpoints/` | + +## 安装 + +Linux、Python 3.12 + venv;训练使用 NVIDIA CUDA GPU,图形窗口需要桌面环境。MuJoCo 与 mujoco-warp 固定为 3.5.0,完整依赖在 requirements.txt。 + +```bash +python3.12 -m venv .venv +source .venv/bin/activate +python -m pip install -e . +``` + +以下命令在仓库根目录执行。 + +## 控制与回放 + +默认控制最终学生策略: + +```bash +python -m scripts.superspider_teleop +``` + +W/S 或上下键增减前进速度,A/D 或左右键转向,Q/E 横移,C 清除转向和横移,X/空格将速度指令归零,L 切换转向保持。学生训练范围为前进 0.05–0.40 m/s、横移 ±0.05 m/s、转向 ±0.30 rad/s;另提供零速指令,零速稳定性不由训练范围保证。 + +平地策略支持前后移动: + +```bash +python -m scripts.superspider_teleop --task Custom-Superspider-Flat --checkpoint-file checkpoints/flat_5999.pt +``` + +自动回放最终学生(无桌面可加 `--viewer viser`): + +```bash +python -m scripts.play Custom-Superspider-Stairs-Distill --checkpoint-file checkpoints/student_5999.pt --num-envs 1 +``` + +## 权重 + +| 文件 | 用途 | +| --- | --- | +| flat_5999.pt | 平地 PPO | +| blind_10000.pt | 盲走台阶 PPO,教师初始化来源 | +| teacher_3800.pt | 318 维高度图教师,蒸馏来源 | +| student_1600.pt | 历史单级台阶评测使用的学生快照 | +| student_5999.pt | 最后保存的学生权重,默认回放版本 | + +学生输入 65 维本体状态、输出 18 维关节位置动作。最后保存不等于评测最优;历史 9 cm 单级台阶结果对应 1600 快照,不能直接归给 5999 快照或连续楼梯。 + +## 模型与适用范围 + +URDF 保留最终建模文件。训练通过 MJCF 与任务后处理设置 100 mm 站高、HTD-45H 参数、4.41 N·m 力矩限幅和站姿中心 ±40° 的 coxa 限位。有效训练参数以任务配置为准,不能只读 URDF 替代训练配置。舵机质量仍沿用 CAD 值,待实物核验。 + +控制脚本运行 MuJoCo 仿真,不包含串口舵机驱动或已验证的真机部署。零速度指令不是硬件急停。 + +模型与策略检查: + +```bash +MUJOCO_GL=egl python -m scripts.verify +``` + +来源与许可见 [NOTICE.md](NOTICE.md)。 + +本次整理验证:URDF/MJCF 编译、网格引用、5 份权重哈希与严格加载、每份策略 8 个 CPU 仿真步通过;训练和控制命令行入口检查通过。结果见 [validation/smoke.json](validation/smoke.json)。未重新训练或复测完整台阶成绩。 diff --git a/TRAINING.md b/TRAINING.md new file mode 100644 index 0000000..79f0881 --- /dev/null +++ b/TRAINING.md @@ -0,0 +1,59 @@ +# 最终训练方法 + +## 训练链 + +采用 mjlab + MuJoCo Warp 批量仿真、RSL-RL PPO 和教师学生蒸馏。动作顺序为腿 1 到 6,每腿 coxa、femur、tibia;在默认站姿上叠加动作,缩放 0.25。 + +1. 平地 PPO 学习速度跟踪,保留 flat_5999.pt。 +2. 盲走单级台阶 PPO 从平地继续训练,65 维本体观测,选用 blind_10000.pt。 +3. 高度图教师从盲走网络扩容:第一层插入 253 个扫描输入,新列权重为零,归一化新通道 mean=0、var/std=1;清空 Adam 参数状态,迭代计数归零。actor 65→318,critic 140→393。选用 teacher_3800.pt。 +4. 固定教师,学生在自己访问的状态上拟合教师动作。student 观测组为 [actor],teacher 为 [actor, height],顺序不可变。最后保存 student_5999.pt。 + +教师初始化第一层前 65 列已与 blind_10000.pt 核对一致。权重来源与哈希见 checkpoints/manifest.json。原运行参数保存在 training/snapshots/,作为历史记录,不直接当作可执行 YAML 加载。 + +## 参数 + +| 参数 | 值 | +| --- | --- | +| 物理步长 / 降采样 | 0.005 s / 4,策略 50 Hz | +| 单回合 | 20 s | +| 平地 / 台阶及蒸馏并行环境 | 1024 / 512 | +| 种子 / 每环境 rollout | 42 / 24 步 | +| 网络 | MLP 512–256–128,ELU,观测归一化 | +| PPO | lr=0.001,自适应 KL,5 epochs,4 mini-batches | +| PPO gamma / GAE lambda / clip | 0.99 / 0.95 / 0.2 | +| PPO entropy / desired KL | 0.01 / 0.01 | +| 蒸馏 | MSE,Adam lr=0.001,1 epoch,gradient_length=15 | +| 梯度裁剪 | 1.0 | +| 蒸馏迭代 / 保存间隔 | 6000 / 200 | + +地形为 8×8 m 地块上的单级台阶、1.5 m 助跑、课程高度 1–6 cm。升级依据为减去 100 mm 站高后的净爬升,而非前进距离。奖励包含速度跟踪、姿态和动作正则、相对上次触地点的抬脚高度、净爬升进度、自碰撞和超过额定角速度 80% 的惩罚。台阶任务取消三角步态奖励。完整参数以代码及历史快照为准。 + +## 训练命令 + +```bash +python -m scripts.train_stage flat +python -m scripts.train_stage blind +python -m scripts.train_stage teacher +python -m scripts.train_stage student +``` + +各阶段默认读取附带的上一阶段权重,便于独立训练。连续从头重训时,用 `--checkpoint logs/rsl_rl/.../model_....pt` 指定本轮上一阶段输出。资源与长度可用 `--num-envs`、`--iterations` 修改。 + +包装入口默认 flat=6000 次更新;blind 从 iter=5999 继续 4002 次,覆盖历史选用的 iter=10000;teacher 扩容后 3801 次;student 6000 次。PPO iter 为零起始标签,恢复迭代数不等于新增更新次数。历史 blind/teacher 配置预算分别是 14000/8000,选用权重不是预算最后一步。新训练不保证逐位复现历史随机结果。 + +更多参数: + +```bash +python -m scripts.train Custom-Superspider-Stairs-Distill --help +``` + +## 评测 + +```bash +MUJOCO_GL=egl python -m scripts.superspider_stair_test checkpoints/student_1600.pt --task Custom-Superspider-Stairs-Distill --heights 0,0.02,0.05,0.08,0.09,0.10 +``` + +该脚本使用 CUDA,24 环境 ×20 s,以后半程超过 80% 时间净机身高度高于台阶高的 85% 为登顶。历史 student 1600 的记录为 2–9 cm 100%、10 cm 0%;这是历史单级台阶仿真记录,本次整理未重新进行完整能力评测,不代表连续楼梯或真机性能。 + +蒸馏权重必须加载 student/teacher 字段,不能沿用 PPO 的 actor 字段。src/policy.py 严格检查任务与权重类型,防止漏载后运行随机网络。 diff --git a/checkpoints/blind_10000.pt b/checkpoints/blind_10000.pt new file mode 100644 index 0000000..6fb53fa Binary files /dev/null and b/checkpoints/blind_10000.pt differ diff --git a/checkpoints/flat_5999.pt b/checkpoints/flat_5999.pt new file mode 100644 index 0000000..093dec0 Binary files /dev/null and b/checkpoints/flat_5999.pt differ diff --git a/checkpoints/manifest.json b/checkpoints/manifest.json new file mode 100644 index 0000000..6ce6d29 --- /dev/null +++ b/checkpoints/manifest.json @@ -0,0 +1,37 @@ +[ + { + "file": "checkpoints/flat_5999.pt", + "source_run": "superspider_flat_velocity/2026-09-08_15-21-43", + "iteration": 5999, + "sha256": "3f0b2b418e4aebc2fb65a4bea9ddec127462d639b46d1bc523b35757244517a9", + "bytes": 5268789 + }, + { + "file": "checkpoints/blind_10000.pt", + "source_run": "superspider_stairs_velocity/2026-09-09_14-22-48", + "iteration": 10000, + "sha256": "ca4b9c785f9b265b1ec0e3ca049b1ccd99b8d8f542c500ab8ccd7c1541586233", + "bytes": 5268871 + }, + { + "file": "checkpoints/teacher_3800.pt", + "source_run": "superspider_stairs_teacher_velocity/2026-09-09_16-35-49", + "iteration": 3800, + "sha256": "089ac2ab2aa991a673528a0079829109cd5d283012e26686bd238df9f0760929", + "bytes": 8383605 + }, + { + "file": "checkpoints/student_5999.pt", + "source_run": "superspider_stairs_distill/2026-09-09_18-21-08", + "iteration": 5999, + "sha256": "62b1c63f0af39e0ef0932dfa856177a2ad761e3f70febdd43ab55e6a1426bd13", + "bytes": 3744501 + }, + { + "file": "checkpoints/student_1600.pt", + "source_run": "superspider_stairs_distill/2026-09-09_18-21-08", + "iteration": 1600, + "sha256": "c250b9d5ae4001c57043f4ec49de7f766ee53b41b1fc9a42746bec29ebce12cf", + "bytes": 3744501 + } +] diff --git a/checkpoints/student_1600.pt b/checkpoints/student_1600.pt new file mode 100644 index 0000000..bb463ff Binary files /dev/null and b/checkpoints/student_1600.pt differ diff --git a/checkpoints/student_5999.pt b/checkpoints/student_5999.pt new file mode 100644 index 0000000..2048989 Binary files /dev/null and b/checkpoints/student_5999.pt differ diff --git a/checkpoints/teacher_3800.pt b/checkpoints/teacher_3800.pt new file mode 100644 index 0000000..75dbd75 Binary files /dev/null and b/checkpoints/teacher_3800.pt differ diff --git a/models/superspider/meshes/1_coxa_0_pin1.STL b/models/superspider/meshes/1_coxa_0_pin1.STL new file mode 100644 index 0000000..b9b3f9d Binary files /dev/null and b/models/superspider/meshes/1_coxa_0_pin1.STL differ diff --git a/models/superspider/meshes/1_coxa_1_pin1.STL b/models/superspider/meshes/1_coxa_1_pin1.STL new file mode 100644 index 0000000..013f9e5 Binary files /dev/null and b/models/superspider/meshes/1_coxa_1_pin1.STL differ diff --git a/models/superspider/meshes/1_femur_0_servo.STL b/models/superspider/meshes/1_femur_0_servo.STL new file mode 100644 index 0000000..ec37663 Binary files /dev/null and b/models/superspider/meshes/1_femur_0_servo.STL differ diff --git a/models/superspider/meshes/1_femur_1_pin2.STL b/models/superspider/meshes/1_femur_1_pin2.STL new file mode 100644 index 0000000..2270a68 Binary files /dev/null and b/models/superspider/meshes/1_femur_1_pin2.STL differ diff --git a/models/superspider/meshes/1_femur_2_servo.STL b/models/superspider/meshes/1_femur_2_servo.STL new file mode 100644 index 0000000..e816b86 Binary files /dev/null and b/models/superspider/meshes/1_femur_2_servo.STL differ diff --git a/models/superspider/meshes/1_femur_3_pin2.STL b/models/superspider/meshes/1_femur_3_pin2.STL new file mode 100644 index 0000000..f863dfc Binary files /dev/null and b/models/superspider/meshes/1_femur_3_pin2.STL differ diff --git a/models/superspider/meshes/1_tibia_0_foot.STL b/models/superspider/meshes/1_tibia_0_foot.STL new file mode 100644 index 0000000..54f54ae Binary files /dev/null and b/models/superspider/meshes/1_tibia_0_foot.STL differ diff --git a/models/superspider/meshes/2_coxa_0_pin1.STL b/models/superspider/meshes/2_coxa_0_pin1.STL new file mode 100644 index 0000000..0f6f8e2 Binary files /dev/null and b/models/superspider/meshes/2_coxa_0_pin1.STL differ diff --git a/models/superspider/meshes/2_coxa_1_pin1.STL b/models/superspider/meshes/2_coxa_1_pin1.STL new file mode 100644 index 0000000..0721e81 Binary files /dev/null and b/models/superspider/meshes/2_coxa_1_pin1.STL differ diff --git a/models/superspider/meshes/2_femur_0_servo.STL b/models/superspider/meshes/2_femur_0_servo.STL new file mode 100644 index 0000000..4f94b12 Binary files /dev/null and b/models/superspider/meshes/2_femur_0_servo.STL differ diff --git a/models/superspider/meshes/2_femur_1_pin2.STL b/models/superspider/meshes/2_femur_1_pin2.STL new file mode 100644 index 0000000..5b1b86e Binary files /dev/null and b/models/superspider/meshes/2_femur_1_pin2.STL differ diff --git a/models/superspider/meshes/2_femur_2_servo.STL b/models/superspider/meshes/2_femur_2_servo.STL new file mode 100644 index 0000000..9f73db3 Binary files /dev/null and b/models/superspider/meshes/2_femur_2_servo.STL differ diff --git a/models/superspider/meshes/2_femur_3_pin2.STL b/models/superspider/meshes/2_femur_3_pin2.STL new file mode 100644 index 0000000..ad1bd14 Binary files /dev/null and b/models/superspider/meshes/2_femur_3_pin2.STL differ diff --git a/models/superspider/meshes/2_tibia_0_foot.STL b/models/superspider/meshes/2_tibia_0_foot.STL new file mode 100644 index 0000000..7a75558 Binary files /dev/null and b/models/superspider/meshes/2_tibia_0_foot.STL differ diff --git a/models/superspider/meshes/3_coxa_0_pin1.STL b/models/superspider/meshes/3_coxa_0_pin1.STL new file mode 100644 index 0000000..d22fbd3 Binary files /dev/null and b/models/superspider/meshes/3_coxa_0_pin1.STL differ diff --git a/models/superspider/meshes/3_coxa_1_pin1.STL b/models/superspider/meshes/3_coxa_1_pin1.STL new file mode 100644 index 0000000..8a02958 Binary files /dev/null and b/models/superspider/meshes/3_coxa_1_pin1.STL differ diff --git a/models/superspider/meshes/3_femur_0_servo.STL b/models/superspider/meshes/3_femur_0_servo.STL new file mode 100644 index 0000000..5192560 Binary files /dev/null and b/models/superspider/meshes/3_femur_0_servo.STL differ diff --git a/models/superspider/meshes/3_femur_1_pin2.STL b/models/superspider/meshes/3_femur_1_pin2.STL new file mode 100644 index 0000000..ef0487e Binary files /dev/null and b/models/superspider/meshes/3_femur_1_pin2.STL differ diff --git a/models/superspider/meshes/3_femur_2_servo.STL b/models/superspider/meshes/3_femur_2_servo.STL new file mode 100644 index 0000000..f878eea Binary files /dev/null and b/models/superspider/meshes/3_femur_2_servo.STL differ diff --git a/models/superspider/meshes/3_femur_3_pin2.STL b/models/superspider/meshes/3_femur_3_pin2.STL new file mode 100644 index 0000000..27ef27e Binary files /dev/null and b/models/superspider/meshes/3_femur_3_pin2.STL differ diff --git a/models/superspider/meshes/3_tibia_0_foot.STL b/models/superspider/meshes/3_tibia_0_foot.STL new file mode 100644 index 0000000..f8d3588 Binary files /dev/null and b/models/superspider/meshes/3_tibia_0_foot.STL differ diff --git a/models/superspider/meshes/4_coxa_0_pin1.STL b/models/superspider/meshes/4_coxa_0_pin1.STL new file mode 100644 index 0000000..f63945f Binary files /dev/null and b/models/superspider/meshes/4_coxa_0_pin1.STL differ diff --git a/models/superspider/meshes/4_coxa_1_pin1.STL b/models/superspider/meshes/4_coxa_1_pin1.STL new file mode 100644 index 0000000..eb1d032 Binary files /dev/null and b/models/superspider/meshes/4_coxa_1_pin1.STL differ diff --git a/models/superspider/meshes/4_femur_0_servo.STL b/models/superspider/meshes/4_femur_0_servo.STL new file mode 100644 index 0000000..6b50fca Binary files /dev/null and b/models/superspider/meshes/4_femur_0_servo.STL differ diff --git a/models/superspider/meshes/4_femur_1_pin2.STL b/models/superspider/meshes/4_femur_1_pin2.STL new file mode 100644 index 0000000..42bbd22 Binary files /dev/null and b/models/superspider/meshes/4_femur_1_pin2.STL differ diff --git a/models/superspider/meshes/4_femur_2_servo.STL b/models/superspider/meshes/4_femur_2_servo.STL new file mode 100644 index 0000000..e7f48c3 Binary files /dev/null and b/models/superspider/meshes/4_femur_2_servo.STL differ diff --git a/models/superspider/meshes/4_femur_3_pin2.STL b/models/superspider/meshes/4_femur_3_pin2.STL new file mode 100644 index 0000000..8097b90 Binary files /dev/null and b/models/superspider/meshes/4_femur_3_pin2.STL differ diff --git a/models/superspider/meshes/4_tibia_0_foot.STL b/models/superspider/meshes/4_tibia_0_foot.STL new file mode 100644 index 0000000..16fe8ce Binary files /dev/null and b/models/superspider/meshes/4_tibia_0_foot.STL differ diff --git a/models/superspider/meshes/5_coxa_0_pin1.STL b/models/superspider/meshes/5_coxa_0_pin1.STL new file mode 100644 index 0000000..e66d059 Binary files /dev/null and b/models/superspider/meshes/5_coxa_0_pin1.STL differ diff --git a/models/superspider/meshes/5_coxa_1_pin1.STL b/models/superspider/meshes/5_coxa_1_pin1.STL new file mode 100644 index 0000000..ee59282 Binary files /dev/null and b/models/superspider/meshes/5_coxa_1_pin1.STL differ diff --git a/models/superspider/meshes/5_femur_0_servo.STL b/models/superspider/meshes/5_femur_0_servo.STL new file mode 100644 index 0000000..e54238f Binary files /dev/null and b/models/superspider/meshes/5_femur_0_servo.STL differ diff --git a/models/superspider/meshes/5_femur_1_pin2.STL b/models/superspider/meshes/5_femur_1_pin2.STL new file mode 100644 index 0000000..add4c5d Binary files /dev/null and b/models/superspider/meshes/5_femur_1_pin2.STL differ diff --git a/models/superspider/meshes/5_femur_2_servo.STL b/models/superspider/meshes/5_femur_2_servo.STL new file mode 100644 index 0000000..32c3707 Binary files /dev/null and b/models/superspider/meshes/5_femur_2_servo.STL differ diff --git a/models/superspider/meshes/5_femur_3_pin2.STL b/models/superspider/meshes/5_femur_3_pin2.STL new file mode 100644 index 0000000..15f9d87 Binary files /dev/null and b/models/superspider/meshes/5_femur_3_pin2.STL differ diff --git a/models/superspider/meshes/5_tibia_0_foot.STL b/models/superspider/meshes/5_tibia_0_foot.STL new file mode 100644 index 0000000..e154335 Binary files /dev/null and b/models/superspider/meshes/5_tibia_0_foot.STL differ diff --git a/models/superspider/meshes/6_coxa_0_pin1.STL b/models/superspider/meshes/6_coxa_0_pin1.STL new file mode 100644 index 0000000..6c62b80 Binary files /dev/null and b/models/superspider/meshes/6_coxa_0_pin1.STL differ diff --git a/models/superspider/meshes/6_coxa_1_pin1.STL b/models/superspider/meshes/6_coxa_1_pin1.STL new file mode 100644 index 0000000..69b0e8e Binary files /dev/null and b/models/superspider/meshes/6_coxa_1_pin1.STL differ diff --git a/models/superspider/meshes/6_femur_0_servo.STL b/models/superspider/meshes/6_femur_0_servo.STL new file mode 100644 index 0000000..a66f34d Binary files /dev/null and b/models/superspider/meshes/6_femur_0_servo.STL differ diff --git a/models/superspider/meshes/6_femur_1_pin2.STL b/models/superspider/meshes/6_femur_1_pin2.STL new file mode 100644 index 0000000..1525a9a Binary files /dev/null and b/models/superspider/meshes/6_femur_1_pin2.STL differ diff --git a/models/superspider/meshes/6_femur_2_servo.STL b/models/superspider/meshes/6_femur_2_servo.STL new file mode 100644 index 0000000..db101d7 Binary files /dev/null and b/models/superspider/meshes/6_femur_2_servo.STL differ diff --git a/models/superspider/meshes/6_femur_3_pin2.STL b/models/superspider/meshes/6_femur_3_pin2.STL new file mode 100644 index 0000000..6052c21 Binary files /dev/null and b/models/superspider/meshes/6_femur_3_pin2.STL differ diff --git a/models/superspider/meshes/6_tibia_0_foot.STL b/models/superspider/meshes/6_tibia_0_foot.STL new file mode 100644 index 0000000..37c27be Binary files /dev/null and b/models/superspider/meshes/6_tibia_0_foot.STL differ diff --git a/models/superspider/meshes/base_link_0_body.STL b/models/superspider/meshes/base_link_0_body.STL new file mode 100644 index 0000000..c09768f Binary files /dev/null and b/models/superspider/meshes/base_link_0_body.STL differ diff --git a/models/superspider/meshes/base_link_1_servo.STL b/models/superspider/meshes/base_link_1_servo.STL new file mode 100644 index 0000000..8890837 Binary files /dev/null and b/models/superspider/meshes/base_link_1_servo.STL differ diff --git a/models/superspider/meshes/base_link_2_servo.STL b/models/superspider/meshes/base_link_2_servo.STL new file mode 100644 index 0000000..5e6cbdd Binary files /dev/null and b/models/superspider/meshes/base_link_2_servo.STL differ diff --git a/models/superspider/meshes/base_link_3_servo.STL b/models/superspider/meshes/base_link_3_servo.STL new file mode 100644 index 0000000..11faa8b Binary files /dev/null and b/models/superspider/meshes/base_link_3_servo.STL differ diff --git a/models/superspider/meshes/base_link_4_servo.STL b/models/superspider/meshes/base_link_4_servo.STL new file mode 100644 index 0000000..c67fe28 Binary files /dev/null and b/models/superspider/meshes/base_link_4_servo.STL differ diff --git a/models/superspider/meshes/base_link_5_servo.STL b/models/superspider/meshes/base_link_5_servo.STL new file mode 100644 index 0000000..af61e06 Binary files /dev/null and b/models/superspider/meshes/base_link_5_servo.STL differ diff --git a/models/superspider/meshes/base_link_6_servo.STL b/models/superspider/meshes/base_link_6_servo.STL new file mode 100644 index 0000000..b269164 Binary files /dev/null and b/models/superspider/meshes/base_link_6_servo.STL differ diff --git a/models/superspider/superspider.urdf b/models/superspider/superspider.urdf new file mode 100644 index 0000000..04454bc --- /dev/null +++ b/models/superspider/superspider.urdf @@ -0,0 +1,935 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/models/superspider_mjlab/assets/1_coxa_0_pin1.STL b/models/superspider_mjlab/assets/1_coxa_0_pin1.STL new file mode 100644 index 0000000..b9b3f9d Binary files /dev/null and b/models/superspider_mjlab/assets/1_coxa_0_pin1.STL differ diff --git a/models/superspider_mjlab/assets/1_coxa_1_pin1.STL b/models/superspider_mjlab/assets/1_coxa_1_pin1.STL new file mode 100644 index 0000000..013f9e5 Binary files /dev/null and b/models/superspider_mjlab/assets/1_coxa_1_pin1.STL differ diff --git a/models/superspider_mjlab/assets/1_femur_0_servo.STL b/models/superspider_mjlab/assets/1_femur_0_servo.STL new file mode 100644 index 0000000..ec37663 Binary files /dev/null and b/models/superspider_mjlab/assets/1_femur_0_servo.STL differ diff --git a/models/superspider_mjlab/assets/1_femur_1_pin2.STL b/models/superspider_mjlab/assets/1_femur_1_pin2.STL new file mode 100644 index 0000000..2270a68 Binary files /dev/null and b/models/superspider_mjlab/assets/1_femur_1_pin2.STL differ diff --git a/models/superspider_mjlab/assets/1_femur_2_servo.STL b/models/superspider_mjlab/assets/1_femur_2_servo.STL new file mode 100644 index 0000000..e816b86 Binary files /dev/null and b/models/superspider_mjlab/assets/1_femur_2_servo.STL differ diff --git a/models/superspider_mjlab/assets/1_femur_3_pin2.STL b/models/superspider_mjlab/assets/1_femur_3_pin2.STL new file mode 100644 index 0000000..f863dfc Binary files /dev/null and b/models/superspider_mjlab/assets/1_femur_3_pin2.STL differ diff --git a/models/superspider_mjlab/assets/1_tibia_0_foot.STL b/models/superspider_mjlab/assets/1_tibia_0_foot.STL new file mode 100644 index 0000000..54f54ae Binary files /dev/null and b/models/superspider_mjlab/assets/1_tibia_0_foot.STL differ diff --git a/models/superspider_mjlab/assets/2_coxa_0_pin1.STL b/models/superspider_mjlab/assets/2_coxa_0_pin1.STL new file mode 100644 index 0000000..0f6f8e2 Binary files /dev/null and b/models/superspider_mjlab/assets/2_coxa_0_pin1.STL differ diff --git a/models/superspider_mjlab/assets/2_coxa_1_pin1.STL b/models/superspider_mjlab/assets/2_coxa_1_pin1.STL new file mode 100644 index 0000000..0721e81 Binary files /dev/null and b/models/superspider_mjlab/assets/2_coxa_1_pin1.STL differ diff --git a/models/superspider_mjlab/assets/2_femur_0_servo.STL b/models/superspider_mjlab/assets/2_femur_0_servo.STL new file mode 100644 index 0000000..4f94b12 Binary files /dev/null and b/models/superspider_mjlab/assets/2_femur_0_servo.STL differ diff --git a/models/superspider_mjlab/assets/2_femur_1_pin2.STL b/models/superspider_mjlab/assets/2_femur_1_pin2.STL new file mode 100644 index 0000000..5b1b86e Binary files /dev/null and b/models/superspider_mjlab/assets/2_femur_1_pin2.STL differ diff --git a/models/superspider_mjlab/assets/2_femur_2_servo.STL b/models/superspider_mjlab/assets/2_femur_2_servo.STL new file mode 100644 index 0000000..9f73db3 Binary files /dev/null and b/models/superspider_mjlab/assets/2_femur_2_servo.STL differ diff --git a/models/superspider_mjlab/assets/2_femur_3_pin2.STL b/models/superspider_mjlab/assets/2_femur_3_pin2.STL new file mode 100644 index 0000000..ad1bd14 Binary files /dev/null and b/models/superspider_mjlab/assets/2_femur_3_pin2.STL differ diff --git a/models/superspider_mjlab/assets/2_tibia_0_foot.STL b/models/superspider_mjlab/assets/2_tibia_0_foot.STL new file mode 100644 index 0000000..7a75558 Binary files /dev/null and b/models/superspider_mjlab/assets/2_tibia_0_foot.STL differ diff --git a/models/superspider_mjlab/assets/3_coxa_0_pin1.STL b/models/superspider_mjlab/assets/3_coxa_0_pin1.STL new file mode 100644 index 0000000..d22fbd3 Binary files /dev/null and b/models/superspider_mjlab/assets/3_coxa_0_pin1.STL differ diff --git a/models/superspider_mjlab/assets/3_coxa_1_pin1.STL b/models/superspider_mjlab/assets/3_coxa_1_pin1.STL new file mode 100644 index 0000000..8a02958 Binary files /dev/null and b/models/superspider_mjlab/assets/3_coxa_1_pin1.STL differ diff --git a/models/superspider_mjlab/assets/3_femur_0_servo.STL b/models/superspider_mjlab/assets/3_femur_0_servo.STL new file mode 100644 index 0000000..5192560 Binary files /dev/null and b/models/superspider_mjlab/assets/3_femur_0_servo.STL differ diff --git a/models/superspider_mjlab/assets/3_femur_1_pin2.STL b/models/superspider_mjlab/assets/3_femur_1_pin2.STL new file mode 100644 index 0000000..ef0487e Binary files /dev/null and b/models/superspider_mjlab/assets/3_femur_1_pin2.STL differ diff --git a/models/superspider_mjlab/assets/3_femur_2_servo.STL b/models/superspider_mjlab/assets/3_femur_2_servo.STL new file mode 100644 index 0000000..f878eea Binary files /dev/null and b/models/superspider_mjlab/assets/3_femur_2_servo.STL differ diff --git a/models/superspider_mjlab/assets/3_femur_3_pin2.STL b/models/superspider_mjlab/assets/3_femur_3_pin2.STL new file mode 100644 index 0000000..27ef27e Binary files /dev/null and b/models/superspider_mjlab/assets/3_femur_3_pin2.STL differ diff --git a/models/superspider_mjlab/assets/3_tibia_0_foot.STL b/models/superspider_mjlab/assets/3_tibia_0_foot.STL new file mode 100644 index 0000000..f8d3588 Binary files /dev/null and b/models/superspider_mjlab/assets/3_tibia_0_foot.STL differ diff --git a/models/superspider_mjlab/assets/4_coxa_0_pin1.STL b/models/superspider_mjlab/assets/4_coxa_0_pin1.STL new file mode 100644 index 0000000..f63945f Binary files /dev/null and b/models/superspider_mjlab/assets/4_coxa_0_pin1.STL differ diff --git a/models/superspider_mjlab/assets/4_coxa_1_pin1.STL b/models/superspider_mjlab/assets/4_coxa_1_pin1.STL new file mode 100644 index 0000000..eb1d032 Binary files /dev/null and b/models/superspider_mjlab/assets/4_coxa_1_pin1.STL differ diff --git a/models/superspider_mjlab/assets/4_femur_0_servo.STL b/models/superspider_mjlab/assets/4_femur_0_servo.STL new file mode 100644 index 0000000..6b50fca Binary files /dev/null and b/models/superspider_mjlab/assets/4_femur_0_servo.STL differ diff --git a/models/superspider_mjlab/assets/4_femur_1_pin2.STL b/models/superspider_mjlab/assets/4_femur_1_pin2.STL new file mode 100644 index 0000000..42bbd22 Binary files /dev/null and b/models/superspider_mjlab/assets/4_femur_1_pin2.STL differ diff --git a/models/superspider_mjlab/assets/4_femur_2_servo.STL b/models/superspider_mjlab/assets/4_femur_2_servo.STL new file mode 100644 index 0000000..e7f48c3 Binary files /dev/null and b/models/superspider_mjlab/assets/4_femur_2_servo.STL differ diff --git a/models/superspider_mjlab/assets/4_femur_3_pin2.STL b/models/superspider_mjlab/assets/4_femur_3_pin2.STL new file mode 100644 index 0000000..8097b90 Binary files /dev/null and b/models/superspider_mjlab/assets/4_femur_3_pin2.STL differ diff --git a/models/superspider_mjlab/assets/4_tibia_0_foot.STL b/models/superspider_mjlab/assets/4_tibia_0_foot.STL new file mode 100644 index 0000000..16fe8ce Binary files /dev/null and b/models/superspider_mjlab/assets/4_tibia_0_foot.STL differ diff --git a/models/superspider_mjlab/assets/5_coxa_0_pin1.STL b/models/superspider_mjlab/assets/5_coxa_0_pin1.STL new file mode 100644 index 0000000..e66d059 Binary files /dev/null and b/models/superspider_mjlab/assets/5_coxa_0_pin1.STL differ diff --git a/models/superspider_mjlab/assets/5_coxa_1_pin1.STL b/models/superspider_mjlab/assets/5_coxa_1_pin1.STL new file mode 100644 index 0000000..ee59282 Binary files /dev/null and b/models/superspider_mjlab/assets/5_coxa_1_pin1.STL differ diff --git a/models/superspider_mjlab/assets/5_femur_0_servo.STL b/models/superspider_mjlab/assets/5_femur_0_servo.STL new file mode 100644 index 0000000..e54238f Binary files /dev/null and b/models/superspider_mjlab/assets/5_femur_0_servo.STL differ diff --git a/models/superspider_mjlab/assets/5_femur_1_pin2.STL b/models/superspider_mjlab/assets/5_femur_1_pin2.STL new file mode 100644 index 0000000..add4c5d Binary files /dev/null and b/models/superspider_mjlab/assets/5_femur_1_pin2.STL differ diff --git a/models/superspider_mjlab/assets/5_femur_2_servo.STL b/models/superspider_mjlab/assets/5_femur_2_servo.STL new file mode 100644 index 0000000..32c3707 Binary files /dev/null and b/models/superspider_mjlab/assets/5_femur_2_servo.STL differ diff --git a/models/superspider_mjlab/assets/5_femur_3_pin2.STL b/models/superspider_mjlab/assets/5_femur_3_pin2.STL new file mode 100644 index 0000000..15f9d87 Binary files /dev/null and b/models/superspider_mjlab/assets/5_femur_3_pin2.STL differ diff --git a/models/superspider_mjlab/assets/5_tibia_0_foot.STL b/models/superspider_mjlab/assets/5_tibia_0_foot.STL new file mode 100644 index 0000000..e154335 Binary files /dev/null and b/models/superspider_mjlab/assets/5_tibia_0_foot.STL differ diff --git a/models/superspider_mjlab/assets/6_coxa_0_pin1.STL b/models/superspider_mjlab/assets/6_coxa_0_pin1.STL new file mode 100644 index 0000000..6c62b80 Binary files /dev/null and b/models/superspider_mjlab/assets/6_coxa_0_pin1.STL differ diff --git a/models/superspider_mjlab/assets/6_coxa_1_pin1.STL b/models/superspider_mjlab/assets/6_coxa_1_pin1.STL new file mode 100644 index 0000000..69b0e8e Binary files /dev/null and b/models/superspider_mjlab/assets/6_coxa_1_pin1.STL differ diff --git a/models/superspider_mjlab/assets/6_femur_0_servo.STL b/models/superspider_mjlab/assets/6_femur_0_servo.STL new file mode 100644 index 0000000..a66f34d Binary files /dev/null and b/models/superspider_mjlab/assets/6_femur_0_servo.STL differ diff --git a/models/superspider_mjlab/assets/6_femur_1_pin2.STL b/models/superspider_mjlab/assets/6_femur_1_pin2.STL new file mode 100644 index 0000000..1525a9a Binary files /dev/null and b/models/superspider_mjlab/assets/6_femur_1_pin2.STL differ diff --git a/models/superspider_mjlab/assets/6_femur_2_servo.STL b/models/superspider_mjlab/assets/6_femur_2_servo.STL new file mode 100644 index 0000000..db101d7 Binary files /dev/null and b/models/superspider_mjlab/assets/6_femur_2_servo.STL differ diff --git a/models/superspider_mjlab/assets/6_femur_3_pin2.STL b/models/superspider_mjlab/assets/6_femur_3_pin2.STL new file mode 100644 index 0000000..6052c21 Binary files /dev/null and b/models/superspider_mjlab/assets/6_femur_3_pin2.STL differ diff --git a/models/superspider_mjlab/assets/6_tibia_0_foot.STL b/models/superspider_mjlab/assets/6_tibia_0_foot.STL new file mode 100644 index 0000000..37c27be Binary files /dev/null and b/models/superspider_mjlab/assets/6_tibia_0_foot.STL differ diff --git a/models/superspider_mjlab/assets/base_link_0_body.STL b/models/superspider_mjlab/assets/base_link_0_body.STL new file mode 100644 index 0000000..c09768f Binary files /dev/null and b/models/superspider_mjlab/assets/base_link_0_body.STL differ diff --git a/models/superspider_mjlab/assets/base_link_1_servo.STL b/models/superspider_mjlab/assets/base_link_1_servo.STL new file mode 100644 index 0000000..8890837 Binary files /dev/null and b/models/superspider_mjlab/assets/base_link_1_servo.STL differ diff --git a/models/superspider_mjlab/assets/base_link_2_servo.STL b/models/superspider_mjlab/assets/base_link_2_servo.STL new file mode 100644 index 0000000..5e6cbdd Binary files /dev/null and b/models/superspider_mjlab/assets/base_link_2_servo.STL differ diff --git a/models/superspider_mjlab/assets/base_link_3_servo.STL b/models/superspider_mjlab/assets/base_link_3_servo.STL new file mode 100644 index 0000000..11faa8b Binary files /dev/null and b/models/superspider_mjlab/assets/base_link_3_servo.STL differ diff --git a/models/superspider_mjlab/assets/base_link_4_servo.STL b/models/superspider_mjlab/assets/base_link_4_servo.STL new file mode 100644 index 0000000..c67fe28 Binary files /dev/null and b/models/superspider_mjlab/assets/base_link_4_servo.STL differ diff --git a/models/superspider_mjlab/assets/base_link_5_servo.STL b/models/superspider_mjlab/assets/base_link_5_servo.STL new file mode 100644 index 0000000..af61e06 Binary files /dev/null and b/models/superspider_mjlab/assets/base_link_5_servo.STL differ diff --git a/models/superspider_mjlab/assets/base_link_6_servo.STL b/models/superspider_mjlab/assets/base_link_6_servo.STL new file mode 100644 index 0000000..b269164 Binary files /dev/null and b/models/superspider_mjlab/assets/base_link_6_servo.STL differ diff --git a/models/superspider_mjlab/superspider.xml b/models/superspider_mjlab/superspider.xml new file mode 100644 index 0000000..5afbc3c --- /dev/null +++ b/models/superspider_mjlab/superspider.xml @@ -0,0 +1,257 @@ + + + + diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c98887d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,15 @@ +[build-system] +requires = ["setuptools>=68"] +build-backend = "setuptools.build_meta" + +[project] +name = "superspider-rl" +version = "0.1.0" +requires-python = ">=3.12" +dynamic = ["dependencies"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} + +[tool.setuptools.packages.find] +include = ["src*"] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2bf41d8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,12 @@ +mjlab==1.2.0 +mujoco==3.5.0 +mujoco-warp==3.5.0 +rsl-rl-lib==5.0.1 +torch==2.13.0 +numpy==2.5.2 +tyro==1.0.16 +warp-lang==1.12.1 +tensorboard==2.21.0 +onnx==1.22.0 +onnxscript==0.7.1 +wandb==0.28.2 diff --git a/scripts/__init__.py b/scripts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/play.py b/scripts/play.py new file mode 100644 index 0000000..e0d0338 --- /dev/null +++ b/scripts/play.py @@ -0,0 +1,208 @@ +"""Script to play RL agent with RSL-RL.""" + +import os +import sys +from dataclasses import asdict, dataclass +from pathlib import Path +from typing import Literal + +import torch +import tyro + +from mjlab.envs import ManagerBasedRlEnv +from mjlab.rl import MjlabOnPolicyRunner, RslRlVecEnvWrapper +from mjlab.tasks.registry import list_tasks, load_env_cfg, load_rl_cfg, load_runner_cls +from mjlab.tasks.tracking.mdp import MotionCommandCfg +from mjlab.utils.os import get_wandb_checkpoint_path +from mjlab.utils.torch import configure_torch_backends +from mjlab.utils.wrappers import VideoRecorder +from mjlab.viewer import NativeMujocoViewer, ViserPlayViewer + + +@dataclass(frozen=True) +class PlayConfig: + agent: Literal["zero", "random", "trained"] = "trained" + checkpoint_file: str | None = None + motion_file: str | None = None + num_envs: int | None = None + device: str | None = None + video: bool = False + video_length: int = 200 + video_height: int | None = None + video_width: int | None = None + camera: int | str | None = None + viewer: Literal["auto", "native", "viser"] = "auto" + no_terminations: bool = False + """Disable all termination conditions (useful for viewing motions with dummy agents).""" + + # Internal flag used by demo script. + _demo_mode: tyro.conf.Suppress[bool] = False + + +def run_play(task_id: str, cfg: PlayConfig): + configure_torch_backends() + + device = cfg.device or ("cuda:0" if torch.cuda.is_available() else "cpu") + + env_cfg = load_env_cfg(task_id, play=True) + agent_cfg = load_rl_cfg(task_id) + + DUMMY_MODE = cfg.agent in {"zero", "random"} + TRAINED_MODE = not DUMMY_MODE + + # Disable terminations if requested (useful for viewing motions). + if cfg.no_terminations: + env_cfg.terminations = {} + print("[INFO]: Terminations disabled") + + # Check if this is a tracking task by checking for motion command. + is_tracking_task = "motion" in env_cfg.commands and isinstance( + env_cfg.commands["motion"], MotionCommandCfg + ) + + if is_tracking_task and cfg._demo_mode: + # Demo mode: use uniform sampling to see more diversity with num_envs > 1. + motion_cmd = env_cfg.commands["motion"] + assert isinstance(motion_cmd, MotionCommandCfg) + motion_cmd.sampling_mode = "uniform" + + if is_tracking_task: + motion_cmd = env_cfg.commands["motion"] + assert isinstance(motion_cmd, MotionCommandCfg) + + # Check for local motion file first (works for both dummy and trained modes). + if cfg.motion_file is not None and Path(cfg.motion_file).exists(): + print(f"[INFO]: Using local motion file: {cfg.motion_file}") + motion_cmd.motion_file = cfg.motion_file + elif DUMMY_MODE: + if not cfg.registry_name: + raise ValueError( + "Tracking tasks require either:\n" + " --motion-file /path/to/motion.npz (local file)\n" + " --registry-name your-org/motions/motion-name (download from WandB)" + ) + log_dir: Path | None = None + resume_path: Path | None = None + if TRAINED_MODE: + log_root_path = (Path("logs") / "rsl_rl" / agent_cfg.experiment_name).resolve() + if cfg.checkpoint_file is not None: + resume_path = Path(cfg.checkpoint_file) + if not resume_path.exists(): + raise FileNotFoundError(f"Checkpoint file not found: {resume_path}") + print(f"[INFO]: Loading checkpoint: {resume_path.name}") + else: + if cfg.wandb_run_path is None: + raise ValueError( + "`wandb_run_path` is required when `checkpoint_file` is not provided." + ) + resume_path, was_cached = get_wandb_checkpoint_path( + log_root_path, Path(cfg.wandb_run_path) + ) + # Extract run_id and checkpoint name from path for display. + run_id = resume_path.parent.name + checkpoint_name = resume_path.name + cached_str = "cached" if was_cached else "downloaded" + print( + f"[INFO]: Loading checkpoint: {checkpoint_name} (run: {run_id}, {cached_str})" + ) + log_dir = resume_path.parent + + if cfg.num_envs is not None: + env_cfg.scene.num_envs = cfg.num_envs + if cfg.video_height is not None: + env_cfg.viewer.height = cfg.video_height + if cfg.video_width is not None: + env_cfg.viewer.width = cfg.video_width + + render_mode = "rgb_array" if (TRAINED_MODE and cfg.video) else None + if cfg.video and DUMMY_MODE: + print( + "[WARN] Video recording with dummy agents is disabled (no checkpoint/log_dir)." + ) + env = ManagerBasedRlEnv(cfg=env_cfg, device=device, render_mode=render_mode) + + if TRAINED_MODE and cfg.video: + print("[INFO] Recording videos during play") + assert log_dir is not None # log_dir is set in TRAINED_MODE block + env = VideoRecorder( + env, + video_folder=log_dir / "videos" / "play", + step_trigger=lambda step: step == 0, + video_length=cfg.video_length, + disable_logger=True, + ) + + env = RslRlVecEnvWrapper(env, clip_actions=agent_cfg.clip_actions) + if DUMMY_MODE: + action_shape: tuple[int, ...] = env.unwrapped.action_space.shape + if cfg.agent == "zero": + + class PolicyZero: + def __call__(self, obs) -> torch.Tensor: + del obs + return torch.zeros(action_shape, device=env.unwrapped.device) + + policy = PolicyZero() + else: + + class PolicyRandom: + def __call__(self, obs) -> torch.Tensor: + del obs + return 2 * torch.rand(action_shape, device=env.unwrapped.device) - 1 + + policy = PolicyRandom() + else: + runner_cls = load_runner_cls(task_id) or MjlabOnPolicyRunner + runner = runner_cls(env, asdict(agent_cfg), device=device) + from src.policy import load_policy + policy = load_policy(runner, resume_path, device) + + # Handle "auto" viewer selection. + if cfg.viewer == "auto": + has_display = bool(os.environ.get("DISPLAY") or os.environ.get("WAYLAND_DISPLAY")) + resolved_viewer = "native" if has_display else "viser" + del has_display + else: + resolved_viewer = cfg.viewer + + if resolved_viewer == "native": + NativeMujocoViewer(env, policy).run() + elif resolved_viewer == "viser": + ViserPlayViewer(env, policy).run() + else: + raise RuntimeError(f"Unsupported viewer backend: {resolved_viewer}") + + env.close() + + +def main(): + # Parse first argument to choose the task. + # Import tasks to populate the registry. + import mjlab.tasks # noqa: F401 + import src.tasks + + all_tasks = list_tasks() + chosen_task, remaining_args = tyro.cli( + tyro.extras.literal_type_from_choices(all_tasks), + add_help=False, + return_unknown_args=True, + config=mjlab.TYRO_FLAGS, + ) + + # Parse the rest of the arguments + allow overriding env_cfg and agent_cfg. + agent_cfg = load_rl_cfg(chosen_task) + + args = tyro.cli( + PlayConfig, + args=remaining_args, + default=PlayConfig(), + prog=sys.argv[0] + f" {chosen_task}", + config=mjlab.TYRO_FLAGS, + ) + del remaining_args, agent_cfg + + run_play(chosen_task, args) + + +if __name__ == "__main__": + main() diff --git a/scripts/superspider_blind_to_teacher.py b/scripts/superspider_blind_to_teacher.py new file mode 100644 index 0000000..42212ec --- /dev/null +++ b/scripts/superspider_blind_to_teacher.py @@ -0,0 +1,56 @@ +"""把【盲走】ckpt 扩成【teacher(带高度图)】的形状,扫描那部分权重置零。 + + .venv/bin/python scripts/superspider_blind_to_teacher.py + +为什么可以这么搬:teacher 的观测**前 65 维与盲走完全一致**,height_scan 是追加的 +(actor 在末尾 [65:318];critic 在中间 [65:318],特权项挪到 [318:393])。 +把对应列拷过去、扫描列置零 ⇒ **扩出来的网络与原网络逐点等价**(零权重的输入不贡献), +teacher 一开始就会走路,全部训练量用在"学会看高度图"上,不用从零学走路。 +(实测:从零训的 teacher 到 2400 迭代平地只能走 0.58m。) + +扫描部分的归一化统计置为 mean 0 / var 1 —— 不能沿用不存在的旧统计。 +""" +import sys +import torch + +BLIND, OUT = sys.argv[1], sys.argv[2] +A_BASE, SCAN, C_PRIV = 65, 253, 75 # 本体维 / 扫描维 / critic 特权维 + +ck = torch.load(BLIND, map_location="cpu", weights_only=False) + +def widen(sd, old_dim, new_dim, insert_at, n_ins): + """在第一层权重与归一化统计的 `insert_at` 处插入 n_ins 个零通道。""" + out = dict(sd) + w = sd["mlp.0.weight"] + assert w.shape[1] == old_dim, (w.shape, old_dim) + nw = torch.zeros((w.shape[0], new_dim), dtype=w.dtype) + nw[:, :insert_at] = w[:, :insert_at] + nw[:, insert_at + n_ins:] = w[:, insert_at:] + out["mlp.0.weight"] = nw + for key, fill in (("_mean", 0.0), ("_var", 1.0), ("_std", 1.0)): + k = "obs_normalizer." + key + if k not in sd: continue + v = sd[k] + nv = torch.full((1, new_dim), fill, dtype=v.dtype) + nv[:, :insert_at] = v[:, :insert_at] + nv[:, insert_at + n_ins:] = v[:, insert_at:] + out[k] = nv + return out + +# actor: 扫描接在末尾 +ck["actor_state_dict"] = widen(ck["actor_state_dict"], A_BASE, A_BASE + SCAN, A_BASE, SCAN) +# critic: 扫描插在本体项之后、特权项之前 +ck["critic_state_dict"] = widen(ck["critic_state_dict"], A_BASE + C_PRIV, + A_BASE + SCAN + C_PRIV, A_BASE, SCAN) +# 优化器的 Adam 动量缓存还是旧形状 (512,65),直接沿用会在第一次 step 就炸: +# RuntimeError: size of tensor a (65) must match tensor b (318) +# train.py 不传 load_cfg 会连优化器一起加载,所以这里把逐参数状态清空, +# 让 Adam 按新形状惰性重建(param_groups 里的超参保留)。 +if "optimizer_state_dict" in ck and isinstance(ck["optimizer_state_dict"], dict): + ck["optimizer_state_dict"]["state"] = {} +ck["iter"] = 0 # 计数归零,免得 max-iterations / 监控条件被偏移坑到 +torch.save(ck, OUT) +print("actor mlp.0.weight ->", tuple(ck["actor_state_dict"]["mlp.0.weight"].shape)) +print("critic mlp.0.weight ->", tuple(ck["critic_state_dict"]["mlp.0.weight"].shape)) +print("扫描列权重全零:", bool(ck["actor_state_dict"]["mlp.0.weight"][:, A_BASE:].abs().max() == 0)) +print("->", OUT) diff --git a/scripts/superspider_stair_test.py b/scripts/superspider_stair_test.py new file mode 100644 index 0000000..a8073fe --- /dev/null +++ b/scripts/superspider_stair_test.py @@ -0,0 +1,155 @@ +"""superspider 台阶能力测试 —— 极简场景,一眼能看懂。 + + MUJOCO_GL=egl .venv/bin/python scripts/superspider_stair_test.py [--task ...] + +为什么不用 mjlab 自带的 pyramid_stairs / _inv(2026-09-08 连栽三次): + ① `pyramid_stairs` 出生在**中心平台顶部**,往外走是**下坡**,测出来的"爬升"恒为 0; + ② `platform_width` 默认 **3.0 m**(中心平台半径 1.5m),机器人走 1.5~2m 都还没碰到 + 第一级台阶,却已经算完了; + ③ 缩小平台后终止频繁,**重置会把机器人传送到别的地形块**,`末位置-初位置` 变成 + 跨块累加的假数字(20s 算出走了 18m)。 + +这里的场景只有两块几何:一块平地 + 一级台阶(立面横跨整个 y,从 x=APPROACH 处起)。 +机器人在平地上出生、朝 +x 走,**只需看机身高度有没有升上台阶面**,没有任何歧义。 +判据:机身 z 稳定超过 台阶高×0.7 视为登顶(留 30% 余量给伺服下沉和姿态)。 +""" + +from __future__ import annotations + +import sys +from dataclasses import asdict, dataclass, replace + +import mujoco +import numpy as np +import torch + +import mjlab.tasks # noqa: F401 +import src.tasks # noqa: F401 +from mjlab.envs import ManagerBasedRlEnv +from mjlab.rl import MjlabOnPolicyRunner, RslRlVecEnvWrapper +from mjlab.tasks.registry import load_env_cfg, load_rl_cfg, load_runner_cls +from mjlab.terrains.terrain_generator import ( + SubTerrainCfg, + TerrainGeometry, + TerrainOutput, +) +from mjlab.terrains.utils import make_plane + +APPROACH = 1.5 # 出生点到台阶立面的距离 (m) + + +@dataclass(kw_only=True) +class SingleStepTerrainCfg(SubTerrainCfg): + """平地 + 一级台阶。台阶从 x=APPROACH 起一直延伸到地块边缘。""" + + step_height: float = 0.05 + + def function(self, difficulty, spec, rng) -> TerrainOutput: + del difficulty, rng + body = spec.body("terrain") + sx, sy = self.size + geoms = make_plane(body, self.size, 0.0, center_zero=False) + colors = [(0.45, 0.45, 0.48, 1.0)] + # 出生点放在地块靠 -x 的一侧,留 APPROACH 的助跑距离。 + ox = sx / 2.0 - APPROACH + step_len = sx - ox - APPROACH # 台阶从 ox+APPROACH 延伸到地块末端 + if self.step_height > 1e-6 and step_len > 0.1: + g = body.add_geom( + type=mujoco.mjtGeom.mjGEOM_BOX, + size=(step_len / 2.0, sy / 2.0, self.step_height / 2.0), + pos=(ox + APPROACH + step_len / 2.0, sy / 2.0, self.step_height / 2.0), + ) + geoms.append(g) + colors.append((0.85, 0.55, 0.25, 1.0)) + return TerrainOutput( + origin=np.array((ox, sy / 2.0, 0.0)), + geometries=[TerrainGeometry(geom=g, color=c) for g, c in zip(geoms, colors)], + ) + + +def run(task: str, ckpt: str, step_h: float, n: int = 24, secs: float = 20.0): + cfg = load_env_cfg(task, play=True) + cfg.scene.num_envs = n + tg = cfg.scene.terrain.terrain_generator + cfg.scene.terrain.terrain_generator = replace( + tg, + sub_terrains={"single_step": SingleStepTerrainCfg(size=(8.0, 8.0), step_height=step_h)}, + curriculum=False, + num_rows=2, + num_cols=2, + ) + cfg.scene.terrain.max_init_terrain_level = 0 + cfg.curriculum.pop("terrain_levels", None) + cfg.curriculum.pop("command_vel", None) + for ev in ("foot_friction", "base_com", "encoder_bias", "push_robot"): + cfg.events.pop(ev, None) + cfg.events["reset_base"].params["pose_range"] = {"x": (0, 0), "y": (0, 0), "yaw": (0, 0)} + tw = cfg.commands["twist"] + tw.heading_command = False + tw.ranges.heading = None + tw.resampling_time_range = (1e9, 1e9) + tw.rel_standing_envs = 0.0 + cfg.episode_length_s = secs + 1.0 # 别让 time_out 提前截断 + cfg.terminations.pop("illegal_contact", None) # 蹭到台阶立面不算失败,我们要看能不能上去 + + env = ManagerBasedRlEnv(cfg=cfg, device="cuda:0") + ac = load_rl_cfg(task) + w = RslRlVecEnvWrapper(env, clip_actions=ac.clip_actions) + r = (load_runner_cls(task) or MjlabOnPolicyRunner)(w, asdict(ac), device="cuda:0") + # ⚠ 蒸馏 ckpt 的键是 student_state_dict / teacher_state_dict, + # 传 load_cfg={"actor":True} 会**一个都加载不上而且不报错**,跑的是随机网络。 + import torch as _t + _keys = _t.load(ckpt, map_location="cpu", weights_only=False).keys() + _lc = ({"student": True, "teacher": True} if "student_state_dict" in _keys + else {"actor": True}) + r.load(ckpt, load_cfg=_lc, strict=True, map_location="cuda:0") + pol = r.get_inference_policy(device="cuda:0") + robot = env.scene["robot"] + term = env.command_manager.get_term("twist") + + obs, _ = w.reset() + z0 = robot.data.root_link_pos_w[:, 2].clone() + x0 = robot.data.root_link_pos_w[:, 0].clone() + steps = int(secs / env.step_dt) + # ⚠ 判据必须是**持续站在台阶面上**,不能是"一次性穿过阈值"。 + # 后者在策略摇晃时会被 z 的瞬间尖峰触发 —— 2026-09-09 实测:一个连平地都只能走 + # 0.57m 的半成品 teacher,被判成 2~5cm 全部"登顶 100%"。 + on_step = torch.zeros(n, device=env.device) + tot = 0 + thresh = step_h * 0.85 + for t_i in range(steps): + term.is_standing_env[:] = False + term.vel_command_b[:, 0] = 0.30 + term.vel_command_b[:, 1] = 0.0 + term.vel_command_b[:, 2] = 0.0 + with torch.no_grad(): + a = pol(obs) + obs, *_ = w.step(a) + if t_i > steps // 2: # 只统计后半程,给它时间走到台阶 + on_step += ((robot.data.root_link_pos_w[:, 2] - z0) > thresh).float() + tot += 1 + dx = (robot.data.root_link_pos_w[:, 0] - x0).cpu().numpy() + dz = (robot.data.root_link_pos_w[:, 2] - z0).cpu().numpy() + frac = (on_step / max(tot, 1)).cpu().numpy() + env.close() + # 登顶 = 后半程 80% 以上时间都在台阶面上 + return float((frac > 0.8).mean()), float(np.median(dx)), float(np.median(dz)) + + +def main() -> None: + ckpt = sys.argv[1] + task = sys.argv[sys.argv.index("--task") + 1] if "--task" in sys.argv else "Custom-Superspider-Rough" + print(f"场景:平地 + 单级台阶(助跑 {APPROACH} m),指令 vx=0.30,24 环境 × 20 s") + print(f"任务:{task}\nckpt:{ckpt}\n") + print("%-9s %-12s %-14s %s" % ("台阶高", "登顶率", "前进(中位)", "净爬升(中位)")) + hs = sys.argv[sys.argv.index("--heights") + 1] if "--heights" in sys.argv else None + heights = [float(x) for x in hs.split(",")] if hs else [0.0, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07] + for h in heights: + rate, dx, dz = run(task, ckpt, h) + tag = " ← 平地对照" if h == 0.0 else "" + print("%-9s %-12s %-14s %s%s" % ( + "%.0f cm" % (h * 100), "%.0f%%" % (rate * 100), "%.2f m" % dx, "%+.0f mm" % (dz * 1000), tag)) + + +if __name__ == "__main__": + main() diff --git a/scripts/superspider_teleop.py b/scripts/superspider_teleop.py new file mode 100644 index 0000000..d1d3ba3 --- /dev/null +++ b/scripts/superspider_teleop.py @@ -0,0 +1,106 @@ +"""Superspider simulation keyboard control. W/S: speed, A/D: yaw, Q/E: lateral, +C: center steering, X/Space: zero command, L: toggle steering latch. +Zero command is not a hardware emergency stop. +""" +import sys +from dataclasses import asdict, dataclass +from pathlib import Path + +import torch +import tyro + +from mjlab.envs import ManagerBasedRlEnv +from mjlab.rl import MjlabOnPolicyRunner, RslRlVecEnvWrapper +from mjlab.tasks.registry import list_tasks, load_env_cfg, load_rl_cfg, load_runner_cls +from mjlab.utils.torch import configure_torch_backends +from mjlab.viewer import NativeMujocoViewer + +TASK = "Custom-Superspider-Flat" +VX_STEP, VY_STEP, WZ_STEP = 0.05, 0.03, 0.10 +VX_RANGE, VY_RANGE, WZ_RANGE = (-0.25, 0.40), (-0.15, 0.15), (-0.8, 0.8) +K_RIGHT, K_LEFT, K_DOWN, K_UP, K_SPACE = 262, 263, 264, 265, 32 +DECAY = 0.98 # 转向/横移每策略步(50Hz)乘的衰减 ⇒ 半衰期 ~0.7s +DEADZONE = 0.01 # 衰减到此以下直接归零,不留尾巴 + + +@dataclass(frozen=True) +class Cfg: + checkpoint_file: str = "checkpoints/student_5999.pt" + task: str = "Custom-Superspider-Stairs-Distill" + device: str | None = None + + +class Teleop: + def __init__(self, policy, env: ManagerBasedRlEnv): + self._p = policy + self._robot = env.scene["robot"] + self._latch = False # False=方向盘回正,True=全部保持 + self._n = 0 + self._t = env.command_manager.get_term("twist") + self._t.cfg.heading_command = False + self._t.cfg.resampling_time_range = (1e9, 1e9) + self._cmd = torch.zeros(3, device=env.device) + ranges = self._t.cfg.ranges + self.ranges = ((min(0.0, ranges.lin_vel_x[0]), ranges.lin_vel_x[1]), ranges.lin_vel_y, ranges.ang_vel_z) + + def _show(self): + vx, vy, wz = self._cmd.tolist() + v = self._robot.data.root_com_lin_vel_b[0, :2].tolist() + w = float(self._robot.data.root_com_ang_vel_b[0, 2]) + print(f"\r[{'保持' if self._latch else '回正'}] 指令 vx={vx:+.2f} vy={vy:+.2f} wz={wz:+.2f}" + f" | 实测 vx={v[0]:+.3f} vy={v[1]:+.3f} wz={w:+.2f} ", end="", flush=True) + + def key_callback(self, key: int) -> None: + c = chr(key).upper() if 0 <= key < 256 else "" + if key == K_UP or c == "W": self._cmd[0] += VX_STEP + elif key == K_DOWN or c == "S": self._cmd[0] -= VX_STEP + elif key == K_LEFT or c == "A": self._cmd[2] += WZ_STEP + elif key == K_RIGHT or c == "D": self._cmd[2] -= WZ_STEP + elif c == "Q": self._cmd[1] += VY_STEP + elif c == "E": self._cmd[1] -= VY_STEP + elif c == "C": self._cmd[1] = 0.0; self._cmd[2] = 0.0 + elif c == "L": self._latch = not self._latch + elif c == "X" or key == K_SPACE: self._cmd[:] = 0.0 + else: return + self._cmd[0].clamp_(*self.ranges[0]) + self._cmd[1].clamp_(*self.ranges[1]) + self._cmd[2].clamp_(*self.ranges[2]) + self._show() + + def __call__(self, obs) -> torch.Tensor: + if not self._latch: # 方向盘回正 + self._cmd[1:] *= DECAY + self._cmd[1:][self._cmd[1:].abs() < DEADZONE] = 0.0 + self._n += 1 + if self._n % 10 == 0: # 5Hz 刷新,顺带显示实测速度 + self._show() + # 每帧都清:这三个 buffer 里任何一个没清干净,指令都会被悄悄改写 + self._t.is_standing_env[:] = False # 否则该 env 的指令被强制归零 + self._t.is_heading_env[:] = False # 否则 wz 被航向控制器覆写 ⇒ X 停不下来 + self._t.vel_command_b[:] = self._cmd + return self._p(obs) + + +def main() -> None: + import mjlab.tasks, src.tasks, mjlab # noqa: F401 + configure_torch_backends() + args = tyro.cli(Cfg, config=mjlab.TYRO_FLAGS) + device = args.device or ("cuda:0" if torch.cuda.is_available() else "cpu") + ck = Path(args.checkpoint_file) + if not ck.exists(): raise FileNotFoundError(ck) + env_cfg = load_env_cfg(args.task, play=True); env_cfg.scene.num_envs = 1 + env_cfg.curriculum.pop("command_vel", None) # 别让课程再改范围 + agent_cfg = load_rl_cfg(args.task) + env = ManagerBasedRlEnv(cfg=env_cfg, device=device) + w = RslRlVecEnvWrapper(env, clip_actions=agent_cfg.clip_actions) + runner = (load_runner_cls(args.task) or MjlabOnPolicyRunner)(w, asdict(agent_cfg), device=device) + from src.policy import load_policy + tele = Teleop(load_policy(runner, ck, device), env) + print(__doc__) + print(f"ckpt: {ck.name}") + NativeMujocoViewer(w, tele, key_callback=tele.key_callback).run() + env.close() + + +if __name__ == "__main__": + main() diff --git a/scripts/train.py b/scripts/train.py new file mode 100644 index 0000000..f727e28 --- /dev/null +++ b/scripts/train.py @@ -0,0 +1,222 @@ +"""Script to train RL agent with RSL-RL.""" + +import logging +import os +import sys +from dataclasses import asdict, dataclass, field +from datetime import datetime +from pathlib import Path +from typing import Literal, cast + +import tyro + +from mjlab.envs import ManagerBasedRlEnv, ManagerBasedRlEnvCfg +from mjlab.rl import MjlabOnPolicyRunner, RslRlBaseRunnerCfg, RslRlVecEnvWrapper +from mjlab.tasks.registry import list_tasks, load_env_cfg, load_rl_cfg, load_runner_cls +from mjlab.tasks.tracking.mdp import MotionCommandCfg +from mjlab.utils.gpu import select_gpus +from mjlab.utils.os import dump_yaml, get_checkpoint_path +from mjlab.utils.torch import configure_torch_backends +from mjlab.utils.wrappers import VideoRecorder + + +@dataclass(frozen=True) +class TrainConfig: + env: ManagerBasedRlEnvCfg + agent: RslRlBaseRunnerCfg + motion_file: str | None = None + video: bool = False + video_length: int = 200 + video_interval: int = 2000 + enable_nan_guard: bool = False + torchrunx_log_dir: str | None = None + gpu_ids: list[int] | Literal["all"] | None = field(default_factory=lambda: [0]) + + @staticmethod + def from_task(task_id: str) -> "TrainConfig": + env_cfg = load_env_cfg(task_id) + agent_cfg = load_rl_cfg(task_id) + return TrainConfig(env=env_cfg, agent=agent_cfg) + + +def run_train(task_id: str, cfg: TrainConfig, log_dir: Path) -> None: + cuda_visible = os.environ.get("CUDA_VISIBLE_DEVICES", "") + if cuda_visible == "": + device = "cpu" + seed = cfg.agent.seed + rank = 0 + else: + local_rank = int(os.environ.get("LOCAL_RANK", "0")) + rank = int(os.environ.get("RANK", "0")) + # Set EGL device to match the CUDA device. + os.environ["MUJOCO_EGL_DEVICE_ID"] = str(local_rank) + device = f"cuda:{local_rank}" + # Set seed to have diversity in different processes. + seed = cfg.agent.seed + local_rank + + configure_torch_backends() + + cfg.agent.seed = seed + cfg.env.seed = seed + + print(f"[INFO] Training with: device={device}, seed={seed}, rank={rank}") + + # Check if this is a tracking task by checking for motion command. + is_tracking_task = "motion" in cfg.env.commands and isinstance( + cfg.env.commands["motion"], MotionCommandCfg + ) + + if is_tracking_task: + if not cfg.motion_file: + raise ValueError("For tracking tasks, --motion-file must be set ...") + motion_path = Path(cfg.motion_file).expanduser().resolve() + if not motion_path.exists(): + raise FileNotFoundError(f"Motion file not found: {motion_path}") + motion_cmd = cfg.env.commands["motion"] + assert isinstance(motion_cmd, MotionCommandCfg) + motion_cmd.motion_file = str(motion_path) + print(f"[INFO] Using motion file: {motion_cmd.motion_file}") + + # Check if motion_file is already set (e.g., via CLI --env.commands.motion.motion-file). + if motion_cmd.motion_file and Path(motion_cmd.motion_file).exists(): + print(f"[INFO] Using local motion file: {motion_cmd.motion_file}") + + # Enable NaN guard if requested. + if cfg.enable_nan_guard: + cfg.env.sim.nan_guard.enabled = True + print(f"[INFO] NaN guard enabled, output dir: {cfg.env.sim.nan_guard.output_dir}") + + if rank == 0: + print(f"[INFO] Logging experiment in directory: {log_dir}") + + env = ManagerBasedRlEnv( + cfg=cfg.env, device=device, render_mode="rgb_array" if cfg.video else None + ) + + log_root_path = log_dir.parent # Go up from specific run dir to experiment dir. + + resume_path: Path | None = None + if cfg.agent.resume: + # Load checkpoint from local filesystem. + resume_path = get_checkpoint_path( + log_root_path, cfg.agent.load_run, cfg.agent.load_checkpoint + ) + + # Only record videos on rank 0 to avoid multiple workers writing to the same files. + if cfg.video and rank == 0: + env = VideoRecorder( + env, + video_folder=Path(log_dir) / "videos" / "train", + step_trigger=lambda step: step % cfg.video_interval == 0, + video_length=cfg.video_length, + disable_logger=True, + ) + print("[INFO] Recording videos during training.") + + env = RslRlVecEnvWrapper(env, clip_actions=cfg.agent.clip_actions) + + agent_cfg = asdict(cfg.agent) + env_cfg = asdict(cfg.env) + + runner_cls = load_runner_cls(task_id) + if runner_cls is None: + runner_cls = MjlabOnPolicyRunner + + runner_kwargs = {} + runner = runner_cls(env, agent_cfg, str(log_dir), device, **runner_kwargs) + + runner.add_git_repo_to_log(__file__) + if resume_path is not None: + print(f"[INFO]: Loading model checkpoint from: {resume_path}") + runner.load(str(resume_path)) + + # Only write config files from rank 0 to avoid race conditions. + if rank == 0: + dump_yaml(log_dir / "params" / "env.yaml", env_cfg) + dump_yaml(log_dir / "params" / "agent.yaml", agent_cfg) + + runner.learn( + num_learning_iterations=cfg.agent.max_iterations, init_at_random_ep_len=True + ) + + env.close() + + +def launch_training(task_id: str, args: TrainConfig | None = None): + args = args or TrainConfig.from_task(task_id) + + # Create log directory once before launching workers. + log_root_path = Path("logs") / "rsl_rl" / args.agent.experiment_name + log_root_path.resolve() + log_dir_name = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + if args.agent.run_name: + log_dir_name += f"_{args.agent.run_name}" + log_dir = log_root_path / log_dir_name + + # Select GPUs based on CUDA_VISIBLE_DEVICES and user specification. + selected_gpus, num_gpus = select_gpus(args.gpu_ids) + + # Set environment variables for all modes. + if selected_gpus is None: + os.environ["CUDA_VISIBLE_DEVICES"] = "" + else: + os.environ["CUDA_VISIBLE_DEVICES"] = ",".join(map(str, selected_gpus)) + os.environ["MUJOCO_GL"] = "egl" + + if num_gpus <= 1: + # CPU or single GPU: run directly without torchrunx. + run_train(task_id, args, log_dir) + else: + # Multi-GPU: use torchrunx. + import torchrunx + + # torchrunx redirects stdout to logging. + logging.basicConfig(level=logging.INFO) + + # Configure torchrunx logging directory. + # Priority: 1) existing env var, 2) user flag, 3) default to {log_dir}/torchrunx. + if "TORCHRUNX_LOG_DIR" not in os.environ: + if args.torchrunx_log_dir is not None: + # User specified a value via flag (could be "" to disable). + os.environ["TORCHRUNX_LOG_DIR"] = args.torchrunx_log_dir + else: + # Default: put logs in training directory. + os.environ["TORCHRUNX_LOG_DIR"] = str(log_dir / "torchrunx") + + print(f"[INFO] Launching training with {num_gpus} GPUs", flush=True) + torchrunx.Launcher( + hostnames=["localhost"], + workers_per_host=num_gpus, + backend=None, # Let rsl_rl handle process group initialization. + copy_env_vars=torchrunx.DEFAULT_ENV_VARS_FOR_COPY + ("MUJOCO*",), + ).run(run_train, task_id, args, log_dir) + + +def main(): + # Parse first argument to choose the task. + # Import tasks to populate the registry. + import mjlab.tasks # noqa: F401 + import src.tasks + + all_tasks = list_tasks() + chosen_task, remaining_args = tyro.cli( + tyro.extras.literal_type_from_choices(all_tasks), + add_help=False, + return_unknown_args=True, + config=mjlab.TYRO_FLAGS, + ) + + args = tyro.cli( + TrainConfig, + args=remaining_args, + default=TrainConfig.from_task(chosen_task), + prog=sys.argv[0] + f" {chosen_task}", + config=mjlab.TYRO_FLAGS, + ) + del remaining_args + + launch_training(task_id=chosen_task, args=args) + + +if __name__ == "__main__": + main() diff --git a/scripts/train_stage.py b/scripts/train_stage.py new file mode 100644 index 0000000..88c866d --- /dev/null +++ b/scripts/train_stage.py @@ -0,0 +1,43 @@ +"""Run the archived Superspider training stages.""" +import argparse +import shutil +from pathlib import Path +import src.tasks +from scripts.train import TrainConfig, launch_training + +ROOT = Path(__file__).resolve().parents[1] + +def main(): + p = argparse.ArgumentParser(description=__doc__) + p.add_argument("stage", choices=["flat", "blind", "teacher", "student"]) + p.add_argument("--checkpoint", type=Path) + p.add_argument("--iterations", type=int) + p.add_argument("--num-envs", type=int) + a = p.parse_args() + tasks = {"flat":"Flat", "blind":"Stairs", "teacher":"Stairs-Teacher", "student":"Stairs-Distill"} + task = "Custom-Superspider-" + tasks[a.stage] + cfg = TrainConfig.from_task(task) + cfg.env.scene.num_envs = a.num_envs or (1024 if a.stage == "flat" else 512) + cfg.agent.seed = 42 + cfg.agent.logger = "tensorboard" + cfg.agent.max_iterations = a.iterations or {"flat":6000,"blind":4002,"teacher":3801,"student":6000}[a.stage] + cfg.agent.save_interval = 200 if a.stage == "student" else 100 + cfg.agent.upload_model = False + defaults = {"blind":"flat_5999.pt", "teacher":"blind_10000.pt", "student":"teacher_3800.pt"} + if a.stage != "flat": + source = (a.checkpoint or ROOT / "checkpoints" / defaults[a.stage]).resolve() + if not source.is_file(): raise FileNotFoundError(source) + seed_dir = Path("logs/rsl_rl") / cfg.agent.experiment_name / "seed_import" + seed_dir.mkdir(parents=True, exist_ok=True) + target = seed_dir / "model_0.pt" + if a.stage == "teacher": + import subprocess, sys + subprocess.run([sys.executable, str(ROOT/"scripts/superspider_blind_to_teacher.py"), str(source), str(target)], check=True) + else: + shutil.copy2(source, target) + cfg.agent.resume = True + cfg.agent.load_run = "seed_import" + cfg.agent.load_checkpoint = "model_0.pt" + launch_training(task, cfg) + +if __name__ == "__main__": main() diff --git a/scripts/verify.py b/scripts/verify.py new file mode 100644 index 0000000..da10019 --- /dev/null +++ b/scripts/verify.py @@ -0,0 +1,50 @@ +"""Check model resources, checkpoint loading and a short simulation rollout.""" +from pathlib import Path +from dataclasses import asdict +import hashlib,json,xml.etree.ElementTree as ET +import mujoco,torch +import src.tasks +from mjlab.envs import ManagerBasedRlEnv +from mjlab.rl import RslRlVecEnvWrapper +from mjlab.tasks.registry import load_env_cfg,load_rl_cfg,load_runner_cls +from src.policy import load_policy + +ROOT=Path(__file__).resolve().parents[1] +def main(): + result={} + urdf=ROOT/'models/superspider/superspider.urdf' + tree=ET.parse(urdf) + for mesh in tree.findall('.//mesh'): + assert (urdf.parent/mesh.attrib['filename']).is_file() + model=mujoco.MjModel.from_xml_path(str(urdf)) + assert model.njnt==18 + result['urdf']={'links':len(tree.findall('link')),'joints':model.njnt} + model=mujoco.MjModel.from_xml_path(str(ROOT/'models/superspider_mjlab/superspider.xml')) + result['mjcf']={'nq':model.nq,'nv':model.nv} + for entry in json.loads((ROOT/'checkpoints/manifest.json').read_text()): + assert hashlib.sha256((ROOT/entry['file']).read_bytes()).hexdigest()==entry['sha256'] + result['checkpoint_hashes']=5 + device='cuda:0' if torch.cuda.is_available() else 'cpu' + for task,files in [('Custom-Superspider-Stairs-Distill',['student_5999.pt','student_1600.pt']),('Custom-Superspider-Flat',['flat_5999.pt']),('Custom-Superspider-Stairs-Teacher',['teacher_3800.pt']),('Custom-Superspider-Stairs',['blind_10000.pt'])]: + cfg=load_env_cfg(task,play=True);cfg.scene.num_envs=1 + agent=load_rl_cfg(task) + env=ManagerBasedRlEnv(cfg,device=device) + wrapped=RslRlVecEnvWrapper(env,clip_actions=agent.clip_actions) + runner=load_runner_cls(task)(wrapped,asdict(agent),device=device) + for name in files: + path=ROOT/'checkpoints'/name + policy=load_policy(runner,path,device) + saved=torch.load(path,map_location=device,weights_only=False) + key='student' if 'student_state_dict' in saved else 'actor' + loaded=getattr(runner.alg,key).state_dict() + assert all(torch.equal(loaded[k],v) for k,v in saved[key+'_state_dict'].items()) + obs,_=wrapped.reset() + with torch.no_grad(): + for _ in range(8): + action=policy(obs);assert action.shape==(1,18) and torch.isfinite(action).all() + obs,*_=wrapped.step(action) + result[name]={'loaded_exactly':True,'actions':18,'simulation_steps':8} + env.close() + print('VERIFICATION_JSON '+json.dumps(result)) + +if __name__=='__main__':main() diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/policy.py b/src/policy.py new file mode 100644 index 0000000..ccb282b --- /dev/null +++ b/src/policy.py @@ -0,0 +1,15 @@ +"""Strict checkpoint loading for PPO and distilled policies.""" +from pathlib import Path +import torch + +def load_policy(runner, checkpoint, device): + checkpoint = Path(checkpoint) + state = torch.load(checkpoint, map_location="cpu", weights_only=False) + distilled = "student_state_dict" in state + if distilled != hasattr(runner.alg, "student"): + raise ValueError("Checkpoint/task mismatch: select Stairs-Distill for student weights, or the matching PPO task.") + if not distilled and "actor_state_dict" not in state: + raise ValueError("No actor or student in checkpoint") + load_cfg = {"student": True, "teacher": True} if distilled else {"actor": True} + runner.load(str(checkpoint), load_cfg=load_cfg, strict=True, map_location=device) + return runner.get_inference_policy(device=device) diff --git a/src/tasks/__init__.py b/src/tasks/__init__.py new file mode 100644 index 0000000..7e3decf --- /dev/null +++ b/src/tasks/__init__.py @@ -0,0 +1 @@ +from .velocity.config.custom_dog.dogs import superspider # noqa: F401 diff --git a/src/tasks/velocity/__init__.py b/src/tasks/velocity/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/tasks/velocity/config/__init__.py b/src/tasks/velocity/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/tasks/velocity/config/custom_dog/__init__.py b/src/tasks/velocity/config/custom_dog/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/tasks/velocity/config/custom_dog/builder.py b/src/tasks/velocity/config/custom_dog/builder.py new file mode 100644 index 0000000..abd49ec --- /dev/null +++ b/src/tasks/velocity/config/custom_dog/builder.py @@ -0,0 +1,363 @@ +"""Build and register velocity tasks from a QuadrupedDescriptor.""" + +import math +from dataclasses import replace + +import mujoco + +from mjlab.actuator import BuiltinPositionActuatorCfg +from mjlab.entity import EntityArticulationInfoCfg, EntityCfg +from mjlab.envs import ManagerBasedRlEnvCfg +from mjlab.envs import mdp as envs_mdp +from mjlab.envs.mdp.actions import JointPositionActionCfg +from mjlab.managers import TerminationTermCfg +from mjlab.managers.event_manager import EventTermCfg +from mjlab.managers.scene_entity_config import SceneEntityCfg +from mjlab.rl import RslRlOnPolicyRunnerCfg +from mjlab.sensor import ContactMatch, ContactSensorCfg, RayCastSensorCfg +from mjlab.tasks.registry import register_mjlab_task +from mjlab.tasks.velocity import mdp as mjlab_vel_mdp +from mjlab.utils.os import update_assets +from mjlab.utils.spec_config import CollisionCfg + +import src.tasks.velocity.mdp as mdp +from src.tasks.velocity.config.go2.rl_cfg import unitree_go2_ppo_runner_cfg +from src.tasks.velocity.rl import VelocityOnPolicyRunner +from src.tasks.velocity.velocity_env_cfg import make_velocity_env_cfg + +from .descriptor import QuadrupedDescriptor + +# Registered descriptors by name (the pick-and-place demo looks dogs up here). +DOG_REGISTRY: dict[str, QuadrupedDescriptor] = {} + + +def _ensure_builtin_sensors(spec: mujoco.MjSpec, base_body: str) -> None: + """Add the imu/angmom sensors the velocity task observations rely on.""" + sensor_names = {s.name for s in spec.sensors} + site_names = {s.name for s in spec.sites} + if "imu" not in site_names: + spec.body(base_body).add_site(name="imu", pos=[0, 0, 0], group=5) + def add(name, stype, objtype, objname): + if name not in sensor_names: + spec.add_sensor(name=name, type=stype, objtype=objtype, objname=objname) + + add("imu_ang_vel", mujoco.mjtSensor.mjSENS_GYRO, + mujoco.mjtObj.mjOBJ_SITE, "imu") + add("imu_lin_vel", mujoco.mjtSensor.mjSENS_VELOCIMETER, + mujoco.mjtObj.mjOBJ_SITE, "imu") + add("imu_lin_acc", mujoco.mjtSensor.mjSENS_ACCELEROMETER, + mujoco.mjtObj.mjOBJ_SITE, "imu") + add("root_angmom", mujoco.mjtSensor.mjSENS_SUBTREEANGMOM, + mujoco.mjtObj.mjOBJ_BODY, base_body) + + +def _make_robot_cfg( + desc: QuadrupedDescriptor, with_arm: bool, grasp: bool = False +) -> EntityCfg: + if with_arm or grasp: + raise ValueError("This package contains the Superspider legs-only model.") + foot_regex = "^(" + "|".join(desc.foot_geom_names) + ")$" + gripper_regex = "^arm_(fixed_jaw|moving_jaw)_.*$" + + def spec_fn() -> mujoco.MjSpec: + spec = mujoco.MjSpec.from_file(str(desc.xml_path)) + if desc.spec_postprocess is not None: + desc.spec_postprocess(spec) + # mjlab 的 disable_other_geoms 按名字匹配,无名 geom(URDF 导入默认 + # contype/conaffinity=1/1)会漏网形成幽灵碰撞对(实测:ANYmal 前臂压脸, + # 肘部被 2.94Nm 接触力顶死)。这里从源头显式禁用所有无名 geom。 + for _b in spec.bodies: + for _g in _b.geoms: + if not _g.name: + _g.contype = 0 + _g.conaffinity = 0 + _ensure_builtin_sensors(spec, desc.base_body) + assets: dict[str, bytes] = {} + asset_dir = desc.xml_path.parent / "assets" + if asset_dir.is_dir(): + update_assets(assets, asset_dir, spec.meshdir) + if with_arm: + arm = mujoco.MjSpec.from_file(str(SO101_XML)) + for act in list(arm.actuators): + arm.delete(act) + frame = spec.body(desc.base_body).add_frame(pos=list(desc.arm_mount_pos)) + frame.attach_body(arm.body("base"), "arm_", "") + update_assets(assets, SO101_XML.parent / "assets", spec.meshdir) + spec.assets = assets + return spec + + if grasp: + # Pick-and-place variant: enable the SO-101 gripper contact geoms with + # the Menagerie-tuned parameters. + collision = CollisionCfg( + geom_names_expr=(desc.collision_geom_regex, foot_regex, gripper_regex), + condim={foot_regex: 3, gripper_regex: 6, desc.collision_geom_regex: 1}, + priority={foot_regex: 1, gripper_regex: 2}, + friction={foot_regex: (0.6,), gripper_regex: (1.0, 5e-3, 5e-4)}, + solref={gripper_regex: (0.01, 1.0)}, + solimp={foot_regex: (0.9, 0.95, 0.023)}, + contype=1, + conaffinity=0, + ) + else: + collision = CollisionCfg( + geom_names_expr=(desc.collision_geom_regex, foot_regex), + condim={foot_regex: 3, desc.collision_geom_regex: 1}, + priority={foot_regex: 1}, + friction={foot_regex: (0.6,)}, + solimp={foot_regex: (0.9, 0.95, 0.023)}, + contype=1, + conaffinity=0, + ) + + joint_pos = dict(desc.standing_joint_pos) + actuators = [ + BuiltinPositionActuatorCfg( + target_names_expr=tuple(g.joint_regex), + stiffness=g.stiffness, + damping=g.damping, + effort_limit=g.effort_limit, + armature=g.armature, + ) + for g in desc.actuator_groups + ] + if with_arm: + joint_pos.update(ARM_CARRY_POSE) + actuators.append(SO101_ACTUATOR_SOFT) + + return EntityCfg( + init_state=EntityCfg.InitialStateCfg( + pos=(0.0, 0.0, desc.standing_height), + joint_pos=joint_pos, + joint_vel={".*": 0.0}, + ), + collisions=(collision,), + spec_fn=spec_fn, + articulation=EntityArticulationInfoCfg( + actuators=tuple(actuators), + soft_joint_pos_limit_factor=0.9, + ), + ) + + +def _rough_env_cfg( + desc: QuadrupedDescriptor, play: bool, with_arm: bool +) -> ManagerBasedRlEnvCfg: + cfg = make_velocity_env_cfg() + cfg.sim.mujoco.ccd_iterations = 500 + cfg.sim.contact_sensor_maxmatch = 500 + cfg.scene.entities = {"robot": _make_robot_cfg(desc, with_arm)} + + for sensor in cfg.scene.sensors or (): + if sensor.name == "terrain_scan": + assert isinstance(sensor, RayCastSensorCfg) + sensor.frame.name = desc.base_body + + feet_ground_cfg = ContactSensorCfg( + name="feet_ground_contact", + primary=ContactMatch( + mode="geom", pattern=tuple(desc.foot_geom_names), entity="robot" + ), + secondary=ContactMatch(mode="body", pattern="terrain"), + fields=("found", "force"), + reduce="netforce", + num_slots=1, + track_air_time=True, + ) + nonfoot_ground_cfg = ContactSensorCfg( + name="nonfoot_ground_touch", + primary=ContactMatch( + mode="geom", + entity="robot", + pattern=desc.collision_geom_regex, + exclude=tuple(desc.foot_geom_names), + ), + secondary=ContactMatch(mode="body", pattern="terrain"), + fields=("found", "force"), + reduce="none", + num_slots=1, + history_length=4, + ) + cfg.scene.sensors = (cfg.scene.sensors or ()) + ( + feet_ground_cfg, + nonfoot_ground_cfg, + ) + + if cfg.scene.terrain is not None and cfg.scene.terrain.terrain_generator is not None: + cfg.scene.terrain.terrain_generator.curriculum = True + + action = cfg.actions["joint_pos"] + assert isinstance(action, JointPositionActionCfg) + action.actuator_names = tuple(desc.leg_joint_regex) + action.scale = desc.action_scale + + cfg.viewer.body_name = desc.base_body + cfg.viewer.distance = 1.5 + cfg.viewer.elevation = -10.0 + + cfg.observations["critic"].terms["foot_height"].params[ + "asset_cfg" + ].site_names = tuple(desc.foot_site_names) + + cfg.events["foot_friction"].params["asset_cfg"].geom_names = tuple( + desc.foot_geom_names + ) + cfg.events["foot_friction"].params["ranges"] = desc.foot_friction_range + cfg.events["base_com"].params["asset_cfg"].body_names = (desc.base_body,) + + legs = tuple(desc.leg_joint_regex) + cfg.rewards["pose"].params["asset_cfg"].joint_names = legs + cfg.rewards["pose"].params["std_standing"] = { + r: desc.posture_std_standing for r in legs + } + cfg.rewards["pose"].params["std_walking"] = { + r: desc.posture_std_walking for r in legs + } + cfg.rewards["pose"].params["std_running"] = { + r: desc.posture_std_walking for r in legs + } + cfg.rewards["stand_still"].params["asset_cfg"].joint_names = legs + cfg.rewards["foot_gait"].params["offset"] = list(desc.gait_offsets) + cfg.rewards["body_orientation_l2"].params["asset_cfg"].body_names = ( + desc.base_body, + ) + cfg.rewards["body_ang_vel"].params["asset_cfg"].body_names = (desc.base_body,) + cfg.rewards["foot_clearance"].params["target_height"] = desc.foot_clearance + cfg.rewards["foot_clearance"].params["asset_cfg"].site_names = tuple( + desc.foot_site_names + ) + cfg.rewards["foot_slip"].params["asset_cfg"].site_names = tuple( + desc.foot_site_names + ) + + cfg.terminations["illegal_contact"] = TerminationTermCfg( + func=mjlab_vel_mdp.illegal_contact, + params={"sensor_name": nonfoot_ground_cfg.name, "force_threshold": 10.0}, + ) + + if with_arm: + # Legs-only policy IO + arm mass/pose randomization (arm-agnostic). + for name in ("joint_pos", "joint_vel"): + cfg.observations["actor"].terms[name].params["asset_cfg"] = ( + SceneEntityCfg("robot", joint_names=legs) + ) + cfg.events["hold_arm_random_pose"] = EventTermCfg( + func=mdp.hold_randomized_joint_position_target, + mode="reset", + params={ + "position_range": (-0.4, 0.4), + "asset_cfg": SceneEntityCfg("robot", joint_names=("arm_.*",)), + }, + ) + from mjlab.envs.mdp import dr + + cfg.events["arm_inertia"] = EventTermCfg( + func=dr.pseudo_inertia, + mode="startup", + params={ + "alpha_range": (-0.35, 0.46), + "t_range": (-0.01, 0.01), + "asset_cfg": SceneEntityCfg("robot", body_names=("arm_.*",)), + }, + ) + cfg.events["arm_payload"] = EventTermCfg( + func=dr.body_mass, + mode="startup", + params={ + "ranges": (0.0, 0.3), + "operation": "add", + "asset_cfg": SceneEntityCfg("robot", body_names=("arm_gripper",)), + }, + ) + + if play: + cfg.episode_length_s = int(1e9) + cfg.observations["actor"].enable_corruption = False + cfg.events.pop("push_robot", None) + cfg.curriculum = {} + cfg.events["randomize_terrain"] = EventTermCfg( + func=envs_mdp.randomize_terrain, mode="reset", params={} + ) + if cfg.scene.terrain is not None: + if cfg.scene.terrain.terrain_generator is not None: + cfg.scene.terrain.terrain_generator.curriculum = False + cfg.scene.terrain.terrain_generator.num_cols = 5 + cfg.scene.terrain.terrain_generator.num_rows = 5 + cfg.scene.terrain.terrain_generator.border_width = 10.0 + return cfg + + +def _flat_env_cfg( + desc: QuadrupedDescriptor, play: bool, with_arm: bool +) -> ManagerBasedRlEnvCfg: + cfg = _rough_env_cfg(desc, play, with_arm) + cfg.sim.njmax = 800 # 大型狗(如 ANYmal)约束多,300 会溢出 + cfg.sim.mujoco.ccd_iterations = 50 + cfg.sim.contact_sensor_maxmatch = 64 + cfg.sim.nconmax = None + assert cfg.scene.terrain is not None + cfg.scene.terrain.terrain_type = "plane" + cfg.scene.terrain.terrain_generator = None + cfg.scene.sensors = tuple( + s for s in (cfg.scene.sensors or ()) if s.name != "terrain_scan" + ) + del cfg.observations["actor"].terms["height_scan"] + del cfg.observations["critic"].terms["height_scan"] + cfg.curriculum.pop("terrain_levels", None) + if play: + twist = cfg.commands["twist"] + twist.ranges.lin_vel_x = (-0.5, 1.0) + twist.ranges.lin_vel_y = (-0.5, 0.5) + twist.ranges.ang_vel_z = (-0.5, 0.5) + return cfg + + +def _runner_cfg(desc: QuadrupedDescriptor, suffix: str) -> RslRlOnPolicyRunnerCfg: + return replace( + unitree_go2_ppo_runner_cfg(), + experiment_name=f"{desc.name.lower()}_{suffix}_velocity", + ) + + +def make_grasp_robot_cfg(desc: QuadrupedDescriptor) -> EntityCfg: + """Dog + SO-101 with gripper collisions enabled (pick-and-place demo).""" + return _make_robot_cfg(desc, with_arm=True, grasp=True) + + +def register_quadruped(desc: QuadrupedDescriptor) -> None: + """Register Custom--{Flat,Rough} (+ -Arm-Flat if arm_mount_pos). + + 重名时**跳过而不是抛异常**:dogs/ 是自动扫描导入的,一个重名的 + descriptor 会让 register_mjlab_task 抛错,进而整个任务注册表导入失败 —— + 连已有的任务都用不了。宁可少注册一只狗,也别把全局搞挂。 + """ + assert desc.xml_path.exists(), f"model not found: {desc.xml_path}" + from mjlab.tasks.registry import list_tasks + + if f"Custom-{desc.name}-Flat" in list_tasks(): + print(f"[custom_dog] 跳过重名 descriptor:Custom-{desc.name}-* 已注册") + return + DOG_REGISTRY[desc.name] = desc + + register_mjlab_task( + task_id=f"Custom-{desc.name}-Rough", + env_cfg=_rough_env_cfg(desc, play=False, with_arm=False), + play_env_cfg=_rough_env_cfg(desc, play=True, with_arm=False), + rl_cfg=_runner_cfg(desc, "rough"), + runner_cls=VelocityOnPolicyRunner, + ) + register_mjlab_task( + task_id=f"Custom-{desc.name}-Flat", + env_cfg=_flat_env_cfg(desc, play=False, with_arm=False), + play_env_cfg=_flat_env_cfg(desc, play=True, with_arm=False), + rl_cfg=_runner_cfg(desc, "flat"), + runner_cls=VelocityOnPolicyRunner, + ) + if desc.arm_mount_pos is not None: + register_mjlab_task( + task_id=f"Custom-{desc.name}-Arm-Flat", + env_cfg=_flat_env_cfg(desc, play=False, with_arm=True), + play_env_cfg=_flat_env_cfg(desc, play=True, with_arm=True), + rl_cfg=_runner_cfg(desc, "arm"), + runner_cls=VelocityOnPolicyRunner, + ) diff --git a/src/tasks/velocity/config/custom_dog/descriptor.py b/src/tasks/velocity/config/custom_dog/descriptor.py new file mode 100644 index 0000000..b5dc8aa --- /dev/null +++ b/src/tasks/velocity/config/custom_dog/descriptor.py @@ -0,0 +1,90 @@ +"""User-facing descriptor for plugging a custom quadruped into training. + +Fill in one ``QuadrupedDescriptor`` per robot (drop a python file into +``dogs/`` that defines ``DOG = QuadrupedDescriptor(...)``) and the velocity +tasks ``Custom--Flat`` / ``Custom--Rough`` plus the arm-carrying +variant ``Custom--Arm-Flat`` are registered automatically. Train with:: + + python scripts/train.py Custom--Flat --env.scene.num-envs=2048 + +模型文件要求(MJCF,或 MuJoCo 可导入的 URDF): + - 网格文件放在 XML 同级的 ``assets/`` 目录; + - 躯干为根 body,带 freejoint; + - 四条腿各关节命名可用正则区分(如 ``FL_hip_joint``); + - 四只脚各有一个碰撞 geom 和一个 site(名字填进下面的字段)。 +""" + +from dataclasses import dataclass, field +from pathlib import Path + + +@dataclass +class ActuatorGroup: + """一组同参数的关节执行器(如所有 hip)。""" + + joint_regex: tuple[str, ...] + """匹配该组关节名的正则,如 (".*_hip_joint",)。""" + stiffness: float + """位置环刚度 kp [Nm/rad]。""" + damping: float + """速度环阻尼 kv [Nms/rad]。""" + effort_limit: float + """扭矩上限 [Nm]。""" + armature: float = 0.01 + """折算转子惯量 [kg m^2]。""" + + +@dataclass +class QuadrupedDescriptor: + # ---- 标识与模型文件 ------------------------------------------------- + name: str + """任务名中的机器人名(字母数字),如 "MyDog" -> Custom-MyDog-Flat。""" + xml_path: Path + """机器狗 MJCF(推荐)或 URDF 的绝对路径。""" + + # ---- 命名映射 ------------------------------------------------------- + base_body: str + """躯干 body 名(策略姿态/质心随机化/相机跟随都用它)。""" + leg_joint_regex: tuple[str, ...] + """全部 12 个腿关节的正则(动作空间 = 这些关节)。""" + foot_geom_names: tuple[str, str, str, str] + """四只脚的碰撞 geom 名,顺序 (FR, FL, RR, RL)。""" + foot_site_names: tuple[str, str, str, str] + """四只脚的 site 名,顺序同上(足端高度/打滑奖励用)。""" + + # ---- 必填物理参数 --------------------------------------------------- + standing_height: float + """站立时躯干离地高度 [m](初始化和终止判据的基准)。""" + standing_joint_pos: dict = field(default_factory=dict) + """站立姿态关节角 {关节名正则: 弧度},未匹配到的关节取 0。""" + actuator_groups: tuple = () + """ActuatorGroup 列表,合起来必须覆盖全部腿关节。""" + + # ---- 可调参数(有合理默认) ----------------------------------------- + action_scale: float = 0.25 + """策略动作 -> 关节目标偏移的缩放。""" + foot_friction_range: tuple = (0.3, 1.6) + """足底摩擦随机化范围。""" + gait_offsets: tuple = (0.0, 0.5, 0.5, 0.0) + """步态相位偏移(FR, FL, RR, RL),默认对角小跑。""" + foot_clearance: float = 0.10 + """摆动腿抬脚目标高度 [m](小型狗建议调小)。""" + collision_geom_regex: str = ".*_collision" + """全部碰撞 geom 的命名正则(非足部的用于摔倒/擦碰判定)。""" + posture_std_standing: float = 0.1 + posture_std_walking: float = 0.35 + """姿态奖励的容忍度(站立/行走),越小越贴近默认姿态。""" + + # ---- 抓取任务适配(可选) ------------------------------------------- + arm_mount_pos: tuple | None = None + """机械臂安装点(躯干系 xyz)。None 则不注册 Arm 变体任务。 + 注意:臂基座会占据 ~12x10cm,z 要落在背部上表面。""" + + nose_length: float = 0.36 + """机头前伸长度 [m](抓取 demo 的进近防撞距离用)。""" + + # ---- 模型修补钩子(可选) ------------------------------------------- + spec_postprocess: object = None + """callable(mujoco.MjSpec) -> None,模型载入后调用。用于补齐 URDF 常见 + 缺口:给根 body 加 freejoint、给足端补命名碰撞 geom 和 site 等 + (参考 dogs/solo12_example.py)。""" diff --git a/src/tasks/velocity/config/custom_dog/dogs/__init__.py b/src/tasks/velocity/config/custom_dog/dogs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/tasks/velocity/config/custom_dog/dogs/superspider.py b/src/tasks/velocity/config/custom_dog/dogs/superspider.py new file mode 100644 index 0000000..56ac253 --- /dev/null +++ b/src/tasks/velocity/config/custom_dog/dogs/superspider.py @@ -0,0 +1,637 @@ +"""Superspider 六足速度跟踪与单级台阶蒸馏任务。 +100 mm 站高,HTD-45H 参数,18 主动轴,每足两个接触球。 +""" +from pathlib import Path + +import mujoco + +from dataclasses import dataclass + +from mjlab.terrains.terrain_generator import SubTerrainCfg, TerrainGeometry, TerrainOutput +from mjlab.terrains.utils import make_plane + +from src.tasks.velocity.config.custom_dog.descriptor import ( + ActuatorGroup, QuadrupedDescriptor, +) + +_XML = Path(__file__).resolve().parents[6] / "models/superspider_mjlab/superspider.xml" +_LEGS = "123456" +_SEGS = ("coxa", "femur", "tibia") + +_LEG_JOINTS = tuple(f"{l}_{s}" for l in _LEGS for s in _SEGS) +_FOOT_GEOMS = tuple(f"edge_{l}{ab}" for l in _LEGS for ab in ("a", "b")) +_FOOT_SITES = tuple(f"fsite_{l}{ab}" for l in _LEGS for ab in ("a", "b")) + +# ---- 舵机选型 ---------------------------------------------------------- +# 幻尔串口总线舵机,按扭矩从小到大。改 SERVO 一行即可整机切换。 +SERVOS = { + # 名称: (堵转扭矩 N·m, 空载角速度 rad/s, 位置环 kp, kv, 备注) + "LX-224HV": (1.96, 5.2, 17.8, 0.6), # 20 kg·cm@7.4V, 0.20 s/60°;原 CAD 按这一档建的 + "HTD-45H": (4.41, 5.8, 40.0, 1.2), # 45 kg·cm@11.1V, 0.18 s/60°;**当前最大的一档** +} +SERVO = "HTD-45H" +_EFFORT, _QD_LIMIT, _KP, _KV = SERVOS[SERVO] +# ⚠ **质量待确认**:CAD 里的 servo 网格与质量是按 LX-224HV 级(59×45×32.5mm 包围盒)建的。 +# HTD-45H 体积/重量更大,18 个舵机换下来整机质量会涨(粗估 +10~15%,**未核实**)。 +# 拿到实物称重后把 SERVO_MASS_SCALE 改掉,或直接回 SolidWorks 换件重导。 +SERVO_MASS_SCALE = 1.0 + +import math as _math +COXA_SWING = _math.radians(40.0) # coxa 相对站姿默认角的允许摆幅,见 _postprocess 的标定 + +# 站姿。**2026-09-08 从 66mm 提到 100mm**:为爬台阶留机身离地间隙。 +# 实测提高站高几乎不花力矩(足端水平位置不变 ⇒ 力臂不变): +# 66mm→0.758 N·m / 100mm→0.757 / 120mm 腿够不到(同半径下的可达上限约 100mm)。 +# 100mm 站姿落地实测:up=1.0000、六足离地 3.21~3.36mm 均匀、静态峰值力矩 0.33 N·m。 +_STAND_H = 0.100 +_STAND = { + "1_coxa": +0.074027, "1_femur": +0.943939, "1_tibia": -0.974578, + "2_coxa": +0.074407, "2_femur": +1.164487, "2_tibia": -0.647146, + "3_coxa": -0.037301, "3_femur": +1.004834, "3_tibia": -0.590105, + "4_coxa": -0.039226, "4_femur": +1.349236, "4_tibia": -0.815209, + "5_coxa": -0.174187, "5_femur": +0.844217, "5_tibia": -0.551420, + "6_coxa": +0.246042, "6_femur": +1.053368, "6_tibia": -0.997824, +} + +# 三角步态:腿 1/3/5 相位 0、腿 2/4/6 相位 0.5(与 record_walk.py 的 GAIT_OFFSET 一致)。 +# 每腿两个球,所以每个相位写两遍,顺序对齐 _FOOT_GEOMS。 +_GAIT = tuple(v for l in _LEGS for v in ((0.0, 0.0) if l in "135" else (0.5, 0.5))) + + +def _postprocess(spec: mujoco.MjSpec) -> None: + """足端 site + 关节力矩钳位 + 舵机质量缩放。""" + # ⚠ **换舵机只改 effort_limit 是不够的**:MJCF 里每个 joint 还带 + # `actuatorfrcrange="-1.96 1.96"`(建模时按 LX-224HV 写的),MuJoCo 会在**关节层** + # 再钳一次,不放开的话执行器的 4.41 N·m 根本出不来。 + for b in spec.bodies: + for j in b.joints: + if j.type != mujoco.mjtJoint.mjJNT_FREE: + j.actfrclimited = 1 + j.actfrcrange[0], j.actfrcrange[1] = -_EFFORT, _EFFORT + # ---- coxa 限位:从 ±120° 占位值收窄到「站姿默认角 ± COXA_SWING」----------- + # 目的是把相邻腿的工作扇区**几何上分开**,让腿互撞不可能发生,而不是指望策略学会躲。 + # 标定依据(2026-09-09 实测,用**足端**方位角,不是 coxa body 位置): + # 站姿足端方位 腿5=-129° 腿4=-69° 腿3=5° 腿2=71° 腿1=125° 腿6=177° + # 相邻间隔 52~74°;**coxa 转 10° 只让足端方位转 4.9°**(增益 0.49,腿不是纯径向) + # ⇒ 允许摆幅 = (最小间隔 − 8° 余量) / 2 / 0.49 = ±45~60°(逐腿) + # 取 ±40° 对所有腿都安全,且是策略实测用量(±16°)的 2.5 倍,不掐掉爬台阶要的大摆幅。 + for b in spec.bodies: + for j in b.joints: + if j.name.endswith("_coxa"): + d0 = _STAND[j.name] + j.limited = 1 + j.range[0], j.range[1] = d0 - COXA_SWING, d0 + COXA_SWING + if SERVO_MASS_SCALE != 1.0: # 舵机换大件后整机变重(拿到实物再标定) + for b in spec.bodies: + b.mass *= SERVO_MASS_SCALE + b.inertia[:] = [v * SERVO_MASS_SCALE for v in b.inertia] + have = {s.name for s in spec.sites} + for b in spec.bodies: + for g in b.geoms: + if g.name and g.name.startswith("edge_"): + name = f"fsite_{g.name[len('edge_'):]}" + if name not in have: + b.add_site(name=name, pos=list(g.pos), group=5) + + +DESC = QuadrupedDescriptor( + name="Superspider", + xml_path=_XML, + base_body="base_link", + leg_joint_regex=_LEG_JOINTS, + foot_geom_names=_FOOT_GEOMS, + foot_site_names=_FOOT_SITES, + standing_height=_STAND_H, + standing_joint_pos=_STAND, + actuator_groups=( + ActuatorGroup( + joint_regex=(r"[1-6]_(coxa|femur|tibia)",), + stiffness=_KP, # 见上面 SERVOS 表 + damping=_KV, + effort_limit=_EFFORT, + armature=0.005, + ), + ), + action_scale=0.25, + gait_offsets=_GAIT, + foot_clearance=0.050, # 抬脚目标高度。66mm 站高时用 0.02(=脚本步态抬脚量); + # 提到 100mm 站高后为过台阶抬到 0.05,Rough 里再抬到 0.07。 + # 腿本身不是瓶颈:±120° 限位内足端能抬到机身上方 238mm。 + # 只有机身/coxa/femur 触地算违规;tibia 同 antsy 一样不参与碰撞(允许擦过) + collision_geom_regex=r"^(base_link|[1-6]_(coxa|femur))_col\d+$", + posture_std_standing=0.1, + posture_std_walking=0.35, + arm_mount_pos=None, + spec_postprocess=_postprocess, +) + + +def _joint_vel_over_limit(env, limit: float, asset_cfg=None): + """只惩罚**超出舵机角速度量程**的那部分(软限位式,类比 joint_pos_limits)。 + + 为什么不用现成的 `joint_vel_l2`:那是对所有关节速度平方求和,会连有用的摆动 + 一起罚,把步频压死。这里 `sum(max(0,|qd|-limit)^2)`,量程内零代价、超了才罚。 + + 为什么必须有这一项(2026-09-08 实测):`BuiltinPositionActuatorCfg` 只有 + effort_limit,**没有速度上限**,MuJoCo 的 joint 也没有 —— 奖励里不写代价, + 优化器就会把关节速度用满去换跟踪精度。model_5999(无此项)达成率 84% 很好, + 但关节峰速 5.29~6.12 rad/s,顶穿了舵机量程;而 qd95 只有 1.35~3.63, + 说明**超速是峰值行为**,正好适合用软限位罚掉。 + """ + import torch as _t + from mjlab.managers.scene_entity_config import SceneEntityCfg as _S + asset = env.scene["robot"] + qd = asset.data.joint_vel.abs() + over = (qd - limit).clip(min=0.0) + return _t.sum(_t.square(over), dim=1) + + +@dataclass(kw_only=True) +class SingleStepTerrainCfg(SubTerrainCfg): + """平地 + 一级台阶,台阶高度随课程难度线性上升。 + + 为什么另起一个地形而不用自带的 pyramid_stairs(2026-09-08~09 连栽三次): + ① `pyramid_stairs` 出生在中心平台**顶部**,往外走是**下坡**; + ② `platform_width` 默认 3.0m,机器人走 1.5~2m 都还没碰到第一级; + ③ 混合地形里台阶只占一部分子地形,机器人可能整局都在平坦块上。 + 这里只有两块几何,判据("机身有没有升上台阶面")一眼可查,课程难度直接就是台阶高度。 + """ + + step_height_range: tuple[float, float] = (0.01, 0.06) + approach: float = 1.5 # 出生点到台阶立面的助跑距离 + + def function(self, difficulty, spec, rng): + del rng + import numpy as _np + lo, hi = self.step_height_range + h = lo + float(difficulty) * (hi - lo) + body = spec.body("terrain") + sx, sy = self.size + geoms = make_plane(body, self.size, 0.0, center_zero=False) + colors = [(0.45, 0.45, 0.48, 1.0)] + ox = sx / 2.0 - self.approach + step_len = sx - ox - self.approach + if h > 1e-6 and step_len > 0.1: + g = body.add_geom( + type=mujoco.mjtGeom.mjGEOM_BOX, + size=(step_len / 2.0, sy / 2.0, h / 2.0), + pos=(ox + self.approach + step_len / 2.0, sy / 2.0, h / 2.0), + ) + geoms.append(g) + colors.append((0.85, 0.55, 0.25, 1.0)) + return TerrainOutput( + origin=_np.array((ox, sy / 2.0, 0.0)), + geometries=[TerrainGeometry(geom=g, color=c) for g, c in zip(geoms, colors)], + ) + + +class _ClimbProgress: + """爬升进度:只奖励**本回合刷新的最大高度**的增量。 + + 为什么需要它:速度跟踪奖励在惩罚"慢下来仔细爬"。指令 vx 0.15~0.40 时, + 一条腿一条腿跨台阶那几秒机身只有 0.02~0.05 m/s,跟踪奖励 + `exp(-err²/0.15²)` 只剩 0.06 —— **正确动作在执行过程中几乎不得分**, + 回报要等爬上去之后才来,隔几十步,PPO 探索不到。停在台阶前同样不得分, + 但那是默认行为、不需要探索,于是策略就停那儿了(实测 4cm 卡住时抬脚反而 + 从 40mm 掉回 21mm —— 不是抬不动,是不再尝试)。 + + 只认"刷新纪录"而不是绝对高度,机身上下晃动不能反复领取,不会被原地起伏套利。 + """ + + def __init__(self, cfg, env): + import torch as _t + self.best = _t.zeros(env.num_envs, device=env.device) + + def __call__(self, env, asset_cfg=None): + import torch as _t + asset = env.scene["robot"] + h = (asset.data.root_link_pos_w[:, 2] + - env.scene.env_origins[:, 2] - _STAND_H) + just_reset = env.episode_length_buf <= 1 # 回合重置后基准要跟着重置 + self.best = _t.where(just_reset, h, self.best) + gain = (h - self.best).clamp(min=0.0) + self.best = _t.maximum(self.best, h) + return gain + + +class _FeetClearanceRelative: + """抬脚惩罚,按【相对上一次触地高度】而不是世界绝对 z。 + + 原版 `feet_clearance` 是 `|site_pos_w.z - target| * 足端水平速度`,用的是**世界绝对 z**。 + 平地上 z 就是离地高度,没问题;**一旦踩上台阶就反了**:站在 5cm 台阶上时,摆动脚 + 抬到台阶上方 5cm(世界 10cm)的 delta 比贴着台阶面(世界 5cm)还大 ⇒ 梯度把脚往 + 台阶里按。最需要抬腿的地方,奖励在压腿。 + + 盲走版的正确参考面是**这只脚上一次触地时的高度** —— 纯本体感知,不需要高度图/ + 深度相机(真机方案里本来就没有)。语义也正好:"比你离开的地方抬高 target", + 爬 h 高的台阶就需要 clearance > h。 + """ + + def __init__(self, cfg, env): + import torch as _t + n = len(cfg.params["asset_cfg"].site_names) + self.ref_z = _t.zeros((env.num_envs, n), device=env.device) + self.primed = False + + def __call__(self, env, target_height, sensor_name, command_name, + command_threshold, asset_cfg): + import torch as _t + asset = env.scene[asset_cfg.name] + sensor = env.scene[sensor_name] + foot_z = asset.data.site_pos_w[:, asset_cfg.site_ids, 2] + if not self.primed: # 首帧:机器人站着,直接以当前高度为基准 + self.ref_z[:] = foot_z + self.primed = True + found = sensor.data.found + in_contact = (found.squeeze(-1) if found.dim() == 3 else found) > 0 + # 触地时刷新参考面;腾空时保持,于是 clearance = 相对"离开时那一级"的高度。 + self.ref_z = _t.where(in_contact, foot_z, self.ref_z) + clearance = foot_z - self.ref_z + vel = _t.norm(asset.data.site_lin_vel_w[:, asset_cfg.site_ids, :2], dim=-1) + cost = _t.sum(_t.abs(clearance - target_height) * vel, dim=1) + if command_name is not None: + cmd = env.command_manager.get_command(command_name) + if cmd is not None: + total = _t.norm(cmd[:, :2], dim=1) + _t.abs(cmd[:, 2]) + cost = cost * (total > command_threshold).float() + return cost + + +def _terrain_levels_stairs(env, env_ids, command_name: str = "twist"): + """Stairs 专用课程:**必须真的爬上台阶**才升级。 + + 2026-09-09 教训:先用的是通用判据「单回合位移 > 0.80m」,而**助跑距离就有 1.5m** —— + 机器人走到台阶前顶住不动,位移已经 1.5m > 0.8m,于是**一级台阶没爬也被一路升到 6 档**; + 课程把它推到 4cm(它连 3cm 都过不了),原本会的 3cm 25% 反而被磨成 0%。 + 判据必须**直接测目标事件**:机身高度有没有升上台阶面。 + """ + import torch as _t + + terrain = env.scene.terrain + assert terrain is not None + asset = env.scene["robot"] + # 机身相对出生点地面的净爬升。 + # ⚠ 必须**减掉站高**:机身本来就离地 0.103m,直接用 root_z − 地面z 得到的恒是 0.103, + # 永远大于阈值(最大 0.036)⇒ 又变成无条件升级(2026-09-09 第二次踩同一个坑)。 + climb = (asset.data.root_link_pos_w[env_ids, 2] + - env.scene.env_origins[env_ids, 2] - _STAND_H) + lvl = terrain.terrain_levels[env_ids].float() + step_h = 0.01 + lvl / max(terrain.max_terrain_level - 1, 1) * 0.05 + fell = env.termination_manager.terminated[env_ids] + # 阈值 0.9 不是 0.6:0.6 等于"爬上去一半就算过" —— 前腿搭上台阶、机身翘起来 + # 就能满足,于是档位虚涨到 6.3(≈4.5cm)而策略实际只会 3cm,4cm 从 1600 到 4000 迭代 + # 原地踏步 2400 次(2026-09-09 实测)。必须真站上去才算。 + move_up = (~fell) & (climb > step_h * 0.9) + move_down = (fell | (climb < step_h * 0.2)) & ~move_up + terrain.update_env_origins(env_ids, move_up, move_down) + return _t.mean(terrain.terrain_levels.float()) + + +def _terrain_levels_superspider(env, env_ids, command_name: str = "twist"): + """地形课程:摔倒或原地不动就降级,活满回合且确实走出去才升级。 + + 判据沿用 antsy 的结论(原版 `terrain_levels_vel` 要求单回合位移 > 4.0 m,是 Go2 + 1~2 m/s 的标定,六足永远够不着、课程会塌到 0 档;只看存活则因为六足静稳定几乎不摔、 + 一路升满,均值稳在随机回绕的平衡点而非真本事)。 + ⚠ **2026-09-08 实测把阈值调高了一轮**。原来按速度比从 antsy 缩放得 0.34/0.14, + 但 0.34m / 20s = **0.017 m/s** —— 原地踏步的漂移就能满足,于是课程一路把地形推到 + 5.4 档,而策略同期在退化(净位移 1.318m → 0.006m)。**课程判据必须严到只有真在走 + 才过得去**:本机能走 0.075 m/s,20s 应有 1.5m;取 0.80m(≈一半)升级、0.30m 降级。 + """ + import torch as _t + + terrain = env.scene.terrain + assert terrain is not None + asset = env.scene["robot"] + distance = _t.norm( + asset.data.root_link_pos_w[env_ids, :2] - env.scene.env_origins[env_ids, :2], dim=1 + ) + fell = env.termination_manager.terminated[env_ids] + move_up = (~fell) & (distance > 0.80) + move_down = (fell | (distance < 0.30)) & ~move_up + terrain.update_env_origins(env_ids, move_up, move_down) + return _t.mean(terrain.terrain_levels.float()) + + +def _register() -> None: + from dataclasses import replace as _rp + from mjlab.tasks.registry import list_tasks, register_mjlab_task + from src.tasks.velocity.config.custom_dog import builder as B + + if "Custom-Superspider-Flat" in list_tasks(): + return + B.DOG_REGISTRY[DESC.name] = DESC + + def tune(cfg, rough=False, blind=True): + # ---- 自碰撞:打开检测 + 惩罚 ----------------------------------------- + # 现状是 `CollisionCfg(contype=1, conaffinity=0)` ⇒ 机器人两两判定 + # `(1&0)|(1&0)=0`,**自碰撞恒不发生**,六条腿在仿真里可以互相穿过去, + # 而且任何指标都看不出来(2026-09-09 实测确认)。 + # 这在有固定三角步态先验时侥幸没出事(实测 0/1600 跨腿接触),但一旦按爬台阶那条 + # 结论把 `foot_gait` 退火到 0、放开破相位,腿交叉的风险会上升 —— 护栏必须先立。 + from dataclasses import replace as _rp2 + from mjlab.managers import RewardTermCfg as _RT2 + from mjlab.sensor import ContactMatch as _CM, ContactSensorCfg as _CS + import src.tasks.velocity.mdp as _vmdp + + ent = cfg.scene.entities["robot"] + ent.collisions = tuple(_rp2(c, conaffinity=1) for c in ent.collisions) + cfg.scene.sensors = (cfg.scene.sensors or ()) + ( + _CS( + name="self_collision", + # primary/secondary 都取整机子树 ⇒ 机器人内部任意两几何的接触都算自碰撞。 + primary=_CM(mode="subtree", pattern="base_link", entity="robot"), + secondary=_CM(mode="subtree", pattern="base_link", entity="robot"), + # ⚠ 只要 found,**不要 force/history**。`self_collision_cost` 一旦看到 + # `force_history` 就走"力超阈值"的分支;而 `reduce="none"` 选中的那个接触 + # 的力实测是 0(两腿交叉 found=14、force 范数 0.0)—— 阈值调到 0.5N 也罚不出来。 + # 去掉 force 后它回落到 `data.found`,直接拿"自碰撞接触点数"当代价: + # 没有阈值要调,而且"腿碰上了"本来就是个是非问题,不是力度问题。 + fields=("found",), + reduce="none", + num_slots=1, + ), + ) + # 只罚不终止:终止会把"站着别动"变成安全解,那正是 Rough 训练塌过四次的陷阱。 + cfg.rewards["self_collision"] = _RT2( + func=_vmdp.self_collision_cost, + # found 是接触点数(轻碰 1、深度交叉 14),权重按此标定:轻碰 0.5/步、交叉 7/步。 + weight=-0.5, + params={"sensor_name": "self_collision"}, + ) + + tw = cfg.commands["twist"] + # 脚本三角步态实测上限 vx 0.075 / vy 0.056 / wz 0.22(几何+舵机限速)。 + # RL 不受那套步幅几何约束(antsy 就跑到脚本步态的 3.6 倍),留出上探空间但别离谱。 + # 指令上限按【实测舵机可行域】定(model_4500 扫描,见 04-Insights/关键结论.md): + # cmd 0.30 → 实测 0.220 · qd_max 3.67 · τ 1.09 ✓ + # cmd 0.40 → 实测 0.315 · qd_max 4.45 · τ 1.31 ✓ ← 天花板 + # cmd 0.50 → 实测 0.407 · qd_max 5.56 · τ 1.95 ✗ 关节超 5rad/s 且力矩饱和 + tw.ranges.lin_vel_x = (-0.25, 0.40) + tw.ranges.lin_vel_y = (-0.15, 0.15) + tw.ranges.ang_vel_z = (-0.8, 0.8) + # ⚠ 课程项叫 **command_vel**,不叫 command_ranges。antsy 里写的 + # `pop("command_ranges")` 是空操作,于是 Go2 的指令课程一直在跑: + # step 0 → lin_vel_x (-0.5, 1.0) ← 从第 0 步就覆盖掉上面设的范围 + # step 5000×24 → lin_vel_x (-1.0, 2.0) ← num_steps_per_env=24 ⇒ 正好第 5000 迭代 + # 2026-09-08 第一次训练就崩在这:iter 5000 指令跳到 2 m/s(机器顶速 0.5), + # track_linear_velocity 0.78 → 0.19 且再没回来。antsy 只跑 4000 迭代, + # 正好停在触发点前一步,所以从没暴露(但它的 stage-0 覆盖同样在生效)。 + # 这里不 pop,而是换成本机自己的两段课程:先窄后宽。 + if "command_vel" in cfg.curriculum: # play 模式没有 curriculum + cfg.curriculum["command_vel"].params["velocity_stages"] = [ + {"step": 0, + "lin_vel_x": (-0.15, 0.25), "lin_vel_y": (-0.10, 0.10), "ang_vel_z": (-0.6, 0.6)}, + {"step": 2500 * 24, + "lin_vel_x": (-0.25, 0.40), "lin_vel_y": (-0.15, 0.15), "ang_vel_z": (-0.8, 0.8)}, + ] + if rough: + # ---- 1) 盲走:去掉高度扫描 ---------------------------------------- + # 理由有两条,都不是"为了省事": + # ① **真机没有深度相机**。硬件方案是 IMU + 舵机位置回读(见 spider-robot 笔记), + # 高度扫描要深度相机→高度图,那是"加视觉那一步"才有的东西。 + # 带 height_scan 训出来的策略,真机上根本喂不进观测。 + # ② 去掉后 obs 从 208 回到 **65,与 Flat 完全一致**(actor/critic 都是), + # 于是可以**直接从 Flat 策略热启动**——这是 2026-09-08 那次站桩解的主要解药: + # 从零开始在崎岖地形上学,"站着不动"比"走两步摔"安全得多,PPO 就卡在那儿了 + # (1545 迭代实测:平地 8s 净位移 0.035m,指令 0.40 应该走 3.2m)。 + if blind: + for grp in ("actor", "critic"): + terms = {k: v for k, v in cfg.observations[grp].terms.items() if k != "height_scan"} + cfg.observations[grp].terms = terms + # 观测里去掉还不够 —— **射线传感器本身仍在每步求交**,白烧算力。 + # 实测:只去观测 1.82 s/iter,连传感器一起摘掉见下方注释里的实测值。 + if blind: + cfg.scene.sensors = tuple(x for x in (cfg.scene.sensors or ()) if x.name != "terrain_scan") + # ---- 2) 地形从最低档起步 ------------------------------------------ + # 原来 max_init_terrain_level=5(Go2 的设定):**一半环境从第 0 迭代就落在中等 + # 难度地形上**,而策略那时连走都不会。先让它在近乎平地上学会走,再让课程往上推。 + cfg.scene.terrain.max_init_terrain_level = 0 + # ---- 接触容量:Rough 默认 nconmax=35 是 Go2 的设定,本机不够 ------------ + # 本机光足端就有 **12 个球**(六腿×2),崎岖地形上 base/coxa/femur 的凸包也参与 + # 碰撞,单环境接触数轻松过 50。超出 nconmax 的接触被 **静默丢弃**(日志里没有 + # 任何报错),等于"脚踩空"。A/B 实测(同一策略、只改这个数): + # nconmax=35 → cmd0.40 8s 净位移 1.773 m + # nconmax=400 → cmd0.40 8s 净位移 **2.918 m** (差 65%) + # 在丢接触的物理里训练,"别走了、站着最稳"就是最优解 —— 2026-09-08 三次 + # Rough 训练都塌成站桩解,这是最可疑的一环(另两环:抬脚目标过高、课程判据过松)。 + # Flat 那边 nconmax=None(不限),所以平地训练一直正常。 + # nconmax 是**每世界**配额(总池 = nconmax × nworld)。Rough 默认写死 35, + # 低于 mujoco_warp 对带高度场模型的启发式(`nv*0.35*10+45 ≈ 129`)。 + # 置 None 让它自己按模型算;显式给 400 会在 1024 env 下要 12.3GB 显存直接 OOM。 + cfg.sim.nconmax = None + cfg.sim.njmax = None + # ---- 3) 违规接触别一碰就终止 -------------------------------------- + # 台阶上蹭到 femur 很难完全避免,10N 阈值太敏感 ⇒ 抬到 30N,只判真正的"压上去"。 + # 阈值调回 10N。之前提到 30 是想让"蹭到台阶立面"不被判死,但那等于**取消了 + # 逼它抬腿的那份代价** —— 文献里让脚抬起来靠的正是"撞到障碍要疼",抬腿是唯一出路。 + cfg.terminations["illegal_contact"].params["force_threshold"] = 10.0 + # 步态先验归零:固定三角相位禁止了爬台阶必需的"停下来单独抬一条腿"。 + # 不做退火而是直接置 0 —— 我们是从**已经会走的 Flat 策略热启动**,三角步态已经 + # 长在权重里了,不需要奖励再按着;而退火要挂在 common_step_counter 上, + # 热启动会把计数一起恢复(2026-09-08 踩过),多一个出错面。 + # 防腿撞已由 coxa 限位 + 自碰撞惩罚接管,放开相位是安全的。 + cfg.rewards["foot_gait"].weight = 0.0 + # 地形按站高再缩一档:Go2 ~300mm → antsy 102mm(×1/2) → 本机 66mm(再 ×2/3) + tg = cfg.scene.terrain.terrain_generator + subs = dict(tg.sub_terrains) + # 台阶高度按【站高 100mm + 抬脚 70mm】重标(原来按 66mm 站高设的 0.05)。 + # 判据:摆动脚能抬到地面上方 站高+抬脚 才谈得上跨上去,再留 ~30% 余量。 + for k in ("pyramid_stairs", "pyramid_stairs_inv"): + if k in subs: + subs[k] = _rp(subs[k], step_height_range=(0.0, 0.07), step_width=0.22) + if "random_rough" in subs: + subs["random_rough"] = _rp(subs["random_rough"], + noise_range=(0.005, 0.04), noise_step=0.005) + if "wave_terrain" in subs: + subs["wave_terrain"] = _rp(subs["wave_terrain"], amplitude_range=(0.0, 0.08)) + for k in ("hf_pyramid_slope", "hf_pyramid_slope_inv"): + if k in subs: + subs[k] = _rp(subs[k], slope_range=(0.0, 0.5)) + cfg.scene.terrain.terrain_generator = _rp(tg, sub_terrains=subs) + # 高度扫描视野。x 方向要够**提前量**:足端伸到身前约 0.15m,0.5m 的窗口 + # (身前 0.25m)只给 0.1m 预警 ≈ 0.33s@0.3m/s,爬台阶来不及决策; + # 放到 0.9m(身前 0.45m)≈ 1s 预警。y 方向 0.4m 覆盖机身宽度即可。 + for sen in cfg.scene.sensors or (): + if sen.name == "terrain_scan": + sen.pattern = _rp(sen.pattern, size=(0.9, 0.4), resolution=0.04) + # ⚠ **2026-09-08 实测:这里设 0.070 是错的**。崎岖地形上够不准这个高度, + # 罚值冲到 -0.63,比整个前进跟踪奖励(+0.10)大 6 倍 ⇒ 策略学会**原地踏步**: + # 抬脚节奏对(foot_gait +0.13)、姿态好(pose +0.38)、转向能拿分(+0.31), + # 合计 0.82,而走路最多值 0.10 —— 收益抵不过罚,于是退化成站桩。 + # 回到与 Flat 相同的 0.05(Flat 实测罚值仅 -0.105,不喧宾夺主)。 + cfg.rewards["foot_clearance"].params["target_height"] = 0.050 + from mjlab.managers import CurriculumTermCfg as _CT + cfg.curriculum["terrain_levels"] = _CT( + func=_terrain_levels_superspider, params={"command_name": "twist"} + ) + # ---- 速度跟踪奖励的 std 必须按本机速域缩 ---- + # 默认 std²=0.25 是 Go2(跑 2 m/s)的标定。对 0.2~0.4 m/s 的本机: + # 达成 50%(误差0.10) → exp(-0.01/0.25)=0.961 + # **站着不动(误差0.20) → 0.852** ⇒ 几乎没有梯度,策略没有动力走准。 + # 实测佐证:2026-09-08 第二次训练 track_lin 高达 0.925,固定指令实测达成率仅 59%; + # 而同一策略的**转向**达成率 88~99% —— 因为 track_angular 的 std²=0.5 对 + # ±0.8 rad/s 的指令域恰好匹配。同策略、同回合,准不准只差在奖励尺度。 + # 取 std=0.15(std²=0.0225):cmd0.2 下达成 58% → 0.735、达成 90% → 0.982, + # 站着不动 → 0.17,梯度回来了。 + # 抬脚惩罚换成相对上一次触地高度的版本(原版用世界绝对 z,在台阶上梯度是反的) + cfg.rewards["foot_clearance"].func = _FeetClearanceRelative + cfg.rewards["foot_clearance"].params["sensor_name"] = "feet_ground_contact" + cfg.rewards["track_linear_velocity"].params["std"] = 0.15 + # 关节超速惩罚。阈值取舵机空载角速度的 80%(留出负载下降速的余量)。 + from mjlab.managers import RewardTermCfg as _RT + cfg.rewards["joint_vel_over_limit"] = _RT( + func=_joint_vel_over_limit, weight=-0.5, + params={"limit": _QD_LIMIT * 0.8}, + ) + return cfg + + def tune_distill(cfg): + """蒸馏用环境:把 teacher 的 318 维观测**拆成两组**。 + + rsl-rl 的 `Distillation` 靠 `obs_groups` 把观测组装成 student / teacher 两套: + student = [actor] (本体 65) + teacher = [actor, height] (本体 65 + 扫描 253,拼接顺序与 teacher 训练时一致) + teacher 的第一层权重按 [本体, 扫描] 的顺序训出来,拆组后按这个顺序拼回去, + 数值上与训练时完全相同 —— 这是能直接 resume teacher 权重的前提。 + """ + from mjlab.managers.observation_manager import ObservationGroupCfg as _OG + cfg = tune_stairs(cfg, blind=False) # 先拿到带扫描的完整配置 + a = cfg.observations["actor"].terms + hs = a["height_scan"] + cfg.observations["actor"] = _OG( + terms={k: v for k, v in a.items() if k != "height_scan"}, + concatenate_terms=True, enable_corruption=cfg.observations["actor"].enable_corruption, + ) + cfg.observations["height"] = _OG( + terms={"height_scan": hs}, concatenate_terms=True, enable_corruption=False, + ) + return cfg + + def tune_stairs(cfg, blind=True, history=0): + """在 Rough 基础上把地形换成"只有单级台阶",课程难度=台阶高度。 + + `blind=False` 是**教师版**:保留高度扫描(特权信息)。teacher 训到会爬, + 再用 rsl-rl 的 Distillation 蒸馏给只有本体感知的 student —— + 真机方案里没有深度相机,最终上机的必须是 blind 版。 + (Lee 2020 / Miki 2022 走的都是这条路。) + """ + cfg = tune(cfg, rough=True, blind=blind) + tg = cfg.scene.terrain.terrain_generator + cfg.scene.terrain.terrain_generator = _rp( + tg, sub_terrains={"single_step": SingleStepTerrainCfg(size=(8.0, 8.0))}, + curriculum=True, + ) + from mjlab.managers import CurriculumTermCfg as _CT2 + cfg.curriculum["terrain_levels"] = _CT2( + func=_terrain_levels_stairs, params={"command_name": "twist"} + ) + # 指令偏向**朝台阶走**。通用速度任务里指令是全向随机的,机器人多半在原地打转, + # "走到台阶前并跨上去"这个事件几乎不会被采样到 —— 课程再准也没样本可学。 + tw = cfg.commands["twist"] + tw.heading_command = False + tw.ranges.heading = None + # 下限放到 0.05:一条腿一条腿爬台阶时机身只有 0.02~0.05 m/s, + # 指令下限 0.15 会让整个爬升过程持续吃跟踪惩罚。 + tw.ranges.lin_vel_x = (0.05, 0.40) # 只朝前 + tw.ranges.lin_vel_y = (-0.05, 0.05) + tw.ranges.ang_vel_z = (-0.3, 0.3) + tw.rel_standing_envs = 0.0 + if "command_vel" in cfg.curriculum: # 别让通用指令课程覆盖上面这几行 + cfg.curriculum.pop("command_vel") + from mjlab.managers import RewardTermCfg as _RT3 + cfg.rewards["climb_progress"] = _RT3(func=_ClimbProgress, weight=1000.0, params={}) + if history > 0: + # 本体感知**历史**:盲走策略要靠"脚踩空了/蹭到了/机身倾角变了"的时间序列去推断 + # 地形,单帧观测里没有这些信息。只给 actor(=student)加,critic 有特权项不需要。 + # 排列实测:flatten 后是 **term-major**,每个 term 的块 = dim×H,**块内最新帧在尾部** + # (误差 0.143→0.0 单调下降)。扩容热启动要按这个位置搬权重。 + cfg.observations["actor"].history_length = history + return cfg + + for suffix, mk, is_rough in (("Rough", B._rough_env_cfg, True), + ("Flat", B._flat_env_cfg, False)): + register_mjlab_task( + task_id=f"Custom-Superspider-{suffix}", + env_cfg=tune(mk(DESC, play=False, with_arm=False), is_rough), + play_env_cfg=tune(mk(DESC, play=True, with_arm=False), is_rough), + rl_cfg=_rp(B._runner_cfg(DESC, suffix.lower())), + runner_cls=B.VelocityOnPolicyRunner, + ) + + # ---- 蒸馏任务 ---------------------------------------------------------- + from dataclasses import dataclass as _dc, field as _fld + from mjlab.rl import RslRlBaseRunnerCfg as _Base + from rsl_rl.runners import DistillationRunner as _DR + + # ⚠ 不能直接用 mjlab 的 `RslRlModelCfg` —— 它带 `cnn_cfg` 字段,而 + # `Distillation.construct_algorithm` 是 `MLPModel(..., **cfg["student"])` 全量透传, + # MLPModel 不接受这个参数,会 TypeError。这里按 MLPModel 的真实签名定义。 + @_dc + class _MCfg: + class_name: str = "MLPModel" + hidden_dims: tuple = (512, 256, 128) + activation: str = "elu" + obs_normalization: bool = True + # teacher 的 state_dict 里有 `distribution.std_param`,不给 distribution_cfg + # 会因缺键而 load 失败(strict=True)。student 沿用同款以保持结构一致。 + distribution_cfg: dict = _fld(default_factory=lambda: { + "class_name": "GaussianDistribution", "init_std": 1.0, "std_type": "scalar"}) + + @_dc + class _DistillAlgCfg: + class_name: str = "Distillation" + num_learning_epochs: int = 1 + gradient_length: int = 15 + learning_rate: float = 1e-3 + max_grad_norm: float = 1.0 + loss_type: str = "mse" + optimizer: str = "adam" + + @_dc + class _DistillRunnerCfg(_Base): + class_name: str = "DistillationRunner" + student: _MCfg = _fld(default_factory=_MCfg) + teacher: _MCfg = _fld(default_factory=_MCfg) + algorithm: _DistillAlgCfg = _fld(default_factory=_DistillAlgCfg) + + register_mjlab_task( + task_id="Custom-Superspider-Stairs-Distill", + env_cfg=tune_distill(B._rough_env_cfg(DESC, play=False, with_arm=False)), + play_env_cfg=tune_distill(B._rough_env_cfg(DESC, play=True, with_arm=False)), + rl_cfg=_DistillRunnerCfg( + # student 只看本体;teacher 看本体+扫描(顺序与其训练时一致) + obs_groups={"student": ("actor",), "teacher": ("actor", "height")}, + num_steps_per_env=24, max_iterations=6000, save_interval=200, + experiment_name="superspider_stairs_distill", logger="tensorboard", + ), + runner_cls=_DR, + ) + + register_mjlab_task( + task_id="Custom-Superspider-Stairs-Hist", + env_cfg=tune_stairs(B._rough_env_cfg(DESC, play=False, with_arm=False), history=10), + play_env_cfg=tune_stairs(B._rough_env_cfg(DESC, play=True, with_arm=False), history=10), + rl_cfg=_rp(B._runner_cfg(DESC, "stairs_hist")), + runner_cls=B.VelocityOnPolicyRunner, + ) + + register_mjlab_task( + task_id="Custom-Superspider-Stairs-Teacher", + env_cfg=tune_stairs(B._rough_env_cfg(DESC, play=False, with_arm=False), blind=False), + play_env_cfg=tune_stairs(B._rough_env_cfg(DESC, play=True, with_arm=False), blind=False), + rl_cfg=_rp(B._runner_cfg(DESC, "stairs_teacher")), + runner_cls=B.VelocityOnPolicyRunner, + ) + + register_mjlab_task( + task_id="Custom-Superspider-Stairs", + env_cfg=tune_stairs(B._rough_env_cfg(DESC, play=False, with_arm=False)), + play_env_cfg=tune_stairs(B._rough_env_cfg(DESC, play=True, with_arm=False)), + rl_cfg=_rp(B._runner_cfg(DESC, "stairs")), + runner_cls=B.VelocityOnPolicyRunner, + ) + + +_register() +DOG = None # 已自行注册,扫描器跳过默认注册 diff --git a/src/tasks/velocity/config/go2/__init__.py b/src/tasks/velocity/config/go2/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/tasks/velocity/config/go2/rl_cfg.py b/src/tasks/velocity/config/go2/rl_cfg.py new file mode 100644 index 0000000..bb57c93 --- /dev/null +++ b/src/tasks/velocity/config/go2/rl_cfg.py @@ -0,0 +1,46 @@ +"""RL configuration for Unitree Go2 velocity task.""" + +from mjlab.rl import ( + RslRlModelCfg, + RslRlOnPolicyRunnerCfg, + RslRlPpoAlgorithmCfg, +) + + +def unitree_go2_ppo_runner_cfg() -> RslRlOnPolicyRunnerCfg: + """Create RL runner configuration for Unitree Go2 velocity task.""" + return RslRlOnPolicyRunnerCfg( + actor=RslRlModelCfg( + hidden_dims=(512, 256, 128), + activation="elu", + obs_normalization=True, + distribution_cfg={ + "class_name": "GaussianDistribution", + "init_std": 1.0, + "std_type": "scalar", + }, + ), + critic=RslRlModelCfg( + hidden_dims=(512, 256, 128), + activation="elu", + obs_normalization=True, + ), + algorithm=RslRlPpoAlgorithmCfg( + value_loss_coef=1.0, + use_clipped_value_loss=True, + clip_param=0.2, + entropy_coef=0.01, + num_learning_epochs=5, + num_mini_batches=4, + learning_rate=1.0e-3, + schedule="adaptive", + gamma=0.99, + lam=0.95, + desired_kl=0.01, + max_grad_norm=1.0, + ), + experiment_name="go2_velocity", + save_interval=100, + num_steps_per_env=24, + max_iterations=10001, + ) diff --git a/src/tasks/velocity/mdp/__init__.py b/src/tasks/velocity/mdp/__init__.py new file mode 100644 index 0000000..4acfc8a --- /dev/null +++ b/src/tasks/velocity/mdp/__init__.py @@ -0,0 +1,8 @@ +from mjlab.envs.mdp import * # noqa: F401, F403 + +from .curriculums import * # noqa: F403 +from .events import * # noqa: F403 +from .observations import * # noqa: F403 +from .rewards import * # noqa: F403 +from .terminations import * # noqa: F403 +from .velocity_command import * # noqa: F403 diff --git a/src/tasks/velocity/mdp/curriculums.py b/src/tasks/velocity/mdp/curriculums.py new file mode 100644 index 0000000..3de0a5f --- /dev/null +++ b/src/tasks/velocity/mdp/curriculums.py @@ -0,0 +1,107 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, TypedDict, cast + +import torch + +from mjlab.entity import Entity +from mjlab.managers.scene_entity_config import SceneEntityCfg + +from .velocity_command import UniformVelocityCommandCfg + +if TYPE_CHECKING: + from mjlab.envs import ManagerBasedRlEnv + +_DEFAULT_SCENE_CFG = SceneEntityCfg("robot") + + +class VelocityStage(TypedDict): + step: int + lin_vel_x: tuple[float, float] | None + lin_vel_y: tuple[float, float] | None + ang_vel_z: tuple[float, float] | None + + +class RewardWeightStage(TypedDict): + step: int + weight: float + + +def terrain_levels_vel( + env: ManagerBasedRlEnv, + env_ids: torch.Tensor, + command_name: str, + asset_cfg: SceneEntityCfg = _DEFAULT_SCENE_CFG, +) -> torch.Tensor: + asset: Entity = env.scene[asset_cfg.name] + + terrain = env.scene.terrain + assert terrain is not None + terrain_generator = terrain.cfg.terrain_generator + assert terrain_generator is not None + + command = env.command_manager.get_command(command_name) + assert command is not None + + # Compute the distance the robot walked. + distance = torch.norm( + asset.data.root_link_pos_w[env_ids, :2] - env.scene.env_origins[env_ids, :2], dim=1 + ) + + # Robots that walked far enough progress to harder terrains. + move_up = distance > terrain_generator.size[0] / 2 + + # Robots that walked less than half of their required distance go to simpler + # terrains. + move_down = ( + distance < torch.norm(command[env_ids, :2], dim=1) * env.max_episode_length_s * 0.5 + ) + move_down *= ~move_up + + # Update terrain levels. + terrain.update_env_origins(env_ids, move_up, move_down) + + return torch.mean(terrain.terrain_levels.float()) + + +def commands_vel( + env: ManagerBasedRlEnv, + env_ids: torch.Tensor, + command_name: str, + velocity_stages: list[VelocityStage], +) -> dict[str, torch.Tensor]: + del env_ids # Unused. + command_term = env.command_manager.get_term(command_name) + assert command_term is not None + cfg = cast(UniformVelocityCommandCfg, command_term.cfg) + for stage in velocity_stages: + if env.common_step_counter > stage["step"]: + if "lin_vel_x" in stage and stage["lin_vel_x"] is not None: + cfg.ranges.lin_vel_x = stage["lin_vel_x"] + if "lin_vel_y" in stage and stage["lin_vel_y"] is not None: + cfg.ranges.lin_vel_y = stage["lin_vel_y"] + if "ang_vel_z" in stage and stage["ang_vel_z"] is not None: + cfg.ranges.ang_vel_z = stage["ang_vel_z"] + return { + # "lin_vel_x_min": torch.tensor(cfg.ranges.lin_vel_x[0]), + # "lin_vel_x_max": torch.tensor(cfg.ranges.lin_vel_x[1]), + # "lin_vel_y_min": torch.tensor(cfg.ranges.lin_vel_y[0]), + # "lin_vel_y_max": torch.tensor(cfg.ranges.lin_vel_y[1]), + # "ang_vel_z_min": torch.tensor(cfg.ranges.ang_vel_z[0]), + # "ang_vel_z_max": torch.tensor(cfg.ranges.ang_vel_z[1]), + } + + +def reward_weight( + env: ManagerBasedRlEnv, + env_ids: torch.Tensor, + reward_name: str, + weight_stages: list[RewardWeightStage], +) -> torch.Tensor: + """Update a reward term's weight based on training step stages.""" + del env_ids # Unused. + reward_term_cfg = env.reward_manager.get_term_cfg(reward_name) + for stage in weight_stages: + if env.common_step_counter > stage["step"]: + reward_term_cfg.weight = stage["weight"] + return torch.tensor([reward_term_cfg.weight]) diff --git a/src/tasks/velocity/mdp/events.py b/src/tasks/velocity/mdp/events.py new file mode 100644 index 0000000..1a746e5 --- /dev/null +++ b/src/tasks/velocity/mdp/events.py @@ -0,0 +1,77 @@ +"""Custom event terms for velocity tasks.""" + +import torch + +from mjlab.entity import Entity +from mjlab.envs import ManagerBasedRlEnv +from mjlab.managers.scene_entity_config import SceneEntityCfg +from mjlab.utils.lab_api.math import sample_uniform + +_DEFAULT_ASSET_CFG = SceneEntityCfg("robot") + + +def hold_default_joint_position_target( + env: ManagerBasedRlEnv, + env_ids: torch.Tensor | None, + asset_cfg: SceneEntityCfg = _DEFAULT_ASSET_CFG, +) -> None: + """Set position targets of the selected joints to their default positions. + + For actuated joints that are not driven by any action term the position + target buffer stays at zero, so their servos would pull them away from the + init-state pose. This event pins those targets to ``default_joint_pos``. + The targets are identical for every environment, so they are written for all + environments regardless of ``env_ids``. + """ + del env_ids + asset: Entity = env.scene[asset_cfg.name] + default_joint_pos = asset.data.default_joint_pos + assert default_joint_pos is not None + + joint_ids = asset_cfg.joint_ids + if isinstance(joint_ids, list): + joint_ids = torch.tensor(joint_ids, device=env.device) + + asset.set_joint_position_target( + default_joint_pos[:, joint_ids], joint_ids=joint_ids + ) + + +def hold_randomized_joint_position_target( + env: ManagerBasedRlEnv, + env_ids: torch.Tensor | None, + position_range: tuple[float, float], + asset_cfg: SceneEntityCfg = _DEFAULT_ASSET_CFG, +) -> None: + """Pin selected joints at a per-episode randomized pose. + + Samples a uniform offset around the default position (clamped to the soft + joint limits), then writes it as both the joint state and the position + target, so the joints start at and hold the randomized pose for the whole + episode. Used to expose the locomotion policy to arbitrary (frozen) arm + configurations so it generalizes across different mounted arms. + """ + asset: Entity = env.scene[asset_cfg.name] + if env_ids is None: + env_ids = torch.arange(env.num_envs, device=env.device, dtype=torch.int) + + default_joint_pos = asset.data.default_joint_pos + soft_limits = asset.data.soft_joint_pos_limits + assert default_joint_pos is not None and soft_limits is not None + + joint_ids = asset_cfg.joint_ids + if isinstance(joint_ids, list): + joint_ids = torch.tensor(joint_ids, device=env.device) + + targets = default_joint_pos[env_ids][:, joint_ids].clone() + targets += sample_uniform(*position_range, targets.shape, env.device) + limits = soft_limits[env_ids][:, joint_ids] + targets = targets.clamp(limits[..., 0], limits[..., 1]) + + asset.write_joint_state_to_sim( + targets, + torch.zeros_like(targets), + env_ids=env_ids, + joint_ids=joint_ids, + ) + asset.data.joint_pos_target[env_ids[:, None], joint_ids[None, :]] = targets diff --git a/src/tasks/velocity/mdp/observations.py b/src/tasks/velocity/mdp/observations.py new file mode 100644 index 0000000..b63793b --- /dev/null +++ b/src/tasks/velocity/mdp/observations.py @@ -0,0 +1,55 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +import torch + +from mjlab.entity import Entity +from mjlab.managers.scene_entity_config import SceneEntityCfg +from mjlab.sensor import ContactSensor + +if TYPE_CHECKING: + from mjlab.envs import ManagerBasedRlEnv + +_DEFAULT_ASSET_CFG = SceneEntityCfg("robot") + + +def foot_height( + env: ManagerBasedRlEnv, asset_cfg: SceneEntityCfg = _DEFAULT_ASSET_CFG +) -> torch.Tensor: + asset: Entity = env.scene[asset_cfg.name] + return asset.data.site_pos_w[:, asset_cfg.site_ids, 2] # (num_envs, num_sites) + + +def foot_air_time(env: ManagerBasedRlEnv, sensor_name: str) -> torch.Tensor: + sensor: ContactSensor = env.scene[sensor_name] + sensor_data = sensor.data + current_air_time = sensor_data.current_air_time + assert current_air_time is not None + return current_air_time + + +def foot_contact(env: ManagerBasedRlEnv, sensor_name: str) -> torch.Tensor: + sensor: ContactSensor = env.scene[sensor_name] + sensor_data = sensor.data + assert sensor_data.found is not None + return (sensor_data.found > 0).float() + + +def foot_contact_forces(env: ManagerBasedRlEnv, sensor_name: str) -> torch.Tensor: + sensor: ContactSensor = env.scene[sensor_name] + sensor_data = sensor.data + assert sensor_data.force is not None + forces_flat = sensor_data.force.flatten(start_dim=1) # [B, N*3] + return torch.sign(forces_flat) * torch.log1p(torch.abs(forces_flat)) + + +def phase(env: ManagerBasedRlEnv, period: float, command_name: str) -> torch.Tensor: + global_phase = (env.episode_length_buf * env.step_dt) % period / period + phase = torch.zeros(env.num_envs, 2, device=env.device) + phase[:, 0] = torch.sin(global_phase * torch.pi * 2.0) + phase[:, 1] = torch.cos(global_phase * torch.pi * 2.0) + stand_mask = torch.linalg.norm(env.command_manager.get_command(command_name), dim=1) < 0.1 + phase = torch.where(stand_mask.unsqueeze(1), torch.zeros_like(phase), phase) + return phase + diff --git a/src/tasks/velocity/mdp/rewards.py b/src/tasks/velocity/mdp/rewards.py new file mode 100644 index 0000000..ef78b63 --- /dev/null +++ b/src/tasks/velocity/mdp/rewards.py @@ -0,0 +1,428 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +import torch + +from mjlab.entity import Entity +from mjlab.managers.reward_manager import RewardTermCfg +from mjlab.managers.scene_entity_config import SceneEntityCfg +from mjlab.sensor import BuiltinSensor, ContactSensor +from mjlab.utils.lab_api.math import quat_apply_inverse +from mjlab.utils.lab_api.string import ( + resolve_matching_names_values, +) + +if TYPE_CHECKING: + from mjlab.envs import ManagerBasedRlEnv + + +_DEFAULT_ASSET_CFG = SceneEntityCfg("robot") + + +def track_linear_velocity( + env: ManagerBasedRlEnv, + std: float, + command_name: str, + asset_cfg: SceneEntityCfg = _DEFAULT_ASSET_CFG, +) -> torch.Tensor: + """Reward for tracking the commanded base linear velocity. + + The commanded z velocity is assumed to be zero. + """ + asset: Entity = env.scene[asset_cfg.name] + command = env.command_manager.get_command(command_name) + assert command is not None, f"Command '{command_name}' not found." + actual = asset.data.root_link_lin_vel_b + xy_error = torch.sum(torch.square(command[:, :2] - actual[:, :2]), dim=1) + z_error = torch.square(actual[:, 2]) + lin_vel_error = xy_error + (2 * z_error) + return torch.exp(-lin_vel_error / std**2) + + +def track_angular_velocity( + env: ManagerBasedRlEnv, + std: float, + command_name: str, + asset_cfg: SceneEntityCfg = _DEFAULT_ASSET_CFG, +) -> torch.Tensor: + """Reward heading error for heading-controlled envs, angular velocity for others. + + The commanded xy angular velocities are assumed to be zero. + """ + asset: Entity = env.scene[asset_cfg.name] + command = env.command_manager.get_command(command_name) + assert command is not None, f"Command '{command_name}' not found." + actual = asset.data.root_link_ang_vel_b + z_error = torch.square(command[:, 2] - actual[:, 2]) + xy_error = torch.sum(torch.square(actual[:, :2]), dim=1) + ang_vel_error = z_error + (0.05 * xy_error) + return torch.exp(-ang_vel_error / std**2) + + +def body_orientation_l2( + env: ManagerBasedRlEnv, + asset_cfg: SceneEntityCfg = _DEFAULT_ASSET_CFG, +) -> torch.Tensor: + """Reward flat base orientation (robot being upright). + + If asset_cfg has body_ids specified, computes the projected gravity + for that specific body. Otherwise, uses the root link projected gravity. + """ + asset: Entity = env.scene[asset_cfg.name] + + # If body_ids are specified, compute projected gravity for that body. + if asset_cfg.body_ids: + body_quat_w = asset.data.body_link_quat_w[:, asset_cfg.body_ids, :] # [B, N, 4] + body_quat_w = body_quat_w.squeeze(1) # [B, 4] + gravity_w = asset.data.gravity_vec_w # [3] + projected_gravity_b = quat_apply_inverse(body_quat_w, gravity_w) # [B, 3] + xy_squared = torch.sum(torch.square(projected_gravity_b[:, :2]), dim=1) + else: + # Use root link projected gravity. + xy_squared = torch.sum(torch.square(asset.data.projected_gravity_b[:, :2]), dim=1) + return xy_squared + + +def self_collision_cost( + env: ManagerBasedRlEnv, + sensor_name: str, + force_threshold: float = 10.0, +) -> torch.Tensor: + """Penalize self-collisions. + + When the sensor provides force history (from ``history_length > 0``), + counts substeps where any contact force exceeds *force_threshold*. + Falls back to the instantaneous ``found`` count otherwise. + """ + sensor: ContactSensor = env.scene[sensor_name] + data = sensor.data + if data.force_history is not None: + # force_history: [B, N, H, 3] + force_mag = torch.norm(data.force_history, dim=-1) # [B, N, H] + hit = (force_mag > force_threshold).any(dim=1) # [B, H] + return hit.sum(dim=-1).float() # [B] + assert data.found is not None + return data.found.squeeze(-1) + + +def body_angular_velocity_penalty( + env: ManagerBasedRlEnv, + asset_cfg: SceneEntityCfg = _DEFAULT_ASSET_CFG, +) -> torch.Tensor: + """Penalize excessive body angular velocities.""" + asset: Entity = env.scene[asset_cfg.name] + ang_vel = asset.data.body_link_ang_vel_w[:, asset_cfg.body_ids, :] + ang_vel = ang_vel.squeeze(1) + ang_vel_xy = ang_vel[:, :2] # Don't penalize z-angular velocity. + return torch.sum(torch.square(ang_vel_xy), dim=1) + + +def angular_momentum_penalty( + env: ManagerBasedRlEnv, + sensor_name: str, +) -> torch.Tensor: + """Penalize whole-body angular momentum to encourage natural arm swing.""" + angmom_sensor: BuiltinSensor = env.scene[sensor_name] + angmom = angmom_sensor.data + angmom_magnitude_sq = torch.sum(torch.square(angmom), dim=-1) + angmom_magnitude = torch.sqrt(angmom_magnitude_sq) + env.extras["log"]["Metrics/angular_momentum_mean"] = torch.mean(angmom_magnitude) + return angmom_magnitude_sq + + +def feet_air_time( + env: ManagerBasedRlEnv, + sensor_name: str, + threshold: float = 0.4, + command_name: str | None = None, + command_threshold: float = 0.1, +) -> torch.Tensor: + """Reward feet air time.""" + sensor: ContactSensor = env.scene[sensor_name] + sensor_data = sensor.data + air_time = sensor_data.current_air_time + contact_time = sensor_data.current_contact_time + in_contact = contact_time > 0.0 + in_mode_time = torch.where(in_contact, contact_time, air_time) + single_stance = torch.mean(in_contact.float(), dim=1) == 0.5 + mode_time = torch.min(torch.where(single_stance.unsqueeze(-1), in_mode_time, 0.0), dim=1)[0] + error = torch.abs(mode_time - threshold) + reward = torch.clamp(threshold - error, min=0.0) + if command_name is not None: + command = env.command_manager.get_command(command_name) + if command is not None: + linear_norm = torch.norm(command[:, :2], dim=1) + angular_norm = torch.abs(command[:, 2]) + total_command = linear_norm + angular_norm + scale = (total_command > command_threshold).float() + reward *= scale + return reward + + +def feet_clearance( + env: ManagerBasedRlEnv, + target_height: float, + command_name: str | None = None, + command_threshold: float = 0.1, + asset_cfg: SceneEntityCfg = _DEFAULT_ASSET_CFG, +) -> torch.Tensor: + """Penalize deviation from target clearance height, weighted by foot velocity.""" + asset: Entity = env.scene[asset_cfg.name] + foot_z = asset.data.site_pos_w[:, asset_cfg.site_ids, 2] # [B, N] + foot_vel_xy = asset.data.site_lin_vel_w[:, asset_cfg.site_ids, :2] # [B, N, 2] + vel_norm = torch.norm(foot_vel_xy, dim=-1) # [B, N] + delta = torch.abs(foot_z - target_height) # [B, N] + cost = torch.sum(delta * vel_norm, dim=1) # [B] + if command_name is not None: + command = env.command_manager.get_command(command_name) + if command is not None: + linear_norm = torch.norm(command[:, :2], dim=1) + angular_norm = torch.abs(command[:, 2]) + total_command = linear_norm + angular_norm + active = (total_command > command_threshold).float() + cost = cost * active + return cost + + +def feet_gait( + env: ManagerBasedRlEnv, + period: float, + offset: list[float], + threshold: float, + command_threshold: float, + command_name: str, + sensor_name: str, +) -> torch.Tensor: + sensor: ContactSensor = env.scene[sensor_name] + is_contact = sensor.data.current_contact_time > 0 + global_phase = ((env.episode_length_buf * env.step_dt) / period).unsqueeze(1) + offsets = torch.as_tensor(offset, device=env.device, dtype=global_phase.dtype).view(1, -1) + leg_phase = (global_phase + offsets) % 1.0 + is_stance = (leg_phase < threshold) + reward = (is_stance == is_contact).float().mean(dim=1) + if command_name is not None: + command = env.command_manager.get_command(command_name) + if command is not None: + linear_norm = torch.norm(command[:, :2], dim=1) + angular_norm = torch.abs(command[:, 2]) + total_command = linear_norm + angular_norm + scale = (total_command > command_threshold).float() + reward *= scale + return reward + + +class feet_swing_height: + """Penalize deviation from target swing height, evaluated at landing.""" + + def __init__(self, cfg: RewardTermCfg, env: ManagerBasedRlEnv): + self.sensor_name = cfg.params["sensor_name"] + self.site_names = cfg.params["asset_cfg"].site_names + self.peak_heights = torch.zeros( + (env.num_envs, len(self.site_names)), device=env.device, dtype=torch.float32 + ) + self.step_dt = env.step_dt + + def __call__( + self, + env: ManagerBasedRlEnv, + sensor_name: str, + target_height: float, + command_name: str, + command_threshold: float, + asset_cfg: SceneEntityCfg, + ) -> torch.Tensor: + asset: Entity = env.scene[asset_cfg.name] + contact_sensor: ContactSensor = env.scene[sensor_name] + command = env.command_manager.get_command(command_name) + assert command is not None + foot_heights = asset.data.site_pos_w[:, asset_cfg.site_ids, 2] + in_air = contact_sensor.data.found == 0 + self.peak_heights = torch.where( + in_air, + torch.maximum(self.peak_heights, foot_heights), + self.peak_heights, + ) + first_contact = contact_sensor.compute_first_contact(dt=self.step_dt) + linear_norm = torch.norm(command[:, :2], dim=1) + angular_norm = torch.abs(command[:, 2]) + total_command = linear_norm + angular_norm + active = (total_command > command_threshold).float() + error = self.peak_heights / target_height - 1.0 + cost = torch.sum(torch.square(error) * first_contact.float(), dim=1) * active + num_landings = torch.sum(first_contact.float()) + peak_heights_at_landing = self.peak_heights * first_contact.float() + mean_peak_height = torch.sum(peak_heights_at_landing) / torch.clamp( + num_landings, min=1 + ) + env.extras["log"]["Metrics/peak_height_mean"] = mean_peak_height + self.peak_heights = torch.where( + first_contact, + torch.zeros_like(self.peak_heights), + self.peak_heights, + ) + return cost + + +def feet_slip( + env: ManagerBasedRlEnv, + sensor_name: str, + command_name: str, + command_threshold: float = 0.01, + asset_cfg: SceneEntityCfg = _DEFAULT_ASSET_CFG, +) -> torch.Tensor: + """Penalize foot sliding (xy velocity while in contact).""" + asset: Entity = env.scene[asset_cfg.name] + contact_sensor: ContactSensor = env.scene[sensor_name] + command = env.command_manager.get_command(command_name) + assert command is not None + linear_norm = torch.norm(command[:, :2], dim=1) + angular_norm = torch.abs(command[:, 2]) + total_command = linear_norm + angular_norm + active = (total_command > command_threshold).float() + assert contact_sensor.data.found is not None + in_contact = (contact_sensor.data.found > 0).float() # [B, N] + foot_vel_xy = asset.data.site_lin_vel_w[:, asset_cfg.site_ids, :2] # [B, N, 2] + vel_xy_norm = torch.norm(foot_vel_xy, dim=-1) # [B, N] + vel_xy_norm_sq = torch.square(vel_xy_norm) # [B, N] + cost = torch.sum(vel_xy_norm_sq * in_contact, dim=1) * active + num_in_contact = torch.sum(in_contact) + mean_slip_vel = torch.sum(vel_xy_norm * in_contact) / torch.clamp( + num_in_contact, min=1 + ) + env.extras["log"]["Metrics/slip_velocity_mean"] = mean_slip_vel + return cost + + +def soft_landing( + env: ManagerBasedRlEnv, + sensor_name: str, + command_name: str | None = None, + command_threshold: float = 0.05, +) -> torch.Tensor: + """Penalize high impact forces at landing to encourage soft footfalls.""" + contact_sensor: ContactSensor = env.scene[sensor_name] + sensor_data = contact_sensor.data + assert sensor_data.force is not None + forces = sensor_data.force # [B, N, 3] + force_magnitude = torch.norm(forces, dim=-1) # [B, N] + first_contact = contact_sensor.compute_first_contact(dt=env.step_dt) # [B, N] + landing_impact = force_magnitude * first_contact.float() # [B, N] + cost = torch.sum(landing_impact, dim=1) # [B] + num_landings = torch.sum(first_contact.float()) + mean_landing_force = torch.sum(landing_impact) / torch.clamp(num_landings, min=1) + env.extras["log"]["Metrics/landing_force_mean"] = mean_landing_force + if command_name is not None: + command = env.command_manager.get_command(command_name) + if command is not None: + linear_norm = torch.norm(command[:, :2], dim=1) + angular_norm = torch.abs(command[:, 2]) + total_command = linear_norm + angular_norm + active = (total_command > command_threshold).float() + cost = cost * active + return cost + + +class variable_posture: + """Penalize deviation from default pose with speed-dependent tolerance. + + Uses per-joint standard deviations to control how much each joint can deviate + from default pose. Smaller std = stricter (less deviation allowed), larger + std = more forgiving. The reward is: exp(-mean(error² / std²)) + + Three speed regimes (based on linear + angular command velocity): + - std_standing (speed < walking_threshold): Tight tolerance for holding pose. + - std_walking (walking_threshold <= speed < running_threshold): Moderate. + - std_running (speed >= running_threshold): Loose tolerance for large motion. + + Tune std values per joint based on how much motion that joint needs at each + speed. Map joint name patterns to std values, e.g. {".*knee.*": 0.35}. + """ + + def __init__(self, cfg: RewardTermCfg, env: ManagerBasedRlEnv): + asset: Entity = env.scene[cfg.params["asset_cfg"].name] + default_joint_pos = asset.data.default_joint_pos + assert default_joint_pos is not None + self.default_joint_pos = default_joint_pos + + _, joint_names = asset.find_joints(cfg.params["asset_cfg"].joint_names) + + _, _, std_standing = resolve_matching_names_values( + data=cfg.params["std_standing"], + list_of_strings=joint_names, + ) + self.std_standing = torch.tensor( + std_standing, device=env.device, dtype=torch.float32 + ) + + _, _, std_walking = resolve_matching_names_values( + data=cfg.params["std_walking"], + list_of_strings=joint_names, + ) + self.std_walking = torch.tensor(std_walking, device=env.device, dtype=torch.float32) + + _, _, std_running = resolve_matching_names_values( + data=cfg.params["std_running"], + list_of_strings=joint_names, + ) + self.std_running = torch.tensor(std_running, device=env.device, dtype=torch.float32) + + def __call__( + self, + env: ManagerBasedRlEnv, + std_standing, + std_walking, + std_running, + asset_cfg: SceneEntityCfg, + command_name: str, + walking_threshold: float = 0.5, + running_threshold: float = 1.5, + ) -> torch.Tensor: + del std_standing, std_walking, std_running # Unused. + + asset: Entity = env.scene[asset_cfg.name] + command = env.command_manager.get_command(command_name) + assert command is not None + + linear_speed = torch.norm(command[:, :2], dim=1) + angular_speed = torch.abs(command[:, 2]) + total_speed = linear_speed + angular_speed + + standing_mask = (total_speed < walking_threshold).float() + walking_mask = ( + (total_speed >= walking_threshold) & (total_speed < running_threshold) + ).float() + running_mask = (total_speed >= running_threshold).float() + + std = ( + self.std_standing * standing_mask.unsqueeze(1) + + self.std_walking * walking_mask.unsqueeze(1) + + self.std_running * running_mask.unsqueeze(1) + ) + + current_joint_pos = asset.data.joint_pos[:, asset_cfg.joint_ids] + desired_joint_pos = self.default_joint_pos[:, asset_cfg.joint_ids] + error_squared = torch.square(current_joint_pos - desired_joint_pos) + + return torch.exp(-torch.mean(error_squared / (std**2), dim=1)) + + +def stand_still( + env: ManagerBasedRlEnv, + command_name: str, + command_threshold: float = 0.1, + asset_cfg: SceneEntityCfg = _DEFAULT_ASSET_CFG +) -> torch.Tensor: + asset: Entity = env.scene[asset_cfg.name] + diff_angle = asset.data.joint_pos[:, asset_cfg.joint_ids] - asset.data.default_joint_pos[:, asset_cfg.joint_ids] + reward = torch.sum(torch.square(diff_angle), dim=1) + if command_name is not None: + command = env.command_manager.get_command(command_name) + if command is not None: + linear_norm = torch.norm(command[:, :2], dim=1) + angular_norm = torch.abs(command[:, 2]) + total_command = linear_norm + angular_norm + scale = (total_command <= command_threshold).float() + reward *= scale + return reward + diff --git a/src/tasks/velocity/mdp/terminations.py b/src/tasks/velocity/mdp/terminations.py new file mode 100644 index 0000000..509ea5e --- /dev/null +++ b/src/tasks/velocity/mdp/terminations.py @@ -0,0 +1,25 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +import torch + +from mjlab.sensor import ContactSensor + +if TYPE_CHECKING: + from mjlab.envs import ManagerBasedRlEnv + + +def illegal_contact( + env: ManagerBasedRlEnv, + sensor_name: str, + force_threshold: float = 10.0, +) -> torch.Tensor: + sensor: ContactSensor = env.scene[sensor_name] + data = sensor.data + if data.force_history is not None: + # force_history: [B, N, H, 3] + force_mag = torch.norm(data.force_history, dim=-1) # [B, N, H] + return (force_mag > force_threshold).any(dim=-1).any(dim=-1) # [B] + assert data.found is not None + return torch.any(data.found, dim=-1) \ No newline at end of file diff --git a/src/tasks/velocity/mdp/velocity_command.py b/src/tasks/velocity/mdp/velocity_command.py new file mode 100644 index 0000000..54cab43 --- /dev/null +++ b/src/tasks/velocity/mdp/velocity_command.py @@ -0,0 +1,282 @@ +from __future__ import annotations + +from collections.abc import Callable +from dataclasses import dataclass, field +from typing import TYPE_CHECKING + +import numpy as np +import torch + +from mjlab.entity import Entity +from mjlab.managers.command_manager import CommandTerm, CommandTermCfg +from mjlab.utils.lab_api.math import ( + matrix_from_quat, + quat_apply, + wrap_to_pi, +) + +if TYPE_CHECKING: + import viser + + from mjlab.envs.manager_based_rl_env import ManagerBasedRlEnv + from mjlab.viewer.debug_visualizer import DebugVisualizer + + +class UniformVelocityCommand(CommandTerm): + cfg: UniformVelocityCommandCfg + + def __init__(self, cfg: UniformVelocityCommandCfg, env: ManagerBasedRlEnv): + super().__init__(cfg, env) + + if self.cfg.heading_command and self.cfg.ranges.heading is None: + raise ValueError("heading_command=True but ranges.heading is set to None.") + if self.cfg.ranges.heading and not self.cfg.heading_command: + raise ValueError("ranges.heading is set but heading_command=False.") + + self.robot: Entity = env.scene[cfg.entity_name] + + self.vel_command_b = torch.zeros(self.num_envs, 3, device=self.device) + self.heading_target = torch.zeros(self.num_envs, device=self.device) + self.heading_error = torch.zeros(self.num_envs, device=self.device) + self.is_heading_env = torch.zeros( + self.num_envs, dtype=torch.bool, device=self.device + ) + self.is_standing_env = torch.zeros_like(self.is_heading_env) + + self.metrics["error_vel_xy"] = torch.zeros(self.num_envs, device=self.device) + self.metrics["error_vel_yaw"] = torch.zeros(self.num_envs, device=self.device) + + # Set by create_gui() when the viewer is active. + self._joystick_enabled: viser.GuiCheckboxHandle | None = None + self._joystick_sliders: list[viser.GuiSliderHandle] = [] + self._joystick_get_env_idx: Callable[[], int] | None = None + + @property + def command(self) -> torch.Tensor: + return self.vel_command_b + + def _update_metrics(self) -> None: + max_command_time = self.cfg.resampling_time_range[1] + max_command_step = max_command_time / self._env.step_dt + self.metrics["error_vel_xy"] += ( + torch.norm( + self.vel_command_b[:, :2] - self.robot.data.root_link_lin_vel_b[:, :2], dim=-1 + ) + / max_command_step + ) + self.metrics["error_vel_yaw"] += ( + torch.abs(self.vel_command_b[:, 2] - self.robot.data.root_link_ang_vel_b[:, 2]) + / max_command_step + ) + + def _resample_command(self, env_ids: torch.Tensor) -> None: + r = torch.empty(len(env_ids), device=self.device) + self.vel_command_b[env_ids, 0] = r.uniform_(*self.cfg.ranges.lin_vel_x) + self.vel_command_b[env_ids, 1] = r.uniform_(*self.cfg.ranges.lin_vel_y) + self.vel_command_b[env_ids, 2] = r.uniform_(*self.cfg.ranges.ang_vel_z) + self.vel_command_b[env_ids, :] *= (torch.norm(self.vel_command_b[env_ids, :], dim=1) > 0.1).unsqueeze(1) + if self.cfg.heading_command: + assert self.cfg.ranges.heading is not None + self.heading_target[env_ids] = r.uniform_(*self.cfg.ranges.heading) + self.is_heading_env[env_ids] = r.uniform_(0.0, 1.0) <= self.cfg.rel_heading_envs + self.is_standing_env[env_ids] = r.uniform_(0.0, 1.0) <= self.cfg.rel_standing_envs + + init_vel_mask = r.uniform_(0.0, 1.0) < self.cfg.init_velocity_prob + init_vel_env_ids = env_ids[init_vel_mask] + if len(init_vel_env_ids) > 0: + root_pos = self.robot.data.root_link_pos_w[init_vel_env_ids] + root_quat = self.robot.data.root_link_quat_w[init_vel_env_ids] + lin_vel_b = self.robot.data.root_link_lin_vel_b[init_vel_env_ids] + lin_vel_b[:, :2] = self.vel_command_b[init_vel_env_ids, :2] + root_lin_vel_w = quat_apply(root_quat, lin_vel_b) + root_ang_vel_b = self.robot.data.root_link_ang_vel_b[init_vel_env_ids] + root_ang_vel_b[:, 2] = self.vel_command_b[init_vel_env_ids, 2] + root_state = torch.cat( + [root_pos, root_quat, root_lin_vel_w, root_ang_vel_b], dim=-1 + ) + self.robot.write_root_state_to_sim(root_state, init_vel_env_ids) + + def _update_command(self) -> None: + if self.cfg.heading_command: + self.heading_error = wrap_to_pi(self.heading_target - self.robot.data.heading_w) + env_ids = self.is_heading_env.nonzero(as_tuple=False).flatten() + self.vel_command_b[env_ids, 2] = torch.clip( + self.cfg.heading_control_stiffness * self.heading_error[env_ids], + min=self.cfg.ranges.ang_vel_z[0], + max=self.cfg.ranges.ang_vel_z[1], + ) + standing_env_ids = self.is_standing_env.nonzero(as_tuple=False).flatten() + self.vel_command_b[standing_env_ids, :] = 0.0 + + # GUI. + + def create_gui( + self, + name: str, + server: "viser.ViserServer", + get_env_idx: Callable[[], int], + ) -> None: + """Create velocity joystick sliders in the Viser viewer.""" + from viser import Icon + + ranges = self.cfg.ranges + + axes = [ + ("lin_vel_x", ranges.lin_vel_x[1]), + ("lin_vel_y", ranges.lin_vel_y[1]), + ("ang_vel_z", ranges.ang_vel_z[1]), + ] + sliders: list = [] + + with server.gui.add_folder(name.capitalize()): + enabled = server.gui.add_checkbox("Enable", initial_value=False) + + for label, max_val in axes: + max_input = server.gui.add_slider( + f"Max {label}", + initial_value=max_val, + step=0.1, + min=0.1, + max=10.0, + ) + slider = server.gui.add_slider( + label, + min=-max_val, + max=max_val, + step=0.05, + initial_value=0.0, + ) + + @max_input.on_update + def _(_ev, _s=slider, _m=max_input) -> None: + _s.min = -_m.value + _s.max = _m.value + + sliders.append(slider) + + zero_btn = server.gui.add_button("Zero", icon=Icon.SQUARE_X) + + @zero_btn.on_click + def _(_) -> None: + for s in sliders: + s.value = 0.0 + + # Store GUI state for compute() override. + self._joystick_enabled = enabled + self._joystick_sliders = sliders + self._joystick_get_env_idx = get_env_idx + + def compute(self, dt: float) -> None: + super().compute(dt) + if self._joystick_enabled is not None and self._joystick_enabled.value: + assert self._joystick_get_env_idx is not None + idx = self._joystick_get_env_idx() + for i, s in enumerate(self._joystick_sliders): + self.vel_command_b[idx, i] = s.value + + # Visualization. + + def _debug_vis_impl(self, visualizer: "DebugVisualizer") -> None: + """Draw velocity command and actual velocity arrows.""" + env_indices = visualizer.get_env_indices(self.num_envs) + if not env_indices: + return + + cmds = self.command.cpu().numpy() + base_pos_ws = self.robot.data.root_link_pos_w.cpu().numpy() + base_quat_w = self.robot.data.root_link_quat_w + base_mat_ws = matrix_from_quat(base_quat_w).cpu().numpy() + lin_vel_bs = self.robot.data.root_link_lin_vel_b.cpu().numpy() + ang_vel_bs = self.robot.data.root_link_ang_vel_b.cpu().numpy() + + scale = self.cfg.viz.scale + z_offset = self.cfg.viz.z_offset + + for batch in env_indices: + base_pos_w = base_pos_ws[batch] + base_mat_w = base_mat_ws[batch] + cmd = cmds[batch] + lin_vel_b = lin_vel_bs[batch] + ang_vel_b = ang_vel_bs[batch] + + # Skip if robot appears uninitialized (at origin). + if np.linalg.norm(base_pos_w) < 1e-6: + continue + + # Helper to transform local to world coordinates. + def local_to_world( + vec: np.ndarray, pos: np.ndarray = base_pos_w, mat: np.ndarray = base_mat_w + ) -> np.ndarray: + return pos + mat @ vec + + # Command linear velocity arrow (blue). + cmd_lin_from = local_to_world(np.array([0, 0, z_offset]) * scale) + cmd_lin_to = local_to_world( + (np.array([0, 0, z_offset]) + np.array([cmd[0], cmd[1], 0])) * scale + ) + visualizer.add_arrow( + cmd_lin_from, cmd_lin_to, color=(0.2, 0.2, 0.6, 0.6), width=0.015 + ) + + # Command angular velocity arrow (green). + cmd_ang_from = cmd_lin_from + cmd_ang_to = local_to_world( + (np.array([0, 0, z_offset]) + np.array([0, 0, cmd[2]])) * scale + ) + visualizer.add_arrow( + cmd_ang_from, cmd_ang_to, color=(0.2, 0.6, 0.2, 0.6), width=0.015 + ) + + # Actual linear velocity arrow (cyan). + act_lin_from = local_to_world(np.array([0, 0, z_offset]) * scale) + act_lin_to = local_to_world( + (np.array([0, 0, z_offset]) + np.array([lin_vel_b[0], lin_vel_b[1], 0])) * scale + ) + visualizer.add_arrow( + act_lin_from, act_lin_to, color=(0.0, 0.6, 1.0, 0.7), width=0.015 + ) + + # Actual angular velocity arrow (light green). + act_ang_from = act_lin_from + act_ang_to = local_to_world( + (np.array([0, 0, z_offset]) + np.array([0, 0, ang_vel_b[2]])) * scale + ) + visualizer.add_arrow( + act_ang_from, act_ang_to, color=(0.0, 1.0, 0.4, 0.7), width=0.015 + ) + + +@dataclass(kw_only=True) +class UniformVelocityCommandCfg(CommandTermCfg): + entity_name: str + heading_command: bool = False + heading_control_stiffness: float = 1.0 + rel_standing_envs: float = 0.0 + rel_heading_envs: float = 1.0 + init_velocity_prob: float = 0.0 + + @dataclass + class Ranges: + lin_vel_x: tuple[float, float] + lin_vel_y: tuple[float, float] + ang_vel_z: tuple[float, float] + heading: tuple[float, float] | None = None + + ranges: Ranges + + @dataclass + class VizCfg: + z_offset: float = 0.2 + scale: float = 0.5 + + viz: VizCfg = field(default_factory=VizCfg) + + def build(self, env: ManagerBasedRlEnv) -> UniformVelocityCommand: + return UniformVelocityCommand(self, env) + + def __post_init__(self): + if self.heading_command and self.ranges.heading is None: + raise ValueError( + "The velocity command has heading commands active (heading_command=True) but " + "the `ranges.heading` parameter is set to None." + ) diff --git a/src/tasks/velocity/rl/__init__.py b/src/tasks/velocity/rl/__init__.py new file mode 100644 index 0000000..6e5e039 --- /dev/null +++ b/src/tasks/velocity/rl/__init__.py @@ -0,0 +1,3 @@ +from .runner import ( + VelocityOnPolicyRunner as VelocityOnPolicyRunner, +) diff --git a/src/tasks/velocity/rl/runner.py b/src/tasks/velocity/rl/runner.py new file mode 100644 index 0000000..4900af6 --- /dev/null +++ b/src/tasks/velocity/rl/runner.py @@ -0,0 +1,28 @@ +import os + +import wandb + +from mjlab.rl import RslRlVecEnvWrapper +from mjlab.rl.exporter_utils import ( + attach_metadata_to_onnx, + get_base_metadata, +) +from mjlab.rl.runner import MjlabOnPolicyRunner + + +class VelocityOnPolicyRunner(MjlabOnPolicyRunner): + env: RslRlVecEnvWrapper + + def save(self, path: str, infos=None): + super().save(path, infos) + policy_path = path.split("model")[0] + filename = "policy.onnx" + self.export_policy_to_onnx(policy_path, filename) + run_name: str = ( + wandb.run.name if self.logger.logger_type == "wandb" and wandb.run else "local" + ) # type: ignore[assignment] + onnx_path = os.path.join(policy_path, filename) + metadata = get_base_metadata(self.env.unwrapped, run_name) + attach_metadata_to_onnx(onnx_path, metadata) + if self.logger.logger_type in ["wandb"]: + wandb.save(policy_path + filename, base_path=os.path.dirname(policy_path)) diff --git a/src/tasks/velocity/velocity_env_cfg.py b/src/tasks/velocity/velocity_env_cfg.py new file mode 100644 index 0000000..feebe37 --- /dev/null +++ b/src/tasks/velocity/velocity_env_cfg.py @@ -0,0 +1,431 @@ +"""Velocity task configuration. + +This module provides a factory function to create a base velocity task config. +Robot-specific configurations call the factory and customize as needed. +""" + +import math +from dataclasses import replace + +from mjlab.envs import ManagerBasedRlEnvCfg +from mjlab.envs import mdp as envs_mdp +from mjlab.envs.mdp import dr +from mjlab.envs.mdp.actions import JointPositionActionCfg +from mjlab.managers.action_manager import ActionTermCfg +from mjlab.managers.command_manager import CommandTermCfg +from mjlab.managers.curriculum_manager import CurriculumTermCfg +from mjlab.managers.event_manager import EventTermCfg +from mjlab.managers.metrics_manager import MetricsTermCfg +from mjlab.managers.observation_manager import ObservationGroupCfg, ObservationTermCfg +from mjlab.managers.reward_manager import RewardTermCfg +from mjlab.managers.scene_entity_config import SceneEntityCfg +from mjlab.managers.termination_manager import TerminationTermCfg +from mjlab.scene import SceneCfg +from mjlab.sensor import GridPatternCfg, ObjRef, RayCastSensorCfg +from mjlab.sim import MujocoCfg, SimulationCfg +from mjlab.tasks.velocity import mdp +from mjlab.tasks.velocity.mdp import UniformVelocityCommandCfg +from mjlab.terrains import TerrainEntityCfg +from mjlab.terrains.config import ROUGH_TERRAINS_CFG +from mjlab.utils.noise import UniformNoiseCfg as Unoise +from mjlab.viewer import ViewerConfig + +import src.tasks.velocity.mdp as mdp + + +def make_velocity_env_cfg() -> ManagerBasedRlEnvCfg: + """Create base velocity tracking task configuration.""" + + ## + # Sensors + ## + + terrain_scan = RayCastSensorCfg( + name="terrain_scan", + frame=ObjRef(type="body", name="", entity="robot"), # Set per-robot. + ray_alignment="yaw", + pattern=GridPatternCfg(size=(1.6, 1.0), resolution=0.1), + max_distance=5.0, + exclude_parent_body=True, + debug_vis=True, + viz=RayCastSensorCfg.VizCfg(show_normals=True), + ) + + ## + # Observations + ## + + actor_terms = { + "base_ang_vel": ObservationTermCfg( + func=mdp.builtin_sensor, + params={"sensor_name": "robot/imu_ang_vel"}, + noise=Unoise(n_min=-0.2, n_max=0.2), + ), + "projected_gravity": ObservationTermCfg( + func=mdp.projected_gravity, + noise=Unoise(n_min=-0.05, n_max=0.05), + ), + "command": ObservationTermCfg( + func=mdp.generated_commands, + params={"command_name": "twist"}, + ), + "phase": ObservationTermCfg( + func=mdp.phase, + params={"period": 0.6, "command_name": "twist"}, + ), + "joint_pos": ObservationTermCfg( + func=mdp.joint_pos_rel, + noise=Unoise(n_min=-0.01, n_max=0.01), + ), + "joint_vel": ObservationTermCfg( + func=mdp.joint_vel_rel, + noise=Unoise(n_min=-1.5, n_max=1.5), + ), + "actions": ObservationTermCfg(func=mdp.last_action), + "height_scan": ObservationTermCfg( + func=envs_mdp.height_scan, + params={"sensor_name": "terrain_scan"}, + noise=Unoise(n_min=-0.1, n_max=0.1), + scale=1 / terrain_scan.max_distance, + ), + } + + critic_terms = { + **actor_terms, + "base_lin_vel": ObservationTermCfg( + func=mdp.builtin_sensor, + params={"sensor_name": "robot/imu_lin_vel"}, + noise=Unoise(n_min=-0.5, n_max=0.5), + ), + "height_scan": ObservationTermCfg( + func=envs_mdp.height_scan, + params={"sensor_name": "terrain_scan"}, + scale=1 / terrain_scan.max_distance, + ), + "foot_height": ObservationTermCfg( + func=mdp.foot_height, + params={"asset_cfg": SceneEntityCfg("robot", site_names=())}, # Set per-robot. + ), + "foot_air_time": ObservationTermCfg( + func=mdp.foot_air_time, + params={"sensor_name": "feet_ground_contact"}, + ), + "foot_contact": ObservationTermCfg( + func=mdp.foot_contact, + params={"sensor_name": "feet_ground_contact"}, + ), + "foot_contact_forces": ObservationTermCfg( + func=mdp.foot_contact_forces, + params={"sensor_name": "feet_ground_contact"}, + ), + } + + observations = { + "actor": ObservationGroupCfg( + terms=actor_terms, + concatenate_terms=True, + enable_corruption=True, + history_length=1, + ), + "critic": ObservationGroupCfg( + terms=critic_terms, + concatenate_terms=True, + enable_corruption=False, + history_length=1, + ), + } + + ## + # Metrics + ## + + metrics = { + "mean_action_acc": MetricsTermCfg( + func=mdp.mean_action_acc, + ), + } + + ## + # Actions + ## + + actions: dict[str, ActionTermCfg] = { + "joint_pos": JointPositionActionCfg( + entity_name="robot", + actuator_names=(".*",), + scale=0.25, # Override per-robot. + use_default_offset=True, + ) + } + + ## + # Commands + ## + + commands: dict[str, CommandTermCfg] = { + "twist": UniformVelocityCommandCfg( + entity_name="robot", + resampling_time_range=(3.0, 8.0), + rel_standing_envs=0.05, + heading_command=True, + heading_control_stiffness=0.5, + debug_vis=True, + ranges=UniformVelocityCommandCfg.Ranges( + lin_vel_x=(-1.0, 2.0), + lin_vel_y=(-1.0, 1.0), + ang_vel_z=(-1.0, 1.0), + heading=(-math.pi, math.pi), + ), + ) + } + + ## + # Events + ## + + events = { + "reset_base": EventTermCfg( + func=mdp.reset_root_state_uniform, + mode="reset", + params={ + "pose_range": { + "x": (-0.5, 0.5), + "y": (-0.5, 0.5), + "z": (0.0, 0.0), + "yaw": (-3.14, 3.14), + }, + "velocity_range": {}, + }, + ), + "reset_robot_joints": EventTermCfg( + func=mdp.reset_joints_by_offset, + mode="reset", + params={ + "position_range": (-0.0, 0.0), + "velocity_range": (-0.0, 0.0), + "asset_cfg": SceneEntityCfg("robot", joint_names=(".*",)), + }, + ), + "push_robot": EventTermCfg( + func=mdp.push_by_setting_velocity, + mode="interval", + interval_range_s=(5.0, 6.0), + params={ + "velocity_range": { + "x": (-0.5, 0.5), + "y": (-0.5, 0.5), + "z": (-0.4, 0.4), + "roll": (-0.52, 0.52), + "pitch": (-0.52, 0.52), + "yaw": (-0.78, 0.78), + }, + }, + ), + "foot_friction": EventTermCfg( + mode="startup", + func=dr.geom_friction, + params={ + "asset_cfg": SceneEntityCfg("robot", geom_names=()), # Set per-robot. + "operation": "abs", + "ranges": (0.3, 1.6), + "shared_random": True, # All foot geoms share the same friction. + }, + ), + "encoder_bias": EventTermCfg( + mode="startup", + func=dr.encoder_bias, + params={ + "asset_cfg": SceneEntityCfg("robot"), + "bias_range": (-0.015, 0.015), + }, + ), + "base_com": EventTermCfg( + mode="startup", + func=dr.body_com_offset, + params={ + "asset_cfg": SceneEntityCfg("robot", body_names=()), # Set per-robot. + "operation": "add", + "ranges": { + 0: (-0.05, 0.05), + 1: (-0.05, 0.05), + 2: (-0.05, 0.05), + }, + }, + ), + } + + ## + # Rewards + ## + + rewards = { + "track_linear_velocity": RewardTermCfg( + func=mdp.track_linear_velocity, + weight=1.0, + params={"command_name": "twist", "std": math.sqrt(0.25)}, + ), + "track_angular_velocity": RewardTermCfg( + func=mdp.track_angular_velocity, + weight=1.0, + params={"command_name": "twist", "std": math.sqrt(0.5)}, + ), + "body_orientation_l2": RewardTermCfg( + func=mdp.body_orientation_l2, + weight=-1.0, + params={"asset_cfg": SceneEntityCfg("robot", body_names=())}, # Set per-robot. + ), + "pose": RewardTermCfg( + func=mdp.variable_posture, + weight=1.0, + params={ + "asset_cfg": SceneEntityCfg("robot", joint_names=".*"), + "command_name": "twist", + "std_standing": {}, # Set per-robot. + "std_walking": {}, # Set per-robot. + "std_running": {}, # Set per-robot. + "walking_threshold": 0.1, + "running_threshold": 1.5, + }, + ), + "body_ang_vel": RewardTermCfg( + func=mdp.body_angular_velocity_penalty, + weight=-0.05, # Override per-robot + params={"asset_cfg": SceneEntityCfg("robot", body_names=())}, # Set per-robot. + ), + "angular_momentum": RewardTermCfg( + func=mdp.angular_momentum_penalty, + weight=-0.025, # Override per-robot + params={"sensor_name": "robot/root_angmom"}, + ), + "is_terminated": RewardTermCfg(func=mdp.is_terminated, weight=-200.0), + "joint_acc_l2": RewardTermCfg(func=mdp.joint_acc_l2, weight=-2.5e-7), + "joint_pos_limits": RewardTermCfg(func=mdp.joint_pos_limits, weight=-10.0), + "action_rate_l2": RewardTermCfg(func=mdp.action_rate_l2, weight=-0.05), + "foot_gait": RewardTermCfg( + func=mdp.feet_gait, + weight=0.5, + params={ + "period": 0.6, + "offset": [0.0, 0.5], + "threshold": 0.56, + "command_threshold": 0.1, + "command_name": "twist", + "sensor_name": "feet_ground_contact", + } + ), + "foot_clearance": RewardTermCfg( + func=mdp.feet_clearance, + weight=-1.0, + params={ + "target_height": 0.10, + "command_name": "twist", + "command_threshold": 0.1, + "asset_cfg": SceneEntityCfg("robot", site_names=()), # Set per-robot. + }, + ), + "foot_slip": RewardTermCfg( + func=mdp.feet_slip, + weight=-0.25, + params={ + "sensor_name": "feet_ground_contact", + "command_name": "twist", + "command_threshold": 0.1, + "asset_cfg": SceneEntityCfg("robot", site_names=()), # Set per-robot. + }, + ), + "soft_landing": RewardTermCfg( + func=mdp.soft_landing, + weight=-1e-3, + params={ + "sensor_name": "feet_ground_contact", + "command_name": "twist", + "command_threshold": 0.1, + }, + ), + "stand_still": RewardTermCfg( + func=mdp.stand_still, + weight=-1.0, + params={ + "command_name": "twist", + "command_threshold": 0.1, + "asset_cfg": SceneEntityCfg("robot", joint_names=".*"), + }, + ), + } + + ## + # Terminations + ## + + terminations = { + "time_out": TerminationTermCfg(func=mdp.time_out, time_out=True), + "fell_over": TerminationTermCfg( + func=mdp.bad_orientation, + params={"limit_angle": math.radians(70.0)}, + ), + } + + ## + # Curriculum + ## + + curriculum = { + "terrain_levels": CurriculumTermCfg( + func=mdp.terrain_levels_vel, + params={"command_name": "twist"}, + ), + "command_vel": CurriculumTermCfg( + func=mdp.commands_vel, + params={ + "command_name": "twist", + "velocity_stages": [ + {"step": 0, "lin_vel_x": (-0.5, 1.0), "lin_vel_y": (-0.5, 0.5), "ang_vel_z": (-1.0, 1.0)}, + {"step": 5000 * 24, "lin_vel_x": (-1.0, 2.0), "lin_vel_y": (-1.0, 1.0)}, + ], + }, + ), + } + + ## + # Assemble and return + ## + + return ManagerBasedRlEnvCfg( + scene=SceneCfg( + terrain=TerrainEntityCfg( + terrain_type="generator", + terrain_generator=replace(ROUGH_TERRAINS_CFG), + max_init_terrain_level=5, + ), + sensors=(terrain_scan,), + num_envs=1, + extent=2.0, + ), + observations=observations, + actions=actions, + commands=commands, + events=events, + rewards=rewards, + terminations=terminations, + curriculum=curriculum, + metrics=metrics, + viewer=ViewerConfig( + origin_type=ViewerConfig.OriginType.ASSET_BODY, + entity_name="robot", + body_name="", # Set per-robot. + distance=3.0, + elevation=-5.0, + azimuth=90.0, + ), + sim=SimulationCfg( + nconmax=35, + njmax=1500, + mujoco=MujocoCfg( + timestep=0.005, + iterations=10, + ls_iterations=20, + ), + ), + decimation=4, + episode_length_s=20.0, + ) diff --git a/training/snapshots/blind/agent.yaml b/training/snapshots/blind/agent.yaml new file mode 100644 index 0000000..dfb0e60 --- /dev/null +++ b/training/snapshots/blind/agent.yaml @@ -0,0 +1,55 @@ +seed: 42 +num_steps_per_env: 24 +max_iterations: 14000 +obs_groups: + actor: !!python/tuple + - actor + critic: !!python/tuple + - critic +save_interval: 100 +experiment_name: superspider_stairs_velocity +run_name: '' +logger: tensorboard +wandb_project: mjlab +wandb_tags: !!python/tuple [] +resume: true +load_run: zz_flat +load_checkpoint: model_5999.pt +clip_actions: null +upload_model: true +class_name: OnPolicyRunner +actor: + hidden_dims: !!python/tuple + - 512 + - 256 + - 128 + activation: elu + obs_normalization: true + distribution_cfg: + init_std: 1.0 + std_type: scalar +critic: + hidden_dims: !!python/tuple + - 512 + - 256 + - 128 + activation: elu + obs_normalization: true +algorithm: + num_learning_epochs: 5 + num_mini_batches: 4 + learning_rate: 0.001 + schedule: adaptive + gamma: 0.99 + lam: 0.95 + entropy_coef: 0.01 + desired_kl: 0.01 + max_grad_norm: 1.0 + value_loss_coef: 1.0 + use_clipped_value_loss: true + clip_param: 0.2 + normalize_advantage_per_mini_batch: false + optimizer: adam + rnd_cfg: null + symmetry_cfg: null +multi_gpu: null diff --git a/training/snapshots/blind/env.yaml b/training/snapshots/blind/env.yaml new file mode 100644 index 0000000..d5df549 --- /dev/null +++ b/training/snapshots/blind/env.yaml @@ -0,0 +1,1630 @@ +decimation: 4 +scene: + num_envs: 512 + env_spacing: 2.0 + terrain: + init_state: + pos: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + rot: !!python/tuple + - 1.0 + - 0.0 + - 0.0 + - 0.0 + lin_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + ang_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + joint_pos: + .*: 0.0 + joint_vel: + .*: 0.0 + spec_fn: !!python/name:mjlab.entity.entity.%3Clambda%3E '' + articulation: null + sort_actuators: false + lights: !!python/tuple + - name: sun + body: world + mode: fixed + target: null + type: directional + castshadow: true + pos: !!python/tuple + - 0.0 + - 0.0 + - 1.5 + dir: !!python/tuple + - 0.0 + - 0.0 + - -1.0 + cutoff: 45.0 + exponent: 10.0 + cameras: !!python/tuple [] + textures: !!python/tuple + - name: groundplane + type: 2d + builtin: checker + rgb1: !!python/tuple + - 0.2 + - 0.3 + - 0.4 + rgb2: !!python/tuple + - 0.1 + - 0.2 + - 0.3 + width: 300 + height: 300 + mark: edge + markrgb: !!python/tuple + - 0.8 + - 0.8 + - 0.8 + materials: !!python/tuple + - name: groundplane + rgba: !!python/tuple + - 1.0 + - 1.0 + - 1.0 + - 1.0 + texuniform: true + texrepeat: !!python/tuple + - 4.0 + - 4.0 + reflectance: 0.2 + texture: groundplane + geom_names_expr: !!python/tuple + - terrain$ + collisions: !!python/tuple [] + terrain_type: generator + terrain_generator: + seed: null + curriculum: true + size: !!python/tuple + - 8.0 + - 8.0 + border_width: 20.0 + border_height: 1.0 + num_rows: 10 + num_cols: 20 + color_scheme: height + sub_terrains: + single_step: + proportion: 1.0 + size: !!python/tuple + - 8.0 + - 8.0 + flat_patch_sampling: null + step_height_range: !!python/tuple + - 0.01 + - 0.06 + approach: 1.5 + difficulty_range: !!python/tuple + - 0.0 + - 1.0 + add_lights: true + env_spacing: 2.0 + max_init_terrain_level: 0 + num_envs: 512 + entities: + robot: + init_state: + pos: !!python/tuple + - 0.0 + - 0.0 + - 0.1 + rot: !!python/tuple + - 1.0 + - 0.0 + - 0.0 + - 0.0 + lin_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + ang_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + joint_pos: + 1_coxa: 0.074027 + 1_femur: 0.943939 + 1_tibia: -0.974578 + 2_coxa: 0.074407 + 2_femur: 1.164487 + 2_tibia: -0.647146 + 3_coxa: -0.037301 + 3_femur: 1.004834 + 3_tibia: -0.590105 + 4_coxa: -0.039226 + 4_femur: 1.349236 + 4_tibia: -0.815209 + 5_coxa: -0.174187 + 5_femur: 0.844217 + 5_tibia: -0.55142 + 6_coxa: 0.246042 + 6_femur: 1.053368 + 6_tibia: -0.997824 + joint_vel: + .*: 0.0 + spec_fn: !!python/name:src.tasks.velocity.config.custom_dog.builder.spec_fn '' + articulation: + actuators: !!python/tuple + - target_names_expr: !!python/tuple + - '[1-6]_(coxa|femur|tibia)' + transmission_type: !!python/object/apply:mjlab.actuator.actuator.TransmissionType + - joint + armature: 0.005 + frictionloss: 0.0 + stiffness: 40.0 + damping: 1.2 + effort_limit: 4.41 + soft_joint_pos_limit_factor: 0.9 + sort_actuators: false + lights: !!python/tuple [] + cameras: !!python/tuple [] + textures: !!python/tuple [] + materials: !!python/tuple [] + collisions: !!python/tuple + - geom_names_expr: !!python/tuple + - ^(base_link|[1-6]_(coxa|femur))_col\d+$ + - ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$ + contype: 1 + conaffinity: 1 + condim: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: 3 + ^(base_link|[1-6]_(coxa|femur))_col\d+$: 1 + priority: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: 1 + friction: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: !!python/tuple + - 0.6 + solref: null + solimp: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: !!python/tuple + - 0.9 + - 0.95 + - 0.023 + disable_other_geoms: true + sensors: !!python/tuple + - name: feet_ground_contact + primary: + mode: geom + pattern: !!python/tuple + - edge_1a + - edge_1b + - edge_2a + - edge_2b + - edge_3a + - edge_3b + - edge_4a + - edge_4b + - edge_5a + - edge_5b + - edge_6a + - edge_6b + entity: robot + exclude: !!python/tuple [] + secondary: + mode: body + pattern: terrain + entity: null + exclude: !!python/tuple [] + fields: !!python/tuple + - found + - force + reduce: netforce + num_slots: 1 + secondary_policy: first + track_air_time: true + global_frame: false + history_length: 0 + debug: false + - name: nonfoot_ground_touch + primary: + mode: geom + pattern: ^(base_link|[1-6]_(coxa|femur))_col\d+$ + entity: robot + exclude: !!python/tuple + - edge_1a + - edge_1b + - edge_2a + - edge_2b + - edge_3a + - edge_3b + - edge_4a + - edge_4b + - edge_5a + - edge_5b + - edge_6a + - edge_6b + secondary: + mode: body + pattern: terrain + entity: null + exclude: !!python/tuple [] + fields: !!python/tuple + - found + - force + reduce: none + num_slots: 1 + secondary_policy: first + track_air_time: false + global_frame: false + history_length: 4 + debug: false + - name: self_collision + primary: + mode: subtree + pattern: base_link + entity: robot + exclude: !!python/tuple [] + secondary: + mode: subtree + pattern: base_link + entity: robot + exclude: !!python/tuple [] + fields: !!python/tuple + - found + reduce: none + num_slots: 1 + secondary_policy: first + track_air_time: false + global_frame: false + history_length: 0 + debug: false + extent: 2.0 + spec_fn: null +observations: + actor: + terms: + base_ang_vel: + func: &id001 !!python/name:mjlab.envs.mdp.observations.builtin_sensor '' + params: + sensor_name: robot/imu_ang_vel + noise: + operation: add + _tensor_cache: {} + n_min: -0.2 + n_max: 0.2 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + projected_gravity: + func: &id002 !!python/name:mjlab.envs.mdp.observations.projected_gravity '' + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.05 + n_max: 0.05 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + command: + func: &id003 !!python/name:mjlab.envs.mdp.observations.generated_commands '' + params: + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + phase: + func: &id004 !!python/name:src.tasks.velocity.mdp.observations.phase '' + params: + period: 0.6 + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_pos: + func: &id005 !!python/name:mjlab.envs.mdp.observations.joint_pos_rel '' + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.01 + n_max: 0.01 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_vel: + func: &id006 !!python/name:mjlab.envs.mdp.observations.joint_vel_rel '' + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -1.5 + n_max: 1.5 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + actions: + func: &id007 !!python/name:mjlab.envs.mdp.observations.last_action '' + params: {} + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + concatenate_terms: true + concatenate_dim: -1 + enable_corruption: true + history_length: 1 + flatten_history_dim: true + nan_policy: disabled + nan_check_per_term: true + critic: + terms: + base_ang_vel: + func: *id001 + params: + sensor_name: robot/imu_ang_vel + noise: + operation: add + _tensor_cache: {} + n_min: -0.2 + n_max: 0.2 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + projected_gravity: + func: *id002 + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.05 + n_max: 0.05 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + command: + func: *id003 + params: + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + phase: + func: *id004 + params: + period: 0.6 + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_pos: + func: *id005 + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.01 + n_max: 0.01 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_vel: + func: *id006 + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -1.5 + n_max: 1.5 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + actions: + func: *id007 + params: {} + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + base_lin_vel: + func: *id001 + params: + sensor_name: robot/imu_lin_vel + noise: + operation: add + _tensor_cache: {} + n_min: -0.5 + n_max: 0.5 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_height: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_height '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: !!python/tuple + - fsite_1a + - fsite_1b + - fsite_2a + - fsite_2b + - fsite_3a + - fsite_3b + - fsite_4a + - fsite_4b + - fsite_5a + - fsite_5b + - fsite_6a + - fsite_6b + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_air_time: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_air_time '' + params: + sensor_name: feet_ground_contact + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_contact: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_contact '' + params: + sensor_name: feet_ground_contact + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_contact_forces: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_contact_forces '' + params: + sensor_name: feet_ground_contact + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + concatenate_terms: true + concatenate_dim: -1 + enable_corruption: false + history_length: 1 + flatten_history_dim: true + nan_policy: disabled + nan_check_per_term: true +actions: + joint_pos: + entity_name: robot + clip: null + transmission_type: !!python/object/apply:mjlab.actuator.actuator.TransmissionType + - joint + actuator_names: !!python/tuple + - 1_coxa + - 1_femur + - 1_tibia + - 2_coxa + - 2_femur + - 2_tibia + - 3_coxa + - 3_femur + - 3_tibia + - 4_coxa + - 4_femur + - 4_tibia + - 5_coxa + - 5_femur + - 5_tibia + - 6_coxa + - 6_femur + - 6_tibia + scale: 0.25 + offset: 0.0 + preserve_order: false + use_default_offset: true +events: + reset_base: + func: !!python/name:mjlab.envs.mdp.events.reset_root_state_uniform '' + params: + pose_range: + x: !!python/tuple + - -0.5 + - 0.5 + y: !!python/tuple + - -0.5 + - 0.5 + z: !!python/tuple + - 0.0 + - 0.0 + yaw: !!python/tuple + - -3.14 + - 3.14 + velocity_range: {} + mode: reset + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + reset_robot_joints: + func: !!python/name:mjlab.envs.mdp.events.reset_joints_by_offset '' + params: + position_range: !!python/tuple + - -0.0 + - 0.0 + velocity_range: !!python/tuple + - -0.0 + - 0.0 + asset_cfg: + name: robot + joint_names: !!python/tuple + - .* + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + mode: reset + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + push_robot: + func: !!python/name:mjlab.envs.mdp.events.push_by_setting_velocity '' + params: + velocity_range: + x: !!python/tuple + - -0.5 + - 0.5 + y: !!python/tuple + - -0.5 + - 0.5 + z: !!python/tuple + - -0.4 + - 0.4 + roll: !!python/tuple + - -0.52 + - 0.52 + pitch: !!python/tuple + - -0.52 + - 0.52 + yaw: !!python/tuple + - -0.78 + - 0.78 + mode: interval + interval_range_s: !!python/tuple + - 5.0 + - 6.0 + is_global_time: false + min_step_count_between_reset: 0 + foot_friction: + func: !!python/name:mjlab.envs.mdp.dr.geom.geom_friction '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: !!python/tuple + - edge_1a + - edge_1b + - edge_2a + - edge_2b + - edge_3a + - edge_3b + - edge_4a + - edge_4b + - edge_5a + - edge_5b + - edge_6a + - edge_6b + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + operation: abs + ranges: !!python/tuple + - 0.3 + - 1.6 + shared_random: true + mode: startup + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + encoder_bias: + func: !!python/name:mjlab.envs.mdp.dr.joint.encoder_bias '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + bias_range: !!python/tuple + - -0.015 + - 0.015 + mode: startup + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + base_com: + func: !!python/name:mjlab.envs.mdp.dr.body.body_com_offset '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: !!python/tuple + - base_link + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + operation: add + ranges: + 0: !!python/tuple + - -0.05 + - 0.05 + 1: !!python/tuple + - -0.05 + - 0.05 + 2: !!python/tuple + - -0.05 + - 0.05 + mode: startup + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 +seed: 42 +sim: + nconmax: null + njmax: null + ls_parallel: true + contact_sensor_maxmatch: 500 + mujoco: + timestep: 0.005 + integrator: implicitfast + impratio: 1.0 + cone: pyramidal + jacobian: auto + solver: newton + iterations: 10 + tolerance: 1.0e-08 + ls_iterations: 20 + ls_tolerance: 0.01 + ccd_iterations: 500 + gravity: !!python/tuple + - 0.0 + - 0.0 + - -9.81 + multiccd: false + nan_guard: + enabled: false + buffer_size: 100 + output_dir: /tmp/mjlab/nan_dumps + max_envs_to_dump: 5 +viewer: + lookat: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + distance: 1.5 + fovy: null + elevation: -10.0 + azimuth: 90.0 + origin_type: !!python/object/apply:mjlab.viewer.viewer_config.OriginType + - 4 + entity_name: robot + body_name: base_link + env_idx: 0 + max_extra_envs: 2 + enable_reflections: true + enable_shadows: true + height: 240 + width: 320 +episode_length_s: 20.0 +rewards: + track_linear_velocity: + func: !!python/name:src.tasks.velocity.mdp.rewards.track_linear_velocity '' + params: + command_name: twist + std: 0.15 + weight: 1.0 + track_angular_velocity: + func: !!python/name:src.tasks.velocity.mdp.rewards.track_angular_velocity '' + params: + command_name: twist + std: 0.7071067811865476 + weight: 1.0 + body_orientation_l2: + func: !!python/name:src.tasks.velocity.mdp.rewards.body_orientation_l2 '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: !!python/tuple + - base_link + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -1.0 + pose: + func: !!python/name:src.tasks.velocity.mdp.rewards.variable_posture '' + params: + asset_cfg: + name: robot + joint_names: !!python/tuple + - 1_coxa + - 1_femur + - 1_tibia + - 2_coxa + - 2_femur + - 2_tibia + - 3_coxa + - 3_femur + - 3_tibia + - 4_coxa + - 4_femur + - 4_tibia + - 5_coxa + - 5_femur + - 5_tibia + - 6_coxa + - 6_femur + - 6_tibia + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + command_name: twist + std_standing: + 1_coxa: 0.1 + 1_femur: 0.1 + 1_tibia: 0.1 + 2_coxa: 0.1 + 2_femur: 0.1 + 2_tibia: 0.1 + 3_coxa: 0.1 + 3_femur: 0.1 + 3_tibia: 0.1 + 4_coxa: 0.1 + 4_femur: 0.1 + 4_tibia: 0.1 + 5_coxa: 0.1 + 5_femur: 0.1 + 5_tibia: 0.1 + 6_coxa: 0.1 + 6_femur: 0.1 + 6_tibia: 0.1 + std_walking: + 1_coxa: 0.35 + 1_femur: 0.35 + 1_tibia: 0.35 + 2_coxa: 0.35 + 2_femur: 0.35 + 2_tibia: 0.35 + 3_coxa: 0.35 + 3_femur: 0.35 + 3_tibia: 0.35 + 4_coxa: 0.35 + 4_femur: 0.35 + 4_tibia: 0.35 + 5_coxa: 0.35 + 5_femur: 0.35 + 5_tibia: 0.35 + 6_coxa: 0.35 + 6_femur: 0.35 + 6_tibia: 0.35 + std_running: + 1_coxa: 0.35 + 1_femur: 0.35 + 1_tibia: 0.35 + 2_coxa: 0.35 + 2_femur: 0.35 + 2_tibia: 0.35 + 3_coxa: 0.35 + 3_femur: 0.35 + 3_tibia: 0.35 + 4_coxa: 0.35 + 4_femur: 0.35 + 4_tibia: 0.35 + 5_coxa: 0.35 + 5_femur: 0.35 + 5_tibia: 0.35 + 6_coxa: 0.35 + 6_femur: 0.35 + 6_tibia: 0.35 + walking_threshold: 0.1 + running_threshold: 1.5 + weight: 1.0 + body_ang_vel: + func: !!python/name:src.tasks.velocity.mdp.rewards.body_angular_velocity_penalty '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: !!python/tuple + - base_link + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -0.05 + angular_momentum: + func: !!python/name:src.tasks.velocity.mdp.rewards.angular_momentum_penalty '' + params: + sensor_name: robot/root_angmom + weight: -0.025 + is_terminated: + func: !!python/name:mjlab.envs.mdp.rewards.is_terminated '' + params: {} + weight: -200.0 + joint_acc_l2: + func: !!python/name:mjlab.envs.mdp.rewards.joint_acc_l2 '' + params: {} + weight: -2.5e-07 + joint_pos_limits: + func: !!python/name:mjlab.envs.mdp.rewards.joint_pos_limits '' + params: {} + weight: -10.0 + action_rate_l2: + func: !!python/name:mjlab.envs.mdp.rewards.action_rate_l2 '' + params: {} + weight: -0.05 + foot_gait: + func: !!python/name:src.tasks.velocity.mdp.rewards.feet_gait '' + params: + period: 0.6 + offset: + - 0.0 + - 0.0 + - 0.5 + - 0.5 + - 0.0 + - 0.0 + - 0.5 + - 0.5 + - 0.0 + - 0.0 + - 0.5 + - 0.5 + threshold: 0.56 + command_threshold: 0.1 + command_name: twist + sensor_name: feet_ground_contact + weight: 0.0 + foot_clearance: + func: !!python/name:src.tasks.velocity.config.custom_dog.dogs.superspider._FeetClearanceRelative '' + params: + target_height: 0.05 + command_name: twist + command_threshold: 0.1 + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: !!python/tuple + - fsite_1a + - fsite_1b + - fsite_2a + - fsite_2b + - fsite_3a + - fsite_3b + - fsite_4a + - fsite_4b + - fsite_5a + - fsite_5b + - fsite_6a + - fsite_6b + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + sensor_name: feet_ground_contact + weight: -1.0 + foot_slip: + func: !!python/name:src.tasks.velocity.mdp.rewards.feet_slip '' + params: + sensor_name: feet_ground_contact + command_name: twist + command_threshold: 0.1 + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: !!python/tuple + - fsite_1a + - fsite_1b + - fsite_2a + - fsite_2b + - fsite_3a + - fsite_3b + - fsite_4a + - fsite_4b + - fsite_5a + - fsite_5b + - fsite_6a + - fsite_6b + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -0.25 + soft_landing: + func: !!python/name:src.tasks.velocity.mdp.rewards.soft_landing '' + params: + sensor_name: feet_ground_contact + command_name: twist + command_threshold: 0.1 + weight: -0.001 + stand_still: + func: !!python/name:src.tasks.velocity.mdp.rewards.stand_still '' + params: + command_name: twist + command_threshold: 0.1 + asset_cfg: + name: robot + joint_names: !!python/tuple + - 1_coxa + - 1_femur + - 1_tibia + - 2_coxa + - 2_femur + - 2_tibia + - 3_coxa + - 3_femur + - 3_tibia + - 4_coxa + - 4_femur + - 4_tibia + - 5_coxa + - 5_femur + - 5_tibia + - 6_coxa + - 6_femur + - 6_tibia + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -1.0 + self_collision: + func: !!python/name:src.tasks.velocity.mdp.rewards.self_collision_cost '' + params: + sensor_name: self_collision + weight: -0.5 + joint_vel_over_limit: + func: !!python/name:src.tasks.velocity.config.custom_dog.dogs.superspider._joint_vel_over_limit '' + params: + limit: 4.64 + weight: -0.5 +terminations: + time_out: + func: !!python/name:mjlab.envs.mdp.terminations.time_out '' + params: {} + time_out: true + fell_over: + func: !!python/name:mjlab.envs.mdp.terminations.bad_orientation '' + params: + limit_angle: 1.2217304763960306 + time_out: false + illegal_contact: + func: !!python/name:mjlab.tasks.velocity.mdp.terminations.illegal_contact '' + params: + sensor_name: nonfoot_ground_touch + force_threshold: 10.0 + time_out: false +commands: + twist: + resampling_time_range: !!python/tuple + - 3.0 + - 8.0 + debug_vis: true + entity_name: robot + heading_command: false + heading_control_stiffness: 0.5 + rel_standing_envs: 0.0 + rel_heading_envs: 1.0 + init_velocity_prob: 0.0 + ranges: + lin_vel_x: !!python/tuple + - 0.15 + - 0.4 + lin_vel_y: !!python/tuple + - -0.05 + - 0.05 + ang_vel_z: !!python/tuple + - -0.3 + - 0.3 + heading: null + viz: + z_offset: 0.2 + scale: 0.5 +curriculum: + terrain_levels: + func: !!python/name:src.tasks.velocity.config.custom_dog.dogs.superspider._terrain_levels_stairs '' + params: + command_name: twist +metrics: + mean_action_acc: + func: !!python/name:mjlab.envs.mdp.metrics.mean_action_acc '' + params: {} +is_finite_horizon: false +scale_rewards_by_dt: true diff --git a/training/snapshots/flat/agent.yaml b/training/snapshots/flat/agent.yaml new file mode 100644 index 0000000..1960925 --- /dev/null +++ b/training/snapshots/flat/agent.yaml @@ -0,0 +1,55 @@ +seed: 42 +num_steps_per_env: 24 +max_iterations: 6000 +obs_groups: + actor: !!python/tuple + - actor + critic: !!python/tuple + - critic +save_interval: 100 +experiment_name: superspider_flat_velocity +run_name: '' +logger: tensorboard +wandb_project: mjlab +wandb_tags: !!python/tuple [] +resume: false +load_run: .* +load_checkpoint: model_.*.pt +clip_actions: null +upload_model: true +class_name: OnPolicyRunner +actor: + hidden_dims: !!python/tuple + - 512 + - 256 + - 128 + activation: elu + obs_normalization: true + distribution_cfg: + init_std: 1.0 + std_type: scalar +critic: + hidden_dims: !!python/tuple + - 512 + - 256 + - 128 + activation: elu + obs_normalization: true +algorithm: + num_learning_epochs: 5 + num_mini_batches: 4 + learning_rate: 0.001 + schedule: adaptive + gamma: 0.99 + lam: 0.95 + entropy_coef: 0.01 + desired_kl: 0.01 + max_grad_norm: 1.0 + value_loss_coef: 1.0 + use_clipped_value_loss: true + clip_param: 0.2 + normalize_advantage_per_mini_batch: false + optimizer: adam + rnd_cfg: null + symmetry_cfg: null +multi_gpu: null diff --git a/training/snapshots/flat/env.yaml b/training/snapshots/flat/env.yaml new file mode 100644 index 0000000..a223c38 --- /dev/null +++ b/training/snapshots/flat/env.yaml @@ -0,0 +1,1602 @@ +decimation: 4 +scene: + num_envs: 1024 + env_spacing: 2.0 + terrain: + init_state: + pos: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + rot: !!python/tuple + - 1.0 + - 0.0 + - 0.0 + - 0.0 + lin_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + ang_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + joint_pos: + .*: 0.0 + joint_vel: + .*: 0.0 + spec_fn: !!python/name:mjlab.entity.entity.%3Clambda%3E '' + articulation: null + sort_actuators: false + lights: !!python/tuple + - name: sun + body: world + mode: fixed + target: null + type: directional + castshadow: true + pos: !!python/tuple + - 0.0 + - 0.0 + - 1.5 + dir: !!python/tuple + - 0.0 + - 0.0 + - -1.0 + cutoff: 45.0 + exponent: 10.0 + cameras: !!python/tuple [] + textures: !!python/tuple + - name: groundplane + type: 2d + builtin: checker + rgb1: !!python/tuple + - 0.2 + - 0.3 + - 0.4 + rgb2: !!python/tuple + - 0.1 + - 0.2 + - 0.3 + width: 300 + height: 300 + mark: edge + markrgb: !!python/tuple + - 0.8 + - 0.8 + - 0.8 + materials: !!python/tuple + - name: groundplane + rgba: !!python/tuple + - 1.0 + - 1.0 + - 1.0 + - 1.0 + texuniform: true + texrepeat: !!python/tuple + - 4.0 + - 4.0 + reflectance: 0.2 + texture: groundplane + geom_names_expr: !!python/tuple + - terrain$ + collisions: !!python/tuple [] + terrain_type: plane + terrain_generator: null + env_spacing: 2.0 + max_init_terrain_level: 5 + num_envs: 1024 + entities: + robot: + init_state: + pos: !!python/tuple + - 0.0 + - 0.0 + - 0.1 + rot: !!python/tuple + - 1.0 + - 0.0 + - 0.0 + - 0.0 + lin_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + ang_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + joint_pos: + 1_coxa: 0.074027 + 1_femur: 0.943939 + 1_tibia: -0.974578 + 2_coxa: 0.074407 + 2_femur: 1.164487 + 2_tibia: -0.647146 + 3_coxa: -0.037301 + 3_femur: 1.004834 + 3_tibia: -0.590105 + 4_coxa: -0.039226 + 4_femur: 1.349236 + 4_tibia: -0.815209 + 5_coxa: -0.174187 + 5_femur: 0.844217 + 5_tibia: -0.55142 + 6_coxa: 0.246042 + 6_femur: 1.053368 + 6_tibia: -0.997824 + joint_vel: + .*: 0.0 + spec_fn: !!python/name:src.tasks.velocity.config.custom_dog.builder.spec_fn '' + articulation: + actuators: !!python/tuple + - target_names_expr: !!python/tuple + - '[1-6]_(coxa|femur|tibia)' + transmission_type: !!python/object/apply:mjlab.actuator.actuator.TransmissionType + - joint + armature: 0.005 + frictionloss: 0.0 + stiffness: 40.0 + damping: 1.2 + effort_limit: 4.41 + soft_joint_pos_limit_factor: 0.9 + sort_actuators: false + lights: !!python/tuple [] + cameras: !!python/tuple [] + textures: !!python/tuple [] + materials: !!python/tuple [] + collisions: !!python/tuple + - geom_names_expr: !!python/tuple + - ^(base_link|[1-6]_(coxa|femur))_col\d+$ + - ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$ + contype: 1 + conaffinity: 0 + condim: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: 3 + ^(base_link|[1-6]_(coxa|femur))_col\d+$: 1 + priority: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: 1 + friction: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: !!python/tuple + - 0.6 + solref: null + solimp: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: !!python/tuple + - 0.9 + - 0.95 + - 0.023 + disable_other_geoms: true + sensors: !!python/tuple + - name: feet_ground_contact + primary: + mode: geom + pattern: !!python/tuple + - edge_1a + - edge_1b + - edge_2a + - edge_2b + - edge_3a + - edge_3b + - edge_4a + - edge_4b + - edge_5a + - edge_5b + - edge_6a + - edge_6b + entity: robot + exclude: !!python/tuple [] + secondary: + mode: body + pattern: terrain + entity: null + exclude: !!python/tuple [] + fields: !!python/tuple + - found + - force + reduce: netforce + num_slots: 1 + secondary_policy: first + track_air_time: true + global_frame: false + history_length: 0 + debug: false + - name: nonfoot_ground_touch + primary: + mode: geom + pattern: ^(base_link|[1-6]_(coxa|femur))_col\d+$ + entity: robot + exclude: !!python/tuple + - edge_1a + - edge_1b + - edge_2a + - edge_2b + - edge_3a + - edge_3b + - edge_4a + - edge_4b + - edge_5a + - edge_5b + - edge_6a + - edge_6b + secondary: + mode: body + pattern: terrain + entity: null + exclude: !!python/tuple [] + fields: !!python/tuple + - found + - force + reduce: none + num_slots: 1 + secondary_policy: first + track_air_time: false + global_frame: false + history_length: 4 + debug: false + extent: 2.0 + spec_fn: null +observations: + actor: + terms: + base_ang_vel: + func: &id001 !!python/name:mjlab.envs.mdp.observations.builtin_sensor '' + params: + sensor_name: robot/imu_ang_vel + noise: + operation: add + _tensor_cache: {} + n_min: -0.2 + n_max: 0.2 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + projected_gravity: + func: &id002 !!python/name:mjlab.envs.mdp.observations.projected_gravity '' + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.05 + n_max: 0.05 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + command: + func: &id003 !!python/name:mjlab.envs.mdp.observations.generated_commands '' + params: + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + phase: + func: &id004 !!python/name:src.tasks.velocity.mdp.observations.phase '' + params: + period: 0.6 + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_pos: + func: &id005 !!python/name:mjlab.envs.mdp.observations.joint_pos_rel '' + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.01 + n_max: 0.01 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_vel: + func: &id006 !!python/name:mjlab.envs.mdp.observations.joint_vel_rel '' + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -1.5 + n_max: 1.5 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + actions: + func: &id007 !!python/name:mjlab.envs.mdp.observations.last_action '' + params: {} + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + concatenate_terms: true + concatenate_dim: -1 + enable_corruption: true + history_length: 1 + flatten_history_dim: true + nan_policy: disabled + nan_check_per_term: true + critic: + terms: + base_ang_vel: + func: *id001 + params: + sensor_name: robot/imu_ang_vel + noise: + operation: add + _tensor_cache: {} + n_min: -0.2 + n_max: 0.2 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + projected_gravity: + func: *id002 + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.05 + n_max: 0.05 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + command: + func: *id003 + params: + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + phase: + func: *id004 + params: + period: 0.6 + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_pos: + func: *id005 + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.01 + n_max: 0.01 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_vel: + func: *id006 + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -1.5 + n_max: 1.5 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + actions: + func: *id007 + params: {} + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + base_lin_vel: + func: *id001 + params: + sensor_name: robot/imu_lin_vel + noise: + operation: add + _tensor_cache: {} + n_min: -0.5 + n_max: 0.5 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_height: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_height '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: !!python/tuple + - fsite_1a + - fsite_1b + - fsite_2a + - fsite_2b + - fsite_3a + - fsite_3b + - fsite_4a + - fsite_4b + - fsite_5a + - fsite_5b + - fsite_6a + - fsite_6b + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_air_time: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_air_time '' + params: + sensor_name: feet_ground_contact + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_contact: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_contact '' + params: + sensor_name: feet_ground_contact + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_contact_forces: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_contact_forces '' + params: + sensor_name: feet_ground_contact + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + concatenate_terms: true + concatenate_dim: -1 + enable_corruption: false + history_length: 1 + flatten_history_dim: true + nan_policy: disabled + nan_check_per_term: true +actions: + joint_pos: + entity_name: robot + clip: null + transmission_type: !!python/object/apply:mjlab.actuator.actuator.TransmissionType + - joint + actuator_names: !!python/tuple + - 1_coxa + - 1_femur + - 1_tibia + - 2_coxa + - 2_femur + - 2_tibia + - 3_coxa + - 3_femur + - 3_tibia + - 4_coxa + - 4_femur + - 4_tibia + - 5_coxa + - 5_femur + - 5_tibia + - 6_coxa + - 6_femur + - 6_tibia + scale: 0.25 + offset: 0.0 + preserve_order: false + use_default_offset: true +events: + reset_base: + func: !!python/name:mjlab.envs.mdp.events.reset_root_state_uniform '' + params: + pose_range: + x: !!python/tuple + - -0.5 + - 0.5 + y: !!python/tuple + - -0.5 + - 0.5 + z: !!python/tuple + - 0.0 + - 0.0 + yaw: !!python/tuple + - -3.14 + - 3.14 + velocity_range: {} + mode: reset + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + reset_robot_joints: + func: !!python/name:mjlab.envs.mdp.events.reset_joints_by_offset '' + params: + position_range: !!python/tuple + - -0.0 + - 0.0 + velocity_range: !!python/tuple + - -0.0 + - 0.0 + asset_cfg: + name: robot + joint_names: !!python/tuple + - .* + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + mode: reset + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + push_robot: + func: !!python/name:mjlab.envs.mdp.events.push_by_setting_velocity '' + params: + velocity_range: + x: !!python/tuple + - -0.5 + - 0.5 + y: !!python/tuple + - -0.5 + - 0.5 + z: !!python/tuple + - -0.4 + - 0.4 + roll: !!python/tuple + - -0.52 + - 0.52 + pitch: !!python/tuple + - -0.52 + - 0.52 + yaw: !!python/tuple + - -0.78 + - 0.78 + mode: interval + interval_range_s: !!python/tuple + - 5.0 + - 6.0 + is_global_time: false + min_step_count_between_reset: 0 + foot_friction: + func: !!python/name:mjlab.envs.mdp.dr.geom.geom_friction '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: !!python/tuple + - edge_1a + - edge_1b + - edge_2a + - edge_2b + - edge_3a + - edge_3b + - edge_4a + - edge_4b + - edge_5a + - edge_5b + - edge_6a + - edge_6b + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + operation: abs + ranges: !!python/tuple + - 0.3 + - 1.6 + shared_random: true + mode: startup + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + encoder_bias: + func: !!python/name:mjlab.envs.mdp.dr.joint.encoder_bias '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + bias_range: !!python/tuple + - -0.015 + - 0.015 + mode: startup + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + base_com: + func: !!python/name:mjlab.envs.mdp.dr.body.body_com_offset '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: !!python/tuple + - base_link + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + operation: add + ranges: + 0: !!python/tuple + - -0.05 + - 0.05 + 1: !!python/tuple + - -0.05 + - 0.05 + 2: !!python/tuple + - -0.05 + - 0.05 + mode: startup + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 +seed: 42 +sim: + nconmax: null + njmax: 800 + ls_parallel: true + contact_sensor_maxmatch: 64 + mujoco: + timestep: 0.005 + integrator: implicitfast + impratio: 1.0 + cone: pyramidal + jacobian: auto + solver: newton + iterations: 10 + tolerance: 1.0e-08 + ls_iterations: 20 + ls_tolerance: 0.01 + ccd_iterations: 50 + gravity: !!python/tuple + - 0.0 + - 0.0 + - -9.81 + multiccd: false + nan_guard: + enabled: false + buffer_size: 100 + output_dir: /tmp/mjlab/nan_dumps + max_envs_to_dump: 5 +viewer: + lookat: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + distance: 1.5 + fovy: null + elevation: -10.0 + azimuth: 90.0 + origin_type: !!python/object/apply:mjlab.viewer.viewer_config.OriginType + - 4 + entity_name: robot + body_name: base_link + env_idx: 0 + max_extra_envs: 2 + enable_reflections: true + enable_shadows: true + height: 240 + width: 320 +episode_length_s: 20.0 +rewards: + track_linear_velocity: + func: !!python/name:src.tasks.velocity.mdp.rewards.track_linear_velocity '' + params: + command_name: twist + std: 0.15 + weight: 1.0 + track_angular_velocity: + func: !!python/name:src.tasks.velocity.mdp.rewards.track_angular_velocity '' + params: + command_name: twist + std: 0.7071067811865476 + weight: 1.0 + body_orientation_l2: + func: !!python/name:src.tasks.velocity.mdp.rewards.body_orientation_l2 '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: !!python/tuple + - base_link + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -1.0 + pose: + func: !!python/name:src.tasks.velocity.mdp.rewards.variable_posture '' + params: + asset_cfg: + name: robot + joint_names: !!python/tuple + - 1_coxa + - 1_femur + - 1_tibia + - 2_coxa + - 2_femur + - 2_tibia + - 3_coxa + - 3_femur + - 3_tibia + - 4_coxa + - 4_femur + - 4_tibia + - 5_coxa + - 5_femur + - 5_tibia + - 6_coxa + - 6_femur + - 6_tibia + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + command_name: twist + std_standing: + 1_coxa: 0.1 + 1_femur: 0.1 + 1_tibia: 0.1 + 2_coxa: 0.1 + 2_femur: 0.1 + 2_tibia: 0.1 + 3_coxa: 0.1 + 3_femur: 0.1 + 3_tibia: 0.1 + 4_coxa: 0.1 + 4_femur: 0.1 + 4_tibia: 0.1 + 5_coxa: 0.1 + 5_femur: 0.1 + 5_tibia: 0.1 + 6_coxa: 0.1 + 6_femur: 0.1 + 6_tibia: 0.1 + std_walking: + 1_coxa: 0.35 + 1_femur: 0.35 + 1_tibia: 0.35 + 2_coxa: 0.35 + 2_femur: 0.35 + 2_tibia: 0.35 + 3_coxa: 0.35 + 3_femur: 0.35 + 3_tibia: 0.35 + 4_coxa: 0.35 + 4_femur: 0.35 + 4_tibia: 0.35 + 5_coxa: 0.35 + 5_femur: 0.35 + 5_tibia: 0.35 + 6_coxa: 0.35 + 6_femur: 0.35 + 6_tibia: 0.35 + std_running: + 1_coxa: 0.35 + 1_femur: 0.35 + 1_tibia: 0.35 + 2_coxa: 0.35 + 2_femur: 0.35 + 2_tibia: 0.35 + 3_coxa: 0.35 + 3_femur: 0.35 + 3_tibia: 0.35 + 4_coxa: 0.35 + 4_femur: 0.35 + 4_tibia: 0.35 + 5_coxa: 0.35 + 5_femur: 0.35 + 5_tibia: 0.35 + 6_coxa: 0.35 + 6_femur: 0.35 + 6_tibia: 0.35 + walking_threshold: 0.1 + running_threshold: 1.5 + weight: 1.0 + body_ang_vel: + func: !!python/name:src.tasks.velocity.mdp.rewards.body_angular_velocity_penalty '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: !!python/tuple + - base_link + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -0.05 + angular_momentum: + func: !!python/name:src.tasks.velocity.mdp.rewards.angular_momentum_penalty '' + params: + sensor_name: robot/root_angmom + weight: -0.025 + is_terminated: + func: !!python/name:mjlab.envs.mdp.rewards.is_terminated '' + params: {} + weight: -200.0 + joint_acc_l2: + func: !!python/name:mjlab.envs.mdp.rewards.joint_acc_l2 '' + params: {} + weight: -2.5e-07 + joint_pos_limits: + func: !!python/name:mjlab.envs.mdp.rewards.joint_pos_limits '' + params: {} + weight: -10.0 + action_rate_l2: + func: !!python/name:mjlab.envs.mdp.rewards.action_rate_l2 '' + params: {} + weight: -0.05 + foot_gait: + func: !!python/name:src.tasks.velocity.mdp.rewards.feet_gait '' + params: + period: 0.6 + offset: + - 0.0 + - 0.0 + - 0.5 + - 0.5 + - 0.0 + - 0.0 + - 0.5 + - 0.5 + - 0.0 + - 0.0 + - 0.5 + - 0.5 + threshold: 0.56 + command_threshold: 0.1 + command_name: twist + sensor_name: feet_ground_contact + weight: 0.5 + foot_clearance: + func: !!python/name:src.tasks.velocity.mdp.rewards.feet_clearance '' + params: + target_height: 0.05 + command_name: twist + command_threshold: 0.1 + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: !!python/tuple + - fsite_1a + - fsite_1b + - fsite_2a + - fsite_2b + - fsite_3a + - fsite_3b + - fsite_4a + - fsite_4b + - fsite_5a + - fsite_5b + - fsite_6a + - fsite_6b + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -1.0 + foot_slip: + func: !!python/name:src.tasks.velocity.mdp.rewards.feet_slip '' + params: + sensor_name: feet_ground_contact + command_name: twist + command_threshold: 0.1 + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: !!python/tuple + - fsite_1a + - fsite_1b + - fsite_2a + - fsite_2b + - fsite_3a + - fsite_3b + - fsite_4a + - fsite_4b + - fsite_5a + - fsite_5b + - fsite_6a + - fsite_6b + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -0.25 + soft_landing: + func: !!python/name:src.tasks.velocity.mdp.rewards.soft_landing '' + params: + sensor_name: feet_ground_contact + command_name: twist + command_threshold: 0.1 + weight: -0.001 + stand_still: + func: !!python/name:src.tasks.velocity.mdp.rewards.stand_still '' + params: + command_name: twist + command_threshold: 0.1 + asset_cfg: + name: robot + joint_names: !!python/tuple + - 1_coxa + - 1_femur + - 1_tibia + - 2_coxa + - 2_femur + - 2_tibia + - 3_coxa + - 3_femur + - 3_tibia + - 4_coxa + - 4_femur + - 4_tibia + - 5_coxa + - 5_femur + - 5_tibia + - 6_coxa + - 6_femur + - 6_tibia + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -1.0 + joint_vel_over_limit: + func: !!python/name:src.tasks.velocity.config.custom_dog.dogs.superspider._joint_vel_over_limit '' + params: + limit: 4.64 + weight: -0.5 +terminations: + time_out: + func: !!python/name:mjlab.envs.mdp.terminations.time_out '' + params: {} + time_out: true + fell_over: + func: !!python/name:mjlab.envs.mdp.terminations.bad_orientation '' + params: + limit_angle: 1.2217304763960306 + time_out: false + illegal_contact: + func: !!python/name:mjlab.tasks.velocity.mdp.terminations.illegal_contact '' + params: + sensor_name: nonfoot_ground_touch + force_threshold: 10.0 + time_out: false +commands: + twist: + resampling_time_range: !!python/tuple + - 3.0 + - 8.0 + debug_vis: true + entity_name: robot + heading_command: true + heading_control_stiffness: 0.5 + rel_standing_envs: 0.05 + rel_heading_envs: 1.0 + init_velocity_prob: 0.0 + ranges: + lin_vel_x: !!python/tuple + - -0.25 + - 0.4 + lin_vel_y: !!python/tuple + - -0.15 + - 0.15 + ang_vel_z: !!python/tuple + - -0.8 + - 0.8 + heading: !!python/tuple + - -3.141592653589793 + - 3.141592653589793 + viz: + z_offset: 0.2 + scale: 0.5 +curriculum: + command_vel: + func: !!python/name:src.tasks.velocity.mdp.curriculums.commands_vel '' + params: + command_name: twist + velocity_stages: + - step: 0 + lin_vel_x: !!python/tuple + - -0.15 + - 0.25 + lin_vel_y: !!python/tuple + - -0.1 + - 0.1 + ang_vel_z: !!python/tuple + - -0.6 + - 0.6 + - step: 60000 + lin_vel_x: !!python/tuple + - -0.25 + - 0.4 + lin_vel_y: !!python/tuple + - -0.15 + - 0.15 + ang_vel_z: !!python/tuple + - -0.8 + - 0.8 +metrics: + mean_action_acc: + func: !!python/name:mjlab.envs.mdp.metrics.mean_action_acc '' + params: {} +is_finite_horizon: false +scale_rewards_by_dt: true diff --git a/training/snapshots/student/agent.yaml b/training/snapshots/student/agent.yaml new file mode 100644 index 0000000..78cea61 --- /dev/null +++ b/training/snapshots/student/agent.yaml @@ -0,0 +1,51 @@ +seed: 42 +num_steps_per_env: 24 +max_iterations: 6000 +obs_groups: + student: + - actor + teacher: + - actor + - height +save_interval: 200 +experiment_name: superspider_stairs_distill +run_name: '' +logger: tensorboard +wandb_project: mjlab +wandb_tags: !!python/tuple [] +resume: true +load_run: zz_teacher +load_checkpoint: model_3800.pt +clip_actions: null +upload_model: true +class_name: DistillationRunner +student: + hidden_dims: !!python/tuple + - 512 + - 256 + - 128 + activation: elu + obs_normalization: true + distribution_cfg: + init_std: 1.0 + std_type: scalar +teacher: + hidden_dims: !!python/tuple + - 512 + - 256 + - 128 + activation: elu + obs_normalization: true + distribution_cfg: + init_std: 1.0 + std_type: scalar +algorithm: + num_learning_epochs: 1 + gradient_length: 15 + learning_rate: 0.001 + max_grad_norm: 1.0 + loss_type: mse + optimizer: adam + rnd_cfg: null + symmetry_cfg: null +multi_gpu: null diff --git a/training/snapshots/student/env.yaml b/training/snapshots/student/env.yaml new file mode 100644 index 0000000..93ecb75 --- /dev/null +++ b/training/snapshots/student/env.yaml @@ -0,0 +1,1724 @@ +decimation: 4 +scene: + num_envs: 512 + env_spacing: 2.0 + terrain: + init_state: + pos: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + rot: !!python/tuple + - 1.0 + - 0.0 + - 0.0 + - 0.0 + lin_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + ang_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + joint_pos: + .*: 0.0 + joint_vel: + .*: 0.0 + spec_fn: !!python/name:mjlab.entity.entity.%3Clambda%3E '' + articulation: null + sort_actuators: false + lights: !!python/tuple + - name: sun + body: world + mode: fixed + target: null + type: directional + castshadow: true + pos: !!python/tuple + - 0.0 + - 0.0 + - 1.5 + dir: !!python/tuple + - 0.0 + - 0.0 + - -1.0 + cutoff: 45.0 + exponent: 10.0 + cameras: !!python/tuple [] + textures: !!python/tuple + - name: groundplane + type: 2d + builtin: checker + rgb1: !!python/tuple + - 0.2 + - 0.3 + - 0.4 + rgb2: !!python/tuple + - 0.1 + - 0.2 + - 0.3 + width: 300 + height: 300 + mark: edge + markrgb: !!python/tuple + - 0.8 + - 0.8 + - 0.8 + materials: !!python/tuple + - name: groundplane + rgba: !!python/tuple + - 1.0 + - 1.0 + - 1.0 + - 1.0 + texuniform: true + texrepeat: !!python/tuple + - 4.0 + - 4.0 + reflectance: 0.2 + texture: groundplane + geom_names_expr: !!python/tuple + - terrain$ + collisions: !!python/tuple [] + terrain_type: generator + terrain_generator: + seed: null + curriculum: true + size: !!python/tuple + - 8.0 + - 8.0 + border_width: 20.0 + border_height: 1.0 + num_rows: 10 + num_cols: 20 + color_scheme: height + sub_terrains: + single_step: + proportion: 1.0 + size: !!python/tuple + - 8.0 + - 8.0 + flat_patch_sampling: null + step_height_range: !!python/tuple + - 0.01 + - 0.06 + approach: 1.5 + difficulty_range: !!python/tuple + - 0.0 + - 1.0 + add_lights: true + env_spacing: 2.0 + max_init_terrain_level: 0 + num_envs: 512 + entities: + robot: + init_state: + pos: !!python/tuple + - 0.0 + - 0.0 + - 0.1 + rot: !!python/tuple + - 1.0 + - 0.0 + - 0.0 + - 0.0 + lin_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + ang_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + joint_pos: + 1_coxa: 0.074027 + 1_femur: 0.943939 + 1_tibia: -0.974578 + 2_coxa: 0.074407 + 2_femur: 1.164487 + 2_tibia: -0.647146 + 3_coxa: -0.037301 + 3_femur: 1.004834 + 3_tibia: -0.590105 + 4_coxa: -0.039226 + 4_femur: 1.349236 + 4_tibia: -0.815209 + 5_coxa: -0.174187 + 5_femur: 0.844217 + 5_tibia: -0.55142 + 6_coxa: 0.246042 + 6_femur: 1.053368 + 6_tibia: -0.997824 + joint_vel: + .*: 0.0 + spec_fn: !!python/name:src.tasks.velocity.config.custom_dog.builder.spec_fn '' + articulation: + actuators: !!python/tuple + - target_names_expr: !!python/tuple + - '[1-6]_(coxa|femur|tibia)' + transmission_type: !!python/object/apply:mjlab.actuator.actuator.TransmissionType + - joint + armature: 0.005 + frictionloss: 0.0 + stiffness: 40.0 + damping: 1.2 + effort_limit: 4.41 + soft_joint_pos_limit_factor: 0.9 + sort_actuators: false + lights: !!python/tuple [] + cameras: !!python/tuple [] + textures: !!python/tuple [] + materials: !!python/tuple [] + collisions: !!python/tuple + - geom_names_expr: !!python/tuple + - ^(base_link|[1-6]_(coxa|femur))_col\d+$ + - ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$ + contype: 1 + conaffinity: 1 + condim: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: 3 + ^(base_link|[1-6]_(coxa|femur))_col\d+$: 1 + priority: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: 1 + friction: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: !!python/tuple + - 0.6 + solref: null + solimp: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: !!python/tuple + - 0.9 + - 0.95 + - 0.023 + disable_other_geoms: true + sensors: !!python/tuple + - name: terrain_scan + frame: + type: body + name: base_link + entity: robot + pattern: + size: !!python/tuple + - 0.9 + - 0.4 + resolution: 0.04 + direction: !!python/tuple + - 0.0 + - 0.0 + - -1.0 + ray_alignment: yaw + max_distance: 5.0 + exclude_parent_body: true + include_geom_groups: !!python/tuple + - 0 + - 1 + - 2 + debug_vis: true + viz: + hit_color: !!python/tuple + - 0.0 + - 1.0 + - 0.0 + - 0.8 + miss_color: !!python/tuple + - 1.0 + - 0.0 + - 0.0 + - 0.4 + hit_sphere_color: !!python/tuple + - 0.0 + - 1.0 + - 1.0 + - 1.0 + hit_sphere_radius: 0.5 + show_rays: false + show_normals: true + normal_color: !!python/tuple + - 1.0 + - 1.0 + - 0.0 + - 1.0 + normal_length: 5.0 + - name: feet_ground_contact + primary: + mode: geom + pattern: !!python/tuple + - edge_1a + - edge_1b + - edge_2a + - edge_2b + - edge_3a + - edge_3b + - edge_4a + - edge_4b + - edge_5a + - edge_5b + - edge_6a + - edge_6b + entity: robot + exclude: !!python/tuple [] + secondary: + mode: body + pattern: terrain + entity: null + exclude: !!python/tuple [] + fields: !!python/tuple + - found + - force + reduce: netforce + num_slots: 1 + secondary_policy: first + track_air_time: true + global_frame: false + history_length: 0 + debug: false + - name: nonfoot_ground_touch + primary: + mode: geom + pattern: ^(base_link|[1-6]_(coxa|femur))_col\d+$ + entity: robot + exclude: !!python/tuple + - edge_1a + - edge_1b + - edge_2a + - edge_2b + - edge_3a + - edge_3b + - edge_4a + - edge_4b + - edge_5a + - edge_5b + - edge_6a + - edge_6b + secondary: + mode: body + pattern: terrain + entity: null + exclude: !!python/tuple [] + fields: !!python/tuple + - found + - force + reduce: none + num_slots: 1 + secondary_policy: first + track_air_time: false + global_frame: false + history_length: 4 + debug: false + - name: self_collision + primary: + mode: subtree + pattern: base_link + entity: robot + exclude: !!python/tuple [] + secondary: + mode: subtree + pattern: base_link + entity: robot + exclude: !!python/tuple [] + fields: !!python/tuple + - found + reduce: none + num_slots: 1 + secondary_policy: first + track_air_time: false + global_frame: false + history_length: 0 + debug: false + extent: 2.0 + spec_fn: null +observations: + actor: + terms: + base_ang_vel: + func: &id001 !!python/name:mjlab.envs.mdp.observations.builtin_sensor '' + params: + sensor_name: robot/imu_ang_vel + noise: + operation: add + _tensor_cache: {} + n_min: -0.2 + n_max: 0.2 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + projected_gravity: + func: &id002 !!python/name:mjlab.envs.mdp.observations.projected_gravity '' + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.05 + n_max: 0.05 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + command: + func: &id003 !!python/name:mjlab.envs.mdp.observations.generated_commands '' + params: + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + phase: + func: &id004 !!python/name:src.tasks.velocity.mdp.observations.phase '' + params: + period: 0.6 + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_pos: + func: &id005 !!python/name:mjlab.envs.mdp.observations.joint_pos_rel '' + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.01 + n_max: 0.01 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_vel: + func: &id006 !!python/name:mjlab.envs.mdp.observations.joint_vel_rel '' + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -1.5 + n_max: 1.5 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + actions: + func: &id007 !!python/name:mjlab.envs.mdp.observations.last_action '' + params: {} + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + concatenate_terms: true + concatenate_dim: -1 + enable_corruption: true + history_length: null + flatten_history_dim: true + nan_policy: disabled + nan_check_per_term: true + critic: + terms: + base_ang_vel: + func: *id001 + params: + sensor_name: robot/imu_ang_vel + noise: + operation: add + _tensor_cache: {} + n_min: -0.2 + n_max: 0.2 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + projected_gravity: + func: *id002 + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.05 + n_max: 0.05 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + command: + func: *id003 + params: + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + phase: + func: *id004 + params: + period: 0.6 + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_pos: + func: *id005 + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.01 + n_max: 0.01 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_vel: + func: *id006 + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -1.5 + n_max: 1.5 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + actions: + func: *id007 + params: {} + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + height_scan: + func: &id008 !!python/name:mjlab.envs.mdp.observations.height_scan '' + params: + sensor_name: terrain_scan + noise: null + clip: null + scale: 0.2 + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + base_lin_vel: + func: *id001 + params: + sensor_name: robot/imu_lin_vel + noise: + operation: add + _tensor_cache: {} + n_min: -0.5 + n_max: 0.5 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_height: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_height '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: !!python/tuple + - fsite_1a + - fsite_1b + - fsite_2a + - fsite_2b + - fsite_3a + - fsite_3b + - fsite_4a + - fsite_4b + - fsite_5a + - fsite_5b + - fsite_6a + - fsite_6b + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_air_time: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_air_time '' + params: + sensor_name: feet_ground_contact + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_contact: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_contact '' + params: + sensor_name: feet_ground_contact + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_contact_forces: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_contact_forces '' + params: + sensor_name: feet_ground_contact + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + concatenate_terms: true + concatenate_dim: -1 + enable_corruption: false + history_length: 1 + flatten_history_dim: true + nan_policy: disabled + nan_check_per_term: true + height: + terms: + height_scan: + func: *id008 + params: + sensor_name: terrain_scan + noise: + operation: add + _tensor_cache: {} + n_min: -0.1 + n_max: 0.1 + clip: null + scale: 0.2 + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + concatenate_terms: true + concatenate_dim: -1 + enable_corruption: false + history_length: null + flatten_history_dim: true + nan_policy: disabled + nan_check_per_term: true +actions: + joint_pos: + entity_name: robot + clip: null + transmission_type: !!python/object/apply:mjlab.actuator.actuator.TransmissionType + - joint + actuator_names: !!python/tuple + - 1_coxa + - 1_femur + - 1_tibia + - 2_coxa + - 2_femur + - 2_tibia + - 3_coxa + - 3_femur + - 3_tibia + - 4_coxa + - 4_femur + - 4_tibia + - 5_coxa + - 5_femur + - 5_tibia + - 6_coxa + - 6_femur + - 6_tibia + scale: 0.25 + offset: 0.0 + preserve_order: false + use_default_offset: true +events: + reset_base: + func: !!python/name:mjlab.envs.mdp.events.reset_root_state_uniform '' + params: + pose_range: + x: !!python/tuple + - -0.5 + - 0.5 + y: !!python/tuple + - -0.5 + - 0.5 + z: !!python/tuple + - 0.0 + - 0.0 + yaw: !!python/tuple + - -3.14 + - 3.14 + velocity_range: {} + mode: reset + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + reset_robot_joints: + func: !!python/name:mjlab.envs.mdp.events.reset_joints_by_offset '' + params: + position_range: !!python/tuple + - -0.0 + - 0.0 + velocity_range: !!python/tuple + - -0.0 + - 0.0 + asset_cfg: + name: robot + joint_names: !!python/tuple + - .* + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + mode: reset + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + push_robot: + func: !!python/name:mjlab.envs.mdp.events.push_by_setting_velocity '' + params: + velocity_range: + x: !!python/tuple + - -0.5 + - 0.5 + y: !!python/tuple + - -0.5 + - 0.5 + z: !!python/tuple + - -0.4 + - 0.4 + roll: !!python/tuple + - -0.52 + - 0.52 + pitch: !!python/tuple + - -0.52 + - 0.52 + yaw: !!python/tuple + - -0.78 + - 0.78 + mode: interval + interval_range_s: !!python/tuple + - 5.0 + - 6.0 + is_global_time: false + min_step_count_between_reset: 0 + foot_friction: + func: !!python/name:mjlab.envs.mdp.dr.geom.geom_friction '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: !!python/tuple + - edge_1a + - edge_1b + - edge_2a + - edge_2b + - edge_3a + - edge_3b + - edge_4a + - edge_4b + - edge_5a + - edge_5b + - edge_6a + - edge_6b + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + operation: abs + ranges: !!python/tuple + - 0.3 + - 1.6 + shared_random: true + mode: startup + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + encoder_bias: + func: !!python/name:mjlab.envs.mdp.dr.joint.encoder_bias '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + bias_range: !!python/tuple + - -0.015 + - 0.015 + mode: startup + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + base_com: + func: !!python/name:mjlab.envs.mdp.dr.body.body_com_offset '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: !!python/tuple + - base_link + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + operation: add + ranges: + 0: !!python/tuple + - -0.05 + - 0.05 + 1: !!python/tuple + - -0.05 + - 0.05 + 2: !!python/tuple + - -0.05 + - 0.05 + mode: startup + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 +seed: 42 +sim: + nconmax: null + njmax: null + ls_parallel: true + contact_sensor_maxmatch: 500 + mujoco: + timestep: 0.005 + integrator: implicitfast + impratio: 1.0 + cone: pyramidal + jacobian: auto + solver: newton + iterations: 10 + tolerance: 1.0e-08 + ls_iterations: 20 + ls_tolerance: 0.01 + ccd_iterations: 500 + gravity: !!python/tuple + - 0.0 + - 0.0 + - -9.81 + multiccd: false + nan_guard: + enabled: false + buffer_size: 100 + output_dir: /tmp/mjlab/nan_dumps + max_envs_to_dump: 5 +viewer: + lookat: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + distance: 1.5 + fovy: null + elevation: -10.0 + azimuth: 90.0 + origin_type: !!python/object/apply:mjlab.viewer.viewer_config.OriginType + - 4 + entity_name: robot + body_name: base_link + env_idx: 0 + max_extra_envs: 2 + enable_reflections: true + enable_shadows: true + height: 240 + width: 320 +episode_length_s: 20.0 +rewards: + track_linear_velocity: + func: !!python/name:src.tasks.velocity.mdp.rewards.track_linear_velocity '' + params: + command_name: twist + std: 0.15 + weight: 1.0 + track_angular_velocity: + func: !!python/name:src.tasks.velocity.mdp.rewards.track_angular_velocity '' + params: + command_name: twist + std: 0.7071067811865476 + weight: 1.0 + body_orientation_l2: + func: !!python/name:src.tasks.velocity.mdp.rewards.body_orientation_l2 '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: !!python/tuple + - base_link + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -1.0 + pose: + func: !!python/name:src.tasks.velocity.mdp.rewards.variable_posture '' + params: + asset_cfg: + name: robot + joint_names: !!python/tuple + - 1_coxa + - 1_femur + - 1_tibia + - 2_coxa + - 2_femur + - 2_tibia + - 3_coxa + - 3_femur + - 3_tibia + - 4_coxa + - 4_femur + - 4_tibia + - 5_coxa + - 5_femur + - 5_tibia + - 6_coxa + - 6_femur + - 6_tibia + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + command_name: twist + std_standing: + 1_coxa: 0.1 + 1_femur: 0.1 + 1_tibia: 0.1 + 2_coxa: 0.1 + 2_femur: 0.1 + 2_tibia: 0.1 + 3_coxa: 0.1 + 3_femur: 0.1 + 3_tibia: 0.1 + 4_coxa: 0.1 + 4_femur: 0.1 + 4_tibia: 0.1 + 5_coxa: 0.1 + 5_femur: 0.1 + 5_tibia: 0.1 + 6_coxa: 0.1 + 6_femur: 0.1 + 6_tibia: 0.1 + std_walking: + 1_coxa: 0.35 + 1_femur: 0.35 + 1_tibia: 0.35 + 2_coxa: 0.35 + 2_femur: 0.35 + 2_tibia: 0.35 + 3_coxa: 0.35 + 3_femur: 0.35 + 3_tibia: 0.35 + 4_coxa: 0.35 + 4_femur: 0.35 + 4_tibia: 0.35 + 5_coxa: 0.35 + 5_femur: 0.35 + 5_tibia: 0.35 + 6_coxa: 0.35 + 6_femur: 0.35 + 6_tibia: 0.35 + std_running: + 1_coxa: 0.35 + 1_femur: 0.35 + 1_tibia: 0.35 + 2_coxa: 0.35 + 2_femur: 0.35 + 2_tibia: 0.35 + 3_coxa: 0.35 + 3_femur: 0.35 + 3_tibia: 0.35 + 4_coxa: 0.35 + 4_femur: 0.35 + 4_tibia: 0.35 + 5_coxa: 0.35 + 5_femur: 0.35 + 5_tibia: 0.35 + 6_coxa: 0.35 + 6_femur: 0.35 + 6_tibia: 0.35 + walking_threshold: 0.1 + running_threshold: 1.5 + weight: 1.0 + body_ang_vel: + func: !!python/name:src.tasks.velocity.mdp.rewards.body_angular_velocity_penalty '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: !!python/tuple + - base_link + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -0.05 + angular_momentum: + func: !!python/name:src.tasks.velocity.mdp.rewards.angular_momentum_penalty '' + params: + sensor_name: robot/root_angmom + weight: -0.025 + is_terminated: + func: !!python/name:mjlab.envs.mdp.rewards.is_terminated '' + params: {} + weight: -200.0 + joint_acc_l2: + func: !!python/name:mjlab.envs.mdp.rewards.joint_acc_l2 '' + params: {} + weight: -2.5e-07 + joint_pos_limits: + func: !!python/name:mjlab.envs.mdp.rewards.joint_pos_limits '' + params: {} + weight: -10.0 + action_rate_l2: + func: !!python/name:mjlab.envs.mdp.rewards.action_rate_l2 '' + params: {} + weight: -0.05 + foot_gait: + func: !!python/name:src.tasks.velocity.mdp.rewards.feet_gait '' + params: + period: 0.6 + offset: + - 0.0 + - 0.0 + - 0.5 + - 0.5 + - 0.0 + - 0.0 + - 0.5 + - 0.5 + - 0.0 + - 0.0 + - 0.5 + - 0.5 + threshold: 0.56 + command_threshold: 0.1 + command_name: twist + sensor_name: feet_ground_contact + weight: 0.0 + foot_clearance: + func: !!python/name:src.tasks.velocity.config.custom_dog.dogs.superspider._FeetClearanceRelative '' + params: + target_height: 0.05 + command_name: twist + command_threshold: 0.1 + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: !!python/tuple + - fsite_1a + - fsite_1b + - fsite_2a + - fsite_2b + - fsite_3a + - fsite_3b + - fsite_4a + - fsite_4b + - fsite_5a + - fsite_5b + - fsite_6a + - fsite_6b + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + sensor_name: feet_ground_contact + weight: -1.0 + foot_slip: + func: !!python/name:src.tasks.velocity.mdp.rewards.feet_slip '' + params: + sensor_name: feet_ground_contact + command_name: twist + command_threshold: 0.1 + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: !!python/tuple + - fsite_1a + - fsite_1b + - fsite_2a + - fsite_2b + - fsite_3a + - fsite_3b + - fsite_4a + - fsite_4b + - fsite_5a + - fsite_5b + - fsite_6a + - fsite_6b + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -0.25 + soft_landing: + func: !!python/name:src.tasks.velocity.mdp.rewards.soft_landing '' + params: + sensor_name: feet_ground_contact + command_name: twist + command_threshold: 0.1 + weight: -0.001 + stand_still: + func: !!python/name:src.tasks.velocity.mdp.rewards.stand_still '' + params: + command_name: twist + command_threshold: 0.1 + asset_cfg: + name: robot + joint_names: !!python/tuple + - 1_coxa + - 1_femur + - 1_tibia + - 2_coxa + - 2_femur + - 2_tibia + - 3_coxa + - 3_femur + - 3_tibia + - 4_coxa + - 4_femur + - 4_tibia + - 5_coxa + - 5_femur + - 5_tibia + - 6_coxa + - 6_femur + - 6_tibia + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -1.0 + self_collision: + func: !!python/name:src.tasks.velocity.mdp.rewards.self_collision_cost '' + params: + sensor_name: self_collision + weight: -0.5 + joint_vel_over_limit: + func: !!python/name:src.tasks.velocity.config.custom_dog.dogs.superspider._joint_vel_over_limit '' + params: + limit: 4.64 + weight: -0.5 + climb_progress: + func: !!python/name:src.tasks.velocity.config.custom_dog.dogs.superspider._ClimbProgress '' + params: {} + weight: 1000.0 +terminations: + time_out: + func: !!python/name:mjlab.envs.mdp.terminations.time_out '' + params: {} + time_out: true + fell_over: + func: !!python/name:mjlab.envs.mdp.terminations.bad_orientation '' + params: + limit_angle: 1.2217304763960306 + time_out: false + illegal_contact: + func: !!python/name:mjlab.tasks.velocity.mdp.terminations.illegal_contact '' + params: + sensor_name: nonfoot_ground_touch + force_threshold: 10.0 + time_out: false +commands: + twist: + resampling_time_range: !!python/tuple + - 3.0 + - 8.0 + debug_vis: true + entity_name: robot + heading_command: false + heading_control_stiffness: 0.5 + rel_standing_envs: 0.0 + rel_heading_envs: 1.0 + init_velocity_prob: 0.0 + ranges: + lin_vel_x: !!python/tuple + - 0.05 + - 0.4 + lin_vel_y: !!python/tuple + - -0.05 + - 0.05 + ang_vel_z: !!python/tuple + - -0.3 + - 0.3 + heading: null + viz: + z_offset: 0.2 + scale: 0.5 +curriculum: + terrain_levels: + func: !!python/name:src.tasks.velocity.config.custom_dog.dogs.superspider._terrain_levels_stairs '' + params: + command_name: twist +metrics: + mean_action_acc: + func: !!python/name:mjlab.envs.mdp.metrics.mean_action_acc '' + params: {} +is_finite_horizon: false +scale_rewards_by_dt: true diff --git a/training/snapshots/teacher/agent.yaml b/training/snapshots/teacher/agent.yaml new file mode 100644 index 0000000..a78132a --- /dev/null +++ b/training/snapshots/teacher/agent.yaml @@ -0,0 +1,55 @@ +seed: 42 +num_steps_per_env: 24 +max_iterations: 8000 +obs_groups: + actor: !!python/tuple + - actor + critic: !!python/tuple + - critic +save_interval: 100 +experiment_name: superspider_stairs_teacher_velocity +run_name: '' +logger: tensorboard +wandb_project: mjlab +wandb_tags: !!python/tuple [] +resume: true +load_run: zz_fromblind +load_checkpoint: model_0.pt +clip_actions: null +upload_model: true +class_name: OnPolicyRunner +actor: + hidden_dims: !!python/tuple + - 512 + - 256 + - 128 + activation: elu + obs_normalization: true + distribution_cfg: + init_std: 1.0 + std_type: scalar +critic: + hidden_dims: !!python/tuple + - 512 + - 256 + - 128 + activation: elu + obs_normalization: true +algorithm: + num_learning_epochs: 5 + num_mini_batches: 4 + learning_rate: 0.001 + schedule: adaptive + gamma: 0.99 + lam: 0.95 + entropy_coef: 0.01 + desired_kl: 0.01 + max_grad_norm: 1.0 + value_loss_coef: 1.0 + use_clipped_value_loss: true + clip_param: 0.2 + normalize_advantage_per_mini_batch: false + optimizer: adam + rnd_cfg: null + symmetry_cfg: null +multi_gpu: null diff --git a/training/snapshots/teacher/env.yaml b/training/snapshots/teacher/env.yaml new file mode 100644 index 0000000..7dabfe3 --- /dev/null +++ b/training/snapshots/teacher/env.yaml @@ -0,0 +1,1715 @@ +decimation: 4 +scene: + num_envs: 512 + env_spacing: 2.0 + terrain: + init_state: + pos: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + rot: !!python/tuple + - 1.0 + - 0.0 + - 0.0 + - 0.0 + lin_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + ang_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + joint_pos: + .*: 0.0 + joint_vel: + .*: 0.0 + spec_fn: !!python/name:mjlab.entity.entity.%3Clambda%3E '' + articulation: null + sort_actuators: false + lights: !!python/tuple + - name: sun + body: world + mode: fixed + target: null + type: directional + castshadow: true + pos: !!python/tuple + - 0.0 + - 0.0 + - 1.5 + dir: !!python/tuple + - 0.0 + - 0.0 + - -1.0 + cutoff: 45.0 + exponent: 10.0 + cameras: !!python/tuple [] + textures: !!python/tuple + - name: groundplane + type: 2d + builtin: checker + rgb1: !!python/tuple + - 0.2 + - 0.3 + - 0.4 + rgb2: !!python/tuple + - 0.1 + - 0.2 + - 0.3 + width: 300 + height: 300 + mark: edge + markrgb: !!python/tuple + - 0.8 + - 0.8 + - 0.8 + materials: !!python/tuple + - name: groundplane + rgba: !!python/tuple + - 1.0 + - 1.0 + - 1.0 + - 1.0 + texuniform: true + texrepeat: !!python/tuple + - 4.0 + - 4.0 + reflectance: 0.2 + texture: groundplane + geom_names_expr: !!python/tuple + - terrain$ + collisions: !!python/tuple [] + terrain_type: generator + terrain_generator: + seed: null + curriculum: true + size: !!python/tuple + - 8.0 + - 8.0 + border_width: 20.0 + border_height: 1.0 + num_rows: 10 + num_cols: 20 + color_scheme: height + sub_terrains: + single_step: + proportion: 1.0 + size: !!python/tuple + - 8.0 + - 8.0 + flat_patch_sampling: null + step_height_range: !!python/tuple + - 0.01 + - 0.06 + approach: 1.5 + difficulty_range: !!python/tuple + - 0.0 + - 1.0 + add_lights: true + env_spacing: 2.0 + max_init_terrain_level: 0 + num_envs: 512 + entities: + robot: + init_state: + pos: !!python/tuple + - 0.0 + - 0.0 + - 0.1 + rot: !!python/tuple + - 1.0 + - 0.0 + - 0.0 + - 0.0 + lin_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + ang_vel: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + joint_pos: + 1_coxa: 0.074027 + 1_femur: 0.943939 + 1_tibia: -0.974578 + 2_coxa: 0.074407 + 2_femur: 1.164487 + 2_tibia: -0.647146 + 3_coxa: -0.037301 + 3_femur: 1.004834 + 3_tibia: -0.590105 + 4_coxa: -0.039226 + 4_femur: 1.349236 + 4_tibia: -0.815209 + 5_coxa: -0.174187 + 5_femur: 0.844217 + 5_tibia: -0.55142 + 6_coxa: 0.246042 + 6_femur: 1.053368 + 6_tibia: -0.997824 + joint_vel: + .*: 0.0 + spec_fn: !!python/name:src.tasks.velocity.config.custom_dog.builder.spec_fn '' + articulation: + actuators: !!python/tuple + - target_names_expr: !!python/tuple + - '[1-6]_(coxa|femur|tibia)' + transmission_type: !!python/object/apply:mjlab.actuator.actuator.TransmissionType + - joint + armature: 0.005 + frictionloss: 0.0 + stiffness: 40.0 + damping: 1.2 + effort_limit: 4.41 + soft_joint_pos_limit_factor: 0.9 + sort_actuators: false + lights: !!python/tuple [] + cameras: !!python/tuple [] + textures: !!python/tuple [] + materials: !!python/tuple [] + collisions: !!python/tuple + - geom_names_expr: !!python/tuple + - ^(base_link|[1-6]_(coxa|femur))_col\d+$ + - ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$ + contype: 1 + conaffinity: 1 + condim: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: 3 + ^(base_link|[1-6]_(coxa|femur))_col\d+$: 1 + priority: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: 1 + friction: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: !!python/tuple + - 0.6 + solref: null + solimp: + ^(edge_1a|edge_1b|edge_2a|edge_2b|edge_3a|edge_3b|edge_4a|edge_4b|edge_5a|edge_5b|edge_6a|edge_6b)$: !!python/tuple + - 0.9 + - 0.95 + - 0.023 + disable_other_geoms: true + sensors: !!python/tuple + - name: terrain_scan + frame: + type: body + name: base_link + entity: robot + pattern: + size: !!python/tuple + - 0.9 + - 0.4 + resolution: 0.04 + direction: !!python/tuple + - 0.0 + - 0.0 + - -1.0 + ray_alignment: yaw + max_distance: 5.0 + exclude_parent_body: true + include_geom_groups: !!python/tuple + - 0 + - 1 + - 2 + debug_vis: true + viz: + hit_color: !!python/tuple + - 0.0 + - 1.0 + - 0.0 + - 0.8 + miss_color: !!python/tuple + - 1.0 + - 0.0 + - 0.0 + - 0.4 + hit_sphere_color: !!python/tuple + - 0.0 + - 1.0 + - 1.0 + - 1.0 + hit_sphere_radius: 0.5 + show_rays: false + show_normals: true + normal_color: !!python/tuple + - 1.0 + - 1.0 + - 0.0 + - 1.0 + normal_length: 5.0 + - name: feet_ground_contact + primary: + mode: geom + pattern: !!python/tuple + - edge_1a + - edge_1b + - edge_2a + - edge_2b + - edge_3a + - edge_3b + - edge_4a + - edge_4b + - edge_5a + - edge_5b + - edge_6a + - edge_6b + entity: robot + exclude: !!python/tuple [] + secondary: + mode: body + pattern: terrain + entity: null + exclude: !!python/tuple [] + fields: !!python/tuple + - found + - force + reduce: netforce + num_slots: 1 + secondary_policy: first + track_air_time: true + global_frame: false + history_length: 0 + debug: false + - name: nonfoot_ground_touch + primary: + mode: geom + pattern: ^(base_link|[1-6]_(coxa|femur))_col\d+$ + entity: robot + exclude: !!python/tuple + - edge_1a + - edge_1b + - edge_2a + - edge_2b + - edge_3a + - edge_3b + - edge_4a + - edge_4b + - edge_5a + - edge_5b + - edge_6a + - edge_6b + secondary: + mode: body + pattern: terrain + entity: null + exclude: !!python/tuple [] + fields: !!python/tuple + - found + - force + reduce: none + num_slots: 1 + secondary_policy: first + track_air_time: false + global_frame: false + history_length: 4 + debug: false + - name: self_collision + primary: + mode: subtree + pattern: base_link + entity: robot + exclude: !!python/tuple [] + secondary: + mode: subtree + pattern: base_link + entity: robot + exclude: !!python/tuple [] + fields: !!python/tuple + - found + reduce: none + num_slots: 1 + secondary_policy: first + track_air_time: false + global_frame: false + history_length: 0 + debug: false + extent: 2.0 + spec_fn: null +observations: + actor: + terms: + base_ang_vel: + func: &id001 !!python/name:mjlab.envs.mdp.observations.builtin_sensor '' + params: + sensor_name: robot/imu_ang_vel + noise: + operation: add + _tensor_cache: {} + n_min: -0.2 + n_max: 0.2 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + projected_gravity: + func: &id002 !!python/name:mjlab.envs.mdp.observations.projected_gravity '' + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.05 + n_max: 0.05 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + command: + func: &id003 !!python/name:mjlab.envs.mdp.observations.generated_commands '' + params: + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + phase: + func: &id004 !!python/name:src.tasks.velocity.mdp.observations.phase '' + params: + period: 0.6 + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_pos: + func: &id005 !!python/name:mjlab.envs.mdp.observations.joint_pos_rel '' + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.01 + n_max: 0.01 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_vel: + func: &id006 !!python/name:mjlab.envs.mdp.observations.joint_vel_rel '' + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -1.5 + n_max: 1.5 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + actions: + func: &id007 !!python/name:mjlab.envs.mdp.observations.last_action '' + params: {} + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + height_scan: + func: &id008 !!python/name:mjlab.envs.mdp.observations.height_scan '' + params: + sensor_name: terrain_scan + noise: + operation: add + _tensor_cache: {} + n_min: -0.1 + n_max: 0.1 + clip: null + scale: 0.2 + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + concatenate_terms: true + concatenate_dim: -1 + enable_corruption: true + history_length: 1 + flatten_history_dim: true + nan_policy: disabled + nan_check_per_term: true + critic: + terms: + base_ang_vel: + func: *id001 + params: + sensor_name: robot/imu_ang_vel + noise: + operation: add + _tensor_cache: {} + n_min: -0.2 + n_max: 0.2 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + projected_gravity: + func: *id002 + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.05 + n_max: 0.05 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + command: + func: *id003 + params: + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + phase: + func: *id004 + params: + period: 0.6 + command_name: twist + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_pos: + func: *id005 + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -0.01 + n_max: 0.01 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + joint_vel: + func: *id006 + params: {} + noise: + operation: add + _tensor_cache: {} + n_min: -1.5 + n_max: 1.5 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + actions: + func: *id007 + params: {} + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + height_scan: + func: *id008 + params: + sensor_name: terrain_scan + noise: null + clip: null + scale: 0.2 + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + base_lin_vel: + func: *id001 + params: + sensor_name: robot/imu_lin_vel + noise: + operation: add + _tensor_cache: {} + n_min: -0.5 + n_max: 0.5 + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_height: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_height '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: !!python/tuple + - fsite_1a + - fsite_1b + - fsite_2a + - fsite_2b + - fsite_3a + - fsite_3b + - fsite_4a + - fsite_4b + - fsite_5a + - fsite_5b + - fsite_6a + - fsite_6b + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_air_time: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_air_time '' + params: + sensor_name: feet_ground_contact + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_contact: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_contact '' + params: + sensor_name: feet_ground_contact + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + foot_contact_forces: + func: !!python/name:src.tasks.velocity.mdp.observations.foot_contact_forces '' + params: + sensor_name: feet_ground_contact + noise: null + clip: null + scale: null + delay_min_lag: 0 + delay_max_lag: 0 + delay_per_env: true + delay_hold_prob: 0.0 + delay_update_period: 0 + delay_per_env_phase: true + history_length: 0 + flatten_history_dim: true + concatenate_terms: true + concatenate_dim: -1 + enable_corruption: false + history_length: 1 + flatten_history_dim: true + nan_policy: disabled + nan_check_per_term: true +actions: + joint_pos: + entity_name: robot + clip: null + transmission_type: !!python/object/apply:mjlab.actuator.actuator.TransmissionType + - joint + actuator_names: !!python/tuple + - 1_coxa + - 1_femur + - 1_tibia + - 2_coxa + - 2_femur + - 2_tibia + - 3_coxa + - 3_femur + - 3_tibia + - 4_coxa + - 4_femur + - 4_tibia + - 5_coxa + - 5_femur + - 5_tibia + - 6_coxa + - 6_femur + - 6_tibia + scale: 0.25 + offset: 0.0 + preserve_order: false + use_default_offset: true +events: + reset_base: + func: !!python/name:mjlab.envs.mdp.events.reset_root_state_uniform '' + params: + pose_range: + x: !!python/tuple + - -0.5 + - 0.5 + y: !!python/tuple + - -0.5 + - 0.5 + z: !!python/tuple + - 0.0 + - 0.0 + yaw: !!python/tuple + - -3.14 + - 3.14 + velocity_range: {} + mode: reset + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + reset_robot_joints: + func: !!python/name:mjlab.envs.mdp.events.reset_joints_by_offset '' + params: + position_range: !!python/tuple + - -0.0 + - 0.0 + velocity_range: !!python/tuple + - -0.0 + - 0.0 + asset_cfg: + name: robot + joint_names: !!python/tuple + - .* + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + mode: reset + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + push_robot: + func: !!python/name:mjlab.envs.mdp.events.push_by_setting_velocity '' + params: + velocity_range: + x: !!python/tuple + - -0.5 + - 0.5 + y: !!python/tuple + - -0.5 + - 0.5 + z: !!python/tuple + - -0.4 + - 0.4 + roll: !!python/tuple + - -0.52 + - 0.52 + pitch: !!python/tuple + - -0.52 + - 0.52 + yaw: !!python/tuple + - -0.78 + - 0.78 + mode: interval + interval_range_s: !!python/tuple + - 5.0 + - 6.0 + is_global_time: false + min_step_count_between_reset: 0 + foot_friction: + func: !!python/name:mjlab.envs.mdp.dr.geom.geom_friction '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: !!python/tuple + - edge_1a + - edge_1b + - edge_2a + - edge_2b + - edge_3a + - edge_3b + - edge_4a + - edge_4b + - edge_5a + - edge_5b + - edge_6a + - edge_6b + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + operation: abs + ranges: !!python/tuple + - 0.3 + - 1.6 + shared_random: true + mode: startup + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + encoder_bias: + func: !!python/name:mjlab.envs.mdp.dr.joint.encoder_bias '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + bias_range: !!python/tuple + - -0.015 + - 0.015 + mode: startup + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 + base_com: + func: !!python/name:mjlab.envs.mdp.dr.body.body_com_offset '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: !!python/tuple + - base_link + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + operation: add + ranges: + 0: !!python/tuple + - -0.05 + - 0.05 + 1: !!python/tuple + - -0.05 + - 0.05 + 2: !!python/tuple + - -0.05 + - 0.05 + mode: startup + interval_range_s: null + is_global_time: false + min_step_count_between_reset: 0 +seed: 42 +sim: + nconmax: null + njmax: null + ls_parallel: true + contact_sensor_maxmatch: 500 + mujoco: + timestep: 0.005 + integrator: implicitfast + impratio: 1.0 + cone: pyramidal + jacobian: auto + solver: newton + iterations: 10 + tolerance: 1.0e-08 + ls_iterations: 20 + ls_tolerance: 0.01 + ccd_iterations: 500 + gravity: !!python/tuple + - 0.0 + - 0.0 + - -9.81 + multiccd: false + nan_guard: + enabled: false + buffer_size: 100 + output_dir: /tmp/mjlab/nan_dumps + max_envs_to_dump: 5 +viewer: + lookat: !!python/tuple + - 0.0 + - 0.0 + - 0.0 + distance: 1.5 + fovy: null + elevation: -10.0 + azimuth: 90.0 + origin_type: !!python/object/apply:mjlab.viewer.viewer_config.OriginType + - 4 + entity_name: robot + body_name: base_link + env_idx: 0 + max_extra_envs: 2 + enable_reflections: true + enable_shadows: true + height: 240 + width: 320 +episode_length_s: 20.0 +rewards: + track_linear_velocity: + func: !!python/name:src.tasks.velocity.mdp.rewards.track_linear_velocity '' + params: + command_name: twist + std: 0.15 + weight: 1.0 + track_angular_velocity: + func: !!python/name:src.tasks.velocity.mdp.rewards.track_angular_velocity '' + params: + command_name: twist + std: 0.7071067811865476 + weight: 1.0 + body_orientation_l2: + func: !!python/name:src.tasks.velocity.mdp.rewards.body_orientation_l2 '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: !!python/tuple + - base_link + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -1.0 + pose: + func: !!python/name:src.tasks.velocity.mdp.rewards.variable_posture '' + params: + asset_cfg: + name: robot + joint_names: !!python/tuple + - 1_coxa + - 1_femur + - 1_tibia + - 2_coxa + - 2_femur + - 2_tibia + - 3_coxa + - 3_femur + - 3_tibia + - 4_coxa + - 4_femur + - 4_tibia + - 5_coxa + - 5_femur + - 5_tibia + - 6_coxa + - 6_femur + - 6_tibia + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + command_name: twist + std_standing: + 1_coxa: 0.1 + 1_femur: 0.1 + 1_tibia: 0.1 + 2_coxa: 0.1 + 2_femur: 0.1 + 2_tibia: 0.1 + 3_coxa: 0.1 + 3_femur: 0.1 + 3_tibia: 0.1 + 4_coxa: 0.1 + 4_femur: 0.1 + 4_tibia: 0.1 + 5_coxa: 0.1 + 5_femur: 0.1 + 5_tibia: 0.1 + 6_coxa: 0.1 + 6_femur: 0.1 + 6_tibia: 0.1 + std_walking: + 1_coxa: 0.35 + 1_femur: 0.35 + 1_tibia: 0.35 + 2_coxa: 0.35 + 2_femur: 0.35 + 2_tibia: 0.35 + 3_coxa: 0.35 + 3_femur: 0.35 + 3_tibia: 0.35 + 4_coxa: 0.35 + 4_femur: 0.35 + 4_tibia: 0.35 + 5_coxa: 0.35 + 5_femur: 0.35 + 5_tibia: 0.35 + 6_coxa: 0.35 + 6_femur: 0.35 + 6_tibia: 0.35 + std_running: + 1_coxa: 0.35 + 1_femur: 0.35 + 1_tibia: 0.35 + 2_coxa: 0.35 + 2_femur: 0.35 + 2_tibia: 0.35 + 3_coxa: 0.35 + 3_femur: 0.35 + 3_tibia: 0.35 + 4_coxa: 0.35 + 4_femur: 0.35 + 4_tibia: 0.35 + 5_coxa: 0.35 + 5_femur: 0.35 + 5_tibia: 0.35 + 6_coxa: 0.35 + 6_femur: 0.35 + 6_tibia: 0.35 + walking_threshold: 0.1 + running_threshold: 1.5 + weight: 1.0 + body_ang_vel: + func: !!python/name:src.tasks.velocity.mdp.rewards.body_angular_velocity_penalty '' + params: + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: !!python/tuple + - base_link + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -0.05 + angular_momentum: + func: !!python/name:src.tasks.velocity.mdp.rewards.angular_momentum_penalty '' + params: + sensor_name: robot/root_angmom + weight: -0.025 + is_terminated: + func: !!python/name:mjlab.envs.mdp.rewards.is_terminated '' + params: {} + weight: -200.0 + joint_acc_l2: + func: !!python/name:mjlab.envs.mdp.rewards.joint_acc_l2 '' + params: {} + weight: -2.5e-07 + joint_pos_limits: + func: !!python/name:mjlab.envs.mdp.rewards.joint_pos_limits '' + params: {} + weight: -10.0 + action_rate_l2: + func: !!python/name:mjlab.envs.mdp.rewards.action_rate_l2 '' + params: {} + weight: -0.05 + foot_gait: + func: !!python/name:src.tasks.velocity.mdp.rewards.feet_gait '' + params: + period: 0.6 + offset: + - 0.0 + - 0.0 + - 0.5 + - 0.5 + - 0.0 + - 0.0 + - 0.5 + - 0.5 + - 0.0 + - 0.0 + - 0.5 + - 0.5 + threshold: 0.56 + command_threshold: 0.1 + command_name: twist + sensor_name: feet_ground_contact + weight: 0.0 + foot_clearance: + func: !!python/name:src.tasks.velocity.config.custom_dog.dogs.superspider._FeetClearanceRelative '' + params: + target_height: 0.05 + command_name: twist + command_threshold: 0.1 + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: !!python/tuple + - fsite_1a + - fsite_1b + - fsite_2a + - fsite_2b + - fsite_3a + - fsite_3b + - fsite_4a + - fsite_4b + - fsite_5a + - fsite_5b + - fsite_6a + - fsite_6b + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + sensor_name: feet_ground_contact + weight: -1.0 + foot_slip: + func: !!python/name:src.tasks.velocity.mdp.rewards.feet_slip '' + params: + sensor_name: feet_ground_contact + command_name: twist + command_threshold: 0.1 + asset_cfg: + name: robot + joint_names: null + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: !!python/tuple + - fsite_1a + - fsite_1b + - fsite_2a + - fsite_2b + - fsite_3a + - fsite_3b + - fsite_4a + - fsite_4b + - fsite_5a + - fsite_5b + - fsite_6a + - fsite_6b + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -0.25 + soft_landing: + func: !!python/name:src.tasks.velocity.mdp.rewards.soft_landing '' + params: + sensor_name: feet_ground_contact + command_name: twist + command_threshold: 0.1 + weight: -0.001 + stand_still: + func: !!python/name:src.tasks.velocity.mdp.rewards.stand_still '' + params: + command_name: twist + command_threshold: 0.1 + asset_cfg: + name: robot + joint_names: !!python/tuple + - 1_coxa + - 1_femur + - 1_tibia + - 2_coxa + - 2_femur + - 2_tibia + - 3_coxa + - 3_femur + - 3_tibia + - 4_coxa + - 4_femur + - 4_tibia + - 5_coxa + - 5_femur + - 5_tibia + - 6_coxa + - 6_femur + - 6_tibia + joint_ids: !!python/object/apply:builtins.slice + - null + - null + - null + body_names: null + body_ids: !!python/object/apply:builtins.slice + - null + - null + - null + geom_names: null + geom_ids: !!python/object/apply:builtins.slice + - null + - null + - null + site_names: null + site_ids: !!python/object/apply:builtins.slice + - null + - null + - null + actuator_names: null + actuator_ids: !!python/object/apply:builtins.slice + - null + - null + - null + tendon_names: null + tendon_ids: !!python/object/apply:builtins.slice + - null + - null + - null + camera_names: null + camera_ids: !!python/object/apply:builtins.slice + - null + - null + - null + light_names: null + light_ids: !!python/object/apply:builtins.slice + - null + - null + - null + material_names: null + material_ids: !!python/object/apply:builtins.slice + - null + - null + - null + preserve_order: false + weight: -1.0 + self_collision: + func: !!python/name:src.tasks.velocity.mdp.rewards.self_collision_cost '' + params: + sensor_name: self_collision + weight: -0.5 + joint_vel_over_limit: + func: !!python/name:src.tasks.velocity.config.custom_dog.dogs.superspider._joint_vel_over_limit '' + params: + limit: 4.64 + weight: -0.5 + climb_progress: + func: !!python/name:src.tasks.velocity.config.custom_dog.dogs.superspider._ClimbProgress '' + params: {} + weight: 1000.0 +terminations: + time_out: + func: !!python/name:mjlab.envs.mdp.terminations.time_out '' + params: {} + time_out: true + fell_over: + func: !!python/name:mjlab.envs.mdp.terminations.bad_orientation '' + params: + limit_angle: 1.2217304763960306 + time_out: false + illegal_contact: + func: !!python/name:mjlab.tasks.velocity.mdp.terminations.illegal_contact '' + params: + sensor_name: nonfoot_ground_touch + force_threshold: 10.0 + time_out: false +commands: + twist: + resampling_time_range: !!python/tuple + - 3.0 + - 8.0 + debug_vis: true + entity_name: robot + heading_command: false + heading_control_stiffness: 0.5 + rel_standing_envs: 0.0 + rel_heading_envs: 1.0 + init_velocity_prob: 0.0 + ranges: + lin_vel_x: !!python/tuple + - 0.05 + - 0.4 + lin_vel_y: !!python/tuple + - -0.05 + - 0.05 + ang_vel_z: !!python/tuple + - -0.3 + - 0.3 + heading: null + viz: + z_offset: 0.2 + scale: 0.5 +curriculum: + terrain_levels: + func: !!python/name:src.tasks.velocity.config.custom_dog.dogs.superspider._terrain_levels_stairs '' + params: + command_name: twist +metrics: + mean_action_acc: + func: !!python/name:mjlab.envs.mdp.metrics.mean_action_acc '' + params: {} +is_finite_horizon: false +scale_rewards_by_dt: true diff --git a/validation/smoke.json b/validation/smoke.json new file mode 100644 index 0000000..d8200ab --- /dev/null +++ b/validation/smoke.json @@ -0,0 +1,39 @@ +{ + "urdf": { + "links": 19, + "joints": 18 + }, + "mjcf": { + "nq": 25, + "nv": 24 + }, + "checkpoint_hashes": 5, + "student_5999.pt": { + "loaded_exactly": true, + "actions": 18, + "simulation_steps": 8 + }, + "student_1600.pt": { + "loaded_exactly": true, + "actions": 18, + "simulation_steps": 8 + }, + "flat_5999.pt": { + "loaded_exactly": true, + "actions": 18, + "simulation_steps": 8 + }, + "teacher_3800.pt": { + "loaded_exactly": true, + "actions": 18, + "simulation_steps": 8 + }, + "blind_10000.pt": { + "loaded_exactly": true, + "actions": 18, + "simulation_steps": 8 + }, + "date": "2026-10-27", + "device": "cpu", + "scope": "Resource, exact checkpoint loading, and eight simulation steps per checkpoint; not locomotion performance evaluation." +}