> For the complete documentation index, see [llms.txt](https://anonymous-humanoid.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://anonymous-humanoid.gitbook.io/docs/getting-started-software/locomotion-sim2sim-and-sim2real.md).

# Locomotion Sim2Sim and Sim2Real

## Select your locomotion

There are two locomotion modes in our code: lower-body locomotion and whole-body locomotion.

<figure><img src="https://3830802523-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHes4aC9tJcLREA5OZOli%2Fuploads%2FXhOFEvIEgLaWpgsLziDG%2Fimage.png?alt=media&amp;token=057ef43d-3e8a-432c-9dfe-ff17149de762" alt=""><figcaption><p>Lower Body Locomotion</p></figcaption></figure>

<figure><img src="https://3830802523-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHes4aC9tJcLREA5OZOli%2Fuploads%2FoHLYtJgzHE64UXwUz7JP%2Fimage.png?alt=media&amp;token=5536a333-7400-48e1-9c9d-109ee51ba2c1" alt=""><figcaption><p>Full Body Locomotion</p></figcaption></figure>

Lower-body locomotion — 11 degrees of freedom (DoF).

Whole-body locomotion — 19 degrees of freedom (DoF).

{% tabs %}
{% tab title="Lower body locomotion" %}

## Lower-Body RL Control

The lower-body RL controller operates **11 motors** (torso + two legs) through the `body_inference` node.

The controller subscribes to:

* `dm_motor_data`
* `imu`
* `gamepad_cmd`

and publishes:

* `dm_motor_cmd`

## Gamepad Controls

* `btn_up`: **RL** mode
* `btn_down`: **GOTO\_DEFAULT** mode
* `btn_left`: **ZERO\_TORQUE** mode
* `btn_right`: **DAMPING** mode
* `params[0]`: safety scale, adjusted using **D-pad Up/Down**, ranging from `0` to `10`

Before running any ROS 2 commands, each terminal must first enter the `humanoid-control` workspace and source the workspace setup:
{% endtab %}

{% tab title="Whole body locomotion" %}

## Whole-Body RL Control

The whole-body RL controller operates the full **19-motor robot** through the `whole_body_inference` node.

The policy observes all **19 joints**:

* 11 body joints
* 8 arm joints

However, the policy directly actuates only the **11 body joints**. The arm joints are held in their commanded configuration during `GOTO_DEFAULT`, `GOTO_ZERO`, and `RL` modes. In `DAMPING` and `ZERO_TORQUE` modes, the arms follow the body joints into damping or zero-torque mode.

## Motor / Joint Order

* `0`: torso
* `1..5`: left leg
* `6..10`: right leg
* `11..14`: left arm
* `15..18`: right arm

## Gamepad Controls

* `btn_up`: **RL** mode
* `btn_down`: **GOTO\_DEFAULT** mode
* `btn_rb` + `btn_down`: **GOTO\_ZERO** mode
* `btn_left`: **ZERO\_TORQUE** mode
* `btn_right`: **DAMPING** mode

These modes apply to both the body joints and the arm joints.

> <mark style="color:$warning;">**Important:**</mark> <mark style="color:$warning;"></mark><mark style="color:$warning;">A single</mark> <mark style="color:$warning;"></mark><mark style="color:$warning;">`dm_motor_driver_node`</mark> <mark style="color:$warning;"></mark><mark style="color:$warning;">controls all 19 motors through two USB2CANFD adapters using</mark> <mark style="color:$warning;"></mark><mark style="color:$warning;">`whole_body_motor.yaml`</mark><mark style="color:$warning;">. Do</mark> <mark style="color:$warning;"></mark><mark style="color:$warning;">**not**</mark> <mark style="color:$warning;"></mark><mark style="color:$warning;">start</mark> <mark style="color:$warning;"></mark><mark style="color:$warning;">`bimanual_arm.launch.py`</mark> <mark style="color:$warning;"></mark><mark style="color:$warning;">at the same time, because it would compete for control of the arm USB2CANFD adapter.</mark>
> {% endtab %}
> {% endtabs %}

## Policy Location

{% tabs %}
{% tab title="Lower body locomotion" %}
For lower-body locomotion, the policy is located at:

```bash
applications/body_inference/policy
```

{% endtab %}

{% tab title="Whole body locomotion" %}
For whole-body locomotion, the policy is located at:

```bash
applications/whole_body_inference/policy
```

{% endtab %}
{% endtabs %}

Replace `policy.onnx` and `policy_ankle_damped.onnx` with your own policy files.

## Start Sim2Sim

To run the controller in **Sim2Sim**, open four terminals and launch the components in the following order.

#### Terminal 1 — Start MuJoCo Simulation

Activate the `arcpy` Conda environment and launch `arc-bridge`:

```bash
conda activate arcpy
arc-bridge
```

{% tabs %}
{% tab title="Lower body locomotion" %}
When prompted, select **0** for the lower-body simulation.
{% endtab %}

{% tab title="Whole body locomotion" %}
When prompted, select **2** for the whole-body simulation.
{% endtab %}
{% endtabs %}

#### Terminal 2 — Start Gamepad Communication

Launch the ROS 2 gamepad publisher:

```bash
cd ~/projects/humanoid-control
source install/setup.bash
ros2 launch gamepad gamepad_publisher.launch.py
```

#### Terminal 3 — Start the ROS 2–LCM Bridge

{% tabs %}
{% tab title="Lower body locomotion" %}
Launch the lower-body `arc_bridge` configuration for simulation:

```bash
cd ~/projects/humanoid-control
source install/setup.bash

ros2 launch arc_bridge arc_bridge_body.launch.py config:=body_sim_mode.yaml
```

{% endtab %}

{% tab title="Whole body locomotion" %}
Launch the whole-body `arc_bridge` configuration for simulation:

```bash
cd ~/projects/humanoid-control
source install/setup.bash
ros2 launch arc_bridge arc_bridge_whole_body.launch.py \
    config:=whole_body_sim_mode.yaml
```

{% endtab %}
{% endtabs %}

#### Terminal 4 — Start the RL Controller

{% tabs %}
{% tab title="Lower body locomotion" %}
Launch the lower-body locomotion inference node:

```bash
cd ~/projects/humanoid-control
source install/setup.bash

ros2 launch body_inference locomotion_inference.launch.py
```

At this point, the data flow is: `Gamepad → ROS 2 → Lower-Body Controller → arc_bridge → MuJoCo`
{% endtab %}

{% tab title="Whole body locomotion" %}
Launch the whole-body locomotion inference node:

```bash
cd ~/projects/humanoid-control
source install/setup.bash
ros2 launch whole_body_inference locomotion_inference.launch.py
```

At this point, the data flow is: `Gamepad → ROS 2 → Whole-Body Controller → arc_bridge → MuJoCo`

{% endtab %}
{% endtabs %}

## Sim2Real

{% tabs %}
{% tab title="Lower body locomotion" %}
For operation on the real robot, open four terminals.

**Terminal 1 — Motor Driver**

```bash
cd ~/projects/humanoid-control
source install/setup.bash

ros2 launch dm_motor motor_driver.launch.py
```

**Terminal 2 — IMU**

```bash
cd ~/projects/humanoid-control
source install/setup.bash

ros2 run iwt603_imu imu_publisher_node --ros-args -p port:=/dev/imu0
```

**Terminal 3 — Gamepad**

```bash
cd ~/projects/humanoid-control
source install/setup.bash

ros2 launch gamepad gamepad_publisher.launch.py
```

**Terminal 4 — RL Controller**

```bash
cd ~/projects/humanoid-control
source install/setup.bash

ros2 launch body_inference locomotion_inference.launch.py
```

{% endtab %}

{% tab title="Whole body locomotion" %}
For operation on the real 19-motor robot, open four terminals.

**Terminal 1 — Motor Driver**

```bash
cd ~/projects/humanoid-control
source install/setup.bash

ros2 launch dm_motor motor_driver.launch.py config:=whole_body_motor.yaml
```

**Terminal 2 — IMU**

```bash
cd ~/projects/humanoid-control
source install/setup.bash

ros2 run iwt603_imu imu_publisher_node --ros-args -p port:=/dev/imu0
```

**Terminal 3 — Gamepad**

```bash
cd ~/projects/humanoid-control
source install/setup.bash

ros2 launch gamepad gamepad_publisher.launch.py
```

**Terminal 4 — Whole-Body RL Controller**

```bash
cd ~/projects/humanoid-control
source install/setup.bash

ros2 launch whole_body_inference locomotion_inference.launch.py
```

{% endtab %}
{% endtabs %}

## Real Robot + arc-bridge Replay Viewer

This mode uses the same setup as **Sim2Real**, with an additional `arc-bridge` terminal for replay visualization.

First, start `arc-bridge` in replay mode using the `--replay` option.

Run **Terminals 1–4 from the Sim2Real section**, then open one additional terminal.

### **Terminal 5 — Replay Bridge**

{% tabs %}
{% tab title="Lower body locomotion" %}

```bash
cd ~/projects/humanoid-control
source install/setup.bash

ros2 launch arc_bridge arc_bridge_body.launch.py config:=body_replay_mode.yaml
```

{% endtab %}

{% tab title="Whole body locomotion" %}

```bash
cd ~/projects/humanoid-control
source install/setup.bash

ros2 launch arc_bridge arc_bridge_whole_body.launch.py config:=whole_body_replay_mode.yaml
```

{% endtab %}
{% endtabs %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://anonymous-humanoid.gitbook.io/docs/getting-started-software/locomotion-sim2sim-and-sim2real.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
