Skip to content

Commit 719091b

Browse files
added policy transfer play script for Newton to physX
Signed-off-by: Milad Rakhsha <[email protected]>
1 parent bd547aa commit 719091b

File tree

5 files changed

+479
-0
lines changed

5 files changed

+479
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright (c) 2022-2025, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
2+
# All rights reserved.
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
6+
# Joint names in the source physics engine where policy is trained (Newton)
7+
source_joint_names:
8+
- "LF_HAA"
9+
- "LF_HFE"
10+
- "LF_KFE"
11+
- "LH_HAA"
12+
- "LH_HFE"
13+
- "LH_KFE"
14+
- "RF_HAA"
15+
- "RF_HFE"
16+
- "RF_KFE"
17+
- "RH_HAA"
18+
- "RH_HFE"
19+
- "RH_KFE"
20+
21+
# Joint names in the target physics engine where policy is deployed (PhysX)
22+
target_joint_names:
23+
- "LF_HAA"
24+
- "LH_HAA"
25+
- "RF_HAA"
26+
- "RH_HAA"
27+
- "LF_HFE"
28+
- "LH_HFE"
29+
- "RF_HFE"
30+
- "RH_HFE"
31+
- "LF_KFE"
32+
- "LH_KFE"
33+
- "RF_KFE"
34+
- "RH_KFE"
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Copyright (c) 2022-2025, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
2+
# All rights reserved.
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
6+
# Joint names in the source physics engine where policy is trained (Newton)
7+
source_joint_names:
8+
- "left_hip_pitch_joint"
9+
- "left_hip_roll_joint"
10+
- "left_hip_yaw_joint"
11+
- "left_knee_joint"
12+
- "left_ankle_pitch_joint"
13+
- "left_ankle_roll_joint"
14+
- "right_hip_pitch_joint"
15+
- "right_hip_roll_joint"
16+
- "right_hip_yaw_joint"
17+
- "right_knee_joint"
18+
- "right_ankle_pitch_joint"
19+
- "right_ankle_roll_joint"
20+
- "torso_joint"
21+
- "left_shoulder_pitch_joint"
22+
- "left_shoulder_roll_joint"
23+
- "left_shoulder_yaw_joint"
24+
- "left_elbow_pitch_joint"
25+
- "left_elbow_roll_joint"
26+
- "left_five_joint"
27+
- "left_six_joint"
28+
- "left_three_joint"
29+
- "left_four_joint"
30+
- "left_zero_joint"
31+
- "left_one_joint"
32+
- "left_two_joint"
33+
- "right_shoulder_pitch_joint"
34+
- "right_shoulder_roll_joint"
35+
- "right_shoulder_yaw_joint"
36+
- "right_elbow_pitch_joint"
37+
- "right_elbow_roll_joint"
38+
- "right_five_joint"
39+
- "right_six_joint"
40+
- "right_three_joint"
41+
- "right_four_joint"
42+
- "right_zero_joint"
43+
- "right_one_joint"
44+
- "right_two_joint"
45+
46+
# Joint names in the target physics engine where policy is deployed (PhysX)
47+
target_joint_names:
48+
- "left_hip_pitch_joint"
49+
- "right_hip_pitch_joint"
50+
- "torso_joint"
51+
- "left_hip_roll_joint"
52+
- "right_hip_roll_joint"
53+
- "left_shoulder_pitch_joint"
54+
- "right_shoulder_pitch_joint"
55+
- "left_hip_yaw_joint"
56+
- "right_hip_yaw_joint"
57+
- "left_shoulder_roll_joint"
58+
- "right_shoulder_roll_joint"
59+
- "left_knee_joint"
60+
- "right_knee_joint"
61+
- "left_shoulder_yaw_joint"
62+
- "right_shoulder_yaw_joint"
63+
- "left_ankle_pitch_joint"
64+
- "right_ankle_pitch_joint"
65+
- "left_elbow_pitch_joint"
66+
- "right_elbow_pitch_joint"
67+
- "left_ankle_roll_joint"
68+
- "right_ankle_roll_joint"
69+
- "left_elbow_roll_joint"
70+
- "right_elbow_roll_joint"
71+
- "left_five_joint"
72+
- "left_three_joint"
73+
- "left_zero_joint"
74+
- "right_five_joint"
75+
- "right_three_joint"
76+
- "right_zero_joint"
77+
- "left_six_joint"
78+
- "left_four_joint"
79+
- "left_one_joint"
80+
- "right_six_joint"
81+
- "right_four_joint"
82+
- "right_one_joint"
83+
- "left_two_joint"
84+
- "right_two_joint"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) 2022-2025, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
2+
# All rights reserved.
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
6+
# Joint names in the source physics engine where policy is trained (Newton)
7+
source_joint_names:
8+
- "left_hip_yaw"
9+
- "left_hip_roll"
10+
- "left_hip_pitch"
11+
- "left_knee"
12+
- "left_ankle"
13+
- "right_hip_yaw"
14+
- "right_hip_roll"
15+
- "right_hip_pitch"
16+
- "right_knee"
17+
- "right_ankle"
18+
- "torso"
19+
- "left_shoulder_pitch"
20+
- "left_shoulder_roll"
21+
- "left_shoulder_yaw"
22+
- "left_elbow"
23+
- "right_shoulder_pitch"
24+
- "right_shoulder_roll"
25+
- "right_shoulder_yaw"
26+
- "right_elbow"
27+
28+
# Joint names in the target physics engine where policy is deployed (PhysX)
29+
target_joint_names:
30+
- "left_hip_yaw"
31+
- "right_hip_yaw"
32+
- "torso"
33+
- "left_hip_roll"
34+
- "right_hip_roll"
35+
- "left_shoulder_pitch"
36+
- "right_shoulder_pitch"
37+
- "left_hip_pitch"
38+
- "right_hip_pitch"
39+
- "left_shoulder_roll"
40+
- "right_shoulder_roll"
41+
- "left_knee"
42+
- "right_knee"
43+
- "left_shoulder_yaw"
44+
- "right_shoulder_yaw"
45+
- "left_ankle"
46+
- "right_ankle"
47+
- "left_elbow"
48+
- "right_elbow"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copyright (c) 2022-2025, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
2+
# All rights reserved.
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
6+
"""Policy transfer utilities for handling joint ordering differences between physics engines.
7+
8+
This module provides functionality to handle policy transfer between different physics engines
9+
that may have different joint orderings. It supports loading joint mappings from YAML files
10+
and provides observation and action remapping functions.
11+
"""
12+
13+
import yaml
14+
15+
16+
def get_joint_mappings(args_cli, action_space_dim):
17+
"""Get joint mappings based on command line arguments.
18+
19+
Args:
20+
args_cli: Command line arguments
21+
action_space_dim: Dimension of the action space (number of joints)
22+
23+
Returns:
24+
tuple: (source_to_target_list, target_to_source_list, source_to_target_obs_list)
25+
"""
26+
num_joints = action_space_dim
27+
if args_cli.policy_transfer_file:
28+
# Load from YAML file
29+
try:
30+
with open(args_cli.policy_transfer_file) as file:
31+
config = yaml.safe_load(file)
32+
except Exception as e:
33+
raise RuntimeError(f"Failed to load joint mapping from {args_cli.policy_transfer_file}: {e}")
34+
35+
source_joint_names = config["source_joint_names"]
36+
target_joint_names = config["target_joint_names"]
37+
# Find joint mapping
38+
source_to_target = []
39+
target_to_source = []
40+
41+
# Create source to target mapping
42+
for joint_name in source_joint_names:
43+
if joint_name in target_joint_names:
44+
source_to_target.append(target_joint_names.index(joint_name))
45+
else:
46+
raise ValueError(f"Joint '{joint_name}' not found in target joint names")
47+
48+
# Create target to source mapping
49+
for joint_name in target_joint_names:
50+
if joint_name in source_joint_names:
51+
target_to_source.append(source_joint_names.index(joint_name))
52+
else:
53+
raise ValueError(f"Joint '{joint_name}' not found in source joint names")
54+
print(f"[INFO] Loaded joint mapping for policy transfer from YAML: {args_cli.policy_transfer_file}")
55+
assert (
56+
len(source_to_target) == len(target_to_source) == num_joints
57+
), "Number of source and target joints must match"
58+
else:
59+
# Use identity mapping (one-to-one)
60+
identity_map = list(range(num_joints))
61+
source_to_target, target_to_source = identity_map, identity_map
62+
63+
# Create observation mapping (first 12 values stay the same for locomotion examples, then map joint-related values)
64+
obs_map = (
65+
[0, 1, 2]
66+
+ [3, 4, 5]
67+
+ [6, 7, 8]
68+
+ [9, 10, 11]
69+
+ [i + 12 + num_joints * 0 for i in source_to_target]
70+
+ [i + 12 + num_joints * 1 for i in source_to_target]
71+
+ [i + 12 + num_joints * 2 for i in source_to_target]
72+
)
73+
74+
return source_to_target, target_to_source, obs_map

0 commit comments

Comments
 (0)