Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9023fd4
Add local docs web app and Codex skills
Albusgive Jun 7, 2026
64601bb
new file: extend/equality/mjwarp_equality.py
Albusgive Jun 7, 2026
7712492
skills适配opencode和claude code
Albusgive Jun 7, 2026
3e40a11
feat: refine skills with quick-reference, official doc links, and int…
Albusgive Jun 7, 2026
2f51f53
docs: refine README skills installation and complete force calculatio…
Albusgive Jun 7, 2026
182efa0
docs: reformat and polish joint tutorial
Albusgive Jun 7, 2026
61aaac7
docs: refactor virtual_world option screenshots into native markdown
Albusgive Jun 7, 2026
51f6d48
docs: refactor sensor_data tutorials to remove screenshots of C++ str…
Albusgive Jun 7, 2026
0613325
docs: refactor get_obj tutorials to remove C++ struct screenshots and…
Albusgive Jun 7, 2026
15e3ea5
docs: refactor ray casting tutorials to remove screenshots
Albusgive Jun 7, 2026
f394137
Refactor draw and force chapters to replace screenshot image tags wit…
Albusgive Jun 7, 2026
b539f08
Refactor soft contact tutorial to replace solver parameter and source…
Albusgive Jun 7, 2026
8e20b74
Replace mujoco_doc_solimp.png with the official high-resolution image…
Albusgive Jun 7, 2026
c6e1e35
Implement local interactive solver parameter visualizer using HTML5 c…
Albusgive Jun 7, 2026
4784173
Refactor soft contact visualizer to support Y-axis scale modes and im…
Albusgive Jun 7, 2026
2d1770d
Adjust chart padding and text alignment to prevent overlap on Y-axis …
Albusgive Jun 7, 2026
72d08cb
Fix formula rendering by adding blank lines before and after block eq…
Albusgive Jun 7, 2026
793cee8
Move mujoco_red_stone from extend to fun section physically and dynam…
Albusgive Jun 7, 2026
77d7626
Remove unused screenshot images from MJCF/asset that were replaced by…
Albusgive Jun 7, 2026
0a78107
Refine MuJoCo skill response style
Albusgive Jun 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .claude/skills/mujoco-cpp-build/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: mujoco-cpp-build
description: Use when building C++ examples, compiling simulation executables, configuring CMake, or resolving C++ building errors in the MuJoCo learning repository. It requires the agent to actively prompt the user for build requirements (source vs release path, target directories).
---

# MuJoCo C++ Build

This is the Claude Code project-local adapter for the canonical skill at:

`../../../skills/mujoco-cpp-build/SKILL.md`

When this skill is loaded, read and follow the canonical skill instructions:

- `../../../skills/mujoco-cpp-build/SKILL.md`

Use repository-relative tutorial paths only. Do not store user-specific paths in this adapter.
17 changes: 17 additions & 0 deletions .claude/skills/mujoco-engineering/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: mujoco-engineering
description: Use when an agent needs to implement, reproduce, debug, or extend MuJoCo projects using this repository's MJCF, Python, C++, ray casting, soft contact, sensors, rendering, viewer, force, or build examples.
---

# MuJoCo Engineering

This is the Claude Code project-local adapter for the canonical skill at:

`../../../skills/mujoco-engineering/SKILL.md`

When this skill is loaded, read and follow the canonical skill instructions and its reference map:

- `../../../skills/mujoco-engineering/SKILL.md`
- `../../../skills/mujoco-engineering/references/tutorial-map.md`

Use repository-relative tutorial paths only. Do not store user-specific paths in this adapter.
17 changes: 17 additions & 0 deletions .claude/skills/mujoco-teaching/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: mujoco-teaching
description: Use when a user wants to learn MuJoCo concepts, MJCF modeling, Python/C++ MuJoCo APIs, sensors, rendering, contact, soft contact, ray casting, or asks conceptual/tutorial questions about this repository's MuJoCo lessons.
---

# MuJoCo Teaching

This is the Claude Code project-local adapter for the canonical skill at:

`../../../skills/mujoco-teaching/SKILL.md`

When this skill is loaded, read and follow the canonical skill instructions and its reference map:

- `../../../skills/mujoco-teaching/SKILL.md`
- `../../../skills/mujoco-teaching/references/tutorial-map.md`

Use repository-relative tutorial paths only. Do not store user-specific paths in this adapter.
15 changes: 14 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,21 @@ extend/equality/.cache/

extend/plugin/.cache/

__pycache__/
*.py[cod]
.venv/
*.egg-info/
build/
dist/
.pytest_cache/
.ruff_cache/
.mypy_cache/
.uv/
uv.lock
skills/*/.local/

extend/soft_contact/C++/build/
extend/soft_contact/C++/.cache/

extend/touch/C++/build/
extend/touch/C++/.cache/
extend/touch/C++/.cache/
18 changes: 18 additions & 0 deletions .opencode/skills/mujoco-cpp-build/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: mujoco-cpp-build
description: Use when building C++ examples, compiling simulation executables, configuring CMake, or resolving C++ building errors in the MuJoCo learning repository. It requires the agent to actively prompt the user for build requirements (source vs release path, target directories).
metadata:
canonical-source: skills/mujoco-cpp-build
---

# MuJoCo C++ Build

This is the OpenCode project-local adapter for the canonical skill at:

`../../../skills/mujoco-cpp-build/SKILL.md`

When this skill is loaded, read and follow the canonical skill instructions:

- `../../../skills/mujoco-cpp-build/SKILL.md`

Use repository-relative tutorial paths only. Do not store user-specific paths in this adapter.
19 changes: 19 additions & 0 deletions .opencode/skills/mujoco-engineering/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: mujoco-engineering
description: Use when an agent needs to implement, reproduce, debug, or extend MuJoCo projects using this repository's MJCF, Python, C++, ray casting, soft contact, sensors, rendering, viewer, force, or build examples.
metadata:
canonical-source: skills/mujoco-engineering
---

# MuJoCo Engineering

This is the OpenCode project-local adapter for the canonical skill at:

`../../../skills/mujoco-engineering/SKILL.md`

When this skill is loaded, read and follow the canonical skill instructions and its reference map:

- `../../../skills/mujoco-engineering/SKILL.md`
- `../../../skills/mujoco-engineering/references/tutorial-map.md`

Use repository-relative tutorial paths only. Do not store user-specific paths in this adapter.
19 changes: 19 additions & 0 deletions .opencode/skills/mujoco-teaching/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: mujoco-teaching
description: Use when a user wants to learn MuJoCo concepts, MJCF modeling, Python/C++ MuJoCo APIs, sensors, rendering, contact, soft contact, ray casting, or asks conceptual/tutorial questions about this repository's MuJoCo lessons.
metadata:
canonical-source: skills/mujoco-teaching
---

# MuJoCo Teaching

This is the OpenCode project-local adapter for the canonical skill at:

`../../../skills/mujoco-teaching/SKILL.md`

When this skill is loaded, read and follow the canonical skill instructions and its reference map:

- `../../../skills/mujoco-teaching/SKILL.md`
- `../../../skills/mujoco-teaching/references/tutorial-map.md`

Use repository-relative tutorial paths only. Do not store user-specific paths in this adapter.
24 changes: 24 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"configurations": [
{
"browse": {
"databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db",
"limitSymbolsToIncludedHeaders": false
},
"includePath": [
"/home/albusgive2/unitree_ros2/cyclonedds_ws/install/unitree_hg/include/**",
"/home/albusgive2/unitree_ros2/cyclonedds_ws/install/unitree_go/include/**",
"/home/albusgive2/unitree_ros2/cyclonedds_ws/install/unitree_api/include/**",
"/home/albusgive2/rlfw/rlfw_interface/install/rlfw_msgs/include/**",
"/opt/ros/humble/include/**",
"/usr/include/**"
],
"name": "ros2",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++17"
}
],
"version": 4
}
18 changes: 17 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,21 @@
"cmake.sourceDirectory": "/home/albusgive2/mujoco_learning/CPP/Chapter1-make",
"python-envs.defaultEnvManager": "ms-python.python:conda",
"python-envs.defaultPackageManager": "ms-python.python:conda",
"python-envs.pythonProjects": []
"ROS2.distro": "humble",
"python.autoComplete.extraPaths": [
"/home/albusgive2/unitree_ros2/cyclonedds_ws/install/unitree_hg/local/lib/python3.10/dist-packages",
"/home/albusgive2/unitree_ros2/cyclonedds_ws/install/unitree_go/local/lib/python3.10/dist-packages",
"/home/albusgive2/unitree_ros2/cyclonedds_ws/install/unitree_api/local/lib/python3.10/dist-packages",
"/home/albusgive2/rlfw/rlfw_interface/install/rlfw_msgs/local/lib/python3.10/dist-packages",
"/opt/ros/humble/lib/python3.10/site-packages",
"/opt/ros/humble/local/lib/python3.10/dist-packages"
],
"python.analysis.extraPaths": [
"/home/albusgive2/unitree_ros2/cyclonedds_ws/install/unitree_hg/local/lib/python3.10/dist-packages",
"/home/albusgive2/unitree_ros2/cyclonedds_ws/install/unitree_go/local/lib/python3.10/dist-packages",
"/home/albusgive2/unitree_ros2/cyclonedds_ws/install/unitree_api/local/lib/python3.10/dist-packages",
"/home/albusgive2/rlfw/rlfw_interface/install/rlfw_msgs/local/lib/python3.10/dist-packages",
"/opt/ros/humble/lib/python3.10/site-packages",
"/opt/ros/humble/local/lib/python3.10/dist-packages"
]
}
122 changes: 103 additions & 19 deletions CPP/Chapter3-get_obj/tutorial.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,107 @@
# get obj
## 获取名字
数量
![](../../MJCF/asset/entity.png)
**先看mjModel结构体开头部分,这里的命名方式都是nXXX,这代表各个元素的数量**
![](../../MJCF/asset/names.png)
## 获取id
`MJAPI int mj_name2id(const mjModel* m, int type, const char* name);`
**通过name获取实体的id
m :mjModel
type: mjmodel.h文件中的mjtObj中定义,这个是要获取id的实体类型一下是部分type类型枚举,在mjtObj中找到
name: name
**
![](../../MJCF/asset/enum_mjtobj.png)
## 获取位置
![](../../MJCF/asset/xpos.png)
**可以通过 xpos和xxx_xpos获取各个对象的位置**
## 获取姿态
**通过xquat可以获取body的姿态**
# 获取仿真世界中的实体信息 (Get Object Info)

在 MuJoCo 中,获取仿真世界中各种实体(Body, Joint, Geom 等)的数量、ID、位置及姿态是非常高频的操作。以下是实现逻辑与核心数据结构。

---

## 1. 获取实体数量与名称 (Get Counts & Names)
所有的数量与命名信息都存储在 `mjModel` 结构体中。

### 1.1 实体数量定义
在 `mjModel` 的开头,定义了所有仿真元素的数量(以 `n` 开头):
```cpp
// 摘自 mujoco/mjmodel.h: 实体数量声明
int nbody; // 身体 (Body) 数量
int njnt; // 关节 (Joint) 数量
int ngeom; // 几何体 (Geom) 数量
int nsite; // 标记点 (Site) 数量
int ncam; // 相机 (Camera) 数量
int nlight; // 光源 (Light) 数量
int nmesh; // 网格 (Mesh) 数量
int nsensor; // 传感器 (Sensor) 数量
int nactuator; // 驱动器 (Actuator) 数量
```
* 源码链接:[mujoco/mjmodel.h (sizes段)](https://github.com/google-deepmind/mujoco/blob/main/include/mujoco/mjmodel.h)

### 1.2 实体名字缓冲区
在 `mjModel` 中,名字均以一维字符缓冲区存储,并通过对应的地址数组记录每个实体的名字指针偏置:
```cpp
// 摘自 mujoco/mjmodel.h: 命名缓冲区
char* names; // 名字缓存区,字符大数组 (nnames x 1)
int* name_bodyadr; // 各 Body 名字在 names 中的起始索引 (nbody x 1)
int* name_jntadr; // 各 Joint 名字在 names 中的起始索引 (njnt x 1)
int* name_geomadr; // 各 Geom 名字在 names 中的起始索引 (ngeom x 1)
int* name_sensoradr; // 各 Sensor 名字在 names 中的起始索引 (nsensor x 1)
```
* 源码链接:[mujoco/mjmodel.h (names段)](https://github.com/google-deepmind/mujoco/blob/main/include/mujoco/mjmodel.h)

---

## 2. 获取实体 ID (Get ID by Name)
因为 MuJoCo 底层物理计算全部基于数组索引(即 ID),在 API 中我们通常需要通过名字(string)获取其 ID。
使用 API 函数:
```cpp
MJAPI int mj_name2id(const mjModel* m, int type, const char* name);
```

### 2.1 参数说明
* `m`: `mjModel` 指针。
* `type`: 实体的类型,由枚举类型 `mjtObj` 定义。
* `name`: 实体的名称。

### 2.2 实体类型枚举 `mjtObj`
`mjtObj` 定义在 `mjmodel.h` 中,代表各种可能的实体类型:
```cpp
typedef enum mjtObj_ {
mjOBJ_UNKNOWN = 0, // 未知对象类型
mjOBJ_BODY, // 身体 (Body)
mjOBJ_XBODY, // Body的替代表示,用于读取常规参考系 (而非惯性系)
mjOBJ_JOINT, // 关节 (Joint)
mjOBJ_DOF, // 自由度 (Degrees of freedom)
mjOBJ_GEOM, // 几何体 (Geom)
mjOBJ_SITE, // 标记点 (Site)
mjOBJ_CAMERA, // 相机 (Camera)
mjOBJ_LIGHT, // 光源 (Light)
mjOBJ_FLEX, // 柔性可变形体 (Flex)
mjOBJ_MESH, // 三角网格 (Mesh)
mjOBJ_SKIN, // 皮肤网格 (Skin)
mjOBJ_HFIELD, // 高度图 (Heightfield)
mjOBJ_TEXTURE, // 纹理 (Texture)
mjOBJ_MATERIAL, // 材质 (Material)
mjOBJ_PAIR, // 特殊碰撞 geom 对 (Pair)
mjOBJ_SENSOR // 传感器 (Sensor)
} mjtObj;
```
* 源码链接:[mujoco/mjmodel.h (mjtObj定义)](https://github.com/google-deepmind/mujoco/blob/main/include/mujoco/mjmodel.h)

演示代码:
```cpp
int body_id = mj_name2id(model, mjOBJ_BODY, "robot_link1");
```

---

## 3. 获取位置与姿态 (Get Pos & Ori)
物体的实时笛卡尔空间状态(三维位置、姿态矩阵等)全部存储在 **`mjData`** 中,由求解器在 `mj_step` 时进行实时更新更新:

```cpp
// 摘自 mujoco/mjdata.h: 笛卡尔坐标状态
mjtNum* xpos; // 各个 Body 的三维笛卡尔中心坐标 (nbody x 3)
mjtNum* xquat; // 各个 Body 的笛卡尔四元数旋转姿态 (nbody x 4)
mjtNum* xmat; // 各个 Body 的笛卡尔旋转矩阵姿态 (nbody x 9)
mjtNum* xipos; // 各个 Body 质心 (com) 的笛卡尔坐标 (nbody x 3)
mjtNum* ximat; // 各个 Body 质心的笛卡尔旋转矩阵 (nbody x 9)
```
* 源码链接:[mujoco/mjdata.h (Cartesian state)](https://github.com/google-deepmind/mujoco/blob/main/include/mujoco/mjdata.h)

演示代码:
```cpp
// 获取特定 body 实时三维位置坐标
int body_id = mj_name2id(model, mjOBJ_BODY, "support");
if (body_id != -1) {
double x = data->xpos[body_id * 3 + 0];
double y = data->xpos[body_id * 3 + 1];
double z = data->xpos[body_id * 3 + 2];
std::cout << "Body position: " << x << ", " << y << ", " << z << std::endl;
}
```
34 changes: 28 additions & 6 deletions CPP/Chapter4-sensor_data/tutorial.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# 传感器数据获取

![](../../MJCF/asset/sensor_adr.png)
**sensordata的索引需要依靠mjData的sensor_adr获取,这个可以使用sensor的id**
**这个我们要注意传感器具有的数据量,有的传感器是一个值,而有的传感器是三个值。我们可以使用mjModel中的sensor_dim获得传感器输出的参数量**
<font color=Green>*演示:*</font>
**`sensordata` 的索引需要依靠 `mjModel` 中的 `sensor_adr` 获取,也可以使用 sensor 的 id。**

**我们要注意传感器具有的数据量,有的传感器是一个值,而有的传感器是三个值。我们可以使用 `mjModel` 中的 `sensor_dim` 获得传感器输出的参数量。**

* `mjModel.sensor_adr` 的定义类似于:
```cpp
int* sensor_adr; // address in sensor array (nsensor x 1)
```

演示:

```C++
std::vector<float> get_sensor_data(const mjModel *model, const mjData *data,
Expand All @@ -21,8 +27,24 @@ std::vector<float> get_sensor_data(const mjModel *model, const mjData *data,
return sensor_data;
}
```
对于传感器其他的属性在 mjModel中可以直接获得。如下:
![](../../MJCF/asset/modelsensors.png)

对于传感器的其他属性,在 `mjModel` 中可以直接获得:
```cpp
// mjModel 中的传感器相关成员变量说明
int* sensor_type; // 传感器类型 (mjtSensor) (nsensor x 1)
int* sensor_datatype; // 数值数据类型 (mjtDataType) (nsensor x 1)
int* sensor_needstage; // 所需 Jun 算阶段 (mjtStage) (nsensor x 1)
int* sensor_objtype; // 被测物体的类型 (mjtObj) (nsensor x 1)
int* sensor_objid; // 被测物体的 ID (nsensor x 1)
int* sensor_reftype; // 参考系物体的类型 (mjtObj) (nsensor x 1)
int* sensor_refid; // 参考系物体的 ID; -1: 全局参考系 (nsensor x 1)
int* sensor_dim; // 标量输出的数量 (nsensor x 1)
int* sensor_adr; // 传感器数据在 sensordata 中的地址 (nsensor x 1)
mjtNum* sensor_cutoff; // 实数/正数的截止值; 0: 忽略 (nsensor x 1)
mjtNum* sensor_noise; // 噪声音频标准差 (nsensor x 1)
mjtNum* sensor_user; // 用户数据 (nsensor x nuser_sensor)
int* sensor_plugin; // 插件实例 ID; -1: 非插件 (nsensor x 1)
```

### 读取相机画面
&emsp;&emsp;相机来源一般是在模型文件中创建相机,或者创建一个相机手动控制,就像 base中
Expand Down
Loading