Ở bài #20 xe đã nhận lệnh từ ROS 2. Muốn chạy SLAM, Nav2 hay thuật toán thị giác, chiều ngược lại cũng phải có: ảnh camera, lidar, odometry và cây TF. Bài này dựng đủ "bộ cảm biến ROS" cho một AMR mô phỏng.

Sau bài này bạn sẽ:
  • Publish ảnh, camera_info, LaserScan, PointCloud2.
  • Publish TF và odometry đúng chuẩn REP 105.
  • Điều chỉnh tần số, QoS, namespace và kiểm tra trên RViz2.

1. Bức tranh topic

Hình 2. Bảng topic – kiểu tin nhắn – node OmniGraph tạo ra nó.
Hình 2. Bảng topic – kiểu tin nhắn – node OmniGraph tạo ra nó.

Nhanh nhất là dùng menu Tools > Robotics > ROS 2 OmniGraphs: chọn Camera, RTX Lidar, TF Publisher, Odometry Publisher, Joint States hoặc Clock, trỏ tới prim tương ứng – công cụ tự dựng đồ thị. Robot có sẵn như Nova Carter ROS (Create > ROS 2 Assets) đã kèm đầy đủ đồ thị.

2. Camera

keys = og.Controller.Keys
og.Controller.edit(
    {"graph_path": "/World/CameraGraph", "evaluator_name": "execution"},
    {
        keys.CREATE_NODES: [
            ("Tick", "omni.graph.action.OnPlaybackTick"),
            ("RP", "isaacsim.core.nodes.IsaacCreateRenderProduct"),
            ("Rgb", "isaacsim.ros2.bridge.ROS2CameraHelper"),
            ("Depth", "isaacsim.ros2.bridge.ROS2CameraHelper"),
            ("Info", "isaacsim.ros2.bridge.ROS2CameraInfoHelper"),
        ],
        keys.SET_VALUES: [
            ("RP.inputs:cameraPrim", [usdrt.Sdf.Path("/World/Carter/chassis_link/front_cam")]),
            ("RP.inputs:width", 640), ("RP.inputs:height", 480),
            ("Rgb.inputs:type", "rgb"), ("Rgb.inputs:topicName", "rgb"), ("Rgb.inputs:frameId", "camera_link"),
            ("Depth.inputs:type", "depth"), ("Depth.inputs:topicName", "depth"), ("Depth.inputs:frameId", "camera_link"),
            ("Info.inputs:topicName", "camera_info"), ("Info.inputs:frameId", "camera_link"),
        ],
        keys.CONNECT: [
            ("Tick.outputs:tick", "RP.inputs:execIn"),
            ("RP.outputs:execOut", "Rgb.inputs:execIn"),
            ("RP.outputs:execOut", "Depth.inputs:execIn"),
            ("RP.outputs:execOut", "Info.inputs:execIn"),
            ("RP.outputs:renderProductPath", "Rgb.inputs:renderProductPath"),
            ("RP.outputs:renderProductPath", "Depth.inputs:renderProductPath"),
            ("RP.outputs:renderProductPath", "Info.inputs:renderProductPath"),
        ],
    },
)

Thuộc tính type của ROS2CameraHelper còn nhận depth_pcl (point cloud từ độ sâu), semantic_segmentation, instance_segmentation, bbox_2d_tight, bbox_3d… – dữ liệu "đáp án" cho bài toán nhận dạng. Dữ liệu camera được chuyển sang khung quang học ROS (bài #4) trước khi publish.

3. Lidar

Node ROS2RtxLidarHelper nhận renderProductPath của lidar và type là laser_scan (lidar 2D) hoặc point_cloud (3D). Từ Python còn có thể dùng writer của Replicator:

import omni.replicator.core as rep
rp = rep.create.render_product("/World/Carter/chassis_link/sensors/XT_32/PandarXT_32_10hz", [1, 1], name="Isaac")
writer = rep.writers.get("RtxLidarROS2PublishPointCloud")
writer.initialize(topicName="point_cloud", frameId="lidar_link")
writer.attach([rp])

4. TF và odometry

Hình 1. Cây TF và node chịu trách nhiệm cho từng đoạn.
Hình 1. Cây TF và node chịu trách nhiệm cho từng đoạn.
  • IsaacComputeOdometry (trỏ chassisPrim vào khâu thân) tính vị trí, hướng, vận tốc. Nối đầu ra vào ROS2PublishOdometry (khung mặc định odom → base_link) và ROS2PublishRawTransformTree để phát TF odom → base_link.
  • ROS2PublishTransformTree với parentPrim = khâu gốc và targetPrims = các khâu cảm biến, phát TF base_link → lidar/camera/imu theo đúng vị trí trên stage – không phải gõ tay static transform.
  • Mọi node publish nối timeStamp từ IsaacReadSimulationTime, và node ROS bên ngoài chạy với use_sim_time:=true.
  • Robot tay máy: ROS2PublishJointState + robot_state_publisher phía ROS cũng cho ra TF.

5. Tần số, QoS và namespace

  • Tần số: các helper có frameSkipCount – 0 publish mỗi khung, 1 publish cách một khung… Với 60 khung/s, frameSkipCount=1 cho 30 Hz. Hoặc chèn node IsaacSimulationGate với bước bỏ qua.
  • QoS: node ROS2QoSProfile tạo hồ sơ QoS (reliability, durability, history, depth) nối vào qosProfile của publisher. Từ 5.1, cài đặt mặc định của bridge chuyển về system_default. Lỗi "không thấy dữ liệu" trong RViz hay do lệch QoS (RViz đặt Reliable còn nguồn là Best Effort).
  • Namespace: thuộc tính nodeNamespace của từng node, hoặc tính năng tự sinh namespace theo tên robot – bắt buộc khi có nhiều robot (/robot1/cmd_vel, /robot2/cmd_vel).
  • Theo dõi tốc độ mô phỏng: node IsaacRealTimeFactor + publisher để biết mô phỏng đang chạy bằng bao nhiêu phần thời gian thực.

6. Kiểm tra trên RViz2

ros2 topic list
ros2 topic hz /scan
ros2 run tf2_tools view_frames            # xuất sơ đồ TF ra PDF
rviz2 --ros-args -p use_sim_time:=true

Trong RViz2: Fixed Frame = odom, thêm LaserScan (/scan), PointCloud2, Image (/rgb), TF. Lái xe bằng teleop (bài #20) và quan sát quét lidar khớp với tường trong cảnh. Workspace mẫu có sẵn cấu hình RViz trong gói isaac_tutorials.

Bài tiếp theo (#22): chạy Nav2 với Nova Carter trong nhà kho mô phỏng.

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.