# Isaac Sim visualization

> Watch your robot program plan and move in NVIDIA Isaac Sim while it runs on Wandelbots NOVA OS. Learn how to attach the Isaac Sim viewer to a program and what it draws into the stage.

Your program runs on Wandelbots NOVA OS and moves a virtual controller.
With the NOVA Isaac Sim extension, NVIDIA Isaac Sim mirrors that controller in a 3D cell.
Attach the Isaac Sim viewer to the program, and every path the program plans appears in that cell before the robot moves along it.

Video: [/video/programming/isaac-sim-visualization.webm](/video/programming/isaac-sim-visualization.webm)

The stacking demo program on NOVA OS, with every planned path drawn into the Isaac Sim stage.

## How it works

1. Your program plans a motion on the NOVA OS instance, e.g., with `plan_and_execute`.
2. The Isaac Sim viewer receives the planned trajectory and draws it into the stage through the extension API.
3. NOVA OS executes the motion on the virtual controller, and Isaac Sim moves the robot along the drawn path.

The program code stays the same as for any other viewer. Only the `viewer` argument of `@nova.program` changes.

## Before you start

1. Build the stacking demo scene with the [Isaac Sim quickstart](/simulation/quickstart): the robot, the gripper, the three workpieces and the ghost objects the program reads.
2. Ensure your program can reach the extension API, e.g., `http://<isaac_sim_ip>:8011/omniservice/api/v2`.

> **Warning:** Pass the full URL, including `/omniservice/api/v2`.
> With only `http://<isaac_sim_ip>:8011`, the viewer cannot reach the extension and draws nothing.

## Attach the viewer

`TrajectoryViewer` ships with `wandelbots-isaacsim-api`. Pass it as the `viewer` of your program:

```python
import nova
from nova import api
from nova.cell import virtual_controller
from wandelbots_isaacsim_api.trajectory import TrajectoryViewer

omniservice_host = "http://<isaac_sim_ip>:8011/omniservice/api/v2"
robot_prim_path = "/World/cell/workspace_kuka/KUKA_KR10_R900_2"

@nova.program(
    id="stacking_demo",
    name="Stacking Demo",
    viewer=TrajectoryViewer(
        omniverse_host=omniservice_host,
        motion_group_prim_paths={"0@kuka": robot_prim_path},
    ),
    preconditions=nova.ProgramPreconditions(
        controllers=[
            virtual_controller(
                name="kuka",
                manufacturer=api.models.Manufacturer.KUKA,
                type="kuka-kr10_r900_2",
            )
        ],
        cleanup_controllers=False,
    ),
)
async def start(ctx: nova.ProgramContext) -> None:
    ...
```

- `omniverse_host`: the extension API of the Isaac Sim instance that shows the cell.
- `motion_group_prim_paths`: maps each motion group, written as `<motion_group_number>@<controller_name>`, to the prim path of its robot in the stage. Add one entry per robot in a multi-robot cell.

## What you see in Isaac Sim

- **Planned path:** a green line under the robot prim for every successful plan. The next plan replaces it.
- **Failed plan:** when NOVA returns the path up to the point where planning stopped, a red line along it and a semi-transparent ghost of the robot at its last reachable joint configuration. A target outside the workspace returns no such path, so nothing is drawn.
- **One path per robot:** with several motion groups, each robot keeps its own line, named after its controller.

The viewer only draws. Isaac Sim moves the robot because the robot prim is connected to the virtual controller, as set up in the [quickstart](/simulation/quickstart).

## Run the stacking demo

The stacking demo reads its pick and place poses from the ghost objects in Isaac Sim, then plans and executes a pick and place sequence for each workpiece.

### Step 1: Create the virtual controller

Video: [/video/programming/isaac-sim-visualization-step-1-controller.webm](/video/programming/isaac-sim-visualization-step-1-controller.webm)

1. On the NOVA OS home screen, open `Setup`. The robots of your cell open.
2. Click `Add robot`.
3. Select `Virtual` and enter the name `kuka`.
4. Select the manufacturer `KUKA`.
5. Under `Motion groups`, select the model `KUKA_KR10_R900_2`.
6. Click `Add robot`.

→ The robot `kuka` appears in the list as `Virtual` with the motion group `KUKA_KR10_R900_2`.

### Step 2: Connect the robot in Isaac Sim

Video: [/video/programming/isaac-sim-visualization-step-2-connect.webm](/video/programming/isaac-sim-visualization-step-2-connect.webm)

1. Open the stacking demo scene in Isaac Sim.
2. Select `Wandelbots NOVA` → `Connect to NOVA`.
3. Expand your NOVA OS instance.
4. In the row `KUKA_KR10_R900_2 (0@kuka)`, click `Connect`.

The robot in the scene now follows the virtual controller.

### Step 3: Create the TCP in NOVA

Video: [/video/programming/isaac-sim-visualization-step-3-tcp.webm](/video/programming/isaac-sim-visualization-step-3-tcp.webm)

1. In the `Stage` tab, select `tcp_gripper` of the gripper.
2. Right-click it and select `Create` → `Wandelbots NOVA` → `TCP in NOVA`.
3. Enter `schunk_coact_gripper` as the TCP name. The program uses this name.
4. Click `Create`.
5. Adding a TCP restarts the virtual controller. In the `Setup` app, wait until `kuka` shows `Virtual` again instead of `Initialising`.

→ The controller `kuka` is ready and has the TCP `schunk_coact_gripper`.

> **Warning:** A program started while the controller restarts fails with a 400 error.

### Step 4: Set up the Python program

Video: [/video/programming/isaac-sim-visualization-step-4-program.webm](/video/programming/isaac-sim-visualization-step-4-program.webm)

1. Create a project and add the NOVA Python SDK and the Isaac Sim client:

   ```bash
   uv init stacking-demo
   cd stacking-demo
   uv add wandelbots-nova wandelbots-isaacsim-api
   ```

2. Create a file named `.env` with the address and access token of your NOVA OS instance:

   ```bash
   NOVA_API="http://<your_nova_instance>"
   NOVA_ACCESS_TOKEN="<your_access_token>"
   ```

3. Copy `scripts/stacking.py` from the stacking demo package into the project as `main.py`.

4. In `main.py`, set `isaacsim_ip_address` to the address of the machine that runs Isaac Sim.

**Show robot program** ([source](https://github.com/wandelbotsgmbh/wandelbots-isaacsim-extension/blob/main/examples/nova_sdk/quickstart_stacking_demo.py))

```python
# package imports
import nova
import wandelbots_isaacsim_api as isaac_sim_api

import wandelbots_isaacsim_api.trajectory as trajectory_utils
from nova import run_program
from nova import api
from nova.actions import cartesian_ptp, io_write, linear, wait
from nova.actions.io import WriteAction
from nova.actions.mock import WaitAction
from nova.actions.motions import CartesianPTP, Linear
from nova.cell import virtual_controller
from nova.cell.cell import Cell
from nova.cell.controller import Controller
from nova.cell.motion_group import MotionGroup
from nova.types.motion_settings import MotionSettings
from nova.types.pose import Pose
from wandelbots_isaacsim_api.api.teaching_api import TeachingApi
from wandelbots_isaacsim_api.models.ghost_object import GhostObject
import logging

logger = logging.getLogger(__name__)

# parameter definitions
isaacsim_ip_address = "<add your_isaac_sim_ip_address_here>"
omniservice_host = f"http://{isaacsim_ip_address}:8011/omniservice/api/v2"
controller_name = "kuka"
robot_prim_path = "/World/cell/workspace_kuka/KUKA_KR10_R900_2"
manufacturer = api.models.Manufacturer.KUKA
robot_model = "kuka-kr10_r900_2"
gripper_signal = "OUT#1"
motion_group_num = 0

# helper function to get poses from ghost objects in isaac sim
async def get_poses_from_ghost_objects(
    isaac_sim_api_url: str, robot_prim_path: str
) -> dict[str, list[Pose]]:
    """
    Helper function to get pick and place poses from ghost objects in the simulation model.
    Returns a dictionary mapping each unique ghost object name to a list of Pose objects.
    """
    async with isaac_sim_api.ApiClient(
        configuration=isaac_sim_api.Configuration(host=isaac_sim_api_url)
    ) as isaac_sim_api_client:
        teaching_api: TeachingApi = isaac_sim_api.TeachingApi(
            api_client=isaac_sim_api_client
        )
        ghost_objects: list[GhostObject] | None = None
        ghost_objects = await teaching_api.list_ghost_objects(
            relative_to_prim=robot_prim_path
        )

        # Create a dictionary mapping each unique ghost object name to a list of Pose objects
        poses_dict: dict[str, list[Pose]] = {}
        for ghost_obj in ghost_objects:
            name = ghost_obj.name
            pose_obj = Pose(tuple(ghost_obj.pose.pose))
            if name not in poses_dict:
                poses_dict[name] = []
            poses_dict[name].append(pose_obj)
        return poses_dict


# configure the robot program
@nova.program(
    id="stacking_demo",
    name="Stacking Demo",
    viewer=trajectory_utils.TrajectoryViewer(
        omniverse_host=omniservice_host,
        motion_group_prim_paths={
            f"{motion_group_num}@{controller_name}": robot_prim_path,
        },
    ),
    preconditions=nova.ProgramPreconditions(
        controllers=[
            virtual_controller(
                name=controller_name,
                manufacturer=manufacturer,
                type=robot_model,
            )
        ],
        cleanup_controllers=False,
    )
)
async def start(ctx: nova.ProgramContext) -> None:
    """Main robot control function."""

    # get cell, controller, and motion group instances from the Nova instance
    cell: Cell = ctx.cell
    controller: Controller = await cell.controller(controller_name)
    motion_group: MotionGroup = controller[motion_group_num]

    # define motion speed and tcp
    fast: MotionSettings = MotionSettings(tcp_velocity_limit=250)
    tcp = "schunk_coact_gripper"

    # get ghost objects from isaac sim
    robot_poses: dict[str, list[Pose]] = await get_poses_from_ghost_objects(
        isaac_sim_api_url=omniservice_host,
        robot_prim_path=robot_prim_path,
    )

    # iterate over ghost objects and run pick and place motion commands
    pick_poses = [pose for key, poses in robot_poses.items() if "PickPose" in key for pose in poses]
    place_poses = [pose for key, poses in robot_poses.items() if "PlacePose" in key for pose in poses]
    for (pick_pose, place_pose) in zip(pick_poses, place_poses):
        # define robot motion sequence
        actions: list[CartesianPTP | Linear | WriteAction | WaitAction] = [
            cartesian_ptp(
                target=pick_pose @ Pose(0, 0, -200, 0, 0, 0),
                settings=fast,
            ),
            linear(target=pick_pose, settings=fast),
            io_write(key=gripper_signal, value=True),
            wait(wait_for_in_seconds=2),
            linear(
                target=pick_pose @ Pose(0, 0, -200, 0, 0, 0),
                settings=fast,
            ),
            cartesian_ptp(
                target=place_pose @ Pose(0, 0, -200, 0, 0, 0),
                settings=fast,
            ),
            linear(target=place_pose, settings=fast),
            io_write(key=gripper_signal, value=False),
            wait(wait_for_in_seconds=2),
            linear(
                target=place_pose @ Pose(0, 0, -200, 0, 0, 0),
                settings=fast,
            ),

        ]
        await motion_group.plan_and_execute(actions, tcp)

# execute program
if __name__ == "__main__":
    run_program(program=start)
```

### Step 5: Run the program

Video: [/video/programming/isaac-sim-visualization-step-5-run.webm](/video/programming/isaac-sim-visualization-step-5-run.webm)

1. In Isaac Sim, click `Play`.
2. Run the program:

   ```bash
   uv run python main.py
   ```

→ Isaac Sim draws each planned path in green, and the robot stacks the three workpieces along it.

## Run the stacking demo from Visual Studio Code

Video: [/video/programming/isaac-sim-vscode-step-4-run.webm](/video/programming/isaac-sim-vscode-step-4-run.webm)

The Visual Studio Code app runs in the browser on your NOVA OS instance and needs no local Python setup.
Install it from the NOVA OS App Store, add the stacking demo to its project and start the program with `Run` from the Wandelbots NOVA extension, while Isaac Sim draws every planned path.
Follow [Program the stacking demo in Visual Studio Code](/developer/isaac-sim-vscode) for each step.

## Next steps

- Prototype interactively with [Jupyter notebooks](/developer/jupyter).
- Compare with the [Rerun visualization](/developer/visualization), which shows planned paths in a separate viewer.
- Hand the program to operators with the [Program Operator](/developer/run-program).
