Robot Models Visualization

Example script: examples/robot_models.py

This example demonstrates how to load and visualize multiple built-in robot models simultaneously.

What This Example Shows

  • Loading multiple pre-configured robot models

  • Arranging robots in a grid layout

  • Creating ground planes for visual context

  • Setting up camera angles for optimal viewing

Running the Example

Basic usage:

python examples/robot_models.py

With different viewers:

# Use Trimesh viewer (faster, simpler)
python examples/robot_models.py --viewer trimesh

# Use Pyrender viewer (smoother rendering)
python examples/robot_models.py --viewer pyrender

Non-interactive mode (useful for CI/testing):

python examples/robot_models.py --no-interactive

Code Walkthrough

Built-in Robot Models

The example showcases five built-in robot models:

robots = [
    skrobot.models.Kuka(),      # Industrial manipulator
    skrobot.models.Fetch(),     # Mobile manipulation robot
    skrobot.models.Nextage(),   # Humanoid torso robot
    skrobot.models.PR2(),       # Research platform robot
    skrobot.models.Panda(),     # Franka Emika Panda arm
]

Grid Layout Algorithm

The _get_tile_shape function calculates optimal grid dimensions:

def _get_tile_shape(num, hw_ratio=1):
    """Calculate grid layout for given number of items"""
    r_num = int(round(np.sqrt(num / hw_ratio)))
    c_num = 0
    while r_num * c_num < num:
        c_num += 1
    while (r_num - 1) * c_num >= num:
        r_num -= 1
    return r_num, c_num

This ensures robots are arranged efficiently, regardless of how many models you want to display.

Adding Ground Planes

Each robot gets its own ground plane for visual separation:

plane = skrobot.model.Box(extents=(row - 0.01, col - 0.01, 0.01))
plane.translate((row * i, col * j, -0.01))
viewer.add(plane)

The slight gap (0.01) between planes creates visual separation.

Positioning Robots

Robots are positioned based on their grid location:

robot.translate((row * i, col * j, 0))
viewer.add(robot)

Camera Setup

The camera angle is set for optimal viewing:

viewer.set_camera(angles=[np.deg2rad(30), 0, 0])

This provides a 30-degree elevated view of the scene.

Key Concepts

RobotModel Loading

All built-in models are loaded with default configurations:

  • URDF files are automatically downloaded and cached

  • Joint angles start in default pose

  • Visual meshes are loaded for rendering

Viewer Flexibility

Two viewer options are provided:

  • TrimeshSceneViewer: Lightweight, good for development

  • PyrenderViewer: OpenGL-based, smoother rendering

Interactive vs Non-Interactive

In interactive mode, the window stays open:

while viewer.is_active:
    time.sleep(0.1)
    viewer.redraw()

In non-interactive mode (--no-interactive), the script exits immediately after display.

Customization Ideas

Add Your Own Robots

from skrobot.model import RobotModel

robots = [
    skrobot.models.PR2(),
    skrobot.models.Fetch(),
    RobotModel.from_urdf_file('/path/to/custom.urdf'),
]

Change Grid Spacing

row, col = 3, 3  # More space between robots

Animate Robots

import time

for robot in robots:
    for _ in range(100):
        # Random joint motion
        av = robot.angle_vector()
        av += np.random.randn(len(av)) * 0.01
        robot.angle_vector(av)
        viewer.redraw()
        time.sleep(0.05)

Add Coordinate Frames

for robot in robots:
    axis = skrobot.model.Axis(
        axis_radius=0.01,
        axis_length=0.2,
        pos=robot.worldpos(),
        rot=robot.worldrot()
    )
    viewer.add(axis)

Expected Output

You should see a window displaying all five robots arranged in a grid, with each robot standing on its own ground plane with proper spacing.

Troubleshooting

Models Don’t Load

If models fail to load:

  1. Check internet connection (first run downloads models)

  2. Verify cache directory: ~/.skrobot/

  3. Try clearing cache and re-running

Viewer Crashes

If viewer crashes:

  1. Try different viewer: --viewer pyrender or --viewer trimesh

  2. Reduce resolution in code:

viewer = skrobot.viewers.TrimeshSceneViewer(resolution=(320, 240))

Performance Issues

For better performance:

  1. Use TrimeshSceneViewer instead of PyrenderViewer

  2. Reduce number of robots

  3. Disable smooth shading

Source Code

Full source: https://github.com/iory/scikit-robot/blob/main/examples/robot_models.py