Nhiều tính năng của Isaac Sim – đặc biệt là cầu nối ROS 2 – được xây bằng OmniGraph: hệ thống lập trình trực quan, nối các "node" bằng dây, chạy mỗi khung hình mà không cần script Python. Hiểu OmniGraph là chìa khóa để đọc, sửa các robot có sẵn ROS và tự dựng giao tiếp cho robot của mình.

Sau bài này bạn sẽ:
  • Hiểu node, thuộc tính, dây thực thi và dây dữ liệu.
  • Tạo đồ thị điều khiển robot bằng giao diện và bằng menu dựng sẵn.
  • Tạo cùng đồ thị đó bằng Python.

1. Khái niệm

Hình 2. Ba kiểu đánh giá đồ thị trong OmniGraph.
Hình 2. Ba kiểu đánh giá đồ thị trong OmniGraph.
  • Node: một khối chức năng có đầu vào (inputs:*), đầu ra (outputs:*). Isaac Sim thêm hàng trăm node: đọc thời gian mô phỏng, tính odometry, điều khiển articulation, publish/subscribe ROS 2…
  • Dây thực thi (execIn/execOut, tick): quyết định khi nào node chạy. Node On Playback Tick phát xung mỗi khung khi mô phỏng đang Play.
  • Dây dữ liệu: truyền giá trị từ đầu ra node này sang đầu vào node khác.
  • Đồ thị cũng là prim USD (thường ở /World/ActionGraph hoặc dưới robot) – được lưu cùng cảnh, cùng asset (layer asset_control.usd, asset_ros.usd ở bài #8).

2. Dựng đồ thị bằng giao diện

Hình 1. Đồ thị điều khiển Jetbot chạy vòng tròn: tick → bộ điều khiển vi sai → articulation controller.
Hình 1. Đồ thị điều khiển Jetbot chạy vòng tròn: tick → bộ điều khiển vi sai → articulation controller.
  1. Window > Graph Editors > Action Graph, bấm New Action Graph.
  2. Gõ tên node vào ô tìm kiếm bên trái và kéo vào: On Playback Tick, Differential Controller, Articulation Controller, hai Constant Double.
  3. Nối dây như hình 1; điền wheelRadius 0,03, wheelDistance 0,1125 (Jetbot), targetPrim trỏ tới robot, jointNames là tên hai khớp bánh theo thứ tự trái, phải.
  4. Play: Jetbot chạy vòng tròn bán kính v/ω ≈ 0,67 m.
Lối tắt: Tools > Robotics > OmniGraph Controllers có sẵn mẫu Differential Controller, Joint Position, Joint Velocity, Open Loop Gripper: chọn robot, điền thông số, công cụ tự dựng đồ thị (tùy chọn thêm điều khiển bằng bàn phím WASD). Tương tự, Tools > Robotics > ROS 2 OmniGraphs dựng sẵn đồ thị Camera, RTX Lidar, TF, Odometry, Joint States, Clock.

3. Dựng đồ thị bằng Python

og.Controller.edit() nhận bốn nhóm thao tác: tạo node, đặt giá trị, nối dây. Đoạn sau tạo đúng đồ thị ở hình 1:

import omni.graph.core as og
import usdrt.Sdf

keys = og.Controller.Keys
og.Controller.edit(
    {"graph_path": "/World/JetbotGraph", "evaluator_name": "execution"},   # execution = Action Graph
    {
        keys.CREATE_NODES: [
            ("Tick", "omni.graph.action.OnPlaybackTick"),
            ("V", "omni.graph.nodes.ConstantDouble"),
            ("W", "omni.graph.nodes.ConstantDouble"),
            ("Diff", "isaacsim.robot.wheeled_robots.DifferentialController"),
            ("Art", "isaacsim.core.nodes.IsaacArticulationController"),
        ],
        keys.SET_VALUES: [
            ("V.inputs:value", 0.2),
            ("W.inputs:value", 0.3),
            ("Diff.inputs:wheelRadius", 0.03),
            ("Diff.inputs:wheelDistance", 0.1125),
            ("Art.inputs:targetPrim", [usdrt.Sdf.Path("/World/Jetbot")]),
            ("Art.inputs:jointNames", ["left_wheel_joint", "right_wheel_joint"]),
        ],
        keys.CONNECT: [
            ("Tick.outputs:tick", "Diff.inputs:execIn"),
            ("Tick.outputs:tick", "Art.inputs:execIn"),
            ("Tick.outputs:deltaSeconds", "Diff.inputs:dt"),
            ("V.inputs:value", "Diff.inputs:linearVelocity"),
            ("W.inputs:value", "Diff.inputs:angularVelocity"),
            ("Diff.outputs:velocityCommand", "Art.inputs:velocityCommand"),
        ],
    },
)

Đọc/ghi thuộc tính lúc đang chạy:

attr = og.Controller.attribute("/World/JetbotGraph/V.inputs:value")
og.Controller.set(attr, 0.0)          # dừng xe
print(og.Controller.get(og.Controller.attribute("/World/JetbotGraph/Diff.outputs:velocityCommand")))

4. Chủ động "kích" đồ thị từ script

Trong script standalone muốn đồ thị chạy đúng lúc bạn chọn (ví dụ chỉ publish khi đã tính xong), thay On Playback Tick bằng On Impulse Event rồi bật xung:

og.Controller.set(og.Controller.attribute("/ActionGraph/OnImpulseEvent.state:enableImpulse"), True)
simulation_context.step(render=True)

Ví dụ MoveIt và ROS 2 Clock của Isaac Sim dùng đúng cách này (bài #20, #23).

5. Node tự viết

Khi thiếu node, bạn có thể viết node OmniGraph bằng Python (file .ogn mô tả thuộc tính + file .py có hàm compute) hoặc C++ cho hiệu năng cao. Tài liệu có hướng dẫn "Custom Python Nodes" và "Custom C++ Nodes"; Extension Template Generator (bài #10) giúp tạo khung.

Bài tiếp theo (#20): cầu nối ROS 2 – cài đặt, đồng hồ mô phỏng và điều khiển xe bằng cmd_vel.

Tài liệu tham khảo

Loạt bài "Robot với Isaac Sim" viết theo tài liệu và mã nguồn NVIDIA Isaac Sim 5.1.0. Isaac Sim, Omniverse, PhysX, RTX là thương hiệu của NVIDIA.