File size: 3,034 Bytes
21e1acb | 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 | """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 # noqa: E402
import numpy as np # noqa: E402
import torch # noqa: E402
from isaaclab.envs import DirectMARLEnv, multi_agent_to_single_agent # noqa: E402
from isaaclab_tasks.utils import parse_env_cfg # noqa: E402
import atec_rl_lab.tasks # noqa: F401,E402
import solution_pca # noqa: E402
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()
|