> For the complete documentation index, see [llms.txt](https://tk233.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tk233.gitbook.io/notes/ml-rl/rl-frameworks/case-study-a-dive-into-unitree-mujoco.md).

# Case Study: A Dive Into Unitree-Mujoco

```python
# ROBOT_SCENE = "../unitree_robots/" + ROBOT + "/scene.xml"
mj_model = mujoco.MjModel.from_xml_path(config.ROBOT_SCENE)
mj_data = mujoco.MjData(mj_model)

```

## Base and Joint Data

The state of the robot can be accessed via the `mj_data.qpos` and `mj_data.qvel` fields.

These two fields are two `numpy.ndarray` that stores both the base state as well as the joint state.

The shape of `qpos` is `3 + 4 + n_dof`, which composes of the base xyz position, base rotation in quaternion, and all the joint rotation positions.

The shape of `qvel` is `3 + 3 + n_dof`. The only difference from the qpos is that the angular rotation is expressed in euler angle, instead of quaternions.

```bash
mj_data.qpos  # (base_x, base_y, base_z, base_qx, base_qy, base_qz, base_qw, joint...)
mj_data.qvel  # (base_vx, base_vy, base_vz, base_vrx, base_vry, base_vrz, jointv...)

```

## Joint Ordering

Different from IsaacLab, which orders the joint in a breath-first search fashion and ordered by capital letter, Mujoco uses a depth-first search. Therefore, the joint order will be different. Here's an example for the A1 robot.

Mujoco Mapping:

```python
 0: FL_Hip
 1: FR_Hip
 2: RL_Hip
 3: RR_Hip
 4: FL_Thigh
 5: FR_Thigh
 6: RL_Thigh
 7: RR_Thigh
 8: FL_Calf
 9: FR_Calf
10: RL_Calf
11: RR_Calf
```

IsaacLab Mapping

```python
 0: FL_Hip
 1: FL_Thigh
 2: FL_Calf
 3: FR_Hip
 4: FR_Thigh
 5: FR_Calf
 6: RL_Hip
 7: RL_Thigh
 8: RL_Calf
 9: RR_Hip
10: RR_Thigh
11: RR_Calf
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://tk233.gitbook.io/notes/ml-rl/rl-frameworks/case-study-a-dive-into-unitree-mujoco.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
