---
# System prepended metadata

title: Isaac Sim 實作
tags: [Omniverse]

---

# Isaac Sim 實作

> 2025-12-12

[TOC]

---

## 啟動 `Isaac-Sim` 容器

前面安裝的時候我們打了舊指令，**但漏掉了最重要的兩樣東西**，導致 Isaac Sim 根本不知道要怎麼跟 ROS 溝通：

:::danger
🛑 **為什麼之前的指令連不上？**
1.  **漏了掛載 `fastdds.xml`**：模擬器不知道要用 UDP 協議。
2.  **漏了設定 `ROS_DOMAIN_ID`**：模擬器不知道要連去哪個頻道。

如果不加這兩個，就算你開了模擬器，它也是「與世隔絕」的，ROS 當然連不上。
:::

### 正確的啟動指令
請使用下面這組指令（已加入 `fastdds.xml` 與 `ROS_DOMAIN_ID`）：

```bash
xhost +local:

docker run --name isaac-sim --entrypoint bash -it --gpus all -e "ACCEPT_EULA=Y" --rm --network=host --privileged \
    -e "PRIVACY_CONSENT=Y" \
    -e DISPLAY=$DISPLAY \
    -v $HOME/.Xauthority:/isaac-sim/.Xauthority \
    -v ~/docker/isaac-sim/cache/kit:/isaac-sim/kit/cache:rw \
    -v ~/docker/isaac-sim/cache/ov:/isaac-sim/.cache/ov:rw \
    -v ~/docker/isaac-sim/cache/pip:/isaac-sim/.cache/pip:rw \
    -v ~/docker/isaac-sim/cache/glcache:/isaac-sim/.cache/nvidia/GLCache:rw \
    -v ~/docker/isaac-sim/cache/computecache:/isaac-sim/.nv/ComputeCache:rw \
    -v ~/docker/isaac-sim/cache/warp:/isaac-sim/.cache/warp:rw \
    -v ~/docker/isaac-sim/logs:/isaac-sim/.nvidia-omniverse/logs:rw \
    -v ~/docker/isaac-sim/config:/isaac-sim/.nvidia-omniverse/config:rw \
    -v ~/docker/isaac-sim/data:/isaac-sim/.local/share/ov/data:rw \
    -v ~/docker/isaac-sim/documents:/isaac-sim/Documents:rw \
    -v ~/MyRobotProject:/isaac-sim/MyRobotProject:rw \
    -v ~/IsaacSim-ros_workspaces/jazzy_ws/fastdds.xml:/tmp/fastdds.xml \
    -e FASTRTPS_DEFAULT_PROFILES_FILE=/tmp/fastdds.xml \
    -e ROS_DOMAIN_ID=30 \
    nvcr.io/nvidia/isaac-sim:5.1.0
```

接著啟動 GUI：
```bash
./runapp.sh
```

---

## 啟動 `ROS2` 容器

打這行啟動 ROS2 容器：
```bash
docker run -it --rm \
    --net=host \
    --env="DISPLAY" \
    --env="ROS_DOMAIN_ID" \
    -v ~/IsaacSim-ros_workspaces/jazzy_ws:/jazzy_ws \
    --name ros_ws_docker \
    my_isaac_ros /bin/bash
```

然後別忘了載入環境變數：
```bash
# 1. 確保環境載入 (保險起見再跑一次)
source /opt/ros/jazzy/setup.bash
source /jazzy_ws/install/local_setup.bash
export FASTRTPS_DEFAULT_PROFILES_FILE=/jazzy_ws/fastdds.xml
export ROS_DOMAIN_ID=30
```

測試連線：
```bash
# 2. 測試連線
ros2 topic list
```

---

## 測試流程

### 第一步：準備 Isaac Sim 場景
確保 Isaac Sim 已經用上面的**正確指令**啟動。

1.  在 `Content Browser` 找到：
    **Isaac Sim > Sample > ROS2 > Scenario > leatherback_ackermann**
2.  右鍵 **Open** 打開場景。
3.  按下 **Play** ▶️。

### 第二步：啟動 ROS 2 Bridge 與控制

#### 🖥️ 開第一個新的 `Terminal` (轉譯節點)
啟動容器：
```bash
docker run -it --rm \
    --net=host \
    --env="DISPLAY" \
    --env="ROS_DOMAIN_ID" \
    -v ~/IsaacSim-ros_workspaces/jazzy_ws:/jazzy_ws \
    --name ros_ws_docker \
    my_isaac_ros /bin/bash
```

載入環境：
```bash
source /opt/ros/jazzy/setup.bash
source /jazzy_ws/install/local_setup.bash
export FASTRTPS_DEFAULT_PROFILES_FILE=/jazzy_ws/fastdds.xml
export ROS_DOMAIN_ID=30
```

如果你這時候打 `ros2 topic list`，應該會看到類似這樣：
```text
root@dodo-System-Product-Name:/# ros2 topic list
/ackermann_cmd
/depth
/odom
/parameter_events
/rgb
/rosout
/tf
```

接著執行範例鍵盤輸入轉譯：
```bash
ros2 launch cmdvel_to_ackermann cmdvel_to_ackermann.launch.py
```

成功的話應該會跳出：
```text
acceleration:=0.5 steering_velocity:=0.5
[INFO] [launch]: All log files can be found below /root/.ros/log/...
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [cmdvel_to_ackermann.py-1]: process started with pid [74]
```

#### 🖥️ 開第二個新的 `Terminal` (鍵盤控制)
進入剛剛已經開啟的容器：
```bash
docker exec -it ros_ws_docker /bin/bash
```

一樣要載入環境：
```bash
source /opt/ros/jazzy/setup.bash
source /jazzy_ws/install/local_setup.bash
export FASTRTPS_DEFAULT_PROFILES_FILE=/jazzy_ws/fastdds.xml
export ROS_DOMAIN_ID=30
```

執行控制鍵盤的範例：
```bash
ros2 run teleop_twist_keyboard teleop_twist_keyboard
```

會跳出控制說明：
```text
This node takes keypresses from the keyboard and publishes them
as Twist/TwistStamped messages. It works best with a US keyboard layout.
---------------------------
Moving around:
   u    i    o
   j    k    l
   m    ,    .

For Holonomic mode (strafing), hold down the shift key:
---------------------------
   U    I    O
   J    K    L
   M    <    >

t : up (+z)
b : down (-z)

anything else : stop

q/z : increase/decrease max speeds by 10%
w/x : increase/decrease only linear speed by 10%
e/c : increase/decrease only angular speed by 10%

CTRL-C to quit

currently:    speed 0.50    turn 1.00 
```

:::info
💡 **操作小提示**
注意：操作時請點一下 Isaac Sim 車子視窗畫面，再回到第二個 `Terminal` 操作。

用 `u i o j k l m , .` 控制應該就會動了。

**我做的時候按 `j` 沒左轉，笑死以為又壞掉了。**
**結果是要按 `u` 才能左前方移動！** 🤣
:::

結果：
{%preview https://youtu.be/_9XID-3-pEg %}