diff --git a/docs/source/how-to/conveyors.rst b/docs/source/how-to/conveyors.rst index 11877faa6b5b..30103acea4a0 100644 --- a/docs/source/how-to/conveyors.rst +++ b/docs/source/how-to/conveyors.rst @@ -3,6 +3,40 @@ Controlling conveyors ===================== +.. _tutorial-conveyor-suction: + +Using a conveyor with suction +----------------------------- + +This standalone Newton MJWarp example has one static belt, one parcel, and one kinematic +suction tool. It builds the scene from primitives. The belt moves the parcel, the tool seals +against its top face and lifts it, and opening the gripper releases it onto the belt. + +.. code-block:: bash + + uv run python scripts/tutorials/01_assets/run_conveyor_suction.py --device cuda:0 --viz newton + +Use ``--viz none`` to run the same sequence without a window. + +Create the scene and conveyor before resetting the simulation. Name the belt's collision +surface and the parcel body in the controller configuration. The belt and parcel use low +contact friction because the conveyor controller supplies their tangential traction. +After stopping the belt, command the kinematic tool above the parcel with its pads facing +down. Stage the gripper command, write the scene before stepping, and refresh it afterward. +Close the conveyor and scene before tearing down the simulation. + +.. dropdown:: Code for run_conveyor_suction.py + :icon: code + + .. literalinclude:: ../../../scripts/tutorials/01_assets/run_conveyor_suction.py + :language: python + :linenos: + +See :ref:`tutorial-interact-surface-gripper` for backend-specific gripper configuration. + +Configuring a controller +------------------------ + Create a controller after authoring the collision geometry and before the first simulation reset. This example assumes ``sim`` is a simulation context and each environment already contains a ``Belt`` collision surface and five parcels named ``Parcel0`` through ``Parcel4``: diff --git a/docs/source/how-to/run_surface_gripper.rst b/docs/source/how-to/run_surface_gripper.rst index 195e4a655f91..f9df110d5ce4 100644 --- a/docs/source/how-to/run_surface_gripper.rst +++ b/docs/source/how-to/run_surface_gripper.rst @@ -62,6 +62,8 @@ after stepping. The scene also handles selected-environment resets. Manager-base use :class:`~isaaclab.envs.mdp.actions.SurfaceGripperBinaryActionCfg`, where negative policy actions close the gripper and nonnegative actions open it. +For a runnable Newton MJWarp example, see :ref:`tutorial-conveyor-suction`. + Managed environments close the scene grippers automatically. In a standalone scene, call ``scene.close()`` before destroying the simulation. If the scene is inside an enclosing CUDA graph, discard the graph before closing it. Custom ``SurfaceGripperCfg.class_type`` constructors continue diff --git a/scripts/tutorials/01_assets/run_conveyor_suction.py b/scripts/tutorials/01_assets/run_conveyor_suction.py new file mode 100644 index 000000000000..f12f7d9c1428 --- /dev/null +++ b/scripts/tutorials/01_assets/run_conveyor_suction.py @@ -0,0 +1,155 @@ +# 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 + +"""Move a parcel along a belt, lift it with suction, and release it in Newton.""" + +import argparse +from contextlib import closing + +import torch +from isaaclab_newton.physics import MJWarpSolverCfg, NewtonCfg + +import isaaclab.sim as sim_utils +from isaaclab.app import add_launcher_args, launch_simulation +from isaaclab.assets import AssetBaseCfg, RigidObjectCfg, SurfaceGripperCfg +from isaaclab.controllers import Conveyor, ConveyorCfg, ConveyorSurfaceCfg +from isaaclab.scene import InteractiveScene, InteractiveSceneCfg +from isaaclab.utils import configclass + +PARCEL_SIZE = 0.05 +TOOL_OFFSET = 0.10 +# The controller supplies belt traction independently of the contact material. +BELT_CONTACT = sim_utils.RigidBodyMaterialBaseCfg(static_friction=1.1e-5, dynamic_friction=1.1e-5) + + +@configclass +class ConveyorSceneCfg(InteractiveSceneCfg): + """A static belt, one parcel, and a kinematic suction tool.""" + + ground = AssetBaseCfg( + prim_path="/World/Ground", + spawn=sim_utils.CuboidCfg(size=(2.0, 1.5, 0.04), collision_props=sim_utils.UsdPhysicsCollisionCfg()), + init_state=AssetBaseCfg.InitialStateCfg(pos=(0.0, 0.0, -0.12)), + ) + light = AssetBaseCfg(prim_path="/World/Light", spawn=sim_utils.DomeLightCfg(intensity=2000.0)) + belt = AssetBaseCfg( + prim_path="{ENV_REGEX_NS}/Belt", + spawn=sim_utils.CuboidCfg( + size=(1.0, 0.28, 0.10), + collision_props=sim_utils.UsdPhysicsCollisionCfg(), + physics_material=BELT_CONTACT, + visual_material=sim_utils.PreviewSurfaceCfg(diffuse_color=(0.25, 0.28, 0.30)), + ), + init_state=AssetBaseCfg.InitialStateCfg(pos=(0.0, 0.0, -0.05)), + ) + parcel = RigidObjectCfg( + prim_path="{ENV_REGEX_NS}/Parcel", + spawn=sim_utils.CuboidCfg( + size=(PARCEL_SIZE, PARCEL_SIZE, PARCEL_SIZE), + rigid_props=sim_utils.UsdPhysicsRigidBodyCfg(), + mass_props=sim_utils.MassCfg(mass=0.05), + physics_material=BELT_CONTACT, + collision_props=sim_utils.UsdPhysicsCollisionCfg(), + visual_material=sim_utils.PreviewSurfaceCfg(diffuse_color=(0.66, 0.33, 0.12)), + ), + init_state=RigidObjectCfg.InitialStateCfg(pos=(-0.25, 0.0, PARCEL_SIZE / 2)), + ) + tool = RigidObjectCfg( + prim_path="{ENV_REGEX_NS}/Tool", + spawn=sim_utils.CuboidCfg( + size=(0.035, 0.035, 0.16), + rigid_props=sim_utils.UsdPhysicsRigidBodyCfg(kinematic_enabled=True), + collision_props=sim_utils.UsdPhysicsCollisionCfg(), + visual_material=sim_utils.PreviewSurfaceCfg(diffuse_color=(0.05, 0.54, 0.82)), + ), + init_state=RigidObjectCfg.InitialStateCfg(pos=(0.20, 0.0, 0.23), rot=(0.0, 1.0, 0.0, 0.0)), + ) + suction = SurfaceGripperCfg( + prim_path="{ENV_REGEX_NS}/Tool", + target_prim_path="{ENV_REGEX_NS}/Parcel", + tool_offset=(0.0, 0.0, TOOL_OFFSET), + ) + + +def step_scene(sim: sim_utils.SimulationContext, scene: InteractiveScene, steps: int) -> None: + """Apply staged commands and refresh the scene after each physics step.""" + dt = sim.get_physics_dt() + for _ in range(steps): + scene.write_data_to_sim() + sim.step() + scene.update(dt) + + +def run_example(sim: sim_utils.SimulationContext) -> None: + """Convey, pick up, and release the parcel.""" + cfg = ConveyorCfg( + surface_specs=(ConveyorSurfaceCfg("{ENV_REGEX_NS}/Belt", velocity=0.20),), + body_pattern=r"/Parcel$", + body_count_per_env=1, + startup_duration_s=0.25, + ) + with closing(InteractiveScene(ConveyorSceneCfg(num_envs=1, env_spacing=1.0))) as scene: + with closing(Conveyor(cfg, num_envs=scene.num_envs, sim=sim)) as conveyor: + sim.reset() + parcel, tool, suction = scene["parcel"], scene["tool"], scene["suction"] + + start_x = parcel.data.root_pos_w.torch[0, 0].item() + conveyor.start() + step_scene(sim, scene, 120) + conveyor.stop() + step_scene(sim, scene, 12) + distance = parcel.data.root_pos_w.torch[0, 0].item() - start_x + if distance <= 0.03: + raise RuntimeError("The belt did not move the parcel.") + print(f"Conveyor moved the parcel {distance:.2f} m.") + + # Keep the tool pointing down and place the pads just above the box. + pose = tool.data.default_root_pose.torch.clone() + pose[:, :3] = parcel.data.root_pos_w.torch + pose[:, 2] += PARCEL_SIZE / 2 + TOOL_OFFSET + 0.002 + tool.write_root_pose_to_sim_index(root_pose=pose) + close = torch.ones(scene.num_envs, device=sim.device) + suction.set_grippers_command_index(close) + step_scene(sim, scene, 60) + if suction.state.numpy()[0] != 1: + raise RuntimeError("The suction pads did not seal.") + + pickup_z = parcel.data.root_pos_w.torch[0, 2].item() + for _ in range(120): + pose[:, 2] += 0.0006 + tool.write_root_pose_to_sim_index(root_pose=pose) + step_scene(sim, scene, 1) + lift = parcel.data.root_pos_w.torch[0, 2].item() - pickup_z + if lift <= 0.04: + raise RuntimeError("The sealed tool did not lift the parcel.") + print(f"Suction lifted the parcel {lift:.2f} m.") + + suction.set_grippers_command_index(-close) + step_scene(sim, scene, 60) + if suction.state.numpy()[0] != -1 or parcel.data.root_pos_w.torch[0, 2].item() > pickup_z + 0.01: + raise RuntimeError("The suction tool did not release the parcel onto the belt.") + print("Suction released the parcel onto the belt.") + + +def main() -> None: + """Run the example in Newton MJWarp.""" + parser = argparse.ArgumentParser(description=__doc__) + add_launcher_args(parser) + args = parser.parse_args() + cfg = sim_utils.SimulationCfg( + device=args.device, + dt=1.0 / 120, + physics=NewtonCfg( + solver_cfg=MJWarpSolverCfg(use_mujoco_contacts=False, integrator="implicitfast", cone="elliptic"), + use_cuda_graph=False, + ), + ) + with launch_simulation(cfg, args), sim_utils.build_simulation_context(sim_cfg=cfg) as sim: + sim.set_camera_view(eye=(1.1, -0.9, 0.65), target=(0.0, 0.0, 0.06)) + run_example(sim) + + +if __name__ == "__main__": + main() diff --git a/source/isaaclab/changelog.d/conveyor-suction-tutorial.skip b/source/isaaclab/changelog.d/conveyor-suction-tutorial.skip new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/source/isaaclab/test/app/standalone_script_cases.py b/source/isaaclab/test/app/standalone_script_cases.py index 56fa4bb02d36..1f41ee298160 100644 --- a/source/isaaclab/test/app/standalone_script_cases.py +++ b/source/isaaclab/test/app/standalone_script_cases.py @@ -63,6 +63,7 @@ class ScriptOverride: args: tuple[str, ...] = () readiness_pattern: str | None = None + run_to_completion: bool = False startup_timeout: float | None = None skip_reason: str | None = None fixed_physics_backend: str | None = None @@ -79,6 +80,7 @@ class ScriptSpec: options: dict[str, tuple[str, ...]] args: tuple[str, ...] readiness_pattern: str | None + run_to_completion: bool startup_timeout: float | None skip_reason: str | None fixed_physics_backend: str | None @@ -93,10 +95,15 @@ def program(self) -> tuple[str, str] | None: return PROGRAMS_BY_PATH.get(self.path) @property - def finite(self) -> bool: - """Return whether CLI discovery or an explicit override bounds the script's steps.""" + def has_step_limit(self) -> bool: + """Return whether the launch supports a step limit.""" return "--max_steps" in self.options or "--max_steps" in self.args + @property + def finite(self) -> bool: + """Return whether the launched script must run to completion.""" + return self.run_to_completion or self.has_step_limit + @property def relative_path(self) -> str: """Return the repository-relative POSIX path.""" @@ -161,7 +168,7 @@ def command(self) -> list[str]: ] if "--num_envs" in self.spec.options and "--num_envs" not in self.spec.args: command.extend(("--num_envs", str(DEFAULT_BATCHED_NUM_ENVS))) - if self.spec.finite and "--max_steps" not in self.spec.args: + if self.spec.has_step_limit and "--max_steps" not in self.spec.args: command.extend(("--max_steps", str(DEFAULT_MAX_STEPS))) if self.physics_option is not None: command.extend((self.physics_option, self.physics_backend)) @@ -249,6 +256,12 @@ class SmokeResult: fixed_physics_backend="newton_coupler", visualizers=(None, "newton", "kit"), ), + "scripts/tutorials/01_assets/run_conveyor_suction.py": ScriptOverride( + args=("--viz", "none"), + run_to_completion=True, + fixed_physics_backend="newton_mjwarp", + visualizers=(None,), + ), "scripts/tutorials/08_mpm/material_parameters.py": ScriptOverride( args=("--max_steps", "2", "--variant_index", "0", "--voxel_size", "0.1"), fixed_physics_backend="newton_mpm", @@ -375,6 +388,7 @@ def discover_specs() -> list[ScriptSpec]: options=options, args=override.args, readiness_pattern=readiness_pattern, + run_to_completion=override.run_to_completion, startup_timeout=override.startup_timeout, skip_reason=override.skip_reason, fixed_physics_backend=override.fixed_physics_backend, diff --git a/source/isaaclab/test/app/test_standalone_scripts.py b/source/isaaclab/test/app/test_standalone_scripts.py index a5ff974e63eb..bcb574d49553 100644 --- a/source/isaaclab/test/app/test_standalone_scripts.py +++ b/source/isaaclab/test/app/test_standalone_scripts.py @@ -6,8 +6,8 @@ """Robustness smoke tests for packaged programs and standalone tutorial scripts. Set ``ISAACLAB_RUN_STANDALONE_SCRIPT_TESTS=1`` to enable the simulator launch -matrix. Scripts with a ``--max_steps`` option run a few steps and must exit -cleanly; other scripts must print their readiness marker and survive a soak. +matrix. Scripts with a ``--max_steps`` option and naturally finite tutorials must +exit cleanly. Other scripts must print their readiness marker and survive a soak. GUI cases additionally require ``DISPLAY`` or ``WAYLAND_DISPLAY``. ``ISAACLAB_STANDALONE_SOAK_TIME`` and ``ISAACLAB_STANDALONE_STARTUP_TIMEOUT`` may be used to tune the default five-second soak and five-minute time limit. @@ -263,14 +263,14 @@ def test_mpm_demos_use_solver_contact_response(script_path): def test_every_standalone_script_has_a_launch_contract_or_exemption(): """Packaged programs must stop themselves; other scripts must be runnable or explicitly exempted.""" - not_finite = [spec.relative_path for spec in SPECS if spec.program is not None and not spec.finite] - assert not not_finite, f"packaged programs need a --max_steps option: {not_finite}" + missing_step_limit = [spec.relative_path for spec in SPECS if spec.program is not None and not spec.has_step_limit] + assert not missing_step_limit, f"packaged programs need a --max_steps option: {missing_step_limit}" missing = [ spec.relative_path for spec in SPECS if not spec.finite and spec.readiness_pattern is None and spec.skip_reason is None ] - assert not missing, f"standalone scripts need --max_steps, a readiness marker, or an OVERRIDES exemption: {missing}" + assert not missing, f"standalone scripts need a finite run, readiness marker, or exemption: {missing}" def test_overrides_only_reference_discovered_standalone_scripts():