Skip to content

Commit 3dd079a

Browse files
committed
clean
1 parent 34ef42d commit 3dd079a

3 files changed

Lines changed: 86 additions & 3 deletions

File tree

source/isaaclab/isaaclab/visualizers/visualizer_cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class VisualizerCfg:
3434
enable_live_plots: bool = True
3535
"""Enable live plotting of data."""
3636

37-
eye: tuple[float, float, float] = (8.0, 8.0, 3.0)
37+
eye: tuple[float, float, float] = (7.5, 7.5, 7.5)
3838
"""Initial camera eye position (x, y, z) in world coordinates."""
3939

4040
lookat: tuple[float, float, float] = (0.0, 0.0, 0.0)

source/isaaclab_mimic/isaaclab_mimic/datagen/generation.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55

66
import asyncio
77
import contextlib
8+
import os
89
import sys
910
import traceback
1011
from typing import Any
1112

1213
import torch
14+
import warp as wp
1315

1416
from isaaclab.envs import ManagerBasedRLMimicEnv
1517
from isaaclab.envs.mdp.recorders.recorders_cfg import ActionStateRecorderManagerCfg
1618
from isaaclab.managers import DatasetExportMode, TerminationTermCfg
1719
from isaaclab.managers.recorder_manager import RecorderManagerBaseCfg
20+
from isaaclab.utils.math import subtract_frame_transforms
1821

1922
from isaaclab_mimic.datagen.data_generator import DataGenerator
2023
from isaaclab_mimic.datagen.datagen_info_pool import DataGenInfoPool
@@ -27,6 +30,59 @@
2730
num_attempts = 0
2831

2932

33+
def _debug_wrist_cam_pose(env: ManagerBasedRLMimicEnv, env_id: int, tag: str, hand_body_idx: int | None):
34+
"""Print wrist camera and hand-link transforms for debugging camera alignment."""
35+
try:
36+
if "wrist_cam" not in env.scene.keys() or "robot" not in env.scene.keys():
37+
print(f"[WRIST_CAM_DEBUG] {tag} env={env_id} missing wrist_cam or robot in scene")
38+
return
39+
40+
wrist_cam = env.scene["wrist_cam"]
41+
robot = env.scene["robot"]
42+
cam_pos = wrist_cam.data.pos_w[env_id].detach().cpu()
43+
cam_quat = wrist_cam.data.quat_w_world[env_id].detach().cpu()
44+
cam_frame = int(wrist_cam.frame[env_id].item()) if wrist_cam.frame.numel() > env_id else -1
45+
live_pos_all, live_quat_all = wrist_cam._view.get_world_poses([env_id])
46+
live_cam_pos = live_pos_all[0].detach().cpu()
47+
live_cam_quat = live_quat_all[0].detach().cpu()
48+
49+
if hand_body_idx is None:
50+
print(
51+
f"[WRIST_CAM_DEBUG] {tag} env={env_id} cam_frame={cam_frame} "
52+
f"cam_pos={cam_pos.tolist()} cam_quat_xyzw={cam_quat.tolist()} "
53+
f"live_cam_pos={live_cam_pos.tolist()} live_cam_quat_xyzw={live_cam_quat.tolist()} "
54+
f"hand_body_idx=None"
55+
)
56+
return
57+
58+
hand_pos = wp.to_torch(robot.data.body_pos_w)[env_id, hand_body_idx].detach().cpu()
59+
hand_quat = wp.to_torch(robot.data.body_quat_w)[env_id, hand_body_idx].detach().cpu()
60+
rel_pos, rel_quat = subtract_frame_transforms(
61+
hand_pos.unsqueeze(0),
62+
hand_quat.unsqueeze(0),
63+
cam_pos.unsqueeze(0),
64+
cam_quat.unsqueeze(0),
65+
)
66+
live_rel_pos, live_rel_quat = subtract_frame_transforms(
67+
hand_pos.unsqueeze(0),
68+
hand_quat.unsqueeze(0),
69+
live_cam_pos.unsqueeze(0),
70+
live_cam_quat.unsqueeze(0),
71+
)
72+
print(
73+
f"[WRIST_CAM_DEBUG] {tag} env={env_id} cam_frame={cam_frame} "
74+
f"cam_pos={cam_pos.tolist()} cam_quat_xyzw={cam_quat.tolist()} "
75+
f"live_cam_pos={live_cam_pos.tolist()} live_cam_quat_xyzw={live_cam_quat.tolist()} "
76+
f"hand_pos={hand_pos.tolist()} hand_quat_xyzw={hand_quat.tolist()} "
77+
f"cam_rel_hand_pos={rel_pos[0].detach().cpu().tolist()} "
78+
f"cam_rel_hand_quat_xyzw={rel_quat[0].detach().cpu().tolist()} "
79+
f"live_cam_rel_hand_pos={live_rel_pos[0].detach().cpu().tolist()} "
80+
f"live_cam_rel_hand_quat_xyzw={live_rel_quat[0].detach().cpu().tolist()}"
81+
)
82+
except Exception as exc:
83+
print(f"[WRIST_CAM_DEBUG] {tag} env={env_id} logging_failed={exc}")
84+
85+
3086
async def run_data_generator(
3187
env: ManagerBasedRLMimicEnv,
3288
env_id: int,
@@ -91,6 +147,18 @@ def env_loop(
91147
global num_success, num_failures, num_attempts
92148
env_id_tensor = torch.tensor([0], dtype=torch.int64, device=env.device)
93149
prev_num_attempts = 0
150+
debug_wrist_cam = os.environ.get("ISAACLAB_DEBUG_WRIST_CAM", "0") == "1"
151+
post_reset_step_counters = [0 for _ in range(env.num_envs)]
152+
hand_body_idx = None
153+
if debug_wrist_cam:
154+
try:
155+
if "robot" in env.scene.keys():
156+
body_ids, _ = env.scene["robot"].find_bodies("panda_hand")
157+
hand_body_idx = int(body_ids[0]) if len(body_ids) > 0 else None
158+
print(f"[WRIST_CAM_DEBUG] enabled=1 hand_body_idx={hand_body_idx}")
159+
except Exception as exc:
160+
print(f"[WRIST_CAM_DEBUG] enabled=1 hand_body_idx_lookup_failed={exc}")
161+
94162
# simulate environment -- run everything in inference mode
95163
with contextlib.suppress(KeyboardInterrupt) and torch.inference_mode():
96164
while True:
@@ -100,6 +168,11 @@ def env_loop(
100168
while not env_reset_queue.empty():
101169
env_id_tensor[0] = env_reset_queue.get_nowait()
102170
env.reset(env_ids=env_id_tensor)
171+
reset_env_id = int(env_id_tensor[0].item())
172+
if 0 <= reset_env_id < env.num_envs:
173+
post_reset_step_counters[reset_env_id] = 0
174+
if debug_wrist_cam:
175+
_debug_wrist_cam_pose(env, reset_env_id, tag="after_reset", hand_body_idx=hand_body_idx)
103176
env_reset_queue.task_done()
104177

105178
actions = torch.zeros(env.action_space.shape)
@@ -112,6 +185,16 @@ def env_loop(
112185

113186
# perform action on environment
114187
env.step(actions)
188+
if debug_wrist_cam:
189+
for env_id in range(env.num_envs):
190+
if post_reset_step_counters[env_id] <= 1:
191+
_debug_wrist_cam_pose(
192+
env,
193+
env_id,
194+
tag=f"after_step_{post_reset_step_counters[env_id]}",
195+
hand_body_idx=hand_body_idx,
196+
)
197+
post_reset_step_counters[env_id] += 1
115198

116199
# mark done so the data generators can continue with the step results
117200
for i in range(env.num_envs):

source/isaaclab_visualizers/isaaclab_visualizers/kit/kit_visualizer_cfg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ class KitVisualizerCfg(VisualizerCfg):
1919
viewport_name: str = "Visualizer Viewport"
2020
"""Viewport name to use when :attr:`create_viewport` is True."""
2121

22-
create_viewport: bool = False
22+
create_viewport: bool = True
2323
"""Create new viewport with specified name and camera pose."""
2424

2525
visualizer_camera_prim_path: str = "/World/Cameras/KitVisualizerCamera"
2626
"""Dedicated camera prim path controlled by the Kit visualizer."""
2727

28-
enable_visualizer_cam: bool = False
28+
enable_visualizer_cam: bool = True
2929
"""Whether the Kit visualizer should control/bind a dedicated viewport camera.
3030
3131
If False, Kit does not create/switch camera prims and ignores visualizer camera control

0 commit comments

Comments
 (0)