File size: 3,761 Bytes
41aebeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Copyright (c) 2026, dishsim project.
#
# SPDX-License-Identifier: BSD-3-Clause

"""Kit side: dump the settled scene's geometry into the collision-world cache.

Builds the locked statics scene, settles it, then writes per-rigid-body meshes (statics +
the active object's body-frame OBJ) + ``scene_state.json`` to ``data/assets/<machine>/cache/<state>/<object>/``. Runs with
``use_fabric=False`` so live USD prim transforms are trustworthy (the Fabric staleness trap).

Run with:
    code/util/run_kit.sh data/assets/bosch800/source/extract_geometry.py --headless
"""

"""Launch Isaac Sim Simulator first."""

import argparse
import os

from isaaclab.app import AppLauncher

PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))  # data/assets/bosch800/source/<file>.py

parser = argparse.ArgumentParser(description="Dump the collision-world cache from the settled scene.")
parser.add_argument("--settle_steps", type=int, default=200)
parser.add_argument("--placement", type=str, default=None,
                    help="Named base placement (see config.BASE_PLACEMENTS); default: the machine's.")
parser.add_argument("--machine", type=str, default=None,
                    help="Machine name (see config.MACHINES); default: the v1 baseline.")
parser.add_argument("--object", type=str, default="mug", help="Object class (see config.OBJECTS).")
parser.add_argument("--scenario", type=str, default="both_out",
                    help="Rack-state scenario (see config.SCENARIOS).")
AppLauncher.add_app_launcher_args(parser)
args_cli = parser.parse_args()

app_launcher = AppLauncher(args_cli)
simulation_app = app_launcher.app

"""Rest everything follows."""

import sys

import isaaclab.sim as sim_utils
from isaaclab.scene import InteractiveScene
from isaaclab.sim import SimulationContext

sys.path.insert(0, os.path.join(PROJECT_ROOT, "code", "src"))

from dishsim import config  # noqa: E402

# scenario BEFORE scene/machine imports — they bind rack targets + the derived USD at import
if args_cli.machine:
    config.apply_machine(args_cli.machine)  # first: it resets scenario + base placement
config.set_active_object(args_cli.object)
config.apply_scenario(args_cli.scenario)
if args_cli.placement:
    config.apply_base_placement(args_cli.placement)  # after machine/scenario — they reset it

import cache_dump as dgeom  # noqa: E402  (this folder: dump_cache)
from dishsim.media import release_sim_for_close  # noqa: E402
from dishsim import scene as dscene  # noqa: E402


def main() -> None:
    sim = SimulationContext(
        sim_utils.SimulationCfg(dt=config.SIM_DT, device=args_cli.device, use_fabric=False)
    )
    scene = InteractiveScene(dscene.make_scene_cfg())
    sim.reset()
    dscene.write_default_states(scene)
    dt = sim.get_physics_dt()
    for _ in range(args_cli.settle_steps):
        dscene.hold_targets(scene)
        scene.write_data_to_sim()
        sim.step()
        scene.update(dt)
    dscene.assert_frames(scene)
    # the settled racks must sit at the scenario targets — also catches a stale derived USD
    # whose baked drive targets fight the configured scenario
    sr = dscene.statics_report(scene)
    rack_err = max(sr["rack_lower_err_m"], sr["rack_upper_err_m"])
    assert rack_err < 5e-3, f"racks off scenario targets by {rack_err * 1e3:.1f} mm: {sr}"

    manifest_path = dgeom.dump_cache(scene, sim, cache_dir=config.scenario_cache_dir())
    print(f"[INFO] scenario {config.SCENARIO_NAME}: rack_lower {sr['rack_lower_m']:+.3f} m, "
          f"rack_upper {sr['rack_upper_m']:+.3f} m")
    print(f"[RESULT] PASS ({manifest_path})")


if __name__ == "__main__":
    main()
    release_sim_for_close()
    simulation_app.close()