08 · カメラ(RealSense D435)¶
目標: Lime に RealSense D435 カメラを、URDF にあるとおりのフレームに取り付けます。そして、実機の realsense2_camera ドライバーと同じトピック名で、RGB 画像、深度画像、カメラの内部パラメーターを ROS 2 にパブリッシュします。


左:/camera/camera/color/image_raw。右:/camera/camera/aligned_depth_to_color/image_raw(32 ビットの float、単位はメートル)を表示用に色付けしたもの。ロボットは「lime_room」の中で、マグカップ、ボウル、バナナ、ボトルの前に立っています。
考え方¶
lime_room: このチュートリアル以降、ロボットは小さな部屋 (isaac/common/scene.py) の中で過ごします。広さは 6 × 5 m で、高さ 0.6 m の壁、オレンジ色の障害物が 3 つあり、床には NVIDIA のアセットライブラリーから取った日用品が 4 つ置かれています。同じファイルを使って、この部屋を GUI 用に assets/scenes/lime_room.usda として保存することもできます (python isaac/common/scene.py)。
カメラの位置: URDF には、すでに D435 のフレームが含まれています。このチュートリアルでは、camera_color_optical_frame に USD カメラを置きます。このフレームは台車の前部にあり、床から 5.8 cm の高さで、前方を向いています。
光学フレームと USD カメラ
ROS の光学フレームは +Z 方向を向き、+Y が下です(画像の行番号は下に向かって増えます)。USD カメラは −Z 方向を向き、+Y が上です。X 軸まわりに 180° 回転させると一方がもう一方になるので、カメラのプリムは camera_color_optical_frame の下に rotateX = 180 で置きます。
実機のカメラに合わせる: URDF によると、解像度は 640 × 480、水平画角は 1.211 rad (69.4°) です。USD カメラはピンホールモデルを使います。焦点距離 \(f\) と開口幅 \(w\)(単位は mm)から、画角 \(\text{FOV} = 2\arctan\frac{w}{2f}\) が決まります。デフォルトの \(w = 20.955\) mm では、\(f = 15.1\) mm になります。このとき、パブリッシュされる camera_info は \(f_x = 640 / (2\tan(1.211/2)) = 462.3\) px になります。
レンダープロダクト: カメラが画像を出力するのは、レンダープロダクト(カメラ + 解像度)を通したときだけです。Isaac Create Render Product がこれを作ります。ROS のヘルパーノードは、そこから RGB、深度、内部パラメーターを読み取ります。
グラフ¶
flowchart LR
tick([On Playback Tick]) --> rp[Isaac Create Render Product<br/>d435_color · 640 × 480]
rp -- renderProductPath --> rgb[ROS2 Camera Helper<br/>type rgb]
rp -- renderProductPath --> dep[ROS2 Camera Helper<br/>type depth]
rp -- renderProductPath --> info[ROS2 Camera Info Helper]
rgb --> t1["/camera/camera/color/image_raw"]
dep --> t2["/camera/camera/aligned_depth_to_color/image_raw"]
info --> t3["/camera/camera/color/camera_info"]
3 つとも frameId = camera_color_optical_frame を使うので、RViz やほかの ROS ツールは画像を正しい位置に配置できます。
作ってみる¶
- 部屋を開き、ロボットを追加します。File ▸ Open で
assets/scenes/lime_room.usdaを開き(最初に一度、python isaac/common/scene.pyで作成してください)、File ▸ Add Reference でassets/usd/turtlebot3_lime_tuned.usdaを/World/turtlebot3_limeに追加します。 …/camera_color_frame/camera_color_optical_frameを選び、右クリックして Create ▸ Camera を選びます。名前はd435_colorにします。Property で次のように設定します:Transform ▸ Rotate = (180, 0, 0)、Focal Length = 15.1、Horizontal Aperture = 20.955、Vertical Aperture = 15.716、Clipping Range = (0.05, 20)。-
このカメラから見てみます。ビューポートのカメラメニュー (Perspective ▾) ▸
d435_colorを選びます。
-
Tools ▸ Robotics ▸ ROS 2 OmniGraphs ▸ Camera を使うと、フォームに入力して上のグラフを作れます。そのデフォルト値(Camera Prim
/OmniverseKit_Persp、Frame IDsim_camera、トピック/rgbと/depth)は仮の値です。カメラのプリムをd435_color、フレーム ID をcamera_color_optical_frameにし、RGB と深度のトピックを図のとおりに設定してから、OK を押します。このフォームには camera_info のトピックを入力する欄がありません(camera_infoが使われます)。作成されたグラフを開き、ROS2 Camera Info Helperノードの topicName を/camera/camera/color/camera_infoに設定します。
-
Play を押します。終わったら Stop ■ を押し、File ▸ Save As で
my_stages/08_camera.usdとして保存します(lime_room.usdaに上書きしないでください)。チュートリアル 09 はこのステージから続けます。
camera_path = sensors.add_d435_camera(robot_path) # USD camera at camera_color_optical_frame
graphs.create_camera_graph(camera_path, 640, 480) # RGB + depth + camera_info
isaac/common/sensors.py の add_d435_camera()
def add_d435_camera(robot_path: str) -> str:
"""Create a USD camera at camera_color_optical_frame. Returns its prim path."""
from pxr import Gf, UsdGeom
import isaacsim.core.experimental.utils.stage as stage_utils
stage = stage_utils.get_current_stage()
path = f"{robot_path}/{lime.CAMERA_COLOR_OPTICAL_FRAME}/d435_color"
camera = UsdGeom.Camera.Define(stage, path)
# A USD camera looks along its -Z axis with +Y up. A ROS *optical* frame looks along +Z with +Y down.
# Rotating 180 deg about X turns one into the other.
UsdGeom.Xformable(camera.GetPrim()).AddRotateXOp().Set(180.0)
# Pinhole model: focal length / aperture (in mm) give the field of view.
h_aperture = 20.955 # mm (default USD camera aperture)
camera.CreateHorizontalApertureAttr(h_aperture)
camera.CreateVerticalApertureAttr(h_aperture * CAMERA_HEIGHT / CAMERA_WIDTH)
camera.CreateFocalLengthAttr(h_aperture / (2.0 * math.tan(CAMERA_HFOV / 2.0))) # = 15.1 mm
camera.CreateClippingRangeAttr(Gf.Vec2f(0.05, 20.0))
return path
isaac/common/graphs.py の create_camera_graph()
def create_camera_graph(
camera_path: str,
width: int = 640,
height: int = 480,
graph_path: str = "/World/ROS2_Camera",
namespace: str = "/camera/camera", # the topic names realsense2_camera uses on the real robot
frame_id: str = "camera_color_optical_frame",
):
"""Tutorial 08: RGB image, depth image (aligned to RGB) and camera_info of one camera."""
import usdrt.Sdf
og = _og()
keys = og.Controller.Keys
og.Controller.edit(
{"graph_path": graph_path, "evaluator_name": "execution"},
{
keys.CREATE_NODES: [
("OnPlaybackTick", "omni.graph.action.OnPlaybackTick"),
("RenderProduct", "isaacsim.core.nodes.IsaacCreateRenderProduct"),
("PublishRGB", "isaacsim.ros2.bridge.ROS2CameraHelper"),
("PublishDepth", "isaacsim.ros2.bridge.ROS2CameraHelper"),
("PublishInfo", "isaacsim.ros2.bridge.ROS2CameraInfoHelper"),
],
keys.SET_VALUES: [
("RenderProduct.inputs:cameraPrim", [usdrt.Sdf.Path(camera_path)]),
("RenderProduct.inputs:width", width),
("RenderProduct.inputs:height", height),
("PublishRGB.inputs:type", "rgb"),
("PublishRGB.inputs:topicName", f"{namespace}/color/image_raw"),
("PublishRGB.inputs:frameId", frame_id),
("PublishDepth.inputs:type", "depth"), # float32 metres (32FC1)
("PublishDepth.inputs:topicName", f"{namespace}/aligned_depth_to_color/image_raw"),
("PublishDepth.inputs:frameId", frame_id),
("PublishInfo.inputs:topicName", f"{namespace}/color/camera_info"),
("PublishInfo.inputs:frameId", frame_id),
],
keys.CONNECT: [
("OnPlaybackTick.outputs:tick", "RenderProduct.inputs:execIn"),
("RenderProduct.outputs:execOut", "PublishRGB.inputs:execIn"),
("RenderProduct.outputs:execOut", "PublishDepth.inputs:execIn"),
("RenderProduct.outputs:execOut", "PublishInfo.inputs:execIn"),
("RenderProduct.outputs:renderProductPath", "PublishRGB.inputs:renderProductPath"),
("RenderProduct.outputs:renderProductPath", "PublishDepth.inputs:renderProductPath"),
("RenderProduct.outputs:renderProductPath", "PublishInfo.inputs:renderProductPath"),
],
},
)
スクリプト全体:isaac/08_camera.py
# SPDX-FileCopyrightText: 2026 An (an-robotics)
# SPDX-License-Identifier: Apache-2.0
"""Tutorial 08 - RealSense D435 camera: RGB, depth and camera_info on ROS 2.
source scripts/isaac_env.sh
python isaac/08_camera.py
# ROS 2 container: look at the images
./docker/run_ros.sh ros2 run rqt_image_view rqt_image_view /camera/camera/color/image_raw
The robot stands in the "lime_room" (isaac/common/scene.py) in front of a cup, a banana, a bowl and a
bottle - the objects tutorial 10 will detect with YOLO.
New in this tutorial:
* a USD camera at the URDF frame camera_color_optical_frame (640 x 480, 69.4 deg FOV, like the D435)
* graph "ROS2_Camera": On Playback Tick -> Isaac Create Render Product -> ROS2 Camera Helper (rgb)
-> ROS2 Camera Helper (depth)
-> ROS2 Camera Info Helper
topics (same names as realsense2_camera on the real robot):
/camera/camera/color/image_raw sensor_msgs/Image (rgb8)
/camera/camera/aligned_depth_to_color/image_raw sensor_msgs/Image (32FC1, metres)
/camera/camera/color/camera_info sensor_msgs/CameraInfo
"""
import math
import sys
from common.cli import parse_args
args = parse_args(__doc__.splitlines()[0])
from isaacsim import SimulationApp
simulation_app = SimulationApp({"headless": args.headless, "width": 1280, "height": 720})
import isaacsim.core.experimental.utils.app as app_utils
import isaacsim.core.experimental.utils.stage as stage_utils
import numpy as np
from common import graphs, lime, sensors
from common.scene import build_lime_room
from isaacsim.core.simulation_manager import SimulationManager
graphs.enable_ros2_realtime(simulation_app)
stage = stage_utils.create_new_stage(template="empty")
build_lime_room(stage)
while stage_utils.is_stage_loading(): # the objects are downloaded from NVIDIA's asset server
simulation_app.update()
robot_path = "/World/turtlebot3_lime"
articulation_root = lime.add_lime(robot_path)
graphs.create_clock_graph()
graphs.create_drive_graph(articulation_root)
graphs.create_odom_tf_joint_states_graph(articulation_root)
# --- NEW: camera + its ROS 2 graph ---------------------------------------------------------------------
camera_path = sensors.add_d435_camera(robot_path)
graphs.create_camera_graph(camera_path, sensors.CAMERA_WIDTH, sensors.CAMERA_HEIGHT)
recorder = None
if args.record:
from common.recorder import Recorder
recorder = Recorder(args.record, eye=(-0.9, -1.0, 0.8), target=(0.7, 0.0, 0.05), every_n=3, fps=20)
SimulationManager.setup_simulation(dt=1.0 / 60.0)
app_utils.play()
simulation_app.update()
print("[08] ready: camera topics on /camera/camera/...", flush=True)
if args.test or args.record:
import rclpy
from sensor_msgs.msg import CameraInfo, Image
rclpy.init()
node = rclpy.create_node("lime_tutorial08_check")
got = {"rgb": [], "depth": None, "info": None}
node.create_subscription(Image, "/camera/camera/color/image_raw", lambda m: got["rgb"].append(m), 10)
node.create_subscription(Image, "/camera/camera/aligned_depth_to_color/image_raw", lambda m: got.__setitem__("depth", m), 10)
node.create_subscription(CameraInfo, "/camera/camera/color/camera_info", lambda m: got.__setitem__("info", m), 10)
steps = 0
while simulation_app.is_running():
simulation_app.update()
steps += 1
if recorder:
recorder.capture()
if args.test or args.record:
for _ in range(10):
rclpy.spin_once(node, timeout_sec=0.0)
if steps > 5 * 60: # 5 s
break
ok = True
if args.test or args.record:
rgb, depth, info = got["rgb"][-1], got["depth"], got["info"]
stamps = [m.header.stamp.sec + m.header.stamp.nanosec * 1e-9 for m in got["rgb"]]
rate = (len(stamps) - 1) / (stamps[-1] - stamps[0]) if len(stamps) > 2 and stamps[-1] > stamps[0] else 0.0
image = np.frombuffer(rgb.data, dtype=np.uint8).reshape(rgb.height, rgb.width, 3)
d = np.frombuffer(depth.data, dtype=np.float32).reshape(depth.height, depth.width)
center = d[depth.height // 2 - 20 : depth.height // 2 + 20, depth.width // 2 - 20 : depth.width // 2 + 20]
center_m = float(np.nanmedian(center[np.isfinite(center)]))
fx_expected = sensors.CAMERA_WIDTH / (2 * math.tan(sensors.CAMERA_HFOV / 2))
checks = {
f"rgb {rgb.width}x{rgb.height} {rgb.encoding}": (rgb.width, rgb.height, rgb.encoding) == (640, 480, "rgb8"),
f"rgb rate {rate:.1f} Hz (sim time)": rate > 10,
f"depth {depth.encoding}, centre distance {center_m:.2f} m": depth.encoding == "32FC1" and 0.2 < center_m < 6.0,
f"camera_info fx={info.k[0]:.1f} (expected {fx_expected:.1f} from the 69.4 deg FOV)": abs(info.k[0] - fx_expected) < 2.0,
f"frame_id {rgb.header.frame_id}": rgb.header.frame_id == "camera_color_optical_frame",
}
for text, passed in checks.items():
print(f"[08][check] {'ok ' if passed else 'FAIL'} {text}")
ok = all(checks.values())
if args.test:
print(f"[08][test] {'PASS' if ok else 'FAIL'}")
if args.record: # what the robot sees -> docs
import imageio.v2 as imageio
from common.paths import IMG_DIR
imageio.imwrite(IMG_DIR / f"{args.record}_rgb.png", image)
import matplotlib
valid = np.isfinite(d) & (d > 0) # no surface hit (the "sky") -> black
vis = np.clip(np.where(valid, d, 0.0) / 4.0, 0.0, 1.0) # 0 .. 4 m
colored = (matplotlib.colormaps["turbo"](vis)[..., :3] * 255 * valid[..., None]).astype(np.uint8)
imageio.imwrite(IMG_DIR / f"{args.record}_depth.png", colored)
node.destroy_node()
rclpy.shutdown()
if recorder:
recorder.save()
app_utils.stop()
simulation_app.close(exit_code=0 if ok else 1)
sys.exit(0 if ok else 1)
ROS 2 から見る¶
./docker/run_ros.sh ros2 run rqt_image_view rqt_image_view /camera/camera/color/image_raw
./docker/run_ros.sh ros2 topic hz /camera/camera/color/image_raw
./docker/run_ros.sh ros2 topic echo /camera/camera/color/camera_info --once
カメラのパネルがある RViz を使うこともできます:ros2 launch lime_isaac_bringup view_sensors.launch.py(チュートリアル 09 を参照)。
自動チェック¶
python isaac/08_camera.py --headless --test は、自分がパブリッシュしたトピックをサブスクライブして確認します。
[08][check] ok rgb 640x480 rgb8
[08][check] ok rgb rate 60.0 Hz (sim time)
[08][check] ok depth 32FC1, centre distance 3.94 m
[08][check] ok camera_info fx=462.3 (expected 462.3 from the 69.4 deg FOV)
[08][check] ok frame_id camera_color_optical_frame
[08][test] PASS
中心の距離 3.94 m は、奥の壁までの距離です。壁の位置 x = 4.0 m から、カメラ自身の x 位置 0.059 m を引いた値です。
パブリッシュレート
カメラのヘルパーは、レンダリングされたフレームをすべてパブリッシュします(ここでは 60 Hz)。Isaac Sim 6.x では、センサーごとのレートは omni:sensor:tickRate 属性で設定します。ヘルパーノードの frameSkipCount は非推奨です。
次へ: 09 · LiDAR と IMU