Skip to content

Commit d22f879

Browse files
feat: stage floor height + fix traj velocity export + numpyless pickle
1 parent 1dc986a commit d22f879

File tree

13 files changed

+132
-27
lines changed

13 files changed

+132
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ data/
66

77
*.so
88
*.npy
9+
*.pkl
910
*.zip
1011
*.urdf
1112
*.xml

examples/play_trajectory.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pickle
12
import numpy as np
23
import glob
34
import time
@@ -12,13 +13,14 @@
1213
"g1": G1_MODEL_PATH,
1314
}
1415

15-
ROBOT_NAME = "g1"
16-
motion_files = glob.glob(os.path.join(os.path.dirname(__file__), f"./motions/{dataset[0]}/{ROBOT_NAME}/*.npy"))
16+
ROBOT_NAME = "h1"
17+
motion_files = glob.glob(os.path.join(os.path.dirname(__file__), f"./motions/{dataset[0]}/{ROBOT_NAME}/*.pkl"))
1718
with MujocoRenderer(robots[ROBOT_NAME]) as renderer:
1819
for motion_file in motion_files:
19-
motion = np.load(motion_file, allow_pickle=True).item()
20+
with open(motion_file, "rb") as f:
21+
motion = pickle.load(f)
2022
data_dt = motion["dt"]
21-
qs = motion["q"]
23+
qs = np.array(motion["q"])
2224
for frame_idx in range(qs.shape[0]):
2325
renderer.set_configuration(qs[frame_idx], pin_notation=True)
2426
renderer.step()

examples/retarget_amass.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"h1": H1_AMASS_CONFIG,
1616
}
1717

18-
ROBOT_NAME = "g1"
18+
ROBOT_NAME = "h1"
1919
RENDER = True
2020

2121
wbik_params = robots[ROBOT_NAME]
@@ -24,6 +24,7 @@
2424
datasets_path=os.path.join(os.path.dirname(__file__), "../data"),
2525
beta=wbik_params.beta,
2626
name_blacklist=["handrail", "jump", "box", "hop", "push"],
27+
name_whitelist=["waltz10"],
2728
target_fps=30,
2829
template_scale=wbik_params.template_scale,
2930
)
@@ -51,6 +52,6 @@
5152
except NoSolutionException:
5253
print(f"Skipping {motion_name}")
5354
continue
54-
out_filename = f"amass_{ROBOT_NAME}_{motion_name}.npy"
55+
out_filename = f"amass_{ROBOT_NAME}_{motion_name}"
5556
trajectory.save(os.path.join(output_path, out_filename))
5657
renderer.flush_frames(fps=data_loader.target_fps)

examples/retarget_cmu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@
5656
except NoSolutionException:
5757
print(f"Skipping {subject} {motion_idx}")
5858
continue
59-
out_filename = f"cmu_{ROBOT_NAME}_{skill_name}_{subject}_{motion_idx}.npy"
59+
out_filename = f"cmu_{ROBOT_NAME}_{skill_name}_{subject}_{motion_idx}"
6060
trajectory.save(os.path.join(output_path, out_filename))
6161
renderer.flush_frames(fps=CMU_DATASET_FPS)

examples/retarget_lafan.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import os
2-
from tqdm import tqdm
32
from recap.wbik_solver import NoSolutionException
43
from recap.trajectory import Trajectory
54
from recap.lafan.retarget import LAFANRetarget, MOTION_PATHS
6-
import time
7-
import numpy as np
85
from recap.config.robot.g1 import G1_LAFAN_CONFIG
96
from recap.config.robot.h1 import H1_LAFAN_CONFIG
107

@@ -28,6 +25,13 @@
2825

2926
with MujocoRenderer(robots[ROBOT_NAME].mjcf_path) as renderer:
3027
for path in MOTION_PATHS:
28+
skip_motion = True
29+
for motion_type in ["run", "walk", "sprint"]:
30+
if motion_type in path:
31+
skip_motion = False
32+
33+
if skip_motion:
34+
continue
3135
retargetee.set_motion(path)
3236
motion_name = os.path.basename(path).split(".")[0]
3337
trajectory = Trajectory(1 / 30)
@@ -40,5 +44,5 @@
4044
except NoSolutionException:
4145
print(f"Skipping {path}")
4246
continue
43-
out_filename = f"lafan_{ROBOT_NAME}_{motion_name}.npy"
47+
out_filename = f"lafan_{ROBOT_NAME}_{motion_name}"
4448
trajectory.save(os.path.join(output_path, out_filename))

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ dependencies = [
1414
"mujoco == 3.2.7",
1515
"torch == 2.6.0",
1616
"joblib == 1.4.2",
17-
"scipy == 1.15.1",
1817
"mediapy == 1.2.2",
1918
]
2019

recap/config/robot/h1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class H1_AMASS_CONFIG(AMASSRetargetConfig):
8181
],
8282
)
8383
template_scale = 1.0128
84+
extra_bodies = ["imu"]
8485

8586

8687
class H1_CMU_CONFIG(CMURetargetConfig):
@@ -147,3 +148,4 @@ class H1_LAFAN_CONFIG(LAFANRetargetConfig):
147148
"left_shoulder": "left_shoulder_roll_link",
148149
"right_shoulder": "right_shoulder_roll_link",
149150
}
151+
extra_bodies = ["imu"]

recap/config/wbik_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class WBIKConfig:
1313
com_pos_weight (float): weight for keeping the com close to the foot support line
1414
body_to_model_map (dict): MJCF to task name mapping of the corresponding frames
1515
step_dt (float): integration step size
16+
extra_bodies (list[string]): names of the body in the xml for which to export transform data aside from the task bodies
1617
"""
1718

1819
mjcf_path: str
@@ -57,3 +58,4 @@ class WBIKConfig:
5758
"left_shoulder": "",
5859
"right_shoulder": "",
5960
}
61+
extra_bodies = []

recap/mujoco/renderer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131

3232
class MujocoRenderer:
33-
def __init__(self, mjcf_path: str, video_path: str = None):
34-
self.setup_scene(mjcf_path)
33+
def __init__(self, mjcf_path: str, video_path: str = None, floor_height=0.0):
34+
self.setup_scene(mjcf_path, floor_height)
3535
self.reset()
3636
self.camera_tracking = True
3737

@@ -78,15 +78,15 @@ def flush_frames(self, fps=None):
7878
)
7979
self.frames = []
8080

81-
def setup_scene(self, mjcf_path: str):
81+
def setup_scene(self, mjcf_path: str, floor_height: float):
8282
self.spec = mujoco.MjSpec.from_file(mjcf_path)
8383
self.spec.visual.quality.shadowsize = 8192
8484
ground = self.spec.worldbody.add_geom()
8585

8686
ground.name = "ground"
8787
ground.type = mujoco.mjtGeom.mjGEOM_PLANE
8888
ground.size = [0, 0, 0.05]
89-
ground.pos = [0, 0, 0]
89+
ground.pos = [0, 0, floor_height]
9090
ground.material = "floor_material"
9191

9292
floor_texture = self.spec.add_texture()

recap/quat_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,17 @@ def quat_inv(q: torch.Tensor) -> torch.Tensor:
8282
return normalize(q * torch.tensor([[1, -1, -1, -1]], device=q.device))
8383

8484

85-
def angular_velocity(q1: torch.Tensor, q2: torch.Tensor, dt: float):
85+
def angular_velocity(q1, q2, dt: float):
8686
need_flatten = len(q1.shape) > 2
8787
batch_size = q1.shape[0]
8888
if need_flatten:
8989
q1 = q1.view(-1, 4)
9090
q2 = q2.view(-1, 4)
91-
velocities = (2 / dt) * torch.column_stack(
91+
if isinstance(q1, torch.Tensor):
92+
stack_func = torch.column_stack
93+
else:
94+
stack_func = np.column_stack
95+
velocities = (2 / dt) * stack_func(
9296
[
9397
q1[:, 0] * q2[:, 1] - q1[:, 1] * q2[:, 0] - q1[:, 2] * q2[:, 3] + q1[:, 3] * q2[:, 2],
9498
q1[:, 0] * q2[:, 2] + q1[:, 1] * q2[:, 3] - q1[:, 2] * q2[:, 0] - q1[:, 3] * q2[:, 1],

0 commit comments

Comments
 (0)