| """Compare submit-style RGB-D PCA estimates against Task-E simulator truth. |
| |
| This script uses simulator object roots only for debugging/calibration. It is |
| not part of the submission policy. |
| """ |
|
|
| from __future__ import annotations |
|
|
| import argparse |
| import os |
| import sys |
|
|
| from isaaclab.app import AppLauncher |
|
|
|
|
| parser = argparse.ArgumentParser() |
| parser.add_argument("--task", type=str, default="ATEC-TaskE-Piper") |
| parser.add_argument("--seed", type=int, default=12) |
| parser.add_argument("--settle_steps", type=int, default=5) |
| AppLauncher.add_app_launcher_args(parser) |
| args_cli = parser.parse_args() |
| args_cli.enable_cameras = True |
|
|
| repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) |
| demo_dir = os.path.join(repo_root, "demo") |
| if repo_root not in sys.path: |
| sys.path.insert(0, repo_root) |
| if demo_dir not in sys.path: |
| sys.path.insert(0, demo_dir) |
|
|
| app_launcher = AppLauncher(args_cli) |
| simulation_app = app_launcher.app |
|
|
| import gymnasium as gym |
| import numpy as np |
| import torch |
| from isaaclab.envs import DirectMARLEnv, multi_agent_to_single_agent |
| from isaaclab_tasks.utils import parse_env_cfg |
|
|
| import atec_rl_lab.tasks |
| import solution_pca |
|
|
|
|
| def main() -> None: |
| env_cfg = parse_env_cfg(args_cli.task, device=args_cli.device, num_envs=1) |
| env_cfg.seed = args_cli.seed |
| env = gym.make(args_cli.task, cfg=env_cfg) |
| if isinstance(env.unwrapped, DirectMARLEnv): |
| env = multi_agent_to_single_agent(env) |
|
|
| policy = solution_pca.AlgSolution() |
| try: |
| obs, _ = env.reset(seed=args_cli.seed) |
| zero = torch.zeros((1, 8), dtype=torch.float32, device=args_cli.device) |
| for _ in range(max(0, args_cli.settle_steps)): |
| obs, *_ = env.step(zero) |
|
|
| rgb, depth = policy._video_rgb_depth(obs) |
| print(f"[PERCEPTION_DEBUG] seed={args_cli.seed} settle_steps={args_cli.settle_steps}") |
| for obj_idx in (1, 2, 3): |
| est, rot = policy._estimate_grasp(rgb, depth, obj_idx) |
| pick_xy = est[:2] + solution_pca.OBJ_GRASP_CENTER_OFFSETS[obj_idx] |
| obj = env.unwrapped.scene.rigid_objects[f"object_{obj_idx}"] |
| truth = obj.data.root_pos_w[0].detach().cpu().numpy().astype(np.float64) |
| delta = est - truth |
| pick_delta = np.r_[pick_xy - truth[:2], est[2] - truth[2]] |
| jaw_yaw = float(np.arctan2(rot[1, 1], rot[0, 1])) |
| print( |
| "[PERCEPTION_DEBUG] " |
| f"obj={obj_idx} truth=({truth[0]:.4f},{truth[1]:.4f},{truth[2]:.4f}) " |
| f"est=({est[0]:.4f},{est[1]:.4f},{est[2]:.4f}) " |
| f"delta=({delta[0]:+.4f},{delta[1]:+.4f},{delta[2]:+.4f}) " |
| f"pick_delta=({pick_delta[0]:+.4f},{pick_delta[1]:+.4f},{pick_delta[2]:+.4f}) " |
| f"jaw_yaw={jaw_yaw:+.3f}" |
| ) |
| finally: |
| env.close() |
|
|
|
|
| if __name__ == "__main__": |
| try: |
| main() |
| finally: |
| simulation_app.close() |
|
|