11 · Nav2 でナビゲーション¶
目標: Isaac Sim で lime_room の地図を作り、ROS 2 のナビゲーションスタックである Nav2 に Lime をゴールまで走らせてもらいます。AMCL で自己位置推定し、障害物を避ける経路を計画し、その経路に沿って進みます。
RViz (navigation.rviz):
- ツールバーの Nav2 Goal:これをクリックしてから地図上で矢印をドラッグすると、ゴールを送れます。
- 地図:壁、仕切り、箱(ここ)、柱です。
- コストマップ:ピンクはインフレーションで膨らませた障害物です。
- カラーコーン:コストマップにだけあります。カラーコーンのことを知っているのは LiDAR だけだからです。地図にはありません。
- AMCL のパーティクル(緑):ロボットがどこにいるかについての AMCL の推測です。
- LiDAR スキャン:壁に沿って並ぶ点です。
- 計画された経路(ピンクの線):カラーコーンと柱を回り込んでいます。
考え方¶
Nav2 はロボットから 5 つのものを必要とします。どれも Isaac Sim が提供しており、チュートリアル 06〜09 で作ったものです。
| Nav2 に必要なもの | トピック | チュートリアル |
|---|---|---|
| クロック | /clock |
06 |
| 走らせる手段 | /cmd_vel(Nav2 がパブリッシュし、Isaac Sim のグラフがサブスクライブします) |
06 |
オドメトリと TF odom → base_footprint |
/odom、/tf |
07 |
| ロボットのフレーム | /joint_states → robot_state_publisher |
07 |
| レーザースキャン | /scan |
09 |
…それに加えて地図が必要です。地図はこのチュートリアルで新しく作ります。
地図に載せるのは動かないもの。新しいものはコストマップが捉えます
地図には、壁、柱、箱、仕切りといった、動かないものが入っています。チュートリアル 08〜10 の物体は片付けてあります。その代わりに 11_nav2.py は、地図を作ったあとで、NVIDIA の倉庫用プロップのカラーコーンを、ロボットの通り道にちょうど重なるように置きます。そのため、地図はカラーコーンのことを知りません。LiDAR がカラーコーンを捉え、コストマップの障害物レイヤーがそれをマークし、プランナーがそれを回り込みます。誰かが床に置きっぱなしにした箱を回り込むのと同じです。
カラーコーンの高さは 46 cm です。LiDAR に見えるのは、床から 16 cm の高さにあるスキャン平面を横切るものだけです。バナナ (4 cm) は LiDAR には見えません(チュートリアル 09)。実際のロボットでは、低い障害物を捉えるために、コストマップに深度カメラを加えます。
isaac/common/scene.py の add_traffic_cone()
def add_traffic_cone(stage, x: float = CONE_XY[0], y: float = CONE_XY[1], root: str = "/World/LimeRoom") -> str:
"""Tutorial 11: put a traffic cone on the floor AFTER the map was made, so it is not in the map.
It is a rigid body (1 kg): if the robot touches it, it moves. The asset already has a mesh collider."""
from isaacsim.core.experimental.prims import XformPrim
from isaacsim.storage.native import get_assets_root_path
from pxr import Usd, UsdGeom, UsdPhysics
import isaacsim.core.experimental.utils.stage as stage_utils
path = f"{root}/Cone"
stage_utils.add_reference_to_stage(get_assets_root_path() + CONE_ASSET, path)
XformPrim(path, reset_xform_op_properties=True).set_world_poses(positions=[[x, y, 0.002]])
prim = stage.GetPrimAtPath(path)
UsdPhysics.RigidBodyAPI.Apply(prim)
UsdPhysics.MassAPI.Apply(prim).CreateMassAttr(1.0) # kg
for p in Usd.PrimRange(prim):
if p.IsA(UsdGeom.Mesh): # a moving body needs a convex collider (a cone is convex anyway)
UsdPhysics.MeshCollisionAPI.Apply(p).CreateApproximationAttr("convexHull")
return path
flowchart LR
map[map_server<br/>lime_room.yaml] --> amcl[AMCL<br/>map → odom]
scan["/scan"] --> amcl
amcl --> planner[planner_server<br/>NavFn]
goal([Nav2 Goal]) --> bt[bt_navigator]
bt --> planner --> ctrl[controller_server<br/>MPPI]
ctrl --> vs[velocity_smoother] --> cm[collision_monitor] -- "/cmd_vel" --> isaac[Isaac Sim]
isaac -- "/odom, /tf, /scan" --> amcl & ctrl
パート 1:地図を作る¶
Nav2 は占有格子地図(occupancy grid)を使って自己位置推定します。占有格子地図は、黒が占有、白が空き、灰色が未知を表す画像と、その解像度と原点を記した YAML ファイルでできています。実機では、SLAM を使いながら走り回って地図を作ります(チュートリアル 14)。シミュレーションではシーンそのものが正解(ground truth)なので、Isaac Sim はコライダーから直接地図を計算できます。
ジェネレーターは、シーンのある高さの帯を調べ、それを 1 枚の 2D 地図に押しつぶします。このチュートリアルでは、床から 1〜50 cm の帯を使います。床そのものを含まない程度に高く、上はどの障害物の上端よりも高い範囲です。先に床を片付けておきます。地図は動かないもののためのものだからです。
assets/scenes/lime_room.usdaを開きます(ロボットなし)。- 床を片付けます。Stage パネルで
/World/LimeRoom/Objectsを選び、Delete を押します。そのあとでシーンを保存しないでください。チュートリアル 08〜10 と 13 では、これらの物体が必要です。 - Tools ▸ Robotics ▸ Occupancy Map を選びます。
- Origin には空いている点 (0.5, 0, 0.16) を設定します。Lower Bound (−2.7, −2.7, −0.15) と Upper Bound (3.7, 2.7, 0.34) は原点からの相対値で、床から 1 cm〜50 cm の帯になります。Cell Size は 0.05 にします。
- CALCULATE、VISUALIZE IMAGE の順にクリックし、Save Image と Save YAML で
ros2_ws/src/lime_isaac_bringup/maps/に保存します。

これらの値なら、GUI はスクリプトと同じ地図を計算します。Rotate Image = 180(デフォルト)のままにしてください。これで北が上になります。保存する前に Map Name を lime_room にします。GUI の地図の YAML の原点 [-2.175, -2.675] は、スクリプトの [-2.2, -2.7] とセル半分 (2.5 cm) ずれていますが、どちらでも動きます。
generator = _omap.Generator(omni.physx.get_physx_interface(), omni.usd.get_context().get_stage_id())
generator.update_settings(0.05, 4.0, 5.0, 6.0) # cell size, occupied / free / unknown values
generator.set_transform((0.5, 0.0, 0.16), lo, hi) # origin (a free point); bounds: x, y and the 1-50 cm band
generator.generate2d() # needs the simulation playing (PhysX queries)
occupied = generator.get_occupied_positions() # world coordinates
スクリプトは、占有セルと空きセルを lime_room.pgm と lime_room.yaml に変換します。原点は origin: [-2.2, -2.7, 0.0] で、これは左下のピクセルのワールド座標です。スクリプトは既知のセルをチェックします。壁と柱は占有、スタート地点、部屋の中央、カラーコーンを置く場所は空きでなければなりません。
[11] generator: 1863 occupied, 11961 free cells
[11] map 128 x 108 cells (6.40 x 5.40 m) -> ros2_ws/src/lime_isaac_bringup/maps
[11][check] ok north wall (1.0, 2.55) occupied
[11][check] ok pillar (2.0, -1.2) occupied
[11][check] ok robot start (0, 0) free
[11][check] ok room centre (1.0, -0.5) free
[11][check] ok where the cone will stand (1.2, -0.3) free (not in the map)
[11][test] map PASS
スクリプト全体:isaac/11_make_map.py
# SPDX-FileCopyrightText: 2026 An (an-robotics)
# SPDX-License-Identifier: Apache-2.0
"""Tutorial 11 (part 1) - Make a Nav2 map of the lime_room with Isaac Sim's occupancy map generator.
source scripts/isaac_env.sh
python isaac/11_make_map.py --headless
Writes ros2_ws/src/lime_isaac_bringup/maps/lime_room.pgm + lime_room.yaml (the ROS map_server format).
The generator (extension isaacsim.asset.gen.omap) checks, cell by cell, whether a physics collider occupies a
height band of the scene, and flattens the band into one 2D map. We map everything from 1 cm to 50 cm above the
floor. A map is for what stays put: the walls, the pillar, the crate and the divider. The floor is cleared first
(no objects); things that come and go, like the traffic cone of 11_nav2.py, are the costmaps' job.
"""
import sys
from common.cli import parse_args
args = parse_args(
__doc__.splitlines()[0],
extra=lambda p: p.add_argument("--out", default=None, help="write the map to this folder instead"),
)
from isaacsim import SimulationApp
simulation_app = SimulationApp({"headless": args.headless})
import isaacsim.core.experimental.utils.app as app_utils
import isaacsim.core.experimental.utils.stage as stage_utils
import numpy as np
from common.paths import IMG_DIR, REPO_ROOT
from common.scene import CONE_XY, ROOM_X, ROOM_Y, WALL_THICKNESS, build_lime_room
from isaacsim.core.simulation_manager import SimulationManager
RESOLUTION = 0.05 # m per cell (the usual value for small indoor robots)
BAND = (0.01, 0.50) # m above the floor: from just above the floor (not the floor itself) to above the obstacles
MAP_DIR = REPO_ROOT / "ros2_ws" / "src" / "lime_isaac_bringup" / "maps"
if args.out:
MAP_DIR = REPO_ROOT / args.out
app_utils.enable_extension("isaacsim.asset.gen.omap")
simulation_app.update()
import omni.physx
import omni.usd
from isaacsim.asset.gen.omap.bindings import _omap
stage = stage_utils.create_new_stage(template="empty")
build_lime_room(stage, with_objects=False) # only what stays put - no objects, no robot (not in its own map)
while stage_utils.is_stage_loading():
simulation_app.update()
# The generator uses PhysX queries: the simulation must be playing.
SimulationManager.setup_simulation(dt=1.0 / 60.0)
app_utils.play()
for _ in range(10):
simulation_app.update()
# Map the inside of the room plus the walls (bounds are offsets from the origin).
pad = WALL_THICKNESS + 0.1
origin = (0.5, 0.0, 0.16) # any FREE point inside the room
lo = (ROOM_X[0] - pad - origin[0], ROOM_Y[0] - pad - origin[1], BAND[0] - origin[2])
hi = (ROOM_X[1] + pad - origin[0], ROOM_Y[1] + pad - origin[1], BAND[1] - origin[2])
generator = _omap.Generator(omni.physx.get_physx_interface(), omni.usd.get_context().get_stage_id())
generator.update_settings(RESOLUTION, 4.0, 5.0, 6.0) # cell size, occupied / free / unknown marker values
generator.set_transform(origin, lo, hi)
generator.generate2d()
occupied = np.array([(p.x, p.y) for p in generator.get_occupied_positions()])
free = np.array([(p.x, p.y) for p in generator.get_free_positions()])
app_utils.stop()
print(f"[11] generator: {len(occupied)} occupied, {len(free)} free cells", flush=True)
# --- Rasterise into a ROS map image: row 0 = largest y (north), column 0 = smallest x (west) ----------------
x_min, y_min = origin[0] + lo[0], origin[1] + lo[1]
width = int(round((hi[0] - lo[0]) / RESOLUTION))
height = int(round((hi[1] - lo[1]) / RESOLUTION))
grid = np.full((height, width), 205, dtype=np.uint8) # 205 = unknown (grey)
def paint(points, value):
cols = np.floor((points[:, 0] - x_min) / RESOLUTION).astype(int)
rows = height - 1 - np.floor((points[:, 1] - y_min) / RESOLUTION).astype(int)
keep = (cols >= 0) & (cols < width) & (rows >= 0) & (rows < height)
grid[rows[keep], cols[keep]] = value
paint(free, 254) # free (white)
paint(occupied, 0) # occupied (black)
MAP_DIR.mkdir(parents=True, exist_ok=True)
from PIL import Image
Image.fromarray(grid, mode="L").save(MAP_DIR / "lime_room.pgm")
(MAP_DIR / "lime_room.yaml").write_text(
"image: lime_room.pgm\n"
"mode: trinary\n"
f"resolution: {RESOLUTION}\n"
f"origin: [{x_min:.3f}, {y_min:.3f}, 0.0] # world position of the bottom-left pixel\n"
"negate: 0\n"
"occupied_thresh: 0.65\n"
"free_thresh: 0.25\n"
)
print(f"[11] map {width} x {height} cells ({width * RESOLUTION:.2f} x {height * RESOLUTION:.2f} m) -> {MAP_DIR}", flush=True)
ok = True
if args.test or args.record:
# Spot checks against the known room: a wall cell must be occupied, the robot's start must be free.
def cell(x, y):
return grid[height - 1 - int((y - y_min) / RESOLUTION), int((x - x_min) / RESOLUTION)]
checks = {
"north wall (1.0, 2.55) occupied": cell(1.0, ROOM_Y[1] + 0.05) == 0,
"pillar (2.0, -1.2) occupied": cell(2.0, -1.2) == 0,
"robot start (0, 0) free": cell(0.0, 0.0) == 254,
"room centre (1.0, -0.5) free": cell(1.0, -0.5) == 254,
f"where the cone will stand {CONE_XY} free (not in the map)": cell(*CONE_XY) == 254,
}
for text, passed in checks.items():
print(f"[11][check] {'ok ' if passed else 'FAIL'} {text}")
ok = all(checks.values())
if args.test:
print(f"[11][test] map {'PASS' if ok else 'FAIL'}")
if args.record:
Image.fromarray(grid, mode="L").resize((width * 4, height * 4), Image.NEAREST).save(IMG_DIR / f"{args.record}.png")
simulation_app.close(exit_code=0 if ok else 1)
sys.exit(0 if ok else 1)

地図:壁、仕切り、箱、柱だけで、ほかには何もありません。カラーコーンはあとで登場します(パート 2)。
地図はシミュレーションと同じ座標から作られているので、map フレーム = ワールドフレームです。ロボットは (0, 0) で +x 方向を向いてスタートし、AMCL にもまさにそのとおりに伝えます (set_initial_pose: true)。
パート 2:ナビゲーションする¶
ターミナル 1 では Isaac Sim を起動します。
source scripts/isaac_env.sh
python isaac/11_nav2.py # the lime_room with a traffic cone on the floor
ターミナル 2 では Nav2 + RViz を起動します。
./scripts/build_ws.sh lime_isaac_bringup # once
./docker/run_ros.sh ros2 launch lime_isaac_bringup navigation.launch.py
Managed nodes are active と表示されるまで待ってから、RViz で Nav2 Goal をクリックし、地図上で矢印をドラッグします。または、コマンドラインからゴールを送ります。
./docker/run_ros.sh ros2 action send_goal /navigate_to_pose nav2_msgs/action/NavigateToPose \
"{pose: {header: {frame_id: map}, pose: {position: {x: 3.2, y: -1.8}, orientation: {w: 1.0}}}}"
カラーコーンで何が変わるか: python isaac/11_nav2.py --no-cone で Isaac Sim を再起動し(Nav2 も再起動します)、同じゴールを送ります。カラーコーンがなければ、Nav2 はほぼまっすぐ進み、柱の北側を通ります。カラーコーンがその線上にあると、カラーコーンの南側を通り、続いて柱の南側を通ります。地図はどちらの場合も同じです。違うのは、LiDAR から情報を受け取るコストマップだけです。
Lime の Nav2 パラメーター¶
lime_isaac_bringup/config/nav2_params.yaml は、Jazzy 自身の nav2_bringup/params/nav2_params.yaml から生成しており、変更したのは次の点だけです。
| パラメーター | 値 | 理由 |
|---|---|---|
robot_base_frame(bt_navigator、コストマップ、ビヘイビア) |
base_footprint |
Isaac Sim が odom → base_footprint をパブリッシュするため |
コストマップの footprint |
[[0.075, 0.165], [0.075, -0.165], [-0.205, -0.165], [-0.205, 0.165]] |
台車の箱と車輪。台車の中心は車輪軸の上にはありません |
inflation_radius |
0.30 m | 狭い部屋、小さなロボット |
AMCL の laser_min_range / laser_max_range、コストマップの距離範囲 |
0.12 / 3.5 m | LDS-01 |
AMCL の set_initial_pose、initial_pose |
true, (0, 0, 0) | 地図上でのロボットのスタート位置 |
vx_max、wz_max、velocity smoother の制限値 |
0.3 m/s、1.2 rad/s | 屋内向けの穏やかな速度(Lime は約 0.48 m/s まで出せます) |
Humble 用の Nav2 パラメーターファイルを Jazzy で使い回さないでください
Jazzy ではプラグイン名が変わり(/ ではなく ::)、デフォルトの BT プラグインを自分で読み込み、パラメーターが必要な追加のサーバー(collision monitor、docking、route server)を起動します。ディストリビューション自身のファイルから始めれば、こうした問題はすべて避けられます。
Isaac Sim 側:isaac/11_nav2.py
# SPDX-FileCopyrightText: 2026 An (an-robotics)
# SPDX-License-Identifier: Apache-2.0
"""Tutorial 11 (part 2) - Navigate the lime_room with Nav2.
source scripts/isaac_env.sh
python isaac/11_make_map.py --headless # once: the map (part 1)
python isaac/11_nav2.py # with a traffic cone on the way - it is not in the map
python isaac/11_nav2.py --no-cone # the same room without the cone: compare the paths
# ROS 2 container: Nav2 + RViz. Click "Nav2 Goal" in RViz, or:
./docker/run_ros.sh ros2 launch lime_isaac_bringup navigation.launch.py
./docker/run_ros.sh ros2 action send_goal /navigate_to_pose nav2_msgs/action/NavigateToPose \\
"{pose: {header: {frame_id: map}, pose: {position: {x: 3.2, y: -1.8}, orientation: {w: 1.0}}}}"
Isaac Sim provides everything Nav2 needs - nothing new to build, only the pieces of tutorials 06-09:
/clock, /cmd_vel (subscribed), /odom, /tf (odom -> base_footprint), /joint_states, /scan
The robot starts at (0, 0) facing +x, the pose AMCL is told to start from (config/nav2_params.yaml).
The traffic cone is not in the map: the LiDAR sees it, the costmaps mark it, and the planner goes round it.
"""
import math
import sys
from common.cli import parse_args
args = parse_args(
__doc__.splitlines()[0],
extra=lambda p: (
p.add_argument("--goal", type=float, nargs=2, default=[3.2, -1.8], help="goal x y checked by --test"),
p.add_argument("--no-cone", action="store_true", help="leave the traffic cone out"),
),
)
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 add_traffic_cone, build_lime_room
from isaacsim.core.experimental.prims import Articulation, XformPrim
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, with_objects=False) # the room as it was mapped (part 1)
cone = None if args.no_cone else add_traffic_cone(stage) # something new on the floor: not in the map
while stage_utils.is_stage_loading():
simulation_app.update()
robot_path = "/World/turtlebot3_lime"
articulation_root = lime.add_lime(robot_path)
graphs.create_clock_graph() # 06
graphs.create_drive_graph(articulation_root) # 06 /cmd_vel
graphs.create_odom_tf_joint_states_graph(articulation_root) # 07 /odom /tf /joint_states
graphs.create_lidar_graph(sensors.add_lds_lidar(robot_path)) # 09 /scan
recorder = None
if args.record:
from common.recorder import Recorder
recorder = Recorder(args.record, eye=(1.0, -4.6, 4.2), target=(1.0, -0.2, 0.0), every_n=6, fps=20)
SimulationManager.setup_simulation(dt=1.0 / 60.0)
app_utils.play()
simulation_app.update()
robot = Articulation(articulation_root)
print("[11] ready: start Nav2 (ros2 launch lime_isaac_bringup navigation.launch.py) and send a goal", flush=True)
goal = np.array(args.goal)
steps, reached_at, path = 0, None, []
cone_prim = XformPrim(cone) if cone else None
rest, closest = None, 9.9 # where the cone stands once it has settled; closest approach of the robot
def footprint_distance(robot_pose, point):
"""Distance from a point to the robot's footprint (the Nav2 rectangle), 0 = inside."""
(x, y, _), (w, qx, qy, qz) = robot_pose
yaw = math.atan2(2 * (w * qz + qx * qy), 1 - 2 * (qy * qy + qz * qz))
dx, dy = point[0] - x, point[1] - y
fx, fy = dx * math.cos(yaw) + dy * math.sin(yaw), -dx * math.sin(yaw) + dy * math.cos(yaw)
return math.hypot(max(-0.205 - fx, 0.0, fx - 0.075), max(-0.165 - fy, 0.0, fy - 0.165))
while simulation_app.is_running():
simulation_app.update()
steps += 1
if recorder:
recorder.capture()
if args.test or args.record:
pos, quat = robot.get_world_poses()
xy = pos.numpy()[0, :2]
if cone_prim and steps == 60: # the cone has settled
rest = cone_prim.get_world_poses()[0].numpy()[0].copy()
if rest is not None and steps % 6 == 0:
d = footprint_distance((pos.numpy()[0], quat.numpy()[0]), cone_prim.get_world_poses()[0].numpy()[0])
closest = min(closest, d)
if steps % 30 == 0:
path.append(xy.copy())
if reached_at is None and np.linalg.norm(xy - goal) < 0.25:
reached_at = steps
print(f"[11] goal reached after {steps / 60:.1f} s (sim time), {np.linalg.norm(xy - goal):.2f} m from the goal", flush=True)
if (reached_at is not None and steps - reached_at > 3 * 60) or steps > 240 * 60:
break
ok = True
if args.test:
ok = reached_at is not None
length = sum(np.linalg.norm(b - a) for a, b in zip(path, path[1:]))
print(f"[11][check] {'ok ' if ok else 'FAIL'} robot reached ({goal[0]}, {goal[1]}) within 0.25 m (ground truth); driven {length:.2f} m")
if cone_prim: # the cone is a rigid body: if the robot touched it, it moved
moved = np.linalg.norm(cone_prim.get_world_poses()[0].numpy()[0] - rest)
untouched = moved < 0.01
ok = ok and untouched
print(f"[11][check] {'ok ' if untouched else 'FAIL'} cone not touched (moved {moved * 100:.1f} cm); "
f"closest approach of the robot's footprint to its centre: {closest * 100:.0f} cm")
print(f"[11][test] {'PASS' if ok else 'FAIL'}")
if recorder:
recorder.save()
app_utils.stop()
simulation_app.close(exit_code=0 if ok else 1)
sys.exit(0 if ok else 1)
自動チェック¶
python isaac/11_nav2.py --headless --test は、Isaac Sim でのロボットの正解(ground truth)の位置が、ゴール (3.2, −1.8) から 0.25 m 以内に入るまで待ちます。tools/run_all_checks.sh 11 は Nav2 を起動し、ゴールを送ります。
[11] goal reached after 25.0 s (sim time), 0.25 m from the goal
[11][check] ok robot reached (3.2, -1.8) within 0.25 m (ground truth); driven 3.96 m
[11][check] ok cone not touched (moved 0.0 cm); closest approach of the robot's footprint to its centre: 58 cm
[11][test] PASS
カラーコーンは剛体 (1 kg) なので、ロボットがカラーコーンに触れたかどうかもテストでわかります。触れていれば、カラーコーンが動いているはずです。
トラブルシューティング¶
| 症状 | 対処 |
|---|---|
| RViz:地図が表示されない / "Frame [map] does not exist" | AMCL にまだ初期姿勢がありません。Managed nodes are active と表示されるまで待つか、2D Pose Estimate で初期姿勢を設定してください。 |
| ロボットがその場で回る、または動かない | シミュレーションは再生中で、/clock はパブリッシュされていますか?実行しているシミュレーションは 1 つだけですか? |
| Isaac Sim を再起動したら、ロボットの自己位置推定がずれた | Nav2 も再起動してください。シミュレーション時間が 0 に戻ったためです。 |
| Nav2 がカラーコーンを突っ切る経路を計画する | カラーコーンはコストマップにしかなく、コストマップはそれを /scan から得ています。LiDAR はパブリッシュしていますか?スキャン平面 (16 cm) より低いものは、LiDAR には見えません。 |