Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/source/api/lab_fovi/isaaclab_fovi.assets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ isaaclab_fovi.assets

PAN_TILT_CFG
PAN_TILT_CAMERA_OFFSET
PAN_TILT_STEREO_OFFSETS
PAN_TILT_STEREO_BASELINE
PAN_TILT_USD_PATH

Pan-tilt mount
Expand All @@ -20,5 +22,10 @@ Pan-tilt mount
.. autodata:: PAN_TILT_CAMERA_OFFSET
:no-value:

.. autodata:: PAN_TILT_STEREO_OFFSETS
:no-value:

.. autodata:: PAN_TILT_STEREO_BASELINE

.. autodata:: PAN_TILT_USD_PATH
:no-value:
19 changes: 19 additions & 0 deletions docs/source/api/lab_fovi/isaaclab_fovi.mdp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ isaaclab_fovi.mdp
GazeAction
GazeActionCfg
GazeRigCfg
BinocularGazeAction
BinocularGazeActionCfg
gaze_teacher_labels
binocular_gaze_teacher_labels

.. rubric:: Functions

.. autosummary::

gaze_state
binocular_gaze_state

Actions
-------
Expand All @@ -36,10 +40,25 @@ Actions
:show-inheritance:
:exclude-members: __init__

.. autoclass:: BinocularGazeAction
:members:
:show-inheritance:

.. autoclass:: BinocularGazeActionCfg
:members:
:inherited-members:
:show-inheritance:
:exclude-members: __init__, class_type

Observations
------------

.. autofunction:: gaze_state

.. autoclass:: gaze_teacher_labels
:show-inheritance:

.. autofunction:: binocular_gaze_state

.. autoclass:: binocular_gaze_teacher_labels
:show-inheritance:
41 changes: 41 additions & 0 deletions docs/source/experimental-features/foveated_camera.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,44 @@ With a rig, :func:`~mdp.gaze_state` reports the head's angles plus the software

Each mode on the pan-tilt mount with Newton's MJWarp solver: the policy pans 4.5° left three times. In hybrid gaze
the fixation jumps at once and holds while the head takes over from the retina.

.. _concepts_sensors_foveated_camera_binocular:

Binocular gaze
--------------

:class:`~mdp.BinocularGazeActionCfg` moves two foveated cameras on one body with three actions: the version, their
shared line of sight (tilt, pan), and the vergence, the angle between their lines of sight. Each eye turns from the
version by half the vergence toward the other, in the plane of the version and the baseline, so the lines of sight
always meet. The version moves as a single camera's gaze does in ``"software"``, ``"physical"`` or ``"hybrid"``
mode; the vergence always turns the retinas. The eyes need parallel optical axes, the same retina, and Newton or
OVRTX. :data:`~assets.PAN_TILT_STEREO_OFFSETS` places two eyes 6.5 cm apart on the pan-tilt mount:

.. code-block:: python

from isaaclab_fovi.assets import PAN_TILT_STEREO_OFFSETS
from isaaclab_fovi.mdp import BinocularGazeActionCfg

link = "{ENV_REGEX_NS}/PanTilt/Geometry/world/pan_link/tilt_link"
left_eye = eye.replace(prim_path=f"{link}/LeftEye", offset=PAN_TILT_STEREO_OFFSETS[0])
right_eye = eye.replace(prim_path=f"{link}/RightEye", offset=PAN_TILT_STEREO_OFFSETS[1])
gaze = BinocularGazeActionCfg(
asset_name="left_eye", right_asset_name="right_eye", mode="hybrid", rig=GazeRigCfg(asset_name="rig")
)

:func:`~mdp.binocular_gaze_state` observes the version, the vergence and their velocities, and
:class:`~mdp.binocular_gaze_teacher_labels` labels the actions that fixate a point with both eyes. The
``foveated-stereo`` example steps both eyes with these labels from object to object: the retinas jump to each object
while the head turns after them, and the eyes converge on near objects. The viewer shows the left eye; its camera menu
switches to the right eye or an overview. The bracketed options render with OVRTX:

.. code-block:: bash

uv run --extra fovi [--extra ovrtx] isaaclab example foveated-stereo [renderer=ovrtx]

.. figure:: ../_static/overview/sensors/foveated_camera_binocular.jpg
:alt: Left and right eye images at four fixations, with the version, head pan and vergence over time.

The ``foveated-stereo`` example in hybrid gaze. The fixated object sits in both foveas, the version jumps to each
object while the head turns after it, and the vergence follows the object's distance, from 1° at 3.6 m to 10° at
0.4 m.
193 changes: 193 additions & 0 deletions examples/sensors/foveated_stereo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause

"""Watch two experimental foveated eyes on a pan-tilt head fixate near and far objects together.

A binocular teacher moves the eyes in hybrid gaze: the retinas jump to each object while the head turns after them,
and the vergence turns the eyes toward each other for near objects and back toward parallel for far ones. The viewer
shows the left eye; switch to the right eye or the overview in its camera menu.

.. code-block:: bash

uv run --extra fovi isaaclab example foveated-stereo
uv run --extra fovi --extra ovrtx isaaclab example foveated-stereo renderer=ovrtx
"""

from __future__ import annotations

import argparse

import gymnasium as gym

from isaaclab.app import add_launcher_args, launch_simulation

from isaaclab_tasks.utils import setup_preset_cli

parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(
"--max_steps", type=int, default=-1, help="Number of environment steps; -1 runs until the viewer closes."
)
parser.add_argument("--dwell", type=int, default=45, help="Steps the eyes stay on each object.")
add_launcher_args(parser)
parser.set_defaults(visualizer=["newton"])
args_cli, overrides = setup_preset_cli(parser)
if args_cli.max_steps == 0 or args_cli.max_steps < -1:
parser.error("--max_steps must be positive or -1.")
if args_cli.dwell <= 0:
parser.error("--dwell must be positive.")

import torch
import warp as wp
from isaaclab_fovi.assets import PAN_TILT_CFG, PAN_TILT_STEREO_OFFSETS
from isaaclab_fovi.mdp import BinocularGazeActionCfg, GazeRigCfg, binocular_gaze_state
from isaaclab_fovi.sensors import FoveatedCameraCfg
from isaaclab_newton.physics import MJWarpSolverCfg, NewtonCfg
from isaaclab_newton.renderers import NewtonWarpRendererCfg
from isaaclab_ov.renderers import OVRTXRendererCfg

import isaaclab.sim as sim_utils
from isaaclab.assets import AssetBaseCfg
from isaaclab.envs import ManagerBasedEnv, ManagerBasedEnvCfg
from isaaclab.managers import ObservationGroupCfg, ObservationTermCfg
from isaaclab.scene import InteractiveSceneCfg
from isaaclab.terrains import TerrainImporterCfg
from isaaclab.utils import configclass
from isaaclab.visualizers import PerspectiveCameraCfg, SceneCameraCfg, VisualizerCfg

from isaaclab_tasks.utils import preset
from isaaclab_tasks.utils.hydra import resolve_task_config

EYE_HEIGHT = 0.5
"""Height of the head's base above the ground [m]; the head looks along +Y with +Z up, so +X is to its right."""

OBJECTS = {
"far_cube": ((0.6, 3.5, 0.3), 0.3, (0.15, 0.3, 0.85)),
"close_sphere": ((0.12, 0.35, 0.56), 0.025, (0.15, 0.7, 0.2)),
"near_sphere": ((-0.1, 0.45, 0.47), 0.03, (0.9, 0.8, 0.1)),
"middle_cube": ((-0.8, 1.8, 0.2), 0.2, (0.8, 0.15, 0.1)),
}
"""Each object's centre [m], half size [m] and colour, in the order the eyes visit them; each lies within both eyes'
view from the one before."""


def _object(prim: str, centre, half_size: float, colour) -> AssetBaseCfg:
"""A static, coloured cube or sphere."""
material = sim_utils.PreviewSurfaceCfg(diffuse_color=colour)
if "sphere" in prim:
spawn = sim_utils.SphereCfg(radius=half_size, visual_material=material)
else:
spawn = sim_utils.CuboidCfg(size=(2 * half_size,) * 3, visual_material=material)
return AssetBaseCfg(
prim_path=f"{{ENV_REGEX_NS}}/{prim}", spawn=spawn, init_state=AssetBaseCfg.InitialStateCfg(pos=centre)
)


EYE_PATHS = tuple(
f"{{ENV_REGEX_NS}}/PanTilt/Geometry/world/pan_link/tilt_link/{eye}" for eye in ("LeftEye", "RightEye")
)
"""The eyes' prim paths (left, right), on the head's tilting link."""


def _eye(prim_path: str, offset) -> FoveatedCameraCfg:
"""A foveated eye on the head's tilting link."""
return FoveatedCameraCfg(
prim_path=prim_path,
data_types=["rgb"],
renderer_cfg=preset(
default=NewtonWarpRendererCfg(render_order="pixel_priority"),
newton_warp=NewtonWarpRendererCfg(render_order="pixel_priority"),
ovrtx=OVRTXRendererCfg(),
),
# An ideal pinhole with a 90 degree field of view; the retina spans its short side.
spawn=sim_utils.PinholeCameraCfg(focal_length=12.0, horizontal_aperture=24.0, clipping_range=(0.05, 100.0)),
foveated_res=128,
mask_to_sensor_fov=True,
offset=offset,
)


@configclass
class StereoSceneCfg(InteractiveSceneCfg):
"""Objects near and far in front of a pan-tilt head with two foveated eyes."""

ground = TerrainImporterCfg(prim_path="/World/ground", terrain_type="plane")
light = AssetBaseCfg(prim_path="/World/Light", spawn=sim_utils.DomeLightCfg(intensity=800.0))
far_cube = _object("far_cube", *OBJECTS["far_cube"])
near_sphere = _object("near_sphere", *OBJECTS["near_sphere"])
middle_cube = _object("middle_cube", *OBJECTS["middle_cube"])
close_sphere = _object("close_sphere", *OBJECTS["close_sphere"])
head = PAN_TILT_CFG.replace(init_state=PAN_TILT_CFG.init_state.replace(pos=(0.0, 0.0, EYE_HEIGHT)))
left_eye = _eye(EYE_PATHS[0], PAN_TILT_STEREO_OFFSETS[0])
right_eye = _eye(EYE_PATHS[1], PAN_TILT_STEREO_OFFSETS[1])


@configclass
class ActionsCfg:
gaze = BinocularGazeActionCfg(
asset_name="left_eye", right_asset_name="right_eye", mode="hybrid", rig=GazeRigCfg(asset_name="head")
)


@configclass
class ObservationsCfg:
@configclass
class PolicyCfg(ObservationGroupCfg):
gaze = ObservationTermCfg(func=binocular_gaze_state)

policy = PolicyCfg()


@configclass
class StereoExampleCfg(ManagerBasedEnvCfg):
"""The head turns on Newton's MJWarp solver at Isaac Lab's usual 120 Hz physics and 30 Hz control."""

decimation = 4
actions = ActionsCfg()
observations = ObservationsCfg()
ui_window_class_type = None
scene: StereoSceneCfg = StereoSceneCfg(num_envs=1, env_spacing=0.0)
sim: sim_utils.SimulationCfg = sim_utils.SimulationCfg(
dt=1 / 120,
render_interval=4,
physics=NewtonCfg(solver_cfg=MJWarpSolverCfg()),
visualizer_cfgs=VisualizerCfg(
cameras=[
SceneCameraCfg(prim_path=EYE_PATHS[0]),
SceneCameraCfg(prim_path=EYE_PATHS[1]),
PerspectiveCameraCfg(eye=(1.4, -1.2, 1.4), lookat=(0.0, 1.2, 0.4)),
]
),
)


def main() -> None:
"""Step the eyes toward each object in turn, with the binocular teacher's actions."""
# Config-only registration reuses the standard preset and Hydra override resolver.
gym.register(
"FoveatedStereoExample",
entry_point="isaaclab.envs:ManagerBasedEnv",
kwargs={"env_cfg_entry_point": StereoExampleCfg},
)
cfg, _ = resolve_task_config("FoveatedStereoExample", None, overrides=overrides)
with launch_simulation(cfg, args_cli):
env = ManagerBasedEnv(cfg)
env.reset()
gaze = env.action_manager.get_term("gaze")
centres = torch.tensor([centre for centre, _, _ in OBJECTS.values()], device=env.device)
point = centres[:1].clone()
labels = torch.zeros(1, 4, device=env.device)
point_wp, labels_wp = wp.from_torch(point, dtype=wp.vec3f), wp.from_torch(labels)
step = 0
while env.sim.is_running() and (args_cli.max_steps < 0 or step < args_cli.max_steps):
point.copy_(centres[(step // args_cli.dwell) % len(centres)] + env.scene.env_origins[:1])
# The teacher's labels step both eyes toward the object; an invalid target holds them still.
gaze.teacher_labels(point_wp, labels_wp)
env.step(labels[:, :3])
step += 1
env.close()


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions source/isaaclab/changelog.d/foveated-stereo-example.added.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Added the ``foveated-stereo`` example (``isaaclab example foveated-stereo``, ``fovi`` extra), in which two
experimental foveated eyes on a pan-tilt head fixate near and far objects together.
Empty file.
7 changes: 7 additions & 0 deletions source/isaaclab/isaaclab/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ def _run_script(path: Path) -> None:
extras=("fovi",),
required_modules=("isaaclab_fovi", "fovi"),
),
ProgramSpec(
"foveated-stereo",
"examples/sensors/foveated_stereo.py",
"Watch two experimental foveated eyes on a pan-tilt head fixate near and far objects together.",
extras=("fovi",),
required_modules=("isaaclab_fovi", "fovi"),
),
)


Expand Down
3 changes: 3 additions & 0 deletions source/isaaclab/test/app/standalone_script_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ class SmokeResult:
"examples/sensors/foveated_camera.py": ScriptOverride(
fixed_physics_backend="newton_xpbd", visualizers=(None, "newton")
),
"examples/sensors/foveated_stereo.py": ScriptOverride(
fixed_physics_backend="newton_mjwarp", visualizers=(None, "newton")
),
"examples/demos/pick_and_place.py": ScriptOverride(visualizers=("kit",)),
"examples/sensors/ppisp_camera.py": ScriptOverride(
args=("--max_steps", "3", "--warmup_steps", "1", "--image_width", "64", "--image_height", "64"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* Added binocular gaze for two foveated cameras on one body: :class:`~isaaclab_fovi.mdp.BinocularGazeActionCfg`
moves a shared version and a vergence in software, physical or hybrid gaze, with
:func:`~isaaclab_fovi.mdp.binocular_gaze_state` and :class:`~isaaclab_fovi.mdp.binocular_gaze_teacher_labels`.
* Added :data:`~isaaclab_fovi.assets.PAN_TILT_STEREO_OFFSETS`, two eyes on the pan-tilt mount, and the
``foveated-stereo`` example.
Empty file.
18 changes: 15 additions & 3 deletions source/isaaclab_fovi/isaaclab_fovi/assets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@
#
# SPDX-License-Identifier: BSD-3-Clause

"""Assets for physical gaze: a pan-tilt camera mount."""
"""Assets for physical gaze: a pan-tilt camera mount, with one or two cameras."""

from .pan_tilt import PAN_TILT_CAMERA_OFFSET, PAN_TILT_CFG, PAN_TILT_USD_PATH
from .pan_tilt import (
PAN_TILT_CAMERA_OFFSET,
PAN_TILT_CFG,
PAN_TILT_STEREO_BASELINE,
PAN_TILT_STEREO_OFFSETS,
PAN_TILT_USD_PATH,
)

__all__ = ["PAN_TILT_CAMERA_OFFSET", "PAN_TILT_CFG", "PAN_TILT_USD_PATH"]
__all__ = [
"PAN_TILT_CAMERA_OFFSET",
"PAN_TILT_CFG",
"PAN_TILT_STEREO_BASELINE",
"PAN_TILT_STEREO_OFFSETS",
"PAN_TILT_USD_PATH",
]
9 changes: 9 additions & 0 deletions source/isaaclab_fovi/isaaclab_fovi/assets/pan_tilt.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
)
"""Pose of a camera under ``tilt_link`` that looks along the mount's forward axis (world convention)."""

PAN_TILT_STEREO_BASELINE = 0.065
"""Distance between the stereo eyes [m], about a human's."""

PAN_TILT_STEREO_OFFSETS = tuple(
PAN_TILT_CAMERA_OFFSET.replace(pos=(side * PAN_TILT_STEREO_BASELINE / 2, 0.0, 0.0)) for side in (-1.0, 1.0)
)
"""Poses (left, right) of two cameras under ``tilt_link`` that look along the mount's forward axis, for binocular
gaze."""

PAN_TILT_CFG = ArticulationCfg(
prim_path="{ENV_REGEX_NS}/PanTilt",
# Gravity stays on: Newton reads a body's disable-gravity flag as the whole scene's.
Expand Down
Loading